Micro Project of Dsu Completed by Me
Micro Project of Dsu Completed by Me
CERTIFICATE
This is to certify that students rahul hirt sisode , Third Semester of Diploma in
Computer Engineering of Brahmdevdada Mane Polytechnic, Belati (Code: 0993) have
submitted the micro-project and defended term work micro-project for the Academic Year
2023-24 as prescribed in the curriculum.
Place: Belati
Date:
• Enrolments no of students
• 1] Rohan Karkale.(2209930071) Enrolment No
2] Mahesh Kasture.
Signature of guide
Algorithm-:
Step 1 − Set MIN to location 0
Step 2 − Search the minimum element in the list
Step 3 − Swap with value at location MIN
Step 4 − Increment MIN to point to next element
Step 5 − Repeat until list is sorted
• For the first position in the sorted list, the whole list is scanned sequentially. The first
position where 14 is stored presently, we search the whole list and find that 10 is the
lowest value.
• So we replace 14 with 10. After one iteration 10, which happens to be the minimum
value in the list, appears in the first position of the sorted list.
• For the second position, where 33 is residing, we start scanning the rest of the list in a
linear manner.
• We find that 14 is the second lowest value in the list and it should appear at the second
place. We swap these values.
After two iterations, two least values are positioned at the beginning in a sorted manner.
The same process is applied to the rest of the items in the array.
Following is a pictorial depiction of the entire sorting process −
Complexity
1. Number of comparisons:(n-1) + (n-2) + (n-3) +.....+ 1 = n(n-1)/2 nearly equals to
n2 Complexity = O(n2)Also, we can analyze the complexity by simply observing
the number of loops. There are 2 loops so the complexity is n*n = n2.Time
Complexities: 1. Worst Case Complexity: O(n2) If we want to sort in ascending
order and the array is in descending order then, the worst case occurs. 2. Best
Case Complexity: O(n2) 3. Average Case Complexity: O(n2) It occurs when the
elements …
1. Time Complexity
Case Time Complexity
Best Case 2
O(n )
Average Case O(n2)
Worst Case O(n2)
o Best Case Complexity - It occurs when there is no sorting required,
i.e. the array is already sorted. The best-case time complexity of
selection sort is O(n2).
o Average Case Complexity - It occurs when the array elements are in
jumbled order that is not properly ascending and not properly
descending. The average case time complexity of selection sort
is O(n2).
o Worst Case Complexity - It occurs when the array elements are
required to be sorted in reverse order. That means suppose you have
to sort the array elements in ascending order, but its elements are in
2. Space Complexity
Space Complexity o(1)
Stable yes
o The space complexity of selection sort is O(1). It is because, in
selection sort, an extra variable is required for swapping.
1. #include <stdio.h>
2.
3. void selection(int arr[], int n)
4. {
5. int i, j, small;
6.
7. for (i = 0; i < n-1; i++) // One by one move boundary of unsorted
subarray
8. {
9. small = i; //minimum element in unsorted array
10.
11. for (j = i+1; j < n; j++)
12. if (arr[j] < arr[small])
13. small = j;
14. // Swap the minimum element with the first element
15. int temp = arr[small];
16. arr[small] = arr[i];
17. arr[i] = temp;
18. }
19. }
20.
21. void printArr(int a[], int n) /* function to print the array */
22.{
23. int i;
24. for (i = 0; i < n; i++)
25. printf("%d ", a[i]);
26.}
27.
28.int main()
29. {
30. int a[] = { 12, 31, 25, 8, 32, 17 };
31. int n = sizeof(a) / sizeof(a[0]);
32. printf("Before sorting array elements are - \n");
33. printArr(a, n);
34. selection(a, n);
35. printf("\nAfter sorting array elements are - \n");
36. printArr(a, n);
37. return 0;
38.}
Output:
1. #include <iostream>
2.
3. using namespace std;
4.
Output:
[END OF LOOP]
Step 4: EXIT
SET pos = j
[END OF if]
[END OF LOOP]