{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

GRAPH

# GRAPH - GRAPH ALGORITHMS Definitions(background Graph...

This preview shows pages 1–5. Sign up to view the full content.

GRAPH ALGORITHMS Definitions (background): Graph : nodes/vertices, and edges/arcs as pairs of nodes. {V, E} e 12 =(v 1 , v 2 , l 12 ) The third term l 12 , if present, could be a label or the weight of an edge. Directed graph: edges are ordered pairs of nodes. Weighted graph: each edge (directed/undirected) has a weight. Path between a pair of nodes v i , v k : sequence of edges with v i , v k at the two ends. Simple path: covers no node in it twice. Loop : a path with the same start and end node. Path length: number of edges in it. Path weight: total wt of all edges in it. Connected graph: there exists a path between every node, no node is disconnected. Complete graph: edge between every pair of nodes [NUMBER OF EDGES?]. Acyclic graph: a graph with no cycles. Etc. Graphs are one of the most used models of real-life problems for computer-solutions. Representations : Adjacency list (a link list or an array of directly connected nodes for each node), and matrix are two representations. Matrix is O(N^2) for N nodes but easy to access, while adjacency list is good for sparse graph (sparsely distributed edges, less connected).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Problem size includes both |V| (number of nodes N), and |E| (number of edges, in the worst case O(N 2 ) for complete graph, but not “fair” for a sparse graph). Also, with matrix representation |E| is always N 2 , because one has to go over all the pairs of nodes to check which ones are in E.
Algorithm 1: For each node v in V do -Steps- // Θ (|V|) Algorithm 2: For each node v in V do For each edge in E do -Steps- // Θ (|V|*|E|) Algorithm 3: For each node v in V do For each edge e of v do -Steps- // Θ ( |E| ) with adjacency list, but Θ (|V|* |V| ) for matrix repres. Algorithm 4: For each node v in V do For each node w adjacent to v do -Steps- // again, Θ ( |E| ) with adjacency list Algorithm 5: For each node v in V do -steps- For each edge e of v do -Steps- // Θ ( |V|+|E| ) or Θ ( max{|V|, |E| })

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
TOPOLOGICAL SORT Input : directed acyclic graph Output : sequentially order the nodes without violating any arc ordering. Note: you may have to check for cycles - depending on the problem definition (input: directed graph). Example: course pre-requisite graph, find a linear ordering of courses. An important data: indegree of each node - number of arcs coming in (#courses pre-requisite to "this" course). A first-pass strategy : Eliminate vertices with indegree zero and their associated (outgoing) arcs (thus, reducing indegrees of the connected nodes) - after attaching an ordering-number (for output of topo-sort ordering) to these nodes, keep doing it for number-of-nodes times. If at any stage before finishing with all nodes there does not exist any node with indegree zero, then a cycle is found! [WHY?]
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 36

GRAPH - GRAPH ALGORITHMS Definitions(background Graph...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online