0% found this document useful (0 votes)
112 views26 pages

Ilovepdf Merged

The document appears to be a project report submitted by four students at KL University on a comparative study of sorting techniques. It includes an introduction on sorting algorithms, the aim of the project, software and hardware details, implementations of sorting algorithms like bubble sort, selection sort, quick sort, and merge sort in C language, output screenshots, and a conclusion. The students analyzed different sorting algorithms and compared their time complexities to determine the most efficient ones.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views26 pages

Ilovepdf Merged

The document appears to be a project report submitted by four students at KL University on a comparative study of sorting techniques. It includes an introduction on sorting algorithms, the aim of the project, software and hardware details, implementations of sorting algorithms like bubble sort, selection sort, quick sort, and merge sort in C language, output screenshots, and a conclusion. The students analyzed different sorting algorithms and compared their time complexities to determine the most efficient ones.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

K L UNIVERSITY

FRESHMAN ENGINEERING DEPARTMENT


A Project Based Lab Report

On

Comparative study of sorting Techniques

SUBMITTED BY:

I.D NUMBER NAME


2200033069 M.Akshaya
2200033070 M.Deva Sainath Reddy
2200033071 R.Navadeep Sai
2200033074 P.Satyanarayana Chowdary

UNDER THE ESTEEMED GUIDANCE OF

Dr.LAVANYA

ASSISTANT PROFESSOR

KL UNIVERSITY
Green fields, Vaddeswaram – 522 502
Guntur Dt., AP, India.
DEPARTMENT OF BASIC ENGINEERING SCIENCES

CERTIFICATE

This is to certify that the project based laboratory report entitled


COMPARITIVE STUDY OF SORTING TECHNIQUES submitted by Mr./Ms.
M.Akshaya, M.Deva Sainath Reddy, R.Navadeep Sai, P.Satyanarayana Chowdary
bearing Regd. No 2200033069, 2200033070, 2200033071, 2200033074 to the
Department of Basic Engineering Sciences, KL University in partial
fulfillment of the requirements for the completion of a project based Laboratory
in “Object Oriented Programming” course in I B Tech II Semester, is a bonafide
record of the workcarried out by him/her under my supervision during the
academic year 2022 – 2023.

PROJECT SUPERVISOR HEAD OF THE DEPARTMENT

Dr.LAVANYA Dr.D.HARITHA

ASSISTANT PROFESSOR
ACKNOWLEDGEMENTS

It is great pleasure for me to express my gratitude to our honorable President


Sri. Koneru Satyanarayana, for giving the opportunity and platform with facilities in
accomplishing the project-based laboratory report.

I express the sincere gratitude to our Director Dr. A. Jagdeesh for


his administration towards our academic growth.

I express sincere gratitude to our Coordinator and HOD-BES Dr. D. Haritha for
her leadership and constant motivation provided in successful completion of our
academic semester. I record it as my privilege to deeply thank for providing us
the efficient faculty and facilities to make our ideas into reality.

I express my sincere thanks to our project supervisor Dr.Lavanya for his/her


novel association of ideas, encouragement, appreciation and intellectual zeal which
motivated us to venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who devoted


themselves directly or indirectly to make this project report success.

I.D NUMBER NAME

2200033069 M.Akshaya
2200033070 M.Deva Sainath Reddy
2200033071 R.Navadeep Sai
2200033074 P.Satyanarayana Chowdary
ABSTRACT

Sorting is used for arranging the data in some sequence like increasing
or decreasing order. I have discussed about various sorting algorithm with their
comparison to each other in basis of time complexity and space complexity i n C .
These papers also show running time of algorithm with the help of C language. I have
compared some types of sorting algorithm like insertion sort, selection sort, quick sort,
and bubble sort by comparing time complexity and space complexity.

There are many popular problems in different practical fields of computer


sciences, database applications, Networks and Artificial intelligence. One of these
basic operations and problems is sorting algorithm; the sorting problem has
attracted a great deal of research. A lot of sorting algorithms has been developed
to enhance the performance in terms of computational complexity. there are
several factors that must be taken in consideration; time complexity, stability,
memory space. Information growth rapidly in our world leads to increase developing
sort algorithms.A stable sorting algorithms maintain the relative order of records
with equal keys This paper makes a comparison between the Grouping
Comparison Sort (GCS) and conventional algorithm such as Selection sort, Quick
sort, Insertion sort , Merge sort and Bubble sort with respect execution time to
show how this algorithm perform reduce execution time.
INDEX

S.NO TITLE PAGE NO

1 Introduction 1-2

2 Aim of the Project 3

2.1 Advantages & Disadvantages 3

2.2 Future Enhancments 3

3 Software & Hardware Details 3

4 Implementation 5-14

5 Output/Screenshots 15-20

6 Conclusion 21
Page 1

INTRODUCTION
Sorting
Let p be a list of m elements P1, P2, P3…….Pn in memory. Sorting P means
arranging the content of P in either increasing or decreasing order
i.e.,P1<P2<P3<P4………..<Pn. There are m elements in the list, therefore there is
m! ways to arrange them. B. Sorting Algorithm Sorting algorithm is an important
task for arranging the elements in the list. Comparing the various types of sorting in
this paper on the basis of C and Java.

Bubble Sort
In Bubble sort, each element is compared with its adjacent element. If the first
element is larger than the second one then the position of the element is interchanged,
other it is not changed. Then next element is compared with its adjacent element and
the same process is repeated for all the elements in the array. In bubble sort, the first
pass requires (n-1) comparison to fix the highest element to its location , the second
pass requires (n-2),……,ith pairs requires (n-i) and the last pass requires only one
comparison to be fixed at its proper position. Therefore the total no. of comparisons
are: T(n)= (n-1)+(n-2)+(n-3)+……..+(n-i)+3+2+1=n(n-1)/2 T(n)=O(n^2).The
execution time of Bubble Sort in C is more as compared to Java.
Selection Sort
In selection sort, the first element of array is compared with minimum value of
array and interchanged the position of element. Then element is compared with the next
minimum value of array and the same process is repeated for all elements in the array.
In selection sort makes first pass in (n-1) comparisons, the second pass in (n-2)
comparisons and so on.Total no. of comparison are: T(n)=(n-1)+(n-2)+(n-
3)+,……………,+(n-i)+3+2+1=n(n-1)/2 T(n)=O(n^2) The execution time of
Selection Sort in C is more as compared to Java.
Quick Sort
Quick sort works by partitioning methods for sorting the array. And each
Page 2

partition is in turn sorted recursively. In partition, one element of array is selected as a


pivot value. This pivot value can be the first element of array. The array elements are
grouped into two partition 1. One partition contains elements that are smaller than pivot
value.2.Another partition contains elements that are larger than pivot value. Time
required to partition the array is: O(n). The execution time of Quick Sort in C is more
as compared to java.
Insertion sort
Insertion sort is very similar to selection sort. It is a simple sorting algorithm
that builds the final sorted list one item at a time. It has O (n2) time complexity, It is
much less efficient on large lists than more advanced algorithms such as quick sort,
heap sort, or merge sort. However, insertion sort provides several advantages
Simple implementation and, Efficient for small data sets.
Merge sort
Merge sort is a divide and conquer algorithm .It's Divide the list into
two approximately equal sub lists, Then Sort the sub lists recursively. It has an
O (n log n) Time complexity .merge sort is a stable sort, parallelizes better, and is more
efficient at handling slow-to-access sequential media. Merge sort is often the best
choice for sorting a linked list.
Page 3

AIM

Advantages –

➢ Desired sorting technique can be selected according to one’s choice.


➢ Every step in sorting is displayed for better understanding.

Disadvantages –

➢ Only one array of elements can be taken as input at a time.


➢ All sorting techniques cannot be performed at a time. They can be
performed only one after another.

Future enhancements –

➢ This could help in evaluating the all types of Sorting Algorithms by which
they could easily understand the pros and cons of Sorting algorithms and
also to find the application of these Algorithms in different areas.
Page 4

SYSTEM REQUIREMENTS

➢ SOFTWARE REQUIREMENTS:
The major software requirements of the project are as follows:
Language : Object Oriented Programming
Operating system : Windows Xp or later.

➢ HARDWARE REQUIREMENTS:
The hardware requirements that map towards the software are as follows:

RAM : 8 GB RAM

Processor : Intel i5 8th Generation


Implementation

----------------"BUBBLE SORT"-------------
#include<stdio.h>
void print(int a[], int n) {
int i;
for(i = 0; i < n; i++){
printf("%d ",a[i]);
}
}
void bubble(int a[], int n){
int i, j, temp;
for(i = 0; i < n; i++) {
for(j = i+1; j < n; j++){
if(a[j] < a[i]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void main (){
int n,a[100],i;
printf("Enter no.of elements: ");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Before sorting - \t");
print(a, n);
bubble(a, n);
printf("\nAfter sorting - \t");
print(a, n);
}
-----------------"SHELL SORT"----------------
#include <stdio.h>
void shellSort(int a[], int n) {
for (int k = n / 2; k> 0; k /= 2) {
for (int i = k; i < n; i += 1) {
int temp = a[i];
int j;
for (j = i; j >= k && a[j - k] > temp; j-= k) {
a[j] = a[j - k];
}
a[j] = temp;
}
}
}
void printArray(int a[], int s) {
for (int i = 0; i < s; ++i) {
printf("%d ", a[i]);
}
printf("\n");
}
int main(){
int i,n;
printf(" Enter the number of elements : " );
scanf("%d",&n);
int a[n];
for( i=0 ; i<n ; i++ ) {
printf("Enter the element %d :\t",i+ 1);
scanf(" %d",&a[i]);
}
shellSort(a,n);
printf( "Sorted Array : \n" );
printArray(a,n);
}
---------------"INSERTION SORT"--------------
#include<stdio.h>
void insertion_sort(int arr[],int n){
int i,j,temp;
for(i=1;i<n;i++){
temp = arr[i];
j=i-1;
while(j>=0 && arr[j]>temp){
arr[j+1]=arr[j];
j--;
}
arr[j+1]=temp;
}
}
int main(){
int i,n;
printf("enter the range of elements : ");
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++){
printf("enter the element %d : ",i+1);
scanf("%d",&arr[i]);
}
insertion_sort(arr,n);
for(i=0;i<n;i++){
printf("%d\t",arr[i]);
}
return 0;
}
---------------"QUICK SORT"-------------
#include <stdio.h>
int partition (int a[], int start, int end){
int pivot = a[end];
int i = (start - 1);
for (int j = start; j <= end - 1; j++){
if (a[j] < pivot){
i++;
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
int t = a[i+1];
a[i+1] = a[end];
a[end] = t;
return (i + 1);
}
void quick(int a[], int start, int end){
if (start < end){
int p = partition(a, start, end);
quick(a, start, p - 1);
quick(a, p + 1, end);
}
}
void printArr(int a[], int n){
int i;
for (i = 0; i < n; i++)
printf("%d ", a[i]);
}
int main(){
int i,n;
printf(" Enter the number of elements: ");
scanf("%d",&n);
int a[n];
for( i=0 ; i<n ; i++ ){
printf("Enter the element %d:\t",i+1);
scanf("%d",&a[i]);
}
quick(a,0,n- 1);
printf( "Sorted Array : \n" );
printArr(a,n);
}
--------------"MERGE SORT"---------------
#include <stdio.h>
#include <stdlib.h>
void merge(int arr[], int l, int m, int r){
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
int L[n1], R[n2];
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
i++;
}
else {
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = L[i];
i++;
k++;
}
while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}
void mergeSort(int arr[], int l, int r){
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);

merge(arr, l, m, r);
}
}
void printArray(int A[], int size){
int i;
for (i = 0; i < size; i++)
printf("%d ", A[i]);
printf("\n");
}
int main(){
int i,n;
printf(" Enter the no.of elements : " );
scanf("%d",&n);
int arr[n];
for( i=0 ; i<n ; i++ ) {
printf("Enter the element %d : ",i+1);
scanf(" %d",&arr[i]);
}
mergeSort(arr, 0, n - 1);
printf("\nSorted array is \n");
printArray(arr, n);
return 0;
}

----------------Menu Driven Program for Different Sortings----------------


#include <stdio.h>
void bubbleSort(int arr[], int n);
void selectionSort(int arr[], int n);
void insertionSort(int arr[], int n);
void quickSort(int arr[], int low, int high);
void mergeSort(int arr[], int l, int r);
void merge(int arr[], int l, int m, int r);
int main() {
int arr[10], ch, i;
printf("1. Bubble Sort\n2. Selection Sort\n3. Insertion Sort\n4. Quick Sort\n5.
Merge Sort\n");
printf("Enter Required Sorting Technique: ");
scanf("%d", &ch);
printf("Enter 10 Elements: ");
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
printf("\n");
switch (ch) {
case 1:
printf("Bubble Sort\n");
bubbleSort(arr, 10);
break;
case 2:
printf("Selection Sort\n");
selectionSort(arr, 10);
break;
case 3:
printf("Insertion Sort\n");
insertionSort(arr, 10);
break;
case 4:
printf("Quick Sort\n");
quickSort(arr, 0, 9);
for (i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
printf("\n");
break;
case 5:
printf("Merge Sort\n");
mergeSort(arr, 0, 9);
for (i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
printf("\n");
break;
default:
printf("Invalid Input\n");
break;
}
return 0;
}
Page 18

INTEGRATION AND SYSTEM TESTING


OUTPUTS

Screen Shots:
Page 19
Page 20
Page 21
Page 22
Page 23
Page 24

CONCLUSION
In this study I have studied about various sorting algorithm and comparison on
the basis of time complexity, execution time and C & Java languages. I used to the C
and Java program for finding the execution time in second. I observe that when
compare all the sorting algorithms to each other then find the execution time of quick
sort algorithm is best to others and also observe that the execution time of all sorting
algorithms in java is best .

You might also like