20 5 24 15 13 17 3 31
1.bubble sort
2.merge sort
Algorithms.. Pa help po
Share
20 5 24 15 13 17 3 31
1.bubble sort
2.merge sort
Algorithms.. Pa help po
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Answer:
Bubble sort is a simple sorting algorithm that works by repeatedly iterating through the list of items, comparing adjacent pairs of items and swapping them if they are in the wrong order. This process is repeated until no more swaps are needed, at which point the list is sorted.
Here is an example of how bubble sort might work on the list of integers you provided:
20 5 24 15 13 17 3 31
5 20 24 15 13 17 3 31
5 20 15 24 13 17 3 31
5 13 20 15 24 17 3 31
5 13 15 20 24 17 3 31
5 13 15 17 20 24 3 31
3 5 13 15 17 20 24 31
3 5 13 15 17 20 24 31 (no swaps needed, so the list is now sorted)
Merge sort is a more efficient sorting algorithm that works by dividing the list of items into smaller sublists, sorting each sublist, and then merging the sorted sublists back together. The merge sort algorithm uses a divide and conquer approach, which means it keeps dividing the list in half until each sublist consists of a single element, and then it merges the sublists back together in a way that results in a fully sorted list.
Here is an example of how merge sort might work on the list of integers you provided:
Step 1: Divide the list into two sublists: [20, 5, 24] and [15, 13, 17, 3, 31]
Step 2: Sort each sublist: [5, 20, 24] and [3, 13, 15, 17, 31]
Step 3: Merge the sorted sublists: [3, 5, 13, 15, 17, 20, 24, 31]