Below are the steps to create a Balance Linked List Binary Tree from a Sorted Array: A top-down approach to create a balanced binary tree. Steps (in general): i.Determine the middle element (median), if n is even then middle= n/2, else middle=n/2+1. Set the element as root ii.Recursively do the same for left half and right half i.Determine the middle left subarray if the subarray is not empty, insert it as the left child. ii.Determine the middle right subarray if the subarray is not empty, insert it as the right child. You are given the partially complete recursive method construct() to build the balanced binary tree.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
You are given the partially complete recursive method construct() to build the balanced binary tree. 
Complete the partially complete codes by answering the questions in the code
Below are the steps to create a Balance Linked List Binary Tree from a Sorted Array:
A top-down approach to create a balanced binary tree. Steps (in general):
i.Determine the middle element (median), if n is even then middle= n/2, else middle=n/2+1. Set the element as
root
ii.Recursively do the same for left half and right half
i.Determine the middle left subarray if the subarray is not empty, insert it as the left child.
ii.Determine the middle right subarray if the subarray is not empty, insert it as the right child.
You are given the partially complete recursive method construct() to build the balanced binary tree.
Complete the partially complete codes by answering the questions in the codes. (5 marks)
public void constructBalance(){
int(] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
BinaryNode root = new BinaryNode(array [array.length/2]);
construct (0, array.length, array, root);
public void construct(int left, int right, int [] array, BinaryNode node){
//Question 1: write the stopping condition for the recursive function
if(.....){
return new BinaryNode(array [left]);
}
if (left > right){
return null;
}
//Question 2: write the condition to check for even/odd
int middle;
if (.....){
middle = n/2;
} else{
//Question 3: fill in the correct statement
}
//Question 4: fill in the arguments
node. setleft( construct(....));
//Question 5: fill in the arguments
node. setRight( construct(....))
return node;
Transcribed Image Text:Below are the steps to create a Balance Linked List Binary Tree from a Sorted Array: A top-down approach to create a balanced binary tree. Steps (in general): i.Determine the middle element (median), if n is even then middle= n/2, else middle=n/2+1. Set the element as root ii.Recursively do the same for left half and right half i.Determine the middle left subarray if the subarray is not empty, insert it as the left child. ii.Determine the middle right subarray if the subarray is not empty, insert it as the right child. You are given the partially complete recursive method construct() to build the balanced binary tree. Complete the partially complete codes by answering the questions in the codes. (5 marks) public void constructBalance(){ int(] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}; BinaryNode root = new BinaryNode(array [array.length/2]); construct (0, array.length, array, root); public void construct(int left, int right, int [] array, BinaryNode node){ //Question 1: write the stopping condition for the recursive function if(.....){ return new BinaryNode(array [left]); } if (left > right){ return null; } //Question 2: write the condition to check for even/odd int middle; if (.....){ middle = n/2; } else{ //Question 3: fill in the correct statement } //Question 4: fill in the arguments node. setleft( construct(....)); //Question 5: fill in the arguments node. setRight( construct(....)) return node;
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY