Program segment for quick sort, Data Structure & Algorithms

Assignment Help:

Illustrates the program segment for Quick sort. It uses recursion.

Program 1: Quick Sort

Quicksort(A,m,n)

int A[ ],m,n

{

int i, j, k;

if m

{

i=m; j=n+1; k=A[m]; do

do

do

++i;

while (A[i] < k);

do

--j;

while (A[j] > k);

if (i < j)

{

temp = A[i];

A[i] = A[j];

A[j] = temp;

}

while (i

temp = A[m];

A[m] = A[j];

A[j] = temp;

Quicksort(A,m,j-1);

Quicksort(A,j+1,n);

}

The Quick sort algorithm uses the O(N Log2N) comparisons on average. The performance can be developed by keeping in mind the following points.

1.         Switch to a faster sorting scheme such as insertion sort while the sublist size becomes comparatively small.

2.      Employ a better dividing element in the implementations.


Related Discussions:- Program segment for quick sort

Collision resolution techniques, complete information about collision resol...

complete information about collision resolution techniques

Post order traversal, Post order traversal: The children of node are vi...

Post order traversal: The children of node are visited before the node itself; the root is visited last. Each node is visited after its descendents are visited. Algorithm fo

Sparse matrix, How sparse matrix stored in the memory of a computer?

How sparse matrix stored in the memory of a computer?

Explain time complexity, Time Complexity:- The time complexity of an algori...

Time Complexity:- The time complexity of an algorithm is the amount of time it requires to run to completion. Some of the reasons for studying time complexity are:- We may be in

Define tractable and intractable problems, Define tractable and intractable...

Define tractable and intractable problems Problems that can be solved in polynomial time are known as tractable problems, problems that cannot be solved in polynomial time are

Heights of 500 students `Algorithms`, Write an algorithm, using a flowchart...

Write an algorithm, using a flowchart, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest p erson in the school.

Explain threaded binary tree, Threaded Binary Tree : If a node in a bin...

Threaded Binary Tree : If a node in a binary tree is not having left or right child or it is a leaf node then that absence of child node is shown by the null pointers. The spac

Determine the components of illumination, Determine the Components of Illum...

Determine the Components of Illumination The light reaching the eye when looking at a surface has clearly come from a source (or sources) of illumination and bounced off the su

DAA, what do we use asymptotic notation in study of algorithm?Describe vari...

what do we use asymptotic notation in study of algorithm?Describe various asymptotic notation and give their significance.

Primitive data structure, Primitive Data Structure These are the basic ...

Primitive Data Structure These are the basic structure and are directly operated upon by the machine instructions. These in general have dissimilar representations on different

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd