Sorting Flashcards

1
Q

Sorting is the process…

A

Converting a list of elements into ascending order

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

What is Selection Sort?

A

Sorting algorithm that treats the input as 2 parts.
A sorted part and an unsorted part

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

What is Insertion Sort?

A

An algorithm that starts at the i = 1 element and skips over the 0th element

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

What is a nearly sorted list?

A

A list that only contains a few elements not in sorted order

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

What is the best case for insertion sort?

A

When the list is in ascending order

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

What is the worst case for insertion sort?

A

When the list is in descending order

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

What is QuickSort?

A

Repeatedly sorts the input into low and high partions and then recursively sorts those parts

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

What is the pivot?

A

The pivot can be any value but it is commonly the middle of the array
numbers[midpoint val] = pivot

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

What is the formula for the midpoint?

A

i + (k -i)/ 2
i is the value of the index

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

If the midpoint is calculated and the number of the array is even, what is the number?

A

Round the number down and that is your midpoint. Example(3/2 = 1.5 round down to 1)

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

The pivot of an even array would be…

A

The index of the midpoint calculated. Example(Midpoint = 1, index 1 is equal to whatever the number is)

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

How many levels are required for a list of 1024 elements

A

N -1 = levels
1024 -1 = 1023

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

How many total comparisons are required for a list of 1024 elements

A

(N-1)N
=(1024-1)
1024=1047552

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

What is merge sort?

A

Divides a list into 2 halves, recursively sorts each half and hen merges the sorted haves to produce a list

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

How many variables are used to keep track of the elements?

A

3

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

What is the base case for merge sort?

A

if (i < k)
j = (i + k)/2

17
Q

The Quick Sort Algorithm uses what method?

A

Divide and Conquer

18
Q

What is insertion sort?

A

Orders a sequence of values by repeatedly taking each value and inserting it in proper position

19
Q

When using insertion with stacks what 2 temp stacks must you have?

A

Sorted and Temp

20
Q

What does the sorted stack hold?

A

Will always be in order and have the smallest item on the top of the stack

21
Q

What will the temp stack hold?

A

Will hold the temp items that need to shifted out inorder to insert the new item in the proper place