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

Sorting, how to do a merge sorting

how to do a merge sorting

Algorithm for finding a key by binary search technique, Q. Write down an al...

Q. Write down an algorithm for finding a key from a sorted list using the binary search technique or method.

Non-recursive algorithm to traverse a tree in preorder, Write the non-recur...

Write the non-recursive algorithm to traverse a tree in preorder.    The Non- Recursive algorithm for preorder traversal is as follows: Initially  push NULL onto stack and

Explain the sum of subset problem, a. Explain the sum of subset problem. Ap...

a. Explain the sum of subset problem. Apply backtracking to solve the following instance of sum of subset problem: w= (3, 4, 5, 6} and d = 13. Briefly define the method using a sta

Inorder and preorder traversal to reconstruct a binary tree, Q. Using the f...

Q. Using the following given inorder and preorder traversal reconstruct a binary tree Inorder sequence is D, G, B, H, E, A, F, I, C

Multiple stack, implement multiple stack in single dimensionl array.write a...

implement multiple stack in single dimensionl array.write algorithms for various stack operation for them

Program, What is a first-in-first-out data structure ? Write algorithms to...

What is a first-in-first-out data structure ? Write algorithms to perform the following operations on it – create, insertion, deletion, for testing overflow and empty conditions.

Data structure- tree, Tree is dynamic data structures. Trees can expand & c...

Tree is dynamic data structures. Trees can expand & contract as the program executes and are implemented via pointers. A tree deallocates memory whereas an element is deleted.

Hashing and five popular hashing functions, Q. Explain the term hashing? Ex...

Q. Explain the term hashing? Explain any five well known hash functions.                         Ans: Hashing method provides us the direct access of record from the f

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