For the following array x, show x after each of the first two passes of simple s
ID: 3626514 • Letter: F
Question
For the following array x, show x after each of the first two passes of simple selection arrange the elements in ascending order For the following array x, below x after each of the flrst two panes of bubble sort to arrange the elements in descending order. How many passes will bubble sort male altogether? In what situation will bubble sort make the moil interchanges? Linear insertion sort has just correctly positioned x[3] in the following array x. Show, after, each of x[4] and x[5] is correctly positioned In what situation will linear insertion sort make the fewest interchanges? Several of the following ask you to write functions by writing correct programs as instructed in programing problems. 1-6 at the end of this chapter.Explanation / Answer
A simple selection sort algorithm finds the minimum value in a list (array), and then swaps it with the first value in the list. So on the first pass, with 10 being the miniumum, x[4] would be swapped with x[1] 30. The next lowest value is 30 which is now in the x[4] spot, and it would be moved to x[2]. 2.a) A bubble sort looks at two adjacent items in the array and swaps them if they are in the wrong order. the first pass would look at x[1] and x[2], since 60 is bigger than 50 they would be switched. the second pass would look at x[2] and x[3] since they are in the right order, nothing would be switched in the second pass. b.) after it makes a pass, it goes back to the beginning to check again. Count the number of swaps it makes. c.) the most interchanges would occur where the items were in descending order since it would have to go through adjacent pairs and swap them through every spot until its in order 3.insertion sort looks at each item and puts it in the order in the sorted list, it would look at the second item first, and if it is larger than the first, it would stay in the same place, otherwise it'd be inserted before the first item. It would then look at the next item, and then compare it to each item preceding it and put it in the correct place. Use this information to answer the question. The best case scenario is a nearly sorted list. This would require the fewest interchanges