CSCE4110 Final Flashcards
Advantages of adjacency list
works well for sparse graphs
space is theta(V + E)
disadvantage of adjacency list
searching for edges slower than adjacency matrix
advantages of adjacency matrix
works well for dense graph
edge lookup is theta(1)
disadvantage of adjacency matrix
requires more space than adjacency list
Examples of a BFS algorithm
Prims and dijkstras
Goal for a BFS algorithm
find smallest number of edges to each reachable vertex
time complexity for BFS
O(V+E)
Explain BFS briefly
Pick a starting vertex
Visit all nodes connected to starting vertex (start alphabetically)
Mark visited node
Add visited node to Queue
Explain DFS briefly
Pick a starting vertex
Visit next connected node (alphabetically)
Mark visited node
Add node to top of stack
Time complexity of DFS
O(V+E)
Are MST always unique
NO
How are Prim’s and Kruskal’s algorithms greedy?
Adds smallest weighted edge each step as long as it maintains tree property
Time complexity of Kruskals and Prims algorithm
O(E lg V)
How is single-source shortest paths exhibit optimal substructure?
If we have a path p(xy) and patch a new path in between it would be impossible
Can shortest paths be computed with negative weight edges?
Yes
Can shortest paths be computed with negative edge cycle?
No