Question

Someone help please Let A be an array of 5 integers, whose contents are as follows:...

Someone help please

Let A be an array of 5 integers, whose contents are as follows:
3, 2, 1, 5, 4
We will apply quick sort to sort this array. Show all of the element-wise comparisons made by the algorithm in the correct order. Here an element-wise comparison means the comparison of one element of the array with another element of the array or the key set in a particular step of the algorithm. Since the algorithm may move the elements of the array, you need to show the values of the elements being compared (rather than the form of A[i]). The first element-wise comparison is 3 ≤ 4? You should start with this element-wise comparison to write out all element-wise comparisons, one comparison per row.

Draw the portion of the decision tree for insertion sort on 5 elements a1,a2,a3,a4,a5 that contains the path from the root node to the permutation < a3,a2,a1,a5,a4 >.

Draw the portion of the decision tree for quicksort on 5 elements a1,a2,a3,a4,a5 that contains the path from the root node to the permutation < a3,a2,a1,a5,a4 >.

T(n) = 6·T(n/2)+n3. Use the master method to solve T(n). You need to specify a, b, logb a, and decide the case. You also need to write the derived conclusion.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Quick Sort follows divide and conquer method. That means it divides the problem into sub problems and find out the solution

In our example 3,2, 1,5,4

consider pivot element is 3 again leftmost element is= 3 and rightmost=4

pivot is 3 that means 3 must be in sorted position that means leftside of 3 contains elements less than 3 and rightside contains elements greater than 3

increment leftmost now its =2 which is less than pivot element then keep it as it is.

increment rightmost now its =4 which is greater than pivot element then keep it as it is  .

increment leftmost now its =1 which is less than pivot element then keep it as it is.

increment rightmost now its =5 which is greater than pivot element then keep it as it is  

increment rightmost now its =1 which is less than pivot element then exchange it with 3

now our list is = 1,2,3 ,5,4

Now divide the list into 2 parts and apply quick sort recurrsively .leftmost part of the 3 is already sorted right part contains elements 5 and 4

now consider pivot as =5 and leftmost element is also 5 rightmost element=4

now 4<5 therefore exchange it

now we get list= 1,2,3,4,5 which is in sorted order

Decision tree for insertion sort

Add a comment
Know the answer?
Add Answer to:
Someone help please Let A be an array of 5 integers, whose contents are as follows:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT