Midterm Flashcards

1
Q

What is an algorithm?

A

Well defined computational
procedure, takes input, and generates
output

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

An algorithm is correct if…?

A

for every
input is halts with the correct output

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

Search algorithm?

A

method for finding an item or
group of items with specific properties within a
collection of items

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

Linear search?

A

Also known as brute force search, and list does not have to be sorted

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

Binary search must be what?

A

sorted to give correct answer

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

Linear Search first step?

A

Start from the leftmost element of a[] and one by one
compare x with each element of a[]

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

Linear Search second step?

A

if x matches with an element, return the index.

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

Linear Search third step?

A

if x doesn’t match with any of the elements, return -1

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

Time Efficiency of An
Algorithm formula?

A

T(n) ≈ cop ∗ C(n)

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

Best Case?

A

List is already sorted

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

Worst Case?

A

Needs to search every element/list is backwards

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

Average Case?

A

The average case efficiency is the time taken by the
algorithm for a typical/average input of size ‘n’. ?

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

Insertion sort?

A

To find the correct position for a card, compare it with each of the cards already in the hand, from right to left.

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

We usually consider the _____ running time for any input. This is
also often the expected running time.

A

Worst Case

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

it can be shown that the
average case for insertion sort is ____

A

quadratic

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

What term do we use for order of growth?

A

The highest order. Ignore constants.

17
Q

How to Evaluate
Efficiency of programs?

A

count the operations
notion of order of growth

18
Q

Running Time?

A

Number of primitive steps that are
executed

19
Q

Lowest complexity case

A

O(1) constant

20
Q

2nd Lowest complexity case

A

O(Log n) logarithmic

21
Q

3rd Lowest complexity case

A

O(n) Linear

22
Q

Highest complexity case

A

O(c^n) exponential

23
Q

2nd Highest complexity case

A

O(n^c) polynomial

24
Q

3rd Highest complexity case

A

O(n log n) loglinear