0% found this document useful (0 votes)
22 views20 pages

DSU Report

DSU report

Uploaded by

Akshada Pande
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)
22 views20 pages

DSU Report

DSU report

Uploaded by

Akshada Pande
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/ 20

1

Project Report On

“Develop a C program for All Sorting


Techniques and Searching Techniques
using Switch case(using Function).”

To Submitted

Amrutvahini Polytechnic, Sangamner

Department: - Information Technology

In Partial Fulfillment of the Requirement for the Diploma in

Information Technology

Submitted By

Deshmukh Sahil Pratap (2200800302)


Ambre Pranav Shivaji (2200800306)
Kachare Shreyas Devidas (2200800810)
Karpe Aryan Amit (2200800812)

Under The Guidance Of


Kasar Y.S.

Amrutvahini Polytechnic, Sangamner

(Approved by AICTE, NEW DELHI and Affiliated To MSBTE)

2023-24
2

2023-24

Amrutvahini Polytechnic Sangamner,


Department: -Information Technology

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,

Deshmukh Sahil Pratap (2200800302)


Ambre Pranav Shivaji (2200800306)
Kachare Shreyas Devidas (2200800810)
Karpe Aryan Amit (2200800812)

In Partial Fulfillment of the Requirement for the Diploma In Information Technology

During The Academic year 2023-24

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.

Deshmukh Sahil Pratap (2200800302)


Ambre Pranav Shivaji (2200800306)
Kachare Shreyas Devidas (2200800810)
Karpe Aryan Amit (2200800812)
4

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

Searching and Sorting


1) Rational:
Developing C programs that integrate sorting and searching techniques by
switching cases and functions provides educational value to learners and practical
benefits to programmers. It improves understanding, addresses various
algorithmic requirements, ensures code reusability, facilitates interactive learning,
and prepares users for real-world applications. Overall, this program is a valuable
tool for understanding algorithms and developing practical programming skills.

2.0 Aims/Benefits of the Micro-project:

Aim : Develop a C program for (All Sorting techniques and Searching


Techniques) using Switch case(using Function).

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.

3.0 Course Outcomes:

CI302.1 Explain basic data structures and operations on arrays.


CI302.2 Implement different searching and sorting techniques.
CI302.3 Implement basic operations on stack and queue using array representation.
CI302.4 Implement basic operations on linked list.
CI302.5 Use concept of creating and traversing tree to solve problems.

4.0 Literature Review:

What is Searching :

In the context of the C programming language, searching typically refers to the


process of finding a specific element or value within a data structure, such as an
array or a linked list. C provides several ways to perform searching operations,
depending on the data structure and the requirements of your program.
6

Types of Searching :

1) Linear Search:

 Linear search is the simplest searching algorithm.


 It involves scanning the entire collection of data from start to finish,
comparing each element with the target value.
 Linear search is suitable for unsorted data.
 Time complexity is a O(n).
 Example :

int linearSearch(int arr[], int size, int target) {


for (int i = 0; i < size; i++) {
if (arr[i] == target) {
return i; // Return the index of the target if found
}
}
return -1; // Return -1 if target is not found
}

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;

while (left <= right) {


int mid = left + (right - left) / 2;

if (arr[mid] == target) {
return mid; // Return the index of the target if found
}
7

else if (arr[mid] < target) {

left = mid + 1;
}
else {
right = mid - 1;
}
}
return -1; // Return -1 if target is not found
}
3) Hash Table:

 Hash tables use a hash function to map keys to indices in an array.


 They offer constant-time (O(1)) average-case complexity for search
operations when properly implemented.
 Hash tables are suitable for scenarios where quick lookups are needed, such
as dictionaries or symbol tables.

4) Binary Search Trees (BST):

 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:

 Ternary search is a divide-and-conquer algorithm that works on sorted


data.
 It repeatedly divides the data into three parts and narrows down the search
space.
 While less common than binary search, ternary search can be useful for
certain scenarios.
8

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 :

void bubbleSort(int arr[], int size) {


for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}

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

void selectionSort(int arr[], int size) {


for (int i = 0; i < size - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < size; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}

3) Insertion Sort:

 Insertion sort builds the sorted array one element at a time.


 It iterates through the unsorted portion of the array, taking each element
and placing it in its correct position within the sorted portion.
 Insertion sort has a time complexity of O(n2) but can be efficient for
small datasets.
 Example :

void insertionSort(int arr[], int size) {


for (int i = 1; i < size; i++) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}

4) Quick Sort:

 Quick sort is a divide-and-conquer algorithm that selects a pivot element and


partitions the array into two sub-arrays.
 Elements smaller than the pivot go to the left sub-array, and elements greater than
the pivot go to the right sub-array.
10

 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).

Need of Searching and Sorting :

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.

Database Queries: In applications that involve databases, searching is used to query


and retrieve relevant records based on specified criteria.

Information Retrieval: In information retrieval systems, searching is essential for


finding relevant documents or information based on user queries.

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:

Data Organization: Sorting arranges data in a specific order, making it easier to


search, analyze, and process. For example, sorting a list of names alphabetically allows
for quick name lookup.

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.

Database Indexing: In databases, sorting is used for creating indexes, which


significantly improve query performance by allowing faster data retrieval.

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.

5.0 Actual Methodology Followed:


1. Algorithm:
I. For Searching:
a) Linear Search:
1) Start.
2) Take n element of array input from user.
3) Take element to be search (key element) from user.
4) For all 0 to n-1 position:
i. Compare key element with first case (0 index position) if it is
equal then return element is found as particular position.
5) Otherwise, element is not found.
6) Stop.
b) Binary Search:
1. Start.
2. Take n element of array input from user.
3. Take element to be search (key element) from user.
4. Set lower bound and upper bound to list index position 0 and n-1
respectively.
5. Find out mid position element using (lower bound + upper
bound)/2.
6. Compare mid position element with key element:
a. If mid position element is equal to key element, then return
“Element is found at mid position”.
b. Otherwise, next step.
7. Check mid element is greater than key element or not.
12

a. If mid element is greater than key element then upper


bound equal to mid-1.
b. Otherwise, next step.
8. Repeat from step 5 to 7 until element is found.
9. Stop.
II. For Sorting:
a) Bubble Sort:
1. Start
2. Take input of n number of array from user.
3. Passes is equal to n-1.
4. In each passes
a. Compare first element to second element in the list.
b. If they are not in order(ascending/descending)then
exchange element with each other.(Swapped)
c. Otherwise we compare next element with second
element.
5. Increment pass and repeat step 4 up to end of list.
6. Display sorted array on screen.
7. Stop.
b) Selection Sort:
1. Start.
2. Take n element of array input from user.
3. Pass=n-1.
4. For each pass:
a. Assume 1st element as a smallest element and store
index position of first element into min variable.
b. Compare min index position element with all other
elements in list.
c. If other element is smaller than minimum index position
element then updates minimum variable.
d. Swap minimum element with first element of list.
5. Increment pass and repeat the step 4 each pass.
6. Display sorted list and end.
13

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();
}

6.0 Actual Resources :

Sr.N Instrument/Object Specifications Remark


o
01 Computer system Intel i5 12th gen 16 GB Hp victus , Asus TUF
RAM 512 SSD

02 Software MS word Microsoft Office


03 Any other resources Turbo C or GCC TC
use
17

7.0 Outputs of Micro project:


1. For Linear Search

2. For Binary Search


18

3. For Bubble Sort

4. For Selection Sort


19

5. For Insertion Sort

8.0 Skill developed:

1. Presentation Skill
2. Report Writing
3. Analysis Information
4. Implementation of Program
5. How to execute program

9.0 Applications of Searching :


1) Information Retrieval Systems:
2) Database Management:
3) User Authentication:
4) Symbol Tables:
5) Spell Checkers and Autocorrection:
6) Data Validation:
7) File Systems:
8) Recommendation Systems:
9) Network Routing:
10) Genetic Sequencing:
11) Natural Language Processing (NLP):
12) Resource Management:
13) Game Development:
14) Graph Algorithms:
15) Security and Intrusion Detection:
20

11.0 Applications of Sorting:


1) Database Systems.
2) Search Algorithms.
3) File Management.
4) Information Retrieval.
5) Contact and Address Books.
6) Inventory Management.
7) Financial Applications.
8) Data Deduplication.
9) Statistical Analysis.
10) Algorithm Optimization.
11) Report Generation.
12) Routing and Scheduling.
13) Task Scheduling.
14) Visualization.
15) Game Development.
16) Data Compression.
17) Text Processing.
18) Genomic Data Analysis.
19) Machine Learning and Data Mining.

12.0 Reference/websites :

Data structure using C : Technical Publication


Data structure using C : Techmax Publication

You might also like