Write down the algorithm of quick sort, Data Structure & Algorithms

Assignment Help:

Write down the algorithm of quick sort.

An algorithm for quick sort:
void quicksort ( int a[ ], int lower, int upper )
{
 int i ;
 if ( upper > lower ) {
  i = split ( a, lower, upper ) ;
  quicksort ( a, lower, i - 1 ) ;
  quicksort ( a, i + 1, upper ) ; }
}
int split ( int a[ ], int lower, int upper ){
 int i, p, q, t ;


 p = lower + 1 ;
 q = upper ;
 i = a[lower] ;
 while ( q >= p )
 {
  while ( a[p] < i )
   p++ ;
  while ( a[q] > i )
   q-- ;
  if ( q > p )
  {
   t = a[p] ;
   a[p] = a[q] ;
   a[q] = t ;
  }
 }
 t = a[lower] ;
 a[lower] = a[q] ;
 a[q] = t ;
 return q ; }


Related Discussions:- Write down the algorithm of quick sort

Properties of red- black tree, Any Binary search tree has to contain follow...

Any Binary search tree has to contain following properties to be called as a red- black tree. 1. Each node of a tree must be either red or black. 2. The root node is always b

Explain expert system, 1. What is an expert system and where are they need...

1. What is an expert system and where are they needed? 2. What are the major issues involved in building an expert system?

Sparse matrix, what are the disadvantages of sparse matrix?

what are the disadvantages of sparse matrix?

Logic circuits, the voltage wave forms are applied at the inputs of an EX-O...

the voltage wave forms are applied at the inputs of an EX-OR gate. determine the output wave form

Array, how to define the size of array

how to define the size of array

Arrays and pointers, C compiler does not verify the bounds of arrays. It is...

C compiler does not verify the bounds of arrays. It is your job to do the essential work for checking boundaries wherever required. One of the most common arrays is a string tha

Stack making use of the linked list, Q. Implement a stack making use of the...

Q. Implement a stack making use of the linked list. Show the PUSH and POP operations both. A n s . Stack implemantation using linked list # include # include

Circular linked list, In a circular linked list There is no beginning a...

In a circular linked list There is no beginning and no end.

Generate a single sorted list of all n elements, Q. Assume that we have sep...

Q. Assume that we have separated n elements in to m sorted lists. Explain how to generate a single sorted list of all n elements in time O (n log m )?

5/10/2013 5:08:29 AM

Thanks for suggesting me this answer, appreciate your knowledge

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