DSA Lab Manual(Selection Sort)
DSA Lab Manual(Selection Sort)
int main() {
int n;
cout << "Enter the number of elements: ";
cin >> n;
int arr[n];
cout << "Enter the elements: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
selectionSort(arr, n);
return 0;
}
Execution Steps
1. Input the size of the array and its elements.
2. Display the original array.
3. Call the selectionSort function to sort the array.
4. Display the sorted array.
Input:
Enter the number of elements: 5
Enter the elements: 64 34 25 12 22
Output:
Array before sorting: 64 34 25 12 22
Array after sorting: 12 22 25 34 64
Conclusion
The Selection Sort algorithm is an effective way to sort small datasets. It is easy to understand
and implement but may not be efficient for larger datasets due to its O(n²) time complexity.