(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)
- Java programarrow_forwardWhat are the advantages and disadvantages of using an unordered array as opposed to an ordered one?arrow_forwardThe given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and selection sort respectively are, a) 5 and 4 b) 4 and 5 c) 2 and 4 d) 2 and 5arrow_forward
- arl = np.array([10,20,30,40]) ar2 = np.array([15,6,7]) np.vstack ( (arl,ar2)) The np.stack() function above will O a. Give error b. Stack the two arrays ar1 and ar2 horizontally c. Stack the two arrays ar1 and ar2 vertically O d. Sums the two arrays art and ar2arrow_forwardMultiply left and right array sum. Basic Accuracy: 54.29% Submissions: 12630 Points: 1 Pitsy needs help in the given task by her teacher. The task is to divide a array into two sub array (left and right) containing n/2 elements each and do the sum of the subarrays and then multiply both the subarrays. Example 1: â€arrow_forwardThe first element in each array is accessed with index number 0. (e.g., array[0]). Select one: True Falsearrow_forwardMultidimensional 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_forwardIn main() for now: do these - one at a time, each in it's own loop (we will make functions out of them later –Declare an array RandArray with 20 integers –Assign each of the 20 values with a random value from 0 to 99 Hint: Use rand()%100 For mimir: Do not call srand at the top of main. // normally: Call srand(time(0)) at the top of main –(you need #include<cstdlib>) –Write another loop that prints the array, with index values Important: If the output values do not match mimir, please add srand(17); // inside your main function - at the top code format: #include <iostream>using namespace std; #include <cstdlib> // required for rand() int main(){ srand(17); // define a constant ARRAYSIZE that is 20 // declare randArray // set the 20 elements in randArray to be a random number between 0 and 99 // hint: use rand()%100 // print the 20 values return 0;}arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- 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