Sorting (Discussion 10) (Các thuật toán sắp xếp) - Christine Zhou

UN
Uni24h
다운로드 0회
10
0

자료 내용

3쪽

Announcements - Midterm 2 is tomorrow! Check room assignments - Best of luck!! - HW6 due Friday - Project 2 milestone due on Monday, just need to pass the integration tests - No slip hours for this! - You do not need your game fully functioning, remember these integration tests are not comprehensive! - Extra office hours Monday and Wednesday night! 6-8PM - More details to come later

4쪽

Insertion Sort - Have a sorted portion and a non-sorted portion - In the non-sorted portion, pick the first element and “insert” its correct position - Keeping swapping with whatever is to the left - Will be at the right position when the left element is less than the element you are inserting

5쪽

Selection Sort - Scan through the array, always “selecting” the smallest item and bringing it to the front

6쪽

Merge Sort - Split array into two equal partitions - Call mergesort on each of the partitions - Now the partitions are sorted or the partitions are one element - Merge the two halves together - Have pointers to each partitions and combine them so the partitions are now sorted

7쪽

Heapsort - Use a max heap - Algorithm: - Turn elements into a heap, represent with an array - Repeat: remove max and rearrange heap, put max at the end

8쪽

Quicksort - Pick a pivot - Divide array into 3 parts: less than portion, equal to portion, greater than portion - Repeat previous steps on 1st and 3rd if they include more than one element - Runtime: - Average case: 𝚹(NlogN) - Worst case: 𝚹(N^2)

9쪽

Counting Sort - Keep an array called counts that keeps track of the count of each value, go through the entire array and collect the counts - Keep an array called starts and this will tell us where to start for each element, go through the counts and collect the starts - Go through all the elements of the array and place the element where it should belong based on the starts array - Runtime: - N is the number of items in our list, K is the radix - Iterate through the list (N), iterate through the counts (K), iterate through the list again (N) - N + N + K, which is roughly N + K

10쪽

Radix Sort - LSD Radix Sort - Run counting sort on each digit, starting from the least significant digit (right most) - MSD Radix Sort - Run counting sort on each digit, starting from the most significant digit (left most)

앞 10페이지만 표시됩니다. 전체를 보려면 자료를 다운로드하세요.

댓글 (0)

로그인 하여 토론에 참여하기

댓글이 없습니다. 첫 댓글을 남겨보세요!