Ada Graphs
Ada Graphs
Used in:
• Transportation networks
• Communication networks
• Information networks
• Social networks
• Dependency Networks
Algorithm
1. Enter starting node on Q
2. If Q is empty, return fail and stop
3. If 1st element on Q is Goal, Success and exit
4. Remove and expand 1st element from Q, place children at end of Q
5. Goto step 2
Q={A}
B C Q={B,C}
Q={C,D,E}
D E F Q={D,E,F}
Q={E,F,G}
Q={F,G}
G H
Q={G,H} GOAL
Q={H}
Q={}
A->B->C->D->E->F->G->H
Dr. Puneet Singh Lamba
BFS
Advantages:
• Find a solution if it exists
• Minimal Sol in least no. steps
Disadvantages:
• Requires more memory
• Needs time if sol is far from root
T.C= O(b^d)
b: branching factor
d: depth
• Recursive Algo
• Starts from the root and each path to its greatest depth node before
moving to next node
• Stack LIFO
Algo:
1. Root on the stack
2. Do until stack is not empty
1. Pop node
2. If node is Goal, stop
3. Push all children of node on Stack
A
A
B C D G
B E E E
C C C C
D E F
G H H
C F
A->B->D->G->E->C->F->H
Advantages:
• Less m/m
• Less time to reach goal if traversal in right path
Disadvantages:
• No guarantee of finding sol. (infinite L/R)
• Infinite
T.C=O(b^d)
S.C=O(bd)
(4, 0)
(0, 3) (4, 0)
A H
B C I J
D E G K
1. Assign RED color to the source vertex (putting into set U).
2. Color all the neighbors with BLUE color (putting into set V).
3. Color all neighbor’s neighbor with RED color (putting into set U).
4. This way, assign color to all vertices such that it satisfies all the constraints of m way coloring
problem where m = 2.
5. While assigning colors, if we find a neighbor which is colored with same color as current
vertex, then the graph cannot be colored with 2 vertices (or graph is not Bipartite)