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

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

View Full Document Right Arrow Icon
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?
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Stacks
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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++;
Background image of page 4
5 Us ing  a n linke d lis t fo r a s ta c k:
Background image of page 5

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

View Full DocumentRight Arrow Icon
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 . 
Background image of page 6
7 Ma jo r diffe re nc e  b e twe e n BFS  a nd DFS :
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

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 Right Arrow Icon
Ask a homework question - tutors are online