Department: Academic Year: Sem: Subject:: Department of Applied Sciences & Humanities 2020-2021 II)
Department: Academic Year: Sem: Subject:: Department of Applied Sciences & Humanities 2020-2021 II)
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
DIVISION
ROLL NO OF STUDENT
NAME OF STUDENT
ASSIGNMENT NO
10
DATE OF COMPLETION
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
Assignment No. 10
Aim: Write a program to store student information (e.g. Roll No, Name, Percentage etc.).
a) Display the data in descending order of Percentage (bubble sort).
b) Display data for roll no specified by user (linear search).
Objective:
To accept the student information and store it in the structure. Write the c functions to
display the student information according to descending order of percentage and search
the data for given roll no.
Outcomes:
The students will acquainted with bubble sort algorithm and linear search algorithm
Theory :
1. Bubble Sort
Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based
algorithm in which each pair of adjacent elements is compared and the elements are
swapped if they are not in order. This algorithm is not suitable for large data sets as its
average and worst case complexity are of Ο(n2) where n is the number of items.
We take an unsorted array for our example. Bubble sort takes Ο(n2) time so we're
keeping it short and precise.
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
Bubble sort starts with very first two elements, comparing them to check which one is
greater.
In this case, value 33 is greater than 14, so it is already in sorted locations. Next, we
compare 33 with 27.
We find that 27 is smaller than 33 and these two values must be swapped.
Next we compare 33 and 35. We find that both are in already sorted positions.
We know then that 10 is smaller 35. Hence they are not sorted.
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
We swap these values. We find that we have reached the end of the array. After one
iteration, the array should look like this −
To be precise, we are now showing how an array should look like after each iteration.
After the second iteration, it should look like this −
Notice that after each iteration, at least one value moves at the end.
And when there's no swap required, bubble sorts learns that an array is completely
sorted.
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
return 0;
}
2. Linear Search:
This is the simplest method for searching. In this technique of searching, the element to be
found in searching the elements to be found is searched sequentially in the list/array. This
method can be performed on a sorted or an unsorted list (usually arrays). In case of a
sorted list searching starts from 0th element and continues until the element is found from
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
the list or the element whose value is greater than (assuming the list is sorted in ascending
order), the value being searched is reached.
As against this, searching in case of unsorted list also begins from the 0th element and
continues until the element or the end of the list is reached.
Example:
The list given above is the list of elements in an unsorted array. The array contains ten
elements. Suppose the element to be searched is '46', so 46 is compared with all the
elements starting from the 0th element, and the searching process ends where 46 is found,
or the list ends.
The performance of the linear search can be measured by counting the comparisons done
to find out an element. The number of comparison is 0(n).
It is a simple algorithm that searches for a specific item inside a list. It operates looping on
each element O(n) unless and until a match occurs or the end of the array is reached.
Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit
Pseudo code:
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
Conclusion:
The program accepts array of elements and sort it in ascending order.
[Note : Attach the copy of program and output]
Pimpri Chinchwad Education Trust’s
Department: Department of Applied Sciences & Humanities Academic Year: 2020-2021 Sem : II
Questions: