Searching and Algorithm Analysis Flashcards

1
Q

Linear Search

A

starts from the beginning of a list and checks each element until the search key is found or the end of the list is reached

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

runtime

A

time the algorithm takes to execute

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

Binary Search

A

faster algorithm for searching a list if the list’s elements are sorted and directly accessible (such as an array). Binary search first checks the middle element of the list. If the search key is found, the algorithm returns the matching location. If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element).

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

Given an array with 32 elements, how many list elements will be checked if the key is less than all elements in the list, using binary search?

A

how many times you divide by 2 and add 1, to get to 1

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

constant time operation

A

operation that, for a given processor, always operates in the same amount of time, regardless of input values

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

Big O notation

A

mathematical way of describing how a function behaves in relation to the input size

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

Big O Notation Rules

A
  1. If f(N) is a sum of several terms, the highest order term (the one with the fastest growth rate) is kept and others are discarded.
  2. If f(N) has a term that is a product of several factors, all constants (those that are not in terms of N) are omitted
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Big O Notation for BinarySearch

A

O(log N)

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

Big O Notation for Linear Search

A

O(N)

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

Big O Notation for MergeSort

A

O(N log N)

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

Big O Notation for Selection Sort

A

O(N^2)

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

Big O Notation for Fibonacci

A

O(c^N)

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

worst-case runtime

A

runtime complexity for an input that results in the longest execution

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

2^20 is approximately

A

1 million (1,048,576)

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

recursive function

A

function that calls itself

must have a base case

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

Binary Search

A

Algorithm that searches a sorted list for a key by first comparing the key to the middle element in the list and recursively searching the half of the remaining list, so long as the key is not found.

17
Q

Recurrence Relation

A

A function f(N) that is defined in terms of the same function operating on a value < N.

Needs to have T on both sides of the equation