DSU Report
DSU Report
Project Report On
To Submitted
Information Technology
Submitted By
2023-24
2
2023-24
Certificate
This is to that the Project Report Entitled,
“ Develop a C program for (All Sorting techniques and Searching Techniques) using Switch case
(using Function).”
Is a Benefited Work Carrier Out By,
Kasar.Y.S Prof.Chaudhari.N.K.
(Project Guide) Hod (IT)
3
ACKNOWLEDGEMENT
We have taken efforts in this project. However, it would not have been possible
without the kind support and help of many individuals and organization.
We would to kind to extend our sincere thanks to all of them.
First and foremost, we want to thanks Prof. Chaudhari N.K H.O.D. (IT)
Amrutvahini polytechnic, Sangamner for giving us an opportunity to work on
this project.
We are highly indebted to Mr.Kasar.Y.S. (Project guide) for his guidance and
constant supervision as well as foe providing Necessary information regarding the project &
also for his support in the Project.
We would like to express our gratitude towards our parents & members of
Information Technology department for their kind co-operation and
encouragement which help us in completion of this Our thanks and appreciations also go to
our colleague in developing
The project and people who have willingly helped us with their abilities.
Index
Sr.No. Contents Page No
1 Rational 5
2 Aims / Benefits 5
3 Course Outcomes 5
4 Literature Review 5
1.What is 5
Searching
2.Types of Searching 6
3. What is Sorting 8
4. Types of Sorting 8
5.Need of Searching and Sorting 10
5 Actual Methodology 11
1. Algorithm 11
2. Program code
13
6 Resources Used 16
7 Outputs 17
8 Skill Developed 19
9 Applications 19
10 Reference 20
5
Report
Benefits : Sorting and searching techniques have a significant impact on our daily
lives, even if we may not always be aware of them. These techniques are essential
in various real-world scenarios, and their benefits extend beyond programming and
computer science.
What is Searching :
Types of Searching :
1) Linear Search:
2) Binary Search :
Binary search is a more efficient searching algorithm but requires that the
data is sorted.
It repeatedly divides the search range in half, making it particularly
effective for large sorted arrays.
Time complexity is a O(logn).
Example :
int binarySearch(int arr[], int size, int target) {
int left = 0;
int right = size - 1;
if (arr[mid] == target) {
return mid; // Return the index of the target if found
}
7
left = mid + 1;
}
else {
right = mid - 1;
}
}
return -1; // Return -1 if target is not found
}
3) Hash Table:
Binary search trees are data structures where each node has two child nodes,
one with a smaller value and one with a larger value.
Searching in a BST has an average time complexity of O(log n), where n is
the number of nodes.
BSTs are often used for maintaining sorted data efficiently.
5) Ternary Search:
What is Sorting :
Sorting in C refers to the process of arranging elements in a specific order within a
collection, typically in ascending or descending order. Sorting is a fundamental
operation in computer science and is used extensively in various applications.
There are several sorting algorithms available in C for different scenarios and data
structures.
Types of Sorting :
1) Bubble Sort:
Bubble sort repeatedly compares adjacent elements and swaps them if they
are in the wrong order.
It continues this process until the entire array is sorted.
Bubble sort has a time complexity of O(n2), making it inefficient for large
datasets.
Example :
2) Selection Sort:
Selection sort divides the array into a sorted and an unsorted region.
It repeatedly selects the minimum (or maximum) element from the
unsorted region and places it in the sorted region.
Selection sort also has a time complexity of O(n2).
Example :
9
3) Insertion Sort:
4) Quick Sort:
Quick sort has an average-case time complexity of O(n log n) and is often faster than
the previous three algorithms for large datasets.
5) Merge Sort:
Merge sort is another divide-and-conquer algorithm that divides the array into two
halves, recursively sorts them, and then merges the sorted halves.
It has a time complexity of O(n logn) in all cases and is stable (maintains the relative
order of equal elements).
Searching and sorting are fundamental operations in computer science and are used in
various applications and scenarios in the C programming language, as well as in
programming in general. Here are the key reasons why searching and sorting are essential
in C and other programming languages:
Searching:
Retrieval of Data: Searching allows you to efficiently locate specific elements within
a data structure, such as an array or a list. This is crucial for retrieving information from
large datasets.
Data Validation: Searching is often used to validate user input. For example,
searching for a username to check if it already exists in a database before allowing
registration.
Algorithms and Data Structures: Many algorithms and data structures rely on
searching operations, including binary search trees, hash tables, and graph traversal
algorithms.
Sorting:
Efficient Searching: Sorted data can be searched more efficiently using algorithms
like binary search, which has a time complexity of O(log n) compared to O(n) for linear
search in unsorted data.
11
Report Generation: Sorting is often used in report generation, where data needs to be
presented in a meaningful and organized manner.
Data Presentation: In user interfaces and visualizations, sorted data is often presented
to users in a way that is easier to understand and navigate.
Optimization: Some algorithms and operations, like merge sort and quicksort, use
sorting as a fundamental step to optimize more complex tasks.
Data Deduplication: Sorting can help identify and eliminate duplicate records in a
dataset.
c) Insertion Sort:
1. Start.
2. Take n element of array input from user.
3. Number of pass=n-1.
4. For each pass:
a) Assume first element of list is sorted and remaining list
is unsorted.
b) Compare first element of unsorted list with sorted list
element.
c) If unsorted list elements smaller than sorted list then
exchange it otherwise place after that element.
5. Repeat step 4 until all element are sorted.
6. Display sorted list.
7. Stop.
2. Program code :
#include<stdio.h>
#include<conio.h>
#define sizemax 100
int a[sizemax],i,n;
void input()
{
printf("\nEnter the size of array:");
scanf("%d",&n);
printf("\nEnter the array elements:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
void output()
{
printf("\nArray is:");
for(i=0;i<n;i++)
{
printf("\t%d",a[i]);
}
}
void search()
{
int ch,key,flag=0,lb,ub,mid;
printf("\nEnter the number to be search:");
scanf("%d",&key);
start:
printf("\n1.Linear Search\n2.Binary Search\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
14
for(i=0;i<n;i++)
{
if(a[i]==key)
{
flag=1;
break;
}
}
if(flag==1)
{
printf("\n%d found at:%d",key,i);
}
break;
case 2:
lb=0;
ub=n-1;
while(lb<=ub)
{
mid=(lb+ub)/2;
if(a[mid]==key)
{
flag=1;
break;
}
else if(a[mid]>key)
{
ub=mid-1;
}
else
{
lb=mid+1;
}
}
if(flag==1)
{
printf("\n%d found at:%d",key,mid);
}
break;
default:
printf("\nWrong choice");
goto start;
}
}
void sort()
{
int tech,j,i,min,temp;
startT:
printf("\n1.Bubble sort\n2.Selection sort\n3.Insertion
sort\n");
scanf("%d",&tech);
switch(tech)
{
case 1:
for(i=0;i<n-1;i++)
{
15
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
break;
case 2:
for(i=0;i<n-1;i++)
{
min=i;
for(j=i+1;j<n;j++)
{
if(a[min]>a[j])
{
min=j;
}
}
if(min!=i)
{
temp=a[min];
a[min]=a[i];
a[i]=temp;
}
}
break;
case 3:
for(i=0;i<n;i++)
{
temp=a[i];
for(j=i-1;j>=0&&a[j]>temp;j--)
{
a[j+1]=a[j];
}
a[j+1]=temp;
}
break;
default:
printf("\nWrong Choice");
goto startT;
}
}
void operation()
{
int op;
startL:
printf("\n1.Searching\n2.Sorting:\n");
scanf("%d",&op);
switch(op)
{
case 1:
search();
16
break;
case 2:
sort();
output();
break;
default:
printf("\nWrong choice");
goto startL;
}
}
void main(){
char c;
clrscr();
do
{
input();
output();
operation();
printf("\nDo you want to do it again:");
scanf("%s",&c);
}while(c=='y'||c=='Y');
getch();
}
1. Presentation Skill
2. Report Writing
3. Analysis Information
4. Implementation of Program
5. How to execute program
12.0 Reference/websites :