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

Circularly linked lists implementation, CIRCULARLY LINKED LISTS IMPLEMENTAT...

CIRCULARLY LINKED LISTS IMPLEMENTATION A linked list wherein the last element points to the first element is called as CIRCULAR linked list. The chains do not specified first o

Deletion of any element from the queue, Program segment for the deletion of...

Program segment for the deletion of any element from the queue delmq(i)  /* Delete any element from queue i */ { int i,x; if ( front[i] == rear[i]) printf("Queue is

Make adjacency matrix for un-directed graph, Q. Describe the adjacency matr...

Q. Describe the adjacency matrix and make the same for the given undirected graph.    Ans: The representation of Adjacency Matrix: This representation consists of

Number of leaf nodes in a complete binary tree, The number of leaf nodes in...

The number of leaf nodes in a complete binary tree of depth d is    2 d

Life science, Define neotaxonomy. Discuss how electron microscopy can help ...

Define neotaxonomy. Discuss how electron microscopy can help in solving a zoological problem faced by taxonomist.

Explain about the containers, Containers Introduction Simple abstr...

Containers Introduction Simple abstract data types are useful for manipulating simple sets of values, such as integers or real numbers however more complex abstract data t

Deletion of a node from an avl tree, For AVL trees the deletion algorithm i...

For AVL trees the deletion algorithm is a little more complicated as there are various extra steps involved in the deletion of node. If the node is not a leaf node, then it contain

Graph, Multilist Representation of graph

Multilist Representation of graph

Program, insertion and deletion in a tree

insertion and deletion in a tree

Design and test a reference array, Instructions Design and test a r...

Instructions Design and test a reference array. Reference array stores the references to user supplied objects of different types. Just think it as a heterogeneous array wh

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