Sie sind auf Seite 1von 17

CERTIFICATE

This to certify that K.BRAHMINI (y8cs215) and G.PUJITHA


(y8cs233) has successfully completed the mini project named
QUICK SORT USING C- GRAPHICS during the academic year 200910.

Project head
D

HO

ACKNOWLEDGEMENT

I sincerely and whole-heartedly express my


gratitude and Indebtedness to our esteemed lecturer SRI
B.VENUGOPAL for giving us the proper guidance in the
preparation of the project.
I take this opportunity to our express my cordial
gratitude to our beloved professor DR. K. RAJASEKHAR
RAO garu. I feel extremely grateful for his guidance.
I am greatly grateful and most obliged to my guide
SRI .B.VENU GOPAL for his great encouragement and
guidance for the successful completion of my project.
Also I would like to thank my group members who
helped me in the proper presentation of the project and
searching the matter from the department library and the
central library.

Project
associates

ABSTRACT

Quick sort is a randomized sorting algorithm based on the divide and


conquers. Quick sort can be implemented to run in place. In the partition step we
use replace operations to rearrange the elements. Quick sort is recursive. So it takes
lot of time to sort small arrays.
C for Graphics is a high-level language. We can use graphics function
included in graphic library to get the output in graphical form. In order to have
graphics we must include required specifications such as graphic header file,
graphic window screen and graphic library.
The source code which we have implemented is applicable to all integer
range values. The performance of the routine is improved by arrays and it is
attractive because of the graphics.

CONTENTS
S.NO
1.
2.
3.

4.
5.

TITLE
ABSTRACT
INTRODUCTION
SYSTEM ANALYSIS
1. Program Interface:
2. Program Execution:
3. Program Structure:
SOURCE CODE
REFERENCE

PAGE.NO
1
2
7
7
7
8
16

INTRODUCTION
Space Complexity:- 1
T(n)wc = O(n2)
Tavg(n) = Twc(n) = O(nlog2n)
It is the fastest known algorithm in practice.
Quicksort is a divide-conquer recursive algorithm.
The basic algorithm to sort an array a consists of the following four easy steps:
1.If the number of elements in a is 0 or 1, then return.
2.Pick any element v in a. This is called the pivot.
3.Partition a- {v}(the remaining elements in s) into two disjoint groups . a1 =
{X a- { v}| x v } and a2 = { x a {v} | x v }
Return { quicksort(a1) followed by v followed by quicksort(a2)}
Picking the pivot:- First /last element
Random number generation
Median of the three Partitioning
Time Complexity :- T(n) = T(i) + T(N-i-1) + cn
i is the no of elements in list a1.
Worst Case :- i =0
T(n) = T(0) + T(n-1) +cn
= T(n-1) +cn
T(n-1) = T(n-2) + c(n-1)
T(n-2) = T(n-3) + c(n-2)
;. :
T(3) = T(2) + c. 3
T(2) = T(1) + c.2
T(n) = T(1) + c. i = O(n2)
i =2
Best Case:- i =n/2
T(n) = 2T(n/2)+cn
T(n) = T(n/2) + c
n n/2
Similar to that of merge sort

T(n) = O(nlog 2 n)
n-1
1/ n T(j) is the average time for one list.
j=0
Average Case:n-1
T(n)= 2/n T(j) +c .n
j=0
n-1
n.T(n) = 2 T(j) +c .n2 ------I
j=0
n-2
(n-1) T(n-1) = 2 T(j) +c .n-1 2 ----II
j=0
I-II : n.T(n) = (n+!) T(n-1) + 2.cn
T(n-1) = T(n-2) + 2c
n + 1 n-1 n +1
::
::
T(n-1) = T(n-2) + 2c
T(n-1) = T(n-2) + 2c
n n-1 n
T(n-2) = T(n-3) + 2c
n n-1 n-1
.....
T(2) = T( 1) + 2c
3 n-2 3
n+1
T(n) T(1) + 2c i/1
n+1 2 i=3
n+1
T(n) = O(log2n) [ . . = loge(n+1) + r- 3 ]
n+1 2
T(n) = O(n log2n)

System analysis
Program Interface:
Here the program has been developed using C language , so a C
Compiler is needed to execute the program .First the source code will be
written over the editor window and then will be saved .Now the program
is compiled to check for errors if any they are corrected .After finishing
the compilation task the program is then executed.
Program Execution:
The basic input to the program will be numbers and that to limited
to range of ordinary integer values. The program provides the user with
basic operation of sorting
After performing the operations the final result will be
the result with desired changes.
Finally after the display of the result control is used to quit from the program.
This brings the user to the editor window where the programmer can make
necessary changes and re-execute the program.
Program Structure:
1.Preprocessor section
2.Function prototypes
3.Global variable declaration
4.Main function
{
A. Local variables
B. Graphic mode initialization
C. Beginning screen ()
D. Main screen ()
E. User input
F. Processing
G. Display output
H. Further processing
}

SOURCE CODE:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graphics.h>

void readlist(int a[],int n);


void printlist(int a[],int n);
void quick_sort(int a[],int n);
void qsort(int a[],int lb,int rb);
void design(int a[],int l,int r);

void design(int a[],int lb,int r)


{
int i,rdw=223,rup=220,cbg=221,cnd=222;
int _color;
/* int gdriver = EGA, gmode = EGAHI, errorcode;
initgraph(&gdriver, &gmode, "c:\\turboc30\\bgi");*/

//FOR PRINTING UPPER STRAIGHT LINE.

for(i=1;i<=r;++i)

printf("%c%c%c%c%c%c",rup,rup,rup,rup,rup,rup);
printf("\n");
printf("%c",cbg);
textbackground ( _color );
if ( _color == 15 )
{
textcolor ( 1 );
}
else
{
textcolor ( 5 );
}

//FOR PRINTING A NUMBER & WALL.


for(i=1;i<=r;i++)
{

textcolor ( 4 );
printf("%2d %c",a[i],cnd); }

printf("\b \b\b%c\n",cnd);
textbackground ( _color );
if ( _color == 10 )
{
textcolor ( 6 );

}
else
{
textcolor ( 9 );
}
//FOR PRINTING LOWER STRAIGHT LINE.
for(i=1;i<=r;i++)
printf("%c%c%c%c%c%c",rdw,rdw,rdw,rdw,rdw,rdw);
printf("\n\n");

//FOR GIVING TIME INTERVAL....//


printf("\nPRESS ANY KEY TO CONTINUE....");
getch();
printf("\r \n");
}

void main()
{
int n, opt, a[20],d,m;
char ch;
textbackground ( 0 );
textcolor ( 5 );
clrscr();

printf("\nenter no of elements:");
scanf("%d",&n);
printf("\nenter the elements in the list:");
readlist(a,n);
quick_sort(a,n);
textbackground ( 6 );
textcolor ( 5 );
getch();
}
void quick_sort(int a[],int n)
{
qsort(a,1,n);
}
void qsort(int a[],int lb,int rb)
{
int i,j,pivot,temp;
if(lb<rb)
{
pivot=a[lb];
i=lb;
j=rb+1;
while(1)
{

i++;
while(a[i]<pivot)
i++;
j--;
while(a[j]>pivot)
j--;
if(i>j)
break;
else
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[lb];
a[lb]=a[j];
a[j]=temp;
puts("\nTHE MODIFIED LIST IS:");
design(a,lb,rb);
qsort(a,lb,j-1);
qsort(a,j+1,rb);
}

puts("\nTHE MODIFIED LIST IS:");


design(a,lb,rb);
}
void readlist(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
puts("\nTHE GIVEN LIST IS:");
design(a,1,n);
puts("\n\nLIST AFTER SELECTING PIVOT:");
/* return; */
}
void printlist(int a[],int n)
{
int i;
for(i=1;i<=n;i++)
{
printf("\n%d",a[i]);
}
/* return; */

REFERENCES
From the guidance of the senior and assistant lecturer our group
collected the matter from the CSE department and also from the IT department.
We also verified the description given by senior professor sir Alfred lozer in the
oxford university on the graphics codes and also studied the lesson written by the
professor S N fried in the Cambridge University. We mainly searched the
Wikipedia for the basic information and for the applications of the quick sort in
graphics. We also surfed the sites of the IITs to find the usage of the graphics in
c code. We also studied the types of representing the graphics in c code and also
in the c++ code. We also referred to the books named graphics under c from
the library.

Das könnte Ihnen auch gefallen