Question: P 5 . ( 2 5 points ) Write a function int follow _ path ( link root, int * A , int F )
P points Write a function int followpathlink root, int A int F that takes as
arguments a tree given by the root node, root an array, A and a number, F and returns the item found in the
tree, following the path given by the first F elements of A:
if you see a in A go left in the tree;
if you see a in A go right in the tree.
Continue the same way. For the function calls below, assume that root is pointing to the root, of the tree
below.
followpath root returns from root, go left, then right
followpath root returns
followpath root returns
followpath root returns
followpath root returns
You can only assume that A has at least F elements in it whenever it is called.
If anything goes wrong in the function call, it should return
You can use a helper function if you want. The nodes and links are defined as follows:
typedef struct node link;
struct node
int data;
link left;
link right;
points What special cases are there? Focus especially on cases that can crash your code. Give an
example function call and tree that show each special case.
;
a b points Fill in the time complexity of the code you wrote for part cIf needed, you can assume the
tree has N nodes in total.
O
c points Write the complete code for the function. It should deal with the special cases that you
mentioned. Each line or section that deals with a special case, should clearly indicate what case it deals
with.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
