5. Consider the following binary tree.
a
/ \
b c
/ \ \
d e f
/ \
g h
Which of the following might be the output of a postorder traversal
of this tree ?
a. dghebafc
b. dgehbfca
c. dghebfca
d. dbgehafc
e. dbgehfca
6. Give the function header for each of the following.
a) Function hypotenuse that takes two double-precision floating point
arguments side1 and side2, and returns double-precision floating
point value.
b) Function IntToFloat that takes an integer argument Number and returns
a floating point value.
7. Here is the adjacency matrix A of a weighted undirected graph. Assume
the vertices are $v sub 1, v sub 2, v sub 3, v sub 4, and v sub 5$ and that
position (i,j) in the matrix corresponds to edge ($v sub i, v sub j$).
0 3 6 2 4
3 0 3 0 4
A = 6 3 0 0 5
2 0 0 0 7
4 4 5 7 0
a. Draw a picture of this graph.
b. Give a breadth first search of the graph starting at vertex $V sub 2$.
8. For any tree depth-first search (dfs) and breadth-first search
(bfs) take about the same number of steps.
However, the space required by the two algorithms may differ greatly.
assume we use a stack to implement the DFS and a queue to do the BFS.
a. Give an example of a tree with n vertices where a stack of size n-1 is
needed to do dfs whereas the queue of the bfs of the same tree will never
have more than two vertices on it at a time. Both searches start from the same vertex.
b. Give an example of an n vertex tree for which the queue used in bfs
will have n-1 vertices on it at some time while the stack used
for dfs has at most one vertex on it at any time. Both searches
start from the same vertex.