COMP2521 - Sorting

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the lower bound efficiency for comparison-based sorting?

n-log n

What are the three main types of order?

random, sorted, reverse

In analysing sorting algorithms, what do N, C, and S denote?

- N: num of items - C: num comparisons between items - S: num times items swapped Want to minimize C and S

What are the main classes of sorting?

- O(n^2) - O(n log n)

What is quicksort?

- Pick a value, then place everything smaller before and everything larger after. - Continue doing this in smaller steps

What are some non-comparative sorting methods?

- Radix sort - Bucket/Pigeonhole sort

What are some comparative sorting methods?

- Selection, bubble, insertion, shell - Merge sort, quick sort - heap

What is insertion sort?

- Take first element and treat as sorted array - Take next element and insert into sorted array

What is radix sort?

- Take the ones digit and place in the same bin, so 461 and 531 would be in the same bin - Sort that bin, create new list - Take the tens digit and place in the same bin, etc.

What is an adaptive sorting algorithm?

- Looks at the input signals - adapts performance based on inputs

What methods are adaptive?

Everything but selection can be adaptive.

What is bubble sort?

- After each pass, the max value goes to the last, next to last, etc. position - You compare every set of 2 values, and the higher value bubbles up to the top

What is merge sort?

- Divide the array into two equal size portions, ultimately dividing them down to individual size portions - Recursively sort each of the partitions into one partition (assumes the two portions are already sorted) - Copy back to original array

What is selection sort?

- Find the smallest element, put in the first slot - Find second smallest, put in second slot

What is bucket/pigeonhole sort?

- For key/value data, when there are multiple values for each key. - Place each value into the corresponding bucket, sort only that bucket.

What is shell sort?

- H-sort the list - Then, insert sort the list

What methods are stable?

Any of them can be made stable.

What is a stable sorting algorithm?

If the values are equal, the order of the value in the initial list are the same

What is heap sort?

You just create a heap, then take largest element, then adjust the heap and take second largest element, etc.


Conjuntos de estudio relacionados

Age Lecture 12-Identity & the Self

View Set

practice test for science unit 3 test

View Set

Chapter 14: Bonds and Long-Term Notes

View Set

International Trade, Transport and Logistics Exam

View Set

Renal, Genitourinary, Reproductive

View Set

9.1 BASIC MATH - BASIC MILL OPERATOR

View Set