A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The...

14
A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information Science

Transcript of A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The...

Page 1: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

A New and More Efficient Implementation of an

Undirected Graph Component

Shawn Christopher Craft

The Ohio State University Department of Computer and

Information Science

Page 2: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

AbstractThis research project entails designing, specifying, coding, testing, debugging, and documenting different implementations of an undirected graph component for the RESOLVE/C++ Component Catalog. Each version uses the same abstract model to represent the state of an undirected graph and the same kernel operations to manipulate the state of that undirected graph. The implementation strategy changes for each version. The first five versions utilize the “classic” strategies (adjacency list, adjacency matrix, and edge list) in a variety of ways. The final version employs a novel data structure that allows each operation to execute in constant time, which dominates the other strategies.

Page 3: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Component Model

• Edge

math subtype EDGE is finite set of integer

exemplar e

constraint

|e| = 2

Page 4: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Component Model• Undirected Graph Model

math subtype UNDIRECTED_GRAPH_MODEL is (

nodes: finite set of integer

edges: finite set of EDGE

)

exemplar g

constraint

there exists nb: integer where (nb > 0)

(g.nodes = {n: integer where

(1 <= n <= nb) (n)}) and

for all e: EDGE where (e is in g.edges)

(for all n: integer where (n is in e)

(n is in g.nodes))

Page 5: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Component Operations• Set_Number_Of_Nodes

• Add_Edge

• Remove_Edge

• Remove_Any_Incident_Edge

• Remove_Any_Edge

• Is_Edge

• Number_Of_Nodes

• Number_Of_Incident_Edges

• Number_Of_Edges

Page 6: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Classic Implementations

• Adjacency List

• Adjacency Matrix

• Edge List

Page 7: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

New Implementation

• The worst case time complexity of every operation is constant

• “New” Adjacency Matrix using Partitionable Array

Page 8: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Partitionable Array

• Specify what is “interesting”

• Find next “interesting” thing in constant time

• “Needle in a Haystack” analogy

• All operations now in constant time

Page 9: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Undirected Graph Component

• We want to represent an undirected graph as a C++ class.

• We want the representation to be very well-defined.

• We want the representation to be highly reusable.

• We want the representation to be easily extensible.

Page 10: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Component Advantages

• No need to “reinvent the wheel”

• Well-defined and well-understood behavior

• More efficient project development

Page 11: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

RESOLVE Discipline

• Component-based software

• Language independent

• Mathematical modeling

• Well-defined specifications

• Objects and operations

• Swapping vs. copying

Page 12: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Picture of an Undirected Graph

1

2

3

4

5

6

Page 13: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Analysis of Time Complexity

Adjacency List Set_Number_Of_Nodes,

Remove_Edge,Remove_Any_Incident_Edge,Remove_Any_Edge, and Is_Edge arelinear in the number of nodes.

All other operations are constant.

Adjacency Matrix Set_Number_Of_Nodes is quadratic in

the number of nodes. Remove_Any_Incident_Edge and

Remove_Any_Edge are linear in thenumber of nodes.

All other operations are constant.

Edge List Set_Number_Of_Nodes is linear in the

number of nodes. Remove_Edge,

Remove_Any_Incident_Edge, andIs_Edge are linear in the number ofedges.

All other operations are constant.

“New” Adjacency Matrix All operations are constant.

Page 14: A New and More Efficient Implementation of an Undirected Graph Component Shawn Christopher Craft The Ohio State University Department of Computer and Information.

Analysis of Space Complexity

Adjacency List Quadratic in the number of nodes

Adjacency Matrix Cubic in the number of nodes

Edge List Quadratic in the number of nodes and

the number of edges

“New” Adjacency Matrix Quartic in the number of nodes