(Recursive Selection Sort) A selection sort searches an array looking for the smallest element in the array. When that element is found, it’s swapped with the first element of the array. The process is then repeated for the subarray, beginning with the second element. Each pass of the array results in one element being placed in its proper location. This sort requires processing capabilities similar to those of the bubble sort—for an array of n elements,
Program Plan-
- Define Header files.
- Define selectionSort()function.
- Define local variables.
- Checking the condition using for() loop till the iteration i is less than 6.
- Display result.
- Checking the condition using if-else() loop.
- Checking the second element with first element.
- Declare main() function.
- Declare local variable.
- Checking the condition using for() loop till the iteration i is less than 6
- Calling selectionSort() function.
- Return successfully to main().
Summary Introduction- (Recursive Selection Sort)A selection sort searches an array looking for the smallest element in the array. When the element is found, it is swapped with the first element of the array. The process is repeated for the sub-array beginning with the second element of the array. Each pass of the array results in one element being placed in its proper location. This sort requires processing capabilities similar to those of bubble sort.
Program Description- The purpose of the program is to implement the recursive selection sort.
Explanation of Solution
Modified program:
/* *This program to implement the recursive selection sort. */ #include<stdio.h> //recursive definition for selcetion sort void selectionSort ( int a[], int size, int i, int j) { //declare local variable int temp; //checking the condtion using if-else loop if(i==size) { //iteration gets executed till value of i is less than 6 for(i=0; i<6; i++) //Displaying result printf("%d ",a[i]); return; //return successfully } else { //checking the condition using if-else() loop if(j<size) { //checking the second element with first //element if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } //function call //calling function with parameters selectionSort(a,size,i,j+1); } else { //function call selectionSort(a,size,i+1,i+1); } } } //Define main() function int main(int argc, char *argv[]) { //Declare local variables int arr[6],i,min,j,temp; printf("Enter the elements of array\n"); //Asking user to enter elements //Executing for() loop for (i=0; i<6; i++) { printf("Element %d: ",i+1); scanf("%d",&arr[i]); } //sorting the value selectionSort(arr,6,0,1); return 0; //return successfully }
Sample Output-
Sample Output:
Enter the element of array
Element 1:37
Element 2:2
Element 3:6
Element 4:4
Element 5:89
Element 6:8
2 4 6 8 37 89
Want to see more full solutions like this?
Chapter D Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Software Engineering (10th Edition)
Starting Out with Python (4th Edition)
Java How To Program (Early Objects)
- Recursivle function to sort two arrays into one in cppExample : Array1[ 1,4,5,2,7,9] , Array2[ 10,3,6] , SortedArray[1,2,3,4,5,6,7,9,10]arrow_forwardNote : Don't Explain .arrow_forwardThe first element in each array is accessed with index number 0. (e.g., array[0]). Select one: True Falsearrow_forward
- Multidimensional Array Enhanced For-loop Input Scanner method using Case-statements Simple AI as machine input 1. Declare a multidimensional array of char to draw a table -+-- -+-+- 2. Use the enhanced for-loop to display the table for (char[] row:charName) for (char c:row) System.out.print(c); } System.out.println (); 3. Initialize some value (inside the table) in the array charName [0] [0] '1'; 4. Using Scanner for user input and case statement to put some character inside the table Scanner scan = new Scanner (System.in); int pos = scan.nextInt (); 5. Create some method/function to be used to add functionality to the application program. 6. Add simple AI (for machine input) 7. Using Arraylist to scan patterns in the multidimensional array.arrow_forwardProgramming Language:- Carrow_forwardProgramming language : Swiftarrow_forward
- Sort an array RECURSIVELY using the insertion sort algorithm. (USE PYTHON and make sure your code has the methods invoked through test statements.)arrow_forwardPython Coding Exercise: Write a function that takes three parameters: a 2-D array arr, a row location i, a column location j and returns a float representing the fraction of neighbors around arr [i,j] # write your function here:def find_frac(arr,i,j):arrow_forward[MATLAB] Code the algorithm that calculates the convolution of two discrete-time signals (x[n] and y[n]) received from the user in MATLAB. The built-in convolution function will not be used. Example: myconv(x,n, y,m) : n and m are the numbers of elements in the array.Example: x[n] = [1 2 3] , y[n] = [1 2 3] Result= [1 4 10 12 9] : Underlined and bold values are n=0 point.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage