Explain quick sort algorithm in detail by taking a example
Answers
Answered by
0
In quick sort, the array is divided into two parts based on a pivot value(mostly the mid value of an unsorted array). The values lesser than the pivot are stored in the first part (the first sub-array) and the greater ones are stored in another sub-array. Both the sub arrays are sorted internally.
Ex:
45, 87, 65, 58, 78, 10, 56.
58 is being selected as pivot being the mid value.
Sub-array 1: 10,45,56. ;after sorting
Sub-array 2: 65,78,87. ;after sorting
Both the sub- arrays are merged to give:
10,45,56,58,65,78,87
Ex:
45, 87, 65, 58, 78, 10, 56.
58 is being selected as pivot being the mid value.
Sub-array 1: 10,45,56. ;after sorting
Sub-array 2: 65,78,87. ;after sorting
Both the sub- arrays are merged to give:
10,45,56,58,65,78,87
Similar questions