14.0k views
0 votes
Here is an array of ten integers 6 4 0 3 9 8 1 7 2 5

Suppose we partition this array using quicksort's partition function and using 5 for the pivot. List the elements of the resulting array after the partition finishes.

User Eav
by
4.4k points

1 Answer

3 votes

Answer:


[4,0,3,1,2,5] and
[6,9,8,7]

Explanation:

GIVEN: an array of ten integers
6,4,0,3,9,8,1,7,2,5.

TO FIND: If we partition this array using Quick sort's partition function and using
5 for the pivot. List the elements of the resulting array after the partition finishes.

SOLUTION:

quick sort is a divide and conquer algorithm in which an array is partitioned into sub-arrays about an pivot element by checking whether elements are greater than pivot or and then sub arrays are sorted recursively.

Here
5 is the pivot element.

two arrays will be created, in first array element less than or equal to pivot element are stored in other elements greater than pivot element are stored.

Starting from first element of array

elements in first array will be
=[4,0,3,1,2,5]

elements in second array will be
=[6,9,8,7]

Hence the resulting array after the partition finishes are
[4,0,3,1,2,5] and
[6,9,8,7]

User Graham Conzett
by
4.3k points