Question: Depth-first search algorithm is applied to a full binary tree of height k. Assume that the edges are directed from parents to children. What is
Depth-first search algorithm is applied to a full binary tree of height k. Assume that the edges are directed from parents to children. What is the maximal number of vertices occurring inside the stack during the execution? How many times is this maximal size repeated? Assume that the vertices are ordered level-by-levelfrom top to bottom and from left to right inside each level. procedure dfs(v: vertex); var x,y: vertex; S: STACK of vertex; begin mark[v] := visited; PUSH(v,S); while not EMPTY(S) do begin x := TOP(S); if there is an unvisited vertex y inside L[x] then begin mark[y] := visited; PUSH(y,S) end else POP(S) end end;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
