1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Darina [25.2K]
3 years ago
5

Suppose you begin with an empty binary search tree, and want to add all the positive integers from 1 through 31 to the tree. If

the first number you add to the tree is 16, what is the smallest possible height of the tree?
Computers and Technology
1 answer:
Ugo [173]3 years ago
7 0

Answer:

4

Explanation:

Trees are data structures fundamental in computer science, widely used in these fields because they are well adapted to the natural representation of homogeneous organized information, and great convenience and speed of manipulation.

A tree is a data structure (often dynamic) representing a set of hierarchically organized (non-linear) values. Each value is stored in a node. The nodes are joined to each other by the edges which represent parent/child relationships.

We can define a binary search tree as a root binary tree with the presence of its internal nodes which usually stores a key that is higher than all the keys remaining in the sub-tree of the left node and lower than those in the right sub-tree.

From the given information; if we want to add all +ve integers from 1 → 31 to the tree and we intend that the first number that to be added should be 16, then the smallest possible height of the tree will be 4.

The right sub-tree computation for the tree diagram can be seen in the image below.

You might be interested in
Long answer questions.
EleoNora [17]

Answer:

  1. ans-I have outlined four types of communication, but I believe there are actually five types of communication: verbal, non-verbal, written, listening, and visual.
4 0
3 years ago
C++You are given an array x of int elements along with an int variable n that contains the number of elements in the array . The
Firdavs [7]

Answer:

C++ Code

#include <iostream>

using namespace std;

int median(int x[], int n)

{

   for (int i = 0; i < n-1; i++)

   {

   for (int j = 0; j < n-i-1; j++)  

       if (x[j] > x[j+1])

       {

           int temp = x[j];

           x[j] = x[j+1];

           x[j+1] = temp;

       }

   }

   if( n%2 == 0 )

   {

       return (x[ (n/2) -1] + x[n/2])/2;

   }

   else

   return x[n/2];

}

int main()

{

   //example 1

   int x[] = {5,8,1,7,9};

   int n = 5;

   

   int m = 0;

   m = median(x,n);

   cout << m << endl;

   

   //example 2

   int x2[] = {3,7,1,4,6,9};

   int n2 = 6;

   m = median(x2,n2);

   cout << m << endl;

}

Explanation:

The main program contains the examples given in the question.

Function Explanation: The function int median(int x[], int n) takes two arguments, one is the array x and the other is the size of the array n.

First, the function sorts the elements in ascending order.

After that, it is calculated whether n is even or odd. If n is an even number,  The middle numbers can be obtained as follows:

Divide n by 2 to get the first middle element.

The second middle element is the element before first middle element, therefore

x[ (n/2 )-1] + x[n/2] gives us the sum of middle elements, where as dividing it by 2 gives us the avg of the two numbers.

If n is an odd number, than the middle element can be simply returned by dividing n by 2.

The working of the program is as follows

Array 1: 5 8 1 9 7

After sorting, it becomes: 1,5,7,8,9.

Array indices are : 0,1,2,3,4. Middle element is at index 2, n = 5, therefore n/2 = 2.5 (This is rounded down to 2 because result is stored in integer)

Array 2: 3 7 1 4 6 9

After sorting, it becomes: 1 3 4 6 7 9

Array indices are : 0,1,2,3,4,5. Middle element is at index 2 and 3,n = 6, therefore it can be obtained by n/2-1 and n/2 (n/2 = 3 and n/2 - 1 = 2)

3 0
3 years ago
PLEASE HELP ITS DRIVERS ED
sasho [114]
I will have to say the answer is.d
3 0
4 years ago
Read 2 more answers
What is the correct format to use when<br> inserting a date in Excel?
kykrilka [37]

Answer:

Dates are whole numbers

Usually, when you insert a date in a cell it is displayed in the format dd/mm/yyyy.

Explanation:

5 0
3 years ago
Which techniques should be used for communicating in the workplace? Check the best answers.
makkiz [27]

Answer:

The 1st 2nd & 4th are correct.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Philip is thinking about customizing his motorcycle. A paint job, saddlebags, and a radio would cost $600. His motorcycle is old
    15·2 answers
  • A(n) ________ button is one that when you click one time it turns the feature on and when you click again, it turns off.
    10·1 answer
  • What direction would you travel to go from japan to the united states
    14·1 answer
  • _____ refers to the busiest calling hour of the day, week, month or year. And _____ refers to the average length of time the sub
    14·1 answer
  • Â A number of companies and/or agencies, such as National ____ and Atmospheric Administrationâs National Weather Service, provid
    9·1 answer
  • Which of the following is not a valid variable name? 2 myInt 2. return 3. myInteger 4. total3
    6·1 answer
  • A kettle is boiled and the
    7·1 answer
  • Can i get some help please .
    5·2 answers
  • The Home editions of Windows 7 do not include the Local Security Policy or Print Management.
    15·1 answer
  • write a function print array to print an array on one line as: 9 8 7 6 5 4 3 2 1 0 write and test a function called bubble sort
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!