Workshop 3 - Iterative Flashcards

1
Q

Binary Search

A

Must be sorted.

Check the middle element of array.

If not found determine, which other half of list where it can be located. (EXCLUDE HALF SPACE).

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

Binary Search - BigO

A

Best Case:

O(1) - searched value is middle element in list/array

Worst Case:

O(log2n) - when searched value is not in list/array.

Average case:

If data is distributed randomly - each elements has equal chance

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

Sorted Vs Unsorted

A

Sorted is better as its in order, and automatically know that its increasing.

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

Sequential/ Linear Search

A

Use a while loop to find object in a list, if not found in index one check the next index.

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

Sequential/Linear Search - BigO

A

Best Case: O(1)
Worst Case: O(n)
Average Case: N/2

Linear Time Complexity: O(n)

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

Binary Search

A

List/array must be sorted.

Check the middle element of the list.

If not found determine which half of list/array item can be located.
– Exclude half elements

Repeat by searching half list array which may contain the element by examining the middle element. Half again.

Repeat till found.

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

Binary Search - BigO

A

Best Case: O(1) when searched value is the middle element.
Worst Case: O(log2n) when searched value is not in array.
Needs 1+log2n comparisons
Average Case: If data is distributed randomly
Needs 1+log2n comparisons
COMPLEXITY : O(log2n)

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

Selection Sort

A

Works searching one item at a time.

Sorted part left - initially empty.
Unsorted on right part - initially completed list.

Selection Sort will find the largest or smallest elements in the array.

1st Comparisons
2nd Swap

Process is iterated till found.

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

Selection Sort - BigO

A

Best Case: O(n2)

Worst Case: O(n2)

Algorithm unsuitable for large data sets.

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

Bubble Sort

A

Repeatedly passing through list - swapping adjacent items if in wrong order.

If sorting on the top ascending/descending order the largest/smallest item will bubble to the top.

Process iterated on the whole list until all items considered - list then sorted.

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

Bubble Sort - BigO

A

Best Case: O(n2)

If efficiency improved for best case using flag variable = O(n)

Worst Case: O(n2)

Algorithm slow for large data sets.

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

Insertion Sort

A

Works by sorting the list item one at a time.

List is split into a sorted and a non-sorted part.

Through each iteration, element is waiting to be sorted and is inserted in its correct location within the sorted list.

Process iterated again and again.

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

Insertion Sort

A

Best Case: O(n) data is already sorted.

Worst Case: O(n2)

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