Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Sorting Arrays--Selection, Bubble, Insertion, Merge and Quick Sorts 109 for (count = 0; count < 20; count++) System.out.print(list[count] + " "); // output unsorted list System.out.println(); System.out.println("Calling QuickSort function"); sort(list,0,19); // call the sort function System.out.println(); System.out.println(" Sorted list "); for (count = 0; count < 20; count++) System.out.print(list[count] + " "); // output sorted list } } Listing 8.9 8.2.5.3 Efficiency of quick sort Quick sort resembles merge sort in that the data set is continually split into two and combined with the exchange of items between the sub-sets. For N elements, the splitting process is log 2 N in terms of effort, whereas the swapping process depends directly on N . This gives a general value of O( N log 2 N ) as for merge sort; however, the actual time taken may be affected by factors such as the choice of pivot value and how well ordered or disordered are the data initially.