QUICK SORT


QUICK SORT

1.1        OBJECTIVE:
Sort a given set of elements using the Quick sort method and determine the time required to sort the elements. Repeat the experiment for different values of n, the number of elements in the list to be sorted and plot a graph of the time taken versus n. The elements can be read from a file or can be generated using the random number generator.

1.2        RESOURCES:

            Dev C++ or C

1.3        PROGRAM LOGIC:

QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. 

There are many different versions of QuickSort that pick pivot in different ways.
1.       Always pick first element as pivot.
2.       Always pick last element as pivot (implemented below)
3.       Pick a random element as pivot.
4.       Pick median as pivot.

The key process in QuickSort is partition. Target of partitions is, given an array and an element x of array as pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. 

1.4        PROCEDURE: 

1.      Create: Open Dev C++, write a program after that save the program with .c extension.
2.      Compile: Alt +  F9
3.      Execute: Ctrl + F10

1.5        SOURCE CODE: 

   
<script src="https://ideone.com/e.js/9UhC6F" type="text/javascript" ></script>


1 comment:

  1. Discover the best Full Stack Developers in the USA for comprehensive, end-to-end solutions. Our skilled professionals master both front-end and back-end technologies, delivering seamless web and app development. From user interfaces to server architecture, trust us to bring your digital visions to life with expertise and innovation.

    ReplyDelete