Sorting and Searching Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Selection Sort: Operation

A

Find the smallest element in a and exchange it with a[0]. Repeat the process with the subarray a[1]…a[n-1]… then sort a[n-2] and a[n-1] at the end.

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

Selection Sort: Passes to sort the array

A

An array of n elements is sorted after n-1 passes.

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

Selection Sort: Elements sorted after k passes

A

After the kth pass, the first k elements are in their sorted positions.

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

Selection Sort: Worst Case

A

Selection Sort always requires the same number of comparisons/moves

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

Selection Sort: Best Case

A

Selection Sort always requires the same number of comparisons/moves

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

Insertion Sort: Operation

A

The array consists of sorted and unsorted portions. Insertion sort moves elements from the unsorted subarray to their correct positions in the sorted subarray, moving elements in the sorted subarray as necessary.

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

Insertion Sort: Passes to sort the array

A

An array of n elements is sorted after n-1 passes.

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

Insertion Sort: Elements sorted after k passes

A

The elements in a[0]..a[k] are sorted with respect to each other (though not necessarily in their final positions).

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

Insertion Sort: Worst Case

A

The array is sorted in reverse order (maximum possible number of comparisons and moves).

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

Insertion Sort: Best Case

A

The array is already sorted in increasing order (each pass involves one comparison that confirms that the sort order is correct).

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

Mergesort: Operation

A

Mergesort the left and right halves of an array, then merge the two sorted lists. In doing this, n subarrays of length 1 are created and then recursively merged to form the final sorted array.

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

Mergesort: Disadvantages

A

Mergesort requires a temporary array of length n to sort an array of length n, so it may not be space-efficient.

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

Mergesort: Worst Case

A

The performance of mergesort is not affected by the initial ordering of elements in the array.

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

Mergesort: Best Case

A

The performance of mergesort is not affected by the initial ordering of elements in the array.

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

Sequential Search: Operation

A

Start at the first element and compare the key to each element. If the list is known to be sorted, the search could be stopped early if the key is less than the current element.

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

Sequential Search: Best Case

A

The key is in the first slot.

17
Q

Sequential Search: Worst Case

A

The key is in the last slot or not in the array.

18
Q

Sequential Search: Average Case

A

There are n/2 comparisons.

19
Q

Binary Search: Operation

A

Find the midpoint of the array at index k and compare it to the key. If the key is less than a[k], recursively search a[0]..a[k-1]. If it is greater than a[k], recursively search a[k+1]..a[n-1].

20
Q

Binary Search: Preconditions

A

The array is sorted on the search key.

21
Q

Binary Search: Best Case

A

The key is at the midpoint of the array (i.e. a[n/2]).

22
Q

Binary Search: Worst Case

A

The key is not in the list or is at either end of a subarray (subarrays must continually be divided until a subarray of length 1 is found and tested).