Access over 20 million homework & study documents

One of the problems we discussed with binary search trees is that whe

Content type
User Generated
Rating
Showing Page:
1/2
One of the problems we discussed with binary search
trees is that when you insert data, if the data is already
sorted or nearly sorted, the tree becomes unbalanced.
Your coworker comes up to you and has the idea of an
O(n) category algorithm already know how many elements
are in the tree, you can use a temporary array size to get
all the values and rebuild the a more balanced (though not
perfectly tree in O(n) time. Her high level idea is this: Go
through the tree and delete all elements. With each
deletion, insert that element into the array Randomize the
order of the array Insert the elements back into a new
binary search tree She wants to know if she is correct in
thinking that this is an O(n) category algorithm and asks
you to do the following: Develop a more detailed algorithm
from this high level idea (you don\'t have to code it, but
you should write it in some form of pseudocode) Analyze
the algorithm and confirm whether or not it is truly category
O(n) If it is O(n), what is its actual order (i.e. is it 0(2n),
0(3n), etc.)? If it is worse than O(n), can her idea be
modified to an algorithm that is O(n)?
Solution
int main() { int data[100],n,temp,i,j;
printf(\"Enter number of terms(should be less than 100):
\"); scanf(\"%d\",&n); printf(\"Enter elements: \");
for(i=0;i=0) /*To sort elements in descending order, change
tempdata[j] in above line.*/ {
data[j+1] = data[j]; --j; }

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/2

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
One of the problems we discussed with binary search trees is that when you insert data, if the data is already sorted or nearly sorted, the tree becomes unbalanced. Your coworker comes up to you and has the idea of an O(n) category algorithm already know how many elements are in the tree, you can use a temporary array size to get all the values and rebuild the a more balanced (though not perfectly tree in O(n) time. Her high level idea is this: Go through the tree and delete all elements. With each deletion, insert that element into the array Randomize the order of the array Insert the element ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4