Question

[5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9, 4, 3). Assuming we call the following function using statement selection sort (int array, 7); Please fill the table to show the changes of the array int_array after each iteration. The first column is filled. void selection_sort (int list[], int list_size) for (int i = 0; i < list size - 1; 1++) int current min = list[1]; int current_min_index-i for (int j - i+ 1; jlist size; j++) if (current min > list[j]) Current_min - 1ist [] Current min index- i if (Currentminindex-i) - - list [Currentminindex] = list[i]; list[i] -current min; - -

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Selection sort is a sorting technique in which we select the minimum element from the array repeatedly from unsorted part and putting it at begning.

So, Rule or step for finding the minimum element and sorting them as follows:

1) Select the lowest element in the remaining array

2.) Bring it to the starting position

3.)change the counter for unsorted array by one

2 2. 耳

Add a comment
Know the answer?
Add Answer to:
[5 marks] Using selection sort algorithm to sort the array int array[7]-5, 6, 2, 7, 9,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • Selection sort is often the first sorting algorithm covered in introductory computer science courses. Java code...

    Selection sort is often the first sorting algorithm covered in introductory computer science courses. Java code that uses selection sort to place the elements of an integer array into non-decreasing order is shown here: public void swapNumbers(int i, int j) { ​int temp = numbers[i];​ /* put numbers[i] somewhere to keep it safe */ ​numbers[i] = numbers[j]; /* put numbers[j] at index i */ ​numbers[j] = temp;​ /* put numbers[i] at index j */ } public void selectionSort(int[] numbers) {...

  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...

  • Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8...

    Sorting Sort the following array using the quick sort algorithm: (4 Marks) a. 12 26 8 9 7 0 4 Pivot selection is defined to be the first element of each sub-list. Show the array before and after each quicksort round (when the array is partitioned after placing the pivot at its correct position). Also, clearly highlight the pivot in each partition b. Consider an unsorted array of integers of size n. Write a Java program to arrange the array...

  •   Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first...

      Given a bubble sort and the following array: [10,7,19,5,16] What are the values after the first iteration? Given an insertion sort and the following array: [50,5,35,70,6] What does the array look like after the first insertion:    Fill in the missing code for InsertionSort method // Insertion Sort method //sorts an array of Auto objects public static void insertionSort(Auto [] arr) { Auto temp; int j; for (int i=1; i<arr.length; i++) {     j=i;     temp=arr[i];                while (j!=0 &&(temp.getModel().compareTo(arr[[j-1].getModel())<0)...

  • Implement the bubble sort algorithm described here: While the array is not sorted For each adjacent...

    Implement the bubble sort algorithm described here: While the array is not sorted For each adjacent pair of elements If the pair is not sorted Swap the elements Use the BubbleSorter class to fill in the code and make it run with the BubbleSorterDemo class. BubbleSorter.java public class BubbleSorter {    /** Sort an integer array using the bubble sort algorithm. @param arr array of integers to sort    */    public static void sort(int[] arr)    { // Your...

  • MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First...

    MIPS MIPS MIPS PLEASE INCLUDE COMMENTS AND OUTPUT Sort array using Bubble sort algorithm. 1) First ask the user how many elements of his/her array. 2) Then, read the integer array elements as input from the User. 3) Then, print out the array before the sorting 4) Apply Bubble sort algorithm on your array 5) Print out the array after the sorting 6) Print some welcome text to th user 7) Add comments to your code to describe how is...

  • 6) Assume that we are using quick sort algorithm to sort the following elements in the...

    6) Assume that we are using quick sort algorithm to sort the following elements in the array 26, 15,30,11,8,17 22, 40, 4, 10. Use the first element in the array as pivot. (20 pts.) 1- How total iterations it would take to complete the sorting process? 2- Simulate the entire sorting process. (If you need additional space, complete it at the other side of the paper) public static void quick_sort(intl] a, int left, int right) if (left < right) (...

  • In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 pro...

    In this assignment you will implement merge-sort algorithm by creating 2 threads instead of 2 processes. First half of the array will be sorted by thread 1 and the second half by thread 2. When the threads complete their tasks, the main program will merge the half arrays. You should not waste your time on merge-sort algorithm. Use the merge sort algorithm given below void mergesort(int a[],int i,int j) { int mid; if(i<j) { mid=(i+j)/2; mergesort(a,i,mid); //left recursion mergesort(a,mid+1,j); //right...

  • (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is...

    (15 points) Consider the algorithm for insertion sort shown below. The input to this algorithm is an earray A. You must assume that indexing begins at 1. 1: for j = 2: A.length do key = A i=j-1 while i > 0 and A[i] > key do Ali + 1] = Ai i=i-1 7: A[i+1] = key (a) Follow this algorithm for A[1..4) =< 7,9,6,8 >. Specifically, please indicate the contents of the array after each iteration of the outer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT