COEN: Sorting Algorithms

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

What is the algorithmic complexity of shell sort? What is the space overhead?

O(n¹⁻²⁵) (1.25). Space O(1)

What is the algorithm for insertion sort?

Remove an element from the data. Then, insert the element into its correct position in the already sorted list until no unsorted elements remain. Sorting is done in place.

What are selection sorts?

Selection sorts' select the smallest item and place it into a sorted list. They repeat this step until all of the data has been sorted.

What is the algorithmic complexity of bubble sort? What is the space overhead?

Best O(n), Average O(n²), Worst O(n²). Space O(1)

What are exchange sorts?

Exchange sorts exchange elements that are out of order until the entire list is sorted.

When should you use merge sort?

When stability is required, when sorting linked lists, and when random access is much more expensive than sequential access (for example, external sorting on tape).

What is the algorithm for selection sort?

1. Find the minimum value in the list 2. Swap it with the value in the current position. 3. Repeat the process until all elements in the array are sorted.

What is quick sort? What is the algorithm for it?

An exchange sort in which a pivot key is placed in its correct position in the array while rearranging other elements widely dispersed across the list. Each iteration partitions elements based on their relation to the pivot: Less than, greater than, or equal to. After, sorting continues by quick sorting the left and right partitions. Quicksort is not stable.

What is shell sort?

An insertion sort where a list of N elements is divided into K segments (the increment). Starts with the first element in the array and progresses through the array, comparing adjacent elements in each segment.If the elements are out of sequence, they are exchanged. Not stable.

Is insertion sort a stable algorithm? Why or why not?

Insertion sort is a stable algorithm because it only does exchanges of items adjacent to one another. It maintains the relative order of the data if the keys are the same.

What are insertion sorts?

Insertion sorts insert one or more pieces of data into their correct location in an ordered list.

Is selection sort a stable algorithm? Why or why not?

No it is not a stable algorithm. Multiple pairs of doubles will make selection sort an unstable algorithm.

When should you use radix sort?

Useful for large lists with short keys.

Why is quick sort not stable?

Quick sort is not stable because the item you place at the pivot is selected from somewhere (can be anyhere). By moving it you've changed the order relative to the items equal to it.

When should you use quick sort?

Quicksort is useful as a general purpose sort. It has low overhead and is adaptive.

What is tree(AVL) sort? Is it stable?

Builds a binary search tree and then traverses the tree in order. Tree sort is not stable.

What is merge sort? Is it stable?

A recursive algorithm that continually splits a list in half. If the list is empty or has one item, it is sorted by definition (the base case). If the list has more than one item, we split the list and recursively call a merge sort on both halves. Once the two halves are sorted, the merge is performed. Merging takes two smaller sorted lists and combines them together into a single, sorted, new list. Merge sort is stable.

What does it mean for a sorting algorithm to be internal vs external?

A sorting algorithm is internal if the algorithm uses the main memory exclusively. It is external if it uses external memory.

What does it mean for a sorting algorithm to be stable vs unstable?

A sorting algorithm is stable if it preserves the original order and unstable if it does not.

What is the algorithmic complexity of quick sort? What is the space overhead?

Average O(nlogn), Best, O(nlogn), Worst O(n²). Space O(n).

What is the algorithmic complexity of selection sort? What is the space overhead?

Average, Best , Worst: O(n²). Space O(1)

What is the algorithmic complexity of merge sort? What is the space overhead?

Average, Best, Worst O (nlogn). Space O(n)

What is the algorithmic complexity of radix sort? What is the space overhead?

Average, Best, Worst O(kn). Space O(n)

What is the algorithmic complexity of heap sort? What is the space overhead?

Average, Best, Worst: O(nlogn). Space Overhead: O(1).

What is the algorithmic complexity of insertion sort? What is the space overhead?

Average, Worst: O(n²) Best: O(n). Space O(1)

What is the algorithmic complexity of tree (AVL) sort? What is the space overhead?

Best, Average, Worst O(nlogn). Spae O(n)

What is the algorithm for bubble sort? Is it stable?

Bubble sort is an exchange sort. Splits data into two lists, sorted and unsorted. Smallest element is sent from the unsorted section to the sorted section. After moving the smallest to the sorted list, the wall moves one element to the right, increasing the number of sorted elements and decreasing the number of unsorted ones. Does pairwise exchanges as needed if the items are in the wrong order. Bubble sort is stable.

When should you use heap sort?

Great sort if you want things sorted in quick fashion.

What is the algorithm for heap sort? Is it stable?

Heapsort is a selection sort. First, it turns the array to be sorted into a heap. Then, the largest (or smallest if min heap) element in the heap is exchanged with the last element in the unsorted list. Next, reheap down to exchange and reconstruct the heap. This is done until the entire list is sorted. Not stable.

What is radix sort? Is it stable?

In a radix sort, each pass through the list orders the data one digit at a time. The first pass orders the data on the units (least significant) digit. The second pass orders the data on the tens digit. This process continues until the data is sorted on the most significant digit. Radix sort is stable.

When should you use insertion sort?

Insertion sort is the algorithm of choice either when the data is nearly sorted (because it is adaptive) or when the problem size is small (because it has low overhead).

What are the sorting algorithm categories?

Internal, external, stable, unstable, selection based, insertion based, exchange.

When should you use shell sort?

Useful when the data to be sorted is not very large or the data is nearly sorted because it gives an O(nlogn) sort with smaller amounts of data.

When should you use selection sort?

You should not use it, one of the worst sorting algorithms.

When should you use bubble sort?

You shouldn't use it because insertion sort is better. It is slow and impractical.


Conjuntos de estudio relacionados

Origins of South African Law (FLS 1501)

View Set

True or false proteins synthesis worksheet

View Set

UNIT 4: Urinary System (Mylab and Mastering)

View Set

Commutative, Associative & Identity Properties of Addition & Multiplication: vocabulary & examples

View Set

Tax Accounting Exam #2 (Chapters 5-7)

View Set

Teoría Jerarquía de Necesidades

View Set