0% found this document useful (0 votes)
56 views4 pages

GeorgiaTech CS-6515: Graduate Algorithms: Graph Algorithms Flashcards by Yang Hu - Brainscape

The flashcards provide information about graph algorithms including: 1) BFS uses a queue and finds the shortest path by reaching vertices with the minimum number of edges from the source, while DFS uses a stack and may traverse through more edges. 2) Prim's algorithm builds an MST from any vertex and can have multiple passes over nodes, while Kruskal's builds from the minimum weight vertex and passes over each node once. 3) Dijkstra's algorithm finds the shortest distances and paths from a source to all other vertices in a graph with positive edge weights, using a min-heap with time complexity of O((V+E)logV).

Uploaded by

Jan_Su
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views4 pages

GeorgiaTech CS-6515: Graduate Algorithms: Graph Algorithms Flashcards by Yang Hu - Brainscape

The flashcards provide information about graph algorithms including: 1) BFS uses a queue and finds the shortest path by reaching vertices with the minimum number of edges from the source, while DFS uses a stack and may traverse through more edges. 2) Prim's algorithm builds an MST from any vertex and can have multiple passes over nodes, while Kruskal's builds from the minimum weight vertex and passes over each node once. 3) Dijkstra's algorithm finds the shortest distances and paths from a source to all other vertices in a graph with positive edge weights, using a min-heap with time complexity of O((V+E)logV).

Uploaded by

Jan_Su
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Study These Flashcards

FLASHCARDS IN GRAPH ALGORITHMS DECK (6)

Q
difference between BFS and DFS

A
BFS

1. BFS stands for Breadth-First Search.


2. BFS(Breadth-First Search) uses a Queue data structure for finding the shortest
path.
3. BFS can be used to find single-source shortest path in an unweighted graph,
because in BFS, we reach a vertex with minimum number of edges from a
source vertex.
4. BFS is more suitable for searching vertices which are closer to the given
source.
5. BFS considers all neighbors first and therefore not suitable for decision-
making trees used in games or puzzles.
6. The Time complexity of BFS is O(V + E) when Adjacency List is used, where V
stands for vertices and E stands for edges.

DFS
1. DFS stands for Depth First Search.
2. DFS(Depth First Search) uses Stack data structure.
In DFS, we might traverse through more edges to reach a destination vertex from a
source.
3. DFS is more suitable when there are solutions away from the source.
4. DFS is more suitable for game or puzzle problems. We make a decision, then
explore all paths through this decision. And if this decision leads to win situation, we
stop.
5. The Time complexity of DFS is also O(V + E) when Adjacency List is used, where V
stands for vertices and E stands for edges.
Here, children are visited before the siblings

Q
Difference between Prim’s and Kruskal’s algorithm for MST

A
Prim’s Algorithm

1. It starts to build the Minimum Spanning Tree from any vertex in the graph.
2. It traverses one node more than one time to get the minimum distance.
3. Prim’s algorithm has a time complexity of O(V^2), V being the number of
vertices, and can be improved up to O(E log V) using Fibonacci heaps.
4. Prim’s algorithm gives connected components as well as it works only on a
connected graph.
5. Prim’s algorithm runs faster in dense graphs.
6. Prim’s algorithm uses List Data Structure.

Kruskal’s Algorithm

1. It starts to build the Minimum Spanning Tree from the vertex carrying
minimum weight in the graph.
2. It traverses one node only once.
3. Kruskal’s algorithm’s time complexity is O(E log V), V being the number of
vertices.
4. Kruskal’s algorithm can generate forest(disconnected components) at any
instant as well as it can work on disconnected components
5. Kruskal’s algorithm runs faster in sparse graphs.
6. Kruskal’s algorithm uses Heap Data Structure.

Q
What is the input and output for Dijkstra’s algorithm?

A
Input: graph = G(V, E) with positive weights.
output: dist array (the shortest distance from the source to each vertex) and prev
array(indicating the previous vertex that the shortest path uses to get to each vertex).

Q
What is the running time of Dijkstra’s algorithm using min-heap (aka priority queue)
data structure?

A
O((V+E)*logV)

Q
What is the main idea for Dijkstra’s algorithm?

A
The main idea of Dijkstra’s algorithm is to find the distances to the nearest nodes,
then gradually expand the frontier of the search and determine the shortest paths to
nodes that are further and further away. Since edge weights must be positive, there
will never be a case where the shortest path must first go through a far away vertex
(the path would already be longer than another one that had been found).

Q
What is the main idea for the Depth First Search algorithm?
A
The DFS algorithm is a recursive algorithm that uses the idea of backtracking.

This recursive nature of DFS can be implemented using stacks. The basic idea is as
follows:

1. Pick a starting node and push all its adjacent nodes into a stack.
2. Pop a node from stack to select the next node to visit and push all its adjacent
nodes into a stack.
3. Repeat this process until the stack is empty. 4. However, ensure that the
nodes that are visited are marked. This will prevent you from visiting the same
node more than once. If you do not mark the nodes that are visited and you
visit the same node more than once, you may end up in an infinite loop.

You might also like