Page 1 of 1

The following algorithms (A1 and A2) solve the same problem. To do so, they receive as input argument: • root: the root

Posted: Fri May 20, 2022 11:45 am
by answerhappygod
The Following Algorithms A1 And A2 Solve The Same Problem To Do So They Receive As Input Argument Root The Root 1
The Following Algorithms A1 And A2 Solve The Same Problem To Do So They Receive As Input Argument Root The Root 1 (357.75 KiB) Viewed 28 times
Describe the task performed by algorithms A1 and A2?
The following algorithms (A1 and A2) solve the same problem. To do so, they receive as input argument: • root: the root of a binary search tree storing integer numbers • x: an integer number ALGORITHM 1 ALGORITHM 2 function A1(root, x) Q = new Queue() ENQUEUE (Q, root) while !ISEMPTY(Q) do t = PEEK(Q) if (t==x) return 1 else ENQUEUE (Q, left(t)) ENQUEUE (Q, right(t)) DEQUEUE (Q) end while return 0 end function function A2(root,x) if (root==NULL) return 0 else if(x == root->data) return 1 else if (x< root->data) return A2 (root->left,x) else return A2 (root->right,x) end function Note: the function ENQUEUE only inserts a new element in the queue if this element is different from NULL