Answered You can buy a ready-made answer or pick a professional tutor to order an original one.


Use the binary balancing algorithm here:

Use the binary balancing algorithm here: 

#include <iostream>#include <iomanip>#include <cstdlib>#include <cmath>using namespace std;

void FindMiddle(int x, int y, int level, int nr,   int round){ int mid;  if (abs(x-y)<2)  { if (x==1)   cout << level << " " << setw(2) << x << endl;  if (y==nr)   cout << level << " " << setw(2) << y << endl;  return;  }  if ((y+x)%2)  { mid=(x+y+round)/2;  cout << level << " " << setw(2) << mid << endl;  } else  { mid = (x+y)/2;  cout << level << " " << setw(2) << mid << endl;  }  FindMiddle(x,mid,(level+1),nr,-1); // round down left  FindMiddle(mid,y,(level+1),nr,1);  // round up right  return;}

int main(){ int nr, level=0;  cout << "Enter integer number of elements: ";  if (cin >> nr)  if (nr>2)  FindMiddle(1,nr,(level+1),nr,1);  return 0;}

I want a program given a data set of these names: William, Ben, Edward, Kevin, Greer, Tim, Nate, John, Raziel, Rongjuan, Ofer, Steve, Ian, Tom.  The program must construct a binary tree which is as balanced as possible. There are 14 names in this list, it is one name short of the count which is required to produce a perfectly balanced binary tree structure which contains four levels. Nevertheless, the program must create a tree which contains these names and which is as balanced as possible by using the code above.

Here is an outline of what the program must do:

(1)  Enter the unsorted list of names into an array and sort this list in the array.  Be sure to retain the count of array elements.  For this problem you may use static arrays which are large enough to handle the sample test data given above.

(2)  Use the count of array elements and the findMiddle algorithm to rearrange the sorted array into a second array which contains the middle element in the first position, the elements in the first quarter and third quarter positions in the second and third positions, the elements in the first, third, fifth and seven-eighths positions into the fourth through seventh positions, etc.

(3)  Move each of the elements of the second array in succession into a binary tree structure.

(4)  Display the balanced tree using one of the available binary tree display algorithms.

Please copy and paste your source code directly to me and screen shot the output.

Show more
  • @
  • 7 orders completed

Tutor has posted answer for $50.00. See answer's preview


******** <algorithm>#include ************************ ********************** *********************** <cstdlib>#include ****************** namespace ***

Click here to download attached files: comp science......docx
or Buy custom answer
Ask a Question