Solution-: Prim's Algorithm Kruskal's Algorithm
Solution-: Prim's Algorithm Kruskal's Algorithm
Solution-
A standard DFS implementation puts each vertex of the graph into one of two categories:
1. Visited
2. Not Visited
The purpose of the algorithm is to mark each vertex as visited while avoiding cycles.
Breadth first traversal or Breadth first Search is a recursive algorithm for searching all the vertices of a
graph or tree data structure.
BFS algorithm
A standard DFS implementation puts each vertex of the graph into one of two categories:
1. Visited
2. Not Visited
The purpose of the algorithm is to mark each vertex as visited while avoiding cycles.
The algorithm works as follows:
1. Start by putting any one of the graph's vertices at the back of a queue.
2. Take the front item of the queue and add it to the visited list.
3. Create a list of that vertex's adjacent nodes. Add the ones which aren't in the visited list to the
back of the queue.
4. Keep repeating steps 2 and 3 until the queue is empty.
Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds
the subset of the edges of that graph which
It falls under a class of algorithms called greedy algorithms which find the local optimum in the
hopes of finding a global optimum.
We start from the edges with the lowest weight and keep adding edges until we we reach our
goal.
Prim's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the
subset of the edges of that graph which
It falls under a class of algorithms called greedy algorithms which find the local optimum in the
hopes of finding a global optimum.
We start from one vertex and keep adding edges with the lowest weight until we we reach our
goal.
Binary search tree is a data structure that quickly allows us to maintain a sorted list of numbers.
It is called a binary tree because each tree node has maximum of two children.
It is called a search tree because it can be used to search for the presence of a number in
O(log(n)) time.
The properties that separates a binary search tree from a regular binary tree is
Dijkstra’s Algorithm-
Algorithm: Dijkstra’s-Algorithm (G, w, s)
for each vertex v Є G.V
v.d := ∞
v.∏ := NIL
s.d := 0
S := Ф
Q := G.V
while Q ≠ Ф
u := Extract-Min (Q)
S := S U {u}
for each vertex v Є G.adj[u]
if v.d > u.d + w(u, v)
v.d := u.d + w(u, v)
v.∏ := u
It is used for solving the single source shortest path problem which gives the shortest paths from
one particular source node to all the other nodes of the given graph.
Dijkstra’s algorithm works only for those graphs that are connected.
Dijkstra’s algorithm works only for those graphs that do not contain any edges with negative weights.
The actual Dijkstra’s algorithm does not output the shortest paths. It only provides the value or cost of
the shortest paths.
By making minor modifications in the actual algorithm, the shortest paths can be easily obtained.
Dijkstra’s algorithm works for directed as well as undirected graphs
It is the most common. Each node has data and a pointer to the next node.
We add a pointer to the previous node in a doubly linked list. Thus, we can go in either direction:
forward or backward.
A circular linked list is a variation of linked list in which the last element is linked to the first
element. This forms a circular loop.
Merge Sort is a kind of Divide and Conquer algorithm in computer programrming. It is one of
the most popular sorting algorithms and a great way to develop confidence in building recursive
algorithms.