Question

Which sorting algorithm works by iterating through an input array a, and swapping a[i] with a[x], where i starts at 0 and end

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

The answer is Selection sort

example :

arr[] = 50 64 12 21 11

find the minimum element in arr[0...4] and place it in the beginning of arr[0...4]

after 1st pass the array would be : 11 64 12 21 50

find the minimum element in arr[1...4] and place it in the beginning of arr[1...4]

after 2nd pass : 11 12 64 21 50

like this the final array is 11 12 21 50 64

Add a comment
Know the answer?
Add Answer to:
Which sorting algorithm works by iterating through an input array a, and swapping a[i] with a[x],...
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
  • Question 27 (Mandatory) (1 point) Which sorting algorithm uses the following pseudocode: For each new, unsorted...

    Question 27 (Mandatory) (1 point) Which sorting algorithm uses the following pseudocode: For each new, unsorted value v in an array, search backward through already sorted values in the array. Move values until a proper position is found for v. Place v in its correct position. Bogo Sort Selection Sort Insertion Sort Ascending Sort Bubble Sort

  • Bubble sort is a popular, but inefficient, sorting algorithm. It works by repeatedly swapping adjacent elements...

    Bubble sort is a popular, but inefficient, sorting algorithm. It works by repeatedly swapping adjacent elements that out of order. BUBBLESORT(A) 1. for i = 1 to A.length – 1 2. for j = i + 1 to A.length 3. if A[j] < A[i] 4. exchange A[j] with A[i] a) A loop invariant for the outer for loop in lines 1 – 4 is: At iteration i, the sub-array A[1..i] is sorted and any element in A[i+1..A.size] is greater or...

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

    I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...

  • 1. Compare and contrast: SORTING -a bubble sort through an array -a selection sort through an...

    1. Compare and contrast: SORTING -a bubble sort through an array -a selection sort through an array Explain how each works and what the advantages and disadvantages are. Note the efficiency of each. 2. Compare and contrast: SEARCHING -a sequential search through a file -a sequential search through an array -a binary search through an array Explain how each works and what the advantages and disadvantages are. Note the efficiency of each.

  • Please come up with an array of 9 random integers then sort the array. Show the...

    Please come up with an array of 9 random integers then sort the array. Show the contents of the array each time a sorting algorithm changes it while sorting the array into ascending order. The 6 sorting algorithm we are using are: 1. Selection Sort 3 points 2. Insertion Sort 3 points 3. Shell Sort 6 points 4. Bubble Sort 3 points 5. Merge Sort 10 points 6. Quick Sort 10 points It is OK to do this assignment on...

  • For each of the sorting algorithms specified, you will show how the algorithm works on the...

    For each of the sorting algorithms specified, you will show how the algorithm works on the given data set. As you work through each sort, KEEP TRACK OF THE NUMBER OF SWAPS THAT ARE MADE BY THE ALGORITHM. BE SURE THAT YOU COUNT ALL SWAPS! See the lecture slides online for more information. (a) For the data below, show the order of the data in the array at the end of each iteration of selection sort. Circle the items that...

  • Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent...

    Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. Example: First Pass: ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4 ( 1 4 5 2 8...

  • Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is...

    Programming language: Java Home Work No.2 due 09.11.2019 either ascending or descending SORTING: An array is said to be ordered if its values order. In an ascending ordered array, the value of each element is less than or equal to the value of the next element. That is, [each element] <= [next element]. A sort is an algorithm for ordering an array. Of the many different techniques for sorting an array we discuss the bubble sort It requires the swapping...

  • 1. Which is the best sorting algorithm for larger arrays if all the items can not...

    1. Which is the best sorting algorithm for larger arrays if all the items can not fit in main memory? selection sort insertion sort quicksort Merge sort 2. Which sorting algorithm sorts items without comparing them? quick sort radix sort merge sort Insertion sort 3 What is the average running time for quicksort? O(n2) O(logn) O(nlogn) O(n) O(n2logn) 4. Examine the steps of the following algorithm and write the name of the algorithm described in the blank provided: Recursively divide...

  • 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...

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