0% found this document useful (0 votes)
22 views15 pages

DAA (Algorithms Knowledge Capsule 1 by Dr. Choudhary Ravi Singh)

Algorithms Knowledge Capsule 1 by Dr. Choudhary Ravi Singh

Uploaded by

ravi singh
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)
22 views15 pages

DAA (Algorithms Knowledge Capsule 1 by Dr. Choudhary Ravi Singh)

Algorithms Knowledge Capsule 1 by Dr. Choudhary Ravi Singh

Uploaded by

ravi singh
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/ 15

DAA KNOWLEDGE CAPSULE - 1

Graph Searching Algorithms:


By: Dr. Choudhary Ravi Singh
BFS:
Breadth-first search: a method to search a graph. Start at s, find all vertices distance 1 from s, keep going until all vertices
have been discovered.

Breadth-first search systematically explores the edges of G graph to discover every vertex that is reachable
from starting node S. The main purpose of BFS is to calculate the distance from S to each reachable vertex.

o White color - not visited nodes


o Gray color - about to be visited (keeping them in FIFO queue)
o Black color - visited nodes

Queue data structure: First in First Out


Graph Searching Algorithms:
DFS:
Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts
at the root node (selecting some arbitrary node as the root node in the case of a graph) and explores as far as possible
along each branch before backtracking.
Single Source Shortest Path:
Dijkstra Algorithms:
The Single-Source Shortest Path (SSSP) problem consists of finding the shortest paths between a given vertex
v and all other vertices in the graph.
Bellman Ford Algorithm:
To detect negative weight cycle.

If (d[v] > d[u] + w(u,v)) //The idea behind this is we are relaxing edges nth time if we found more shortest
path than (n-1)th level, we can say that graph is having negative edge cycle and
detected.
Return False
Else

Return True
All Pair Shortest Path Problem:
All Pairs Shortest Path Algorithm is also known as the Floyd-Warshall algorithm is used to find all pair
shortest path problem from a given weighted graph. As a result of this algorithm, it will generate a matrix,
which will represent the minimum distance from any node to all other nodes in the graph.
Flow Network:
Ford Fulkerson Algorithm:
Ford-Fulkerson algorithm is a greedy approach for calculating the maximum possible flow in a network or a
graph.

Flow on an edge doesn't exceed the given capacity of the edge. · Incoming flow is equal to outgoing flow for
every vertex except s and t.

Each Directed Edge is labelled with capacity. Use the Ford-Fulkerson algorithm to find the maximum flow.

The left side of each part shows the residual network Gf with a shaded augmenting path p, and the right side
of each part shows the net flow f.
Minimum Spanning Tree
Kruskal's algorithm is the concept that is introduced in the graph theory of discrete mathematics. It is used to
discover the shortest path between two points in a connected weighted graph. This algorithm converts a given
graph into the forest, considering each node as a separate tree.
Prim's Algorithm is a greedy algorithm that is used to find the minimum spanning tree from a graph. Prim's
algorithm finds the subset of edges that includes every vertex of the graph such that the sum of the weights of
the edges can be minimized.
Backtracking
Hamiltonian circuit:
A Hamiltonian circuit is a circuit that visits every vertex once with no repeats. Being a circuit, it must start
and end at the same vertex.
Again
Backtrack
Sum of Subset:
Subset sum problem is to find subset of elements that are selected from a given set whose sum adds up to a
given number K. We are considering the set contains non-negative values.

The Subset-Sum Problem is to find a subset's' of the given set S = (S1 S2 S3...Sn) where the elements of the
set S are n positive integers in such a manner that s'∈S and sum of the elements of subset's' is equal to some
positive integer 'X.'

Example: Given a set S = (3, 4, 5, 6) and X =9. Obtain the subset sum using Backtracking approach.

4/8 Queens:

4 – Queens’ problem is to place 4 – queens on a 4 x 4 chessboard in such a manner that no queens attack each
other by being in the same row, column, or diagonal.
8 Queen Solution:

Graph Coloring:
Vertex coloring is the most common graph coloring problem. The problem is, given m colors, find a way of
coloring the vertices of a graph such that no two adjacent vertices are colored using same color. The other
graph coloring problems like Edge Coloring (No vertex is incident to two edges of same color) and Face
Coloring (Geographical Map Coloring) can be transformed into vertex coloring.
X: Dead End
V: Solution

You might also like