List of Problems - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

List of Problems

Description:

... there are train tracks linking city X to city Y ... a route to fly from city X to city Y with the minimum number of ... Recursively traverse all vertices ... – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 25
Provided by: depts177
Category:
Tags: city | list | problems | traverse

less

Transcript and Presenter's Notes

Title: List of Problems


1
List of Problems
  • Building roads connecting all cities with the
    minimum cost
  • Determining if there are train tracks linking
    city X to city Y
  • Finding a shortest tour to visit all cities
  • Finding a cheapest route to fly from city X to
    city Y
  • Getting out of a maze
  • Finding a route to fly from city X to city Y with
    the minimum number of transits
  • Checking if there is a loop in the network of
    train tracks.

2
Building Roads connecting Cities
3
Testing if cities X and Y are connected
X
Z
Y
4
Finding shortest tour to visit all cities
5
Finding cheapest air ticket
X
Y
6
Getting out of a Maze
7
Finding route with minimum transits
X
Y
8
Loop Detection
9
Subgraph
  • Graph G1(V1,E1) is a subgraph of graph
    G2(V2,E2) if
  • V1 ? V2 and E1 ? E2
  • G1 is a spanning subgraph of G2 if
  • V1 V2 and E1 ? E2

10
Spanning Tree
  • Graph G1(V1,E1) is a spanning tree of graph
    G2(V2,E2) if
  • G1 is a spanning subgraph of G2
  • G1 is a tree

11
Algorithms involving graphs
  • Graph traversal BFS , DFS
  • Strongly connected components
  • Topological sorting
  • Shortest path algorithms
  • In an unweighted graph shortest length between
    two vertices
  • In a weighted graph smallest cost between two
    vertices
  • Dijakstra
  • Minimum Spanning Trees
  • Using a tree to connect all the vertices at
    lowest total cost

12
General Graph Search AlgorithmLooking for a node
with a property
  • Set Store equal to the some node
  • while ( Store is non-empty) do
  • choose a node n in Store
  • if n is solution, stop
  • Decisions
  • else add SOME sons of n to store
  • What should store be?
  • How do we choose a node?
  • what does add mean?
  • How do pick which sons to store.
  • Cycles are a problem

13
DFS and BFS
  • Depth First Search (DFS)
  • Start at a node
  • Travel to new nodes as far as possible.
  • If stuck, go back and repeat the process.
  • Breadth First Search (BFS)
  • Start at a node
  • Travel to all the nodes which are 1 step away
  • Repeat the process

14
Breadth First Search
  • G is a undirected Graph
  • Each node has a boolean visited field.
  • Initial node is arbitrary
  • Store Queue
  • Choose dequeue and mark as visited
  • Add enqueue only those sons that have not been
    visited
  • Properties
  • Time Number of nodes to solution
  • Space Number of nodes
  • Guaranteed to find shortest solution

15
Breadth First Search
  • Breadth_First_Search( u )
  • enqueue(Q,u) and cross u
  • while Q not empty
  • v dequeue(Q)
  • process v
  • for each x adjacent to v
  • if (x is not crossed) // crossedvisited
  • enqueue(Q,x) and cross x

16
Breadth First Search
z
w
v
u
t
y
x
t u v y z w x
17
Depth First Search (DFS)
  • A graph traversal technique
  • A generalization of preorder traversal of trees
  • Idea
  • Start at a node
  • Travel to new nodes as far as possible.
  • If cant go to a new node from the current node,
    go back to previous node and repeat the process.

18
Depth First Search (DFS)
  • Start at some vertex v
  • Process v
  • Recursively traverse all vertices adjacent from v
  • Must avoid processing each node more than once
  • Must avoid cycles
  • When a vertex is visited, mark it as visited

19
Depth First Search Pseudo-Code
  • Store Stack
  • Choose pop
  • Initial node any node
  • Add push only new sons (unvisited ones)
  • keep a boolean field visited, initialized to
    false.
  • When a node is popped, mark it as visitied.
  • Graph connected if all nodes visited.
  • Properties
  • Memory cost number of nodes
  • Guarantee to find a solution, if one exists (not
    shortest solution) How could we guarantee that?
  • Time number of nodes

20
Depth-first spanning tree Tree edges Back edges
21
  • preorder( Node T )
  • Print T.info
  • for each node W adjacent to T
  • preorder( W )
  • dfs( Node V )
  • V.visited True
  • Print V.info
  • for each node W adjacent to V
  • if (W.visited ! True)
  • dfs( W )

22
Depth First Search (DFS)
  • Depth_First_Search( u )
  • push(S,u) and cross u
  • while S not empty
  • v pop(S)
  • process v
  • for each x adjacent to v
  • if (x is not crossed)//visited
  • push(S,x) and cross x

23
a
b
e
d
c
g
f
a
24
a
Write a Comment
User Comments (0)
About PowerShow.com