The instructions to answer my question are below in bulletpo

The instructions to answer my question are below in bulletpoints, and write the code in Java, thank you.

Search 2D (Table) Binary Tree To access a 2D array you need 2 indexes. e.g. array2d[row] [column] The key will be in column 0. the left child index in column 1 and right child index in column 2 The 2D array/table the table contains a binary tree with the root at row = 0; Write a while loop to search for the value in the variable akey Write an if-else to change the variable row to search the left or right child When the loop completes row must be the slot that equals variable akey Do not declare the variable row, but do initialize and change it during the search. Implement the instructions above by placing your Code here: row =; while () {if () {} else {}}

Solution

public class SearchKeyin2DBT {


   public static void main(String args[])
   {
       int [][]arr={{1,2,3,4},
       {5,6,7,8},
       {9,10,11,12},
       {13,14,15,16}};
      
       //initializing element to top right
       int i=0;int j=3;


//search for the akey
       while(i<4&&j>=0)
       {

int akey=9;
           if(arr[i][j]==akey)
           {
               System.out.println(\"aKey found at location: \"+i+\" \"+j);
               return ;
           }
           else if(arr[i][j]<akey)
               i++;
           else
               j--;
          
       }
       System.out.println(\"aKey not found\");
   }
}

The instructions to answer my question are below in bulletpoints, and write the code in Java, thank you. Search 2D (Table) Binary Tree To access a 2D array you

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site