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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 27 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply