when we discussed binary treesvisit means to perform some operation on the vertexsuch as displaying it there are two common approaches to searching graphdepth-first search (dfsand breadth-first search (bfsboth will eventually reach all connected vertices the difference is that the depth-first search is implemented with stackwhereas the breadthfirst search is implemented with queue these mechanisms resultas we'll seein the graph being searched in different ways depth-first search the depth-first search uses stack to remember where it should go when it reaches dead end we'll show an exampleencourage you to try similar examples with the graphn workshop appletand then finally show some code that carries out the search an example we'll discuss the idea behind the depth-first search in relation to figure the numbers in this figure show the order in which the vertices are visited figure depth-first search to carry out the depth-first searchyou pick starting point--in this casevertex you then do three thingsvisit this vertexpush it onto stack so you can remember itand mark it so you won' visit it again next you go to any vertex adjacent to that hasn' yet been visited we'll assume the vertices are selected in alphabetical orderso that brings up you visit bmark itand push it on the stack now whatyou're at band you do the same thing as beforego to an adjacent vertex that hasn' been visited this leads you to we can call this process rule remember rule if possiblevisit an adjacent unvisited vertexmark itand push it on the stack applying rule again leads you to at this pointhoweveryou need to do something elsebecause there are no unvisited vertices adjacent to here' where rule comes in remember rule if you can' follow rule thenif possiblepop vertex off the stack following this ruleyou pop off the stackwhich brings you back to has no unvisited adjacent verticesso you pop it ditto now only is left on the stack ahoweverdoes have unvisited adjacent verticesso you visit the next onec but is the end of the line againso you pop it and you're back to you visit dgand iand then pop them all when you reach the dead end at now you're back to you visit