Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Human Sorting” It’s a “Problem Solving” game:

Similar presentations


Presentation on theme: "“Human Sorting” It’s a “Problem Solving” game:"— Presentation transcript:

1 “Human Sorting” It’s a “Problem Solving” game:
Students are divided into teams. Each team works on the given problem independently and look for the best solution that they can come up with. Each team presents its solution to the other teams. . CS331 D. & A. of Algorithms

2 Problem: Given a list of n numbers, sort them in
non-increasing (descending) order Game: For each team Sort your team (e.g. 2 rows each) in descending order by using the assigned sorting algorithms (either Selection Sort, Bubble Sort, Merge Sort, or Quick Sort). The output should have the tallest person on the front seat (seat #1), the second tallest person on the second seat (seat #2), and so on. (2) How many comparisons are needed in your solution? n – number of persons in your team . CS331 D. & A. of Algorithms

3 One way (Algorithm) to do it
Repeat the process of finding the tallest person in your team. Called “Selection Sort” 1 st time: find the tallest person in your team, put him on the front seat, take this person off the team. (n-1 comparisons) 2 nd time: find the tallest person in your remaining team, put him on the 2 nd seat, take this person off the team. (n-2 comparisons) n-1 th time: find the tallest person in your remaining team, put him on the n-1 th seat, take this person off the team. (1 comparisons) n th time: just one person left, put him on the last seat. (0 comparison)   total # of comparisons: (n–1) + (n-2) + … = n(n-1)/2 . CS331 D. & A. of Algorithms

4 Another way (Algorithm) to do it
Repeat the process of bubbling the the tallest person in your team up the row. Called “Bubble Sort” 1 st time: bubble up the tallest person in your team, have him on the front seat, take this person off the team. (n-1 comparisons) 2 nd time: bubble up the tallest person in your remaining team, have him on the 2nd seat, take this person off the team. (n-2 comparisons) n-1 th time: bubble up the tallest person in your remaining team, put him on the n-1 th seat, take this person off the team. (1 comparisons) n th time: just one person left, put him on the last seat. (0 comparison)   total # of comparisons: (n–1) + (n-2) + … = n(n-1)/2 . CS331 D. & A. of Algorithms

5 List List#1 List#2 Called “Merge Sort”
Another way (Algorithm) to sort your team “Divide-and-Conquer Method” List List#1 List#2 n elements n/2 elements n/2 elements You can repeat this process repeatedly until their sizes are small enough. Then sort it directly. Called “Merge Sort” Number of comparisons required is in the order of n  log2n Sort List#1 Sort List#2 Sorted list of list#1 Sorted list of list#2 (n/2 elements) (n/2 elements) Sorted list of the original list (n elements) Merge them . CS331 D. & A. of Algorithms

6 List Pivot List#1 List#2 Called “Quick Sort”
Another way (Algorithm) to sort your team “Divide-and-Conquer Method” List Pivot List#1 List#2 n elements larger List Smaller List You can repeat this process repeatedly until their sizes are small enough. Then sort it directly. Called “Quick Sort” Number of comparisons required is in the order of n2 Sort List#1 Sort List#2 Sorted list of list#1 Pivot Sorted list of list#2 Sorted list of the original list (n elements) . CS331 D. & A. of Algorithms


Download ppt "“Human Sorting” It’s a “Problem Solving” game:"

Similar presentations


Ads by Google