Array in C/ C++:- Array declaration by initializing elements:- // Array declaration by initializing elements int arr[] = { 10, 20, 30, 40 } // Compiler creates an array of size 4. // above is same as "int arr[4] = {10, 20, 30, 40}" Advantages of an Array in C/C++: Random access of elements using array index. Use of less line of code as it creates a single array of multiple elements. Easy access to all the elements. Traversal through the array becomes easy using a single loop. Sorting becomes easy as it can be accomplished by writing less line of code. Disadvantages of an Array in C/C++: Allows a fixed number of elements to be entered which is decided at the time of declaration. Unlike a linked list, an array in C is not dynamic. Insertion and deletion of elements can be costly since the elements are needed to be managed in accordance with the new memory allocation. Accessing Array Elements: Array eleme...
Selection Sort Selection sort algorithm sorts an array by reapetly finding the minimum element (considering ascending order) from unsorted port and putting it at the beginning. Complexity of Selection Sort: Time Complexity Best Case: O(n2) Worst Case: O(n2) Space Complexity Worst Case: O(1) Advantages of Selection Sort Selction sort algorithm easy to implement. No additional data-structure is required. It is in-place sorting method & stable method. The number of swap reduced.O(n) swap in all cases. Disadvantages of Selction Sort Best & Worst case efficiency is O(n2). CODE 👇 #include <stdio.h> int comp_cnt=0; int main() { int a[20], n , i; printf("\t>>Selection Sort<<\n"); printf("How many numbers you want in array ?\t"); scanf("%d",&n); printf("\nEnter %d element:",n); accept(a,n); selection_sort(a,n); printf("\t>>Sorted Array<<\n"); display(a,n); printf("\nTotal ...