logo

Crowdly

Browser

Add to Chrome

IS52054A: ALGORITHMS 2 (2024-25)

Looking for IS52054A: ALGORITHMS 2 (2024-25) test answers and solutions? Browse our comprehensive collection of verified answers for IS52054A: ALGORITHMS 2 (2024-25) at learn.gold.ac.uk.

Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!

For this pseudocode:

function Z(root,x) 

   if (root==NULL) 

      Node newNode= new Node(x) 

      root=newNode 

   else 

      if(x %2==0) 

          Z(root->left,x) 

      else 

          Z(root->right,x) 

end function

Assume that the tree starts empty. After executing the function Z with the following numbers: 8, 9, 6, 3, 4. What number is stored in the root of the tree?

0%
0%
0%
0%
0%
View this question

The following numbers are inserted in a BST: 8, 10, 5, 9

What is the data content of the right child of the root after executing function K?

   

function

 K(root) 

if

(root==NULL)

      return

else 

      K(root->left)  

      k(root->right)  

      

 if (root->left!= NULL and root->right!=NULL) 

             print("C3:", root->data) 

      

else 

             if

 (root->left== NULL and root->right==NULL) 

                  print("C1:", root->data) 

             

else

 

                 

if

(root->left== NULL)

                     tmp=root->data

root->data=root->right->data

                    root->right->data=tmp

             

  else

 

                      tmp=root->data

root->data=root->left->data

                  root->left->data=tmp

end function

0%
0%
0%
0%
0%
View this question

The following numbers are inserted (in this order) in a BST: 

8 (0xA), 3 (0xB), 2 (0xC), 5 (0xD), 17 (0xE), 13 (0xF), 29(0xA1), 31 (0xB1), 23 (0xC1), 15 (0xD1), 10 (0xE1)

The numbers between parenthesis are the memory addresses of the nodes where those numbers were stored. 

What is the value returned by function X when the root of the just described tree is used as input argument? 

function X(root) 

   Node tmp=root->left

   if(tmp!=NULL) 

       while(tmp->left!=NULL AND tmp->right!=NULL) 

                        tmp=tmp->left

       return tmp 

end function

0%
0%
0%
0%
0%
View this question

The following numbers are inserted in a BST (in this order): 25 (0x2), 17 (0xF), 32 (0xA), 35 (0xC), 28 (0xB). 

What is the memory address the root of this tree after executing function Z  with the input parameters: the root of the above described tree and number 25?

function Z(root, x) 

   if (root==NULL) 

     return NULL 

   else 

         if (x < root->data) 

            root->left=Z(root->left,x) 

         else 

             if (x > root->data) 

                 root->right=Z(root->right,x) 

             else 

                 if (root->left== NULL and root->right==NULL) 

                     root=NULL 

                     return root 

                 else 

                     return root 

end function  

0%
0%
0%
0%
0%
View this question

For this tree:

What of the following traversal functions visit the nodes in this order?

32, 28, 19, 6, 4, 23, 10, 18, 14, 15

0%
0%
0%
0%
View this question

For this pseudocode:

function W(root,x) 

   if (root==NULL) 

      Node newNode= new Node(x) 

      root=newNode 

   else 

      if(x > root->data) 

          W(root->left,x) 

      else 

          W(root->right,x) 

end function

Assume that the tree starts empty. After executing the function W with the following numbers: 9, 18, 6, 3, 7. What is the rightmost leaf of the tree? 

0%
0%
0%
0%
0%
View this question

Consider the following function:

 function F(root,x) 

     if (root!=NULL) 

          if (x == root->data) 

   

         

print('root')

           else 

               if (x< root->data) 

     

                

print('left')

                     F(root->left,x) 

               else 

 

                   

print(`right')

                    F(root->right,x) 

   else 

       print ('---')

end function

After

inserting the following numbers in a BST (in this order): 4, 2, 1, 3, 7, 5; function F was executed and the following data was print on screen:

left

left 

left     

---

What number was entered as input argument to this function? 

0%
0%
0%
0%
0%
View this question

For this tree:

What of the following traversal functions visit the nodes in this order?

26, 30, 32, 8, 3, 5, 21

0%
0%
0%
0%
0%
View this question

For this pseudocode:

function W(root,x) 

   if (root==NULL) 

      Node newNode= new Node(x) 

      root=newNode 

   else 

      if(x > root->data) 

          W(root->left,x) 

      else 

          W(root->right,x) 

end function

Assume that the tree starts empty. After executing the function W with the following numbers: 9, 18, 6, 3, 7. What is the left child of 6? 

0%
0%
0%
0%
View this question

For this pseudocode:

function M(root,x) 

   if (root==NULL) 

      Node newNode= new Node(x) 

      root=newNode 

   else 

      if(x < root->data) 

          M(root->left,x+1) 

      else 

          M(root->right,x-1) 

end function

Assume that the tree starts empty. After executing the function M with the following numbers: 4, 7, 12, 1, 3. What node is stored in the parent of 3?

0%
0%
0%
0%
0%
View this question

Want instant access to all verified answers on learn.gold.ac.uk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome