Question
JAVA: Integer Arrays sorting SAMPLE OUTPUTS: *Array* before selection sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 2
JAVA: Integer Arrays sorting
SAMPLE OUTPUTS:
*Array* before selection sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 2 at index 1. ---Swap elements at index 0 and 1 -Array after loop where i= 0: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Found next smallest value: 7 at index 6. ---Swap elements at index 1 and 6 -Array after loop where i= 1: [2, 7, 34, 14, 95, 26, 11, 18, 9, 16] --Found next smallest value: 9 at index 8. ---Swap elements at index 2 and 8 -Array after loop where i= 2: [2, 7, 9, 14, 95, 26, 11, 18, 34, 16] --Found next smallest value: 11 at index 6. ---Swap elements at index 3 and 6 -Array after loop where i= 3: [2, 7, 9, 11, 95, 26, 14, 18, 34, 16] --Found next smallest value: 14 at index 6. ---Swap elements at index 4 and 6 -Array after loop where i= 4: [2, 7, 9, 11, 14, 26, 95, 18, 34, 16] --Found next smallest value: 16 at index 9. ---Swap elements at index 5 and 9 -Array after loop where i= 5: [2, 7, 9, 11, 14, 16, 95, 18, 34, 26] --Found next smallest value: 18 at index 7. ---Swap elements at index 6 and 7 -Array after loop where i= 6: [2, 7, 9, 11, 14, 16, 18, 95, 34, 26] --Found next smallest value: 26 at index 9. ---Swap elements at index 7 and 9 -Array after loop where i= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] --Found next smallest value: 34 at index 8. ---Swap elements at index 8 and 8 -Array after loop where i= 8: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] *Array* after selection sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press
*Array* before insertion sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 2 into sorted numbers before 2 ---Swap elements at index 1 and 0 -Array after loop where i= 1: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 34 into sorted numbers before 34 -Array after loop where i= 2: [2, 11, 34, 14, 95, 26, 7, 18, 9, 16] --Insert 14 into sorted numbers before 14 ---Swap elements at index 3 and 2 -Array after loop where i= 3: [2, 11, 14, 34, 95, 26, 7, 18, 9, 16] --Insert 95 into sorted numbers before 95 -Array after loop where i= 4: [2, 11, 14, 34, 95, 26, 7, 18, 9, 16] --Insert 26 into sorted numbers before 26 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 -Array after loop where i= 5: [2, 11, 14, 26, 34, 95, 7, 18, 9, 16] --Insert 7 into sorted numbers before 7 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 ---Swap elements at index 3 and 2 ---Swap elements at index 2 and 1 -Array after loop where i= 6: [2, 7, 11, 14, 26, 34, 95, 18, 9, 16] --Insert 18 into sorted numbers before 18 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 -Array after loop where i= 7: [2, 7, 11, 14, 18, 26, 34, 95, 9, 16] --Insert 9 into sorted numbers before 9 ---Swap elements at index 8 and 7 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 ---Swap elements at index 5 and 4 ---Swap elements at index 4 and 3 ---Swap elements at index 3 and 2 -Array after loop where i= 8: [2, 7, 9, 11, 14, 18, 26, 34, 95, 16] --Insert 16 into sorted numbers before 16 ---Swap elements at index 9 and 8 ---Swap elements at index 8 and 7 ---Swap elements at index 7 and 6 ---Swap elements at index 6 and 5 -Array after loop where i= 9: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]
*Array* after insertion sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press
*Array* before bubble sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] -Starting at index 1, bubbling up highest numbers until index 9 ---Swap elements at index 0 and 1 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 ---Swap elements at index 8 and 9 --Array after loop with i= 1: [2, 11, 14, 34, 26, 7, 18, 9, 16, 95]. -Starting at index 2, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 --Array after loop with i= 2: [2, 11, 14, 26, 7, 18, 9, 16, 34, 95]. -Starting at index 3, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 --Array after loop with i= 3: [2, 11, 14, 7, 18, 9, 16, 26, 34, 95]. -Starting at index 4, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 --Array after loop with i= 4: [2, 11, 7, 14, 9, 16, 18, 26, 34, 95]. -Starting at index 5, bubbling up highest numbers until index 9 ---Swap elements at index 1 and 2 ---Swap elements at index 3 and 4 --Array after loop with i= 5: [2, 7, 11, 9, 14, 16, 18, 26, 34, 95]. -Starting at index 6, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 --Array after loop with i= 6: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 7, bubbling up highest numbers until index 9 --Array after loop with i= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 8, bubbling up highest numbers until index 9 --Array after loop with i= 8: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 9, bubbling up highest numbers until index 9 --Array after loop with i= 9: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95].
*Array* after bubble sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press
*Array* before improved bubble sort: [11, 2, 34, 14, 95, 26, 7, 18, 9, 16] -Starting at index 1, bubbling up highest numbers until index 9 ---Swap elements at index 0 and 1 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 ---Swap elements at index 8 and 9 --Array after loop with k= 1: [2, 11, 14, 34, 26, 7, 18, 9, 16, 95]. -Starting at index 2, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 ---Swap elements at index 7 and 8 --Array after loop with k= 2: [2, 11, 14, 26, 7, 18, 9, 16, 34, 95]. -Starting at index 3, bubbling up highest numbers until index 9 ---Swap elements at index 3 and 4 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 ---Swap elements at index 6 and 7 --Array after loop with k= 3: [2, 11, 14, 7, 18, 9, 16, 26, 34, 95]. -Starting at index 4, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 ---Swap elements at index 4 and 5 ---Swap elements at index 5 and 6 --Array after loop with k= 4: [2, 11, 7, 14, 9, 16, 18, 26, 34, 95]. -Starting at index 5, bubbling up highest numbers until index 9 ---Swap elements at index 1 and 2 ---Swap elements at index 3 and 4 --Array after loop with k= 5: [2, 7, 11, 9, 14, 16, 18, 26, 34, 95]. -Starting at index 6, bubbling up highest numbers until index 9 ---Swap elements at index 2 and 3 --Array after loop with k= 6: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. -Starting at index 7, bubbling up highest numbers until index 9 --Array after loop with k= 7: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95]. Improved bubble sort executed 2 less loops.
*Array* after improved bubble sort: [2, 7, 9, 11, 14, 16, 18, 26, 34, 95] Press
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started