Graph Algorithms and Dijkstra's Algorithm: Running Time and Complexity - Prof. Zhaojun Bai, Assignments of Computer Science

Various graph algorithms, including dijkstra's algorithm, and their running times and complexities. Topics covered include dijkstra's running time, extract-min and decrease-key operations, and the relationship between different queue implementations. The document also mentions other graph algorithms such as bfs, dfs, topology sorting, and minimum spanning trees (prim and kruskal).

Typology: Assignments

Pre 2010

Uploaded on 07/31/2009

koofers-user-o7d
koofers-user-o7d 🇺🇸

10 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Discussion 9
Yuanbo Zhu
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Graph Algorithms and Dijkstra's Algorithm: Running Time and Complexity - Prof. Zhaojun Bai and more Assignments Computer Science in PDF only on Docsity!

Discussion 9

Yuanbo Zhu

Notice: •^

Hw # 5 is on desk (/160)

-^

Hw # 6 is published and due next Tue.

-^

An extra office hour on June 8

Graph Algorithm

-^

BFS

-^

DFS

-^

Topology sorting

-^

Dijkstra

-^

Bellman-Ford

-^

Minimum Spanning Tree^ – Prim^ – Kruskal

Discovering Graph Topologies

•^

Two algorithms for systematically discovering

the

topology and layout

of a graph from a particular vertex

of the graph^ –

Breadth-first search

begins at a vertex and visits all vertices

which can be reached directly from that node, then repeats thevisitation from each new vertex discovered (good for discoveringshortest paths)

-^

Depth-first search

is similar, except it explores entire paths in

turn -- paths from a single neighbor of the starting vertex areexhaustively visited before the next neighbor is considered

  • detect cycles in a graph • topology sorting for DAG (Shortest Path for DAG) :

Ordering

nodes in acyclic directed graphs

-^

strong connected components

Minimum Spanning Tree

  • there can be many spanningtrees of a graph• there can be many

minimum

spanning trees of a graph• But if

every edge has a

unique weight

, then there is a

unique MST

Minimum Spanning Trees

-^

Kruskal :

greedy algorithm

for MSTs

  • consider the edges in increasing order of weight, – smallest (not yet), and add in an edge iff it does not

cause a cycle

-^

Prim :

greedy algorithm

  • start at a source vertex and grow a single tree – choose the smallest

outgoing

edge to add

-^

Two problems:^ – Graph coloring^ – Network flow

Graph Colorability

•^

A graph

G

is said to be

k

-colorable if its vertices can be

colored with

k

different colors such that

no two adjacent vertices share the same color. 1:

Describe a polynomial-time algorithm to solve the graph-2-colorability problem. 2: Show that graph-4-colorability problem is NP-Complete.

Hint: graph-3-colorability is NP-Complete

Graph Algorithms

Testing bipartiteness

Method

: use BFS search tree

Recall

: BFS is a rooted spanning tree having the same layers as the original graph G (each node has the same distance from the root in BFS tree andin graph G) Algorithm

:

-^

Run BFS search and colour all nodes in odd layers red, others blue

-^

Go through all edges in adjacency list and check if each of them has twodifferent colours at its ends - if so then G is bipartite, otherwise it is not We use the following alternative definitions in the analysis:•^

Graph G = (V,E) is bipartite iff all its cycles have even length, or

-^

Graph G = (V,E) is bipartite iff it has no odd cycle

non bipartite

bipartite

Graph Algorithms

14

Testing bipartiteness - why it works

Property of layers: •^

Every edge is either between two consecutive layers or in a single layer (twoends are in the same layer) - it follows from BFS property

Suppose that graph G is

not bipartite

. Hence there is an odd cycle. This cycle

must have an edge in one layer, and so the ends of this edge have the samecolour. Thus the algorithm answers

not bipartite

correctly.

Suppose that graph G is

bipartite

. Hence all its cycles have even length.

Suppose, to the contrary, that the algorithm answers incorrectly that G is

not

bipartite

. Hence it found a monochromatic edge. This edge must be in one layer.

Consider one of such edges which is in the smallest possible layer. Consider acycle containing this edge and the BFS path between its two ends. The length ofthis cycle is odd, thus G is

not bipartite

. Contradiction!

not bipartite

bipartite

Max flow

-^

Ford-Fulkerson Algorithm– Residual graph

  • For each edge

e

in E with

c

f^ we put weight

c

-^ f^ (

residual

capacity

)

  • For each edge

e

= (

u,v

) in E we put weight

f (

e ) to backward

edge (

v,u

) (

residual capacity

)

  • Augment path
    • in residual graph• Find minimum capacity on the path• Go through the path and modify weights

Max flow (Example)

Maximum bipartite matching

-^ Add node

s, t

  • For each edge, itscapacity is unit 1• Find themaximum flow from s to

t

  • As a result, themaximum flow in G

is a maximummatching in G.

G

Backup

-^

Bellman-Ford