Use the binary balancing algorithm here:
#include
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.
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.