Sorts Flashcards

1
Q

Insertion

A

The insertion sort
algorithm sorts a list
of values by
repeatedly inserting
an unsorted element
into a sorted sublist
until the whole list
is sorted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Merge

A

Let T(n) denote the time required for sorting an
array of n elements using merge sort. Without loss
of generality, assume n is a power of 2. The merge
sort algorithm splits the array into two subarrays,
sorts the subarrays using the same algorithm
recursively, and then merges the subarrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Quick sort

A

Quick sort, developed by C. A. R. Hoare (1962),
works as follows: The algorithm selects an element,
called the pivot, in the array. Divide the array into
two parts such that all the elements in the first part
are less than or equal to the pivot and all the
elements in the second part are greater than the
pivot. Recursively apply the quick sort algorithm to
the first part and then the second part.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bucket Sort

A

The bucket sort algorithm works as follows.

Assume
the keys are in the range from 0 to N-1. We need N
buckets labeled 0, 1, …, and N-1.

If an element’s key
is i, the element is put into the bucket i.

Each bucket
holds the elements with the same key value.

You can
use an ArrayList to implement a bucket.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why sorting

A

Sorting is a classic subject in computer science. There are three
reasons for studying sorting algorithms.
1. Sorting algorithms illustrate many creative approaches
to problem solving and these approaches can be applied
to solve other problems.
2. Sorting algorithms are good for practicing fundamental
programming techniques using selection statements,
loops, methods, and arrays.
3. Sorting algorithms are excellent examples to
demonstrate algorithm performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly