In: Computer Science
6. Given the following array of characters: REALITYSHOWShow how this array will be sorted with the help of : (a) insertion sort; (b) selection sort; (c) bubble sort with swaps counting; (d) bubble sort without swaps counting
subject design and analysis of algorithms
answer should be like eg p u r p l e
p r u p l e
i) Insertion Sort
Pass 0:
R E A L I T Y S H O W
[Unsorted]
Pass 1:
E R A L I T Y S H O W
Pass 2:
A E R L I T Y S H O W
Pass 3:
A E L R I T Y S H O W
Pass 4:
A E I L R T Y S H O W
Pass 5:
A E I L R S T Y H O W
Pass 6:
A E H I L R S T Y O W
Pass 7:
A E H I L O R S T Y W
Pass 8:
A E H I L O R S T W Y
[Sorted]
ii) Selection Sort
Pass 0:
R E A L I T Y S H O W
[Unsorted]
Pass 1:
A E R L I T Y S H O W
Pass 2:
A E H L I T Y S R O W
Pass 3:
A E H I L T Y S R O W
Pass 4:
A E H I L O Y S R T W
Pass 5:
A E H I L O R S Y T W
Pass 6:
A E H I L O R S T Y W
Pass 7:
A E H I L O R S T W Y
[Sorted]
iii) Bubble Sort with swap counting
Pass 0:
R E A L I T Y S H O W
[Unsorted]
Pass 1:
E A L I R T S H O W Y
Pass 2:
A E I L R S H O T W Y
Pass 3:
A E I L R H O S T W Y
Pass 4:
A E I L H O R S T W Y
Pass 5:
A E I H L O R S T W Y
Pass 6:
A E H I L O R S T W Y
Pass 7:
A E H I L O R S T W Y
Pass 8:
A E H I L O R S T W Y
Pass 9:
A E H I L O R S T W Y
Pass 10: A E H I L O R
S T W Y [Sorted]
Total swaps: 19
iv) Bubble Sort without swap counting
Pass 0:
R E A L I T Y S H O W
[Unsorted]
Pass 1:
E A L I R T S H O W Y
Pass 2:
A E I L R S H O T W Y
Pass 3:
A E I L R H O S T W Y
Pass 4:
A E I L H O R S T W Y
Pass 5:
A E I H L O R S T W Y
Pass 6:
A E H I L O R S T W Y
Pass 7:
A E H I L O R S T W Y
Pass 8:
A E H I L O R S T W Y
Pass 9:
A E H I L O R S T W Y
Pass 10: A E H I L O R
S T W Y [Sorted]