225_32_DFS

# 225_32_DFS - 1 .Wh a tis th e a d ja c e nc y m a trixfo...

This preview shows pages 1–8. Sign up to view the full content.

1 2. Apply BFS  s tarting  a t ve rte x 0. S ho w the   q ue ue , the  BFI, the  le ve l,  and the  pare nt  a rra ys . 1. What is  the  adjac e nc y m atrix fo r this   g ra ph?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Stacks
3 S tac k Da ta S truc ture : pe rm its  pus h a nd  po p a t the  to p o f the  s tac k.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Us ing  a n a rray fo r a  s ta c k: to p=5 = # ite m s  in s ta c k To  te s t if the  s ta c k is  no n-e m pty: if (to p > 0) To  po p x fro m  the  s ta c k: to p--; x= S [to p]; To  pus h x o nto  the  s tac k: S [to p]= x; to p++;
5 Us ing  a n linke d lis t fo r a s ta c k:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 DFS  (De pth Firs t S e a rc h) us e s  a s tac k  ins te a d o f a q ue ue . Da ta s truc ture s :  A s ta c k o f e dg e s  o f the  fo rm  (p, v) whe re  p  is  the  DFS  pa re nt o f no de  v.  vis ite d[i]= true  is  ve rte x i ha s  b e e n vis ite d  and fa ls e  if no t.  pa re nt[i]= DFS  tre e  pa re nt o f no de  i. The   pa re nt o f the  ro o t s  is  s .
7 Ma jo r diffe re nc e  b e twe e n BFS  a nd DFS :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## 225_32_DFS - 1 .Wh a tis th e a d ja c e nc y m a trixfo...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online