Test 1 Flashcards

1
Q

When confronted with a new ___________ , there may be several possible solutions.

A

problem

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

A __________ is a question which requires an answer.

A

problem

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

A problem usually includes variables, called __________.

A

parameters

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

What is an algorithm?

A

A step - by- step procedure to solve all instances of a problem.

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

What are problems of an algorithm?

A

Difficult for complex algorithms

Hard to translate to a programming language

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

It is possible for sequential search to examine _______ element before solving the problem . It can be used whether the array is sorted or not.

A

every

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

A much faster algorithm is available if the array is sorted:

A

Binary Search

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

works by comparing x with the middle of the array. The algorithm then “ discards” either the first or second half of the array .

A

Binary search

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

It can be shown by mathematical induction that the recursive version performs approximately _________ operations.

A

2 ^ (n / 2)

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

The iterative version if recursion performs ____ operations.

A

n + 1

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

when the basic operation is done the same number of times for every instance of size n. In algorithm 1.2 (sum of array values), T(n) = n

A

Every-Case Time Complexity

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

when the amount of work performed by the algorithm depends on the values of other parameters. W(n) is the largest number of times the basic operation will be performed for an instance of size n. In algorithm (sequential search) W(n) = n

A

Worst-Case Time Complexity

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

When analyzing the Complexity of an algorithm, it is useful to observe some simplifying abstractions:

A

Do not worry about actual CPU time

Determine the number of times a basic operation is done as a function of n (the size of the input)

The total amount of work done by the algorithm is proportional to the number of times the basic operation is performed .

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

Once we determine the number of operations performed as a function of n(T (n) or W(n)) , we are interested in classifying algorithms according to their ________ or ____________ class.

A

order

complexity

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

Algorithms with time complexities such as n,100n, and 50n + 10 are called ____________ algorithms

A

linear -time

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

Algorithms with time complexities such as n ^ 2, 0.5n ^ 2 , and n ^ 2 + 10n + 1 are called _____________ algorithms

A

quadratic-time

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

Any linear -time algorithm is ______________________ than any quadratic-time algorithm.

A

eventually more efficient

18
Q

In order to define order formally, it is useful to define a similar concept:

A

Big O notation.

19
Q

Big notation is used to establish an _____________ on the growth of a function .

A

upper bound

20
Q

Big Theta is defined in a similar way as Big O, except that it provides both _______ (big O ) and ______ (big Omega) bounds on the growth of the function

A

upper

lower

21
Q

What is wrong with an algorithm such as Exchange ( Bubble ) Sort?

A

Usually, the least efficient of all sorting algorithms , because of the excessive number of swap operations

Exchange sort requires n - 1 major loop iterations, and up to n - 1 swaps in each iteration, resulting in a worst case of sim n^ 2 element swaps!!

22
Q

This sorting causes each iteration, selection sort. Finds the smallest entry in the unsorted portion of the array , and Swaps it with the element in the corresponding position.

A

Selection sorting

23
Q

This type of sorting works by extending the length of the sorted portion one step at a time:
After zero iterations, A[1] is sorted After one iteration, A[1..2] is sorted After two iterations, A[1..3] is sorted After three iterations A[1.4] is sorted, and so on, until A[1..N] is sorted .

A

Insertion sorting

24
Q

For a list of length n, an average selection sort makes about key comparisons and exactly ______ swap operations .

A

n - 1

25
Q

Selection sort is not affected by the __________ of the array elements.

A

original order

26
Q

The insertion sort is particularly appropriate for small arrays that are _____________

A

nearly sorted

27
Q

The divide -and-conquer strategy solves a problem by:

A
  1. Breaking it into subproblems that are themselves smaller instances of the same type of problem
  2. Recursively solving these subproblems
  3. Appropriately combining their answers
28
Q

Finds the middle element, if one exists If target is equal to middle element Target found , return location

A

Recursive binary search

29
Q

What do you do if the recursive binary search hits an else?

A
  1. DIVIDE the array into two smaller subarrays . Choose either left or right subarray , AND
  2. CONQUER by recursively applying binary search to the smaller subarray .
  3. OBTAIN overall solution from subarray result.
30
Q

Let ____ be the number comparisons performed by recursive binary search for an array of size n. ____ can be expressed with a recurrence relation:

A

W(n)-worst case time complexity

31
Q

Given an array with n items, Mergesort involves three steps:

A
  1. Divide the array into two subarrays each with n / 2 items
  2. Conquer (solve) each subarray by sorting it.
  3. Unless the array is sufficiently small, use recursion to do this Combine the solutions to the subarrays by merging them into a single sorted array
32
Q

Mergesort uses additional storage: an array of the _______ as the one being ________

A

same size

sorted

33
Q

Quicksort is another sort based on the ______________ pattern .

A

divide-and-conquer

34
Q

Quicksort the most efficient general sorting algorithm in existence for _____________.

A

random arrays

35
Q

Quicksort worst-case time complexity is:

A

O(n ^ 2)

36
Q

For Quicksort, the worst-case time complexity of Theta(n ^ 2) occurs when the array is:

A

already sorted!!

37
Q

The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist ). This algorithm offers guaranteed n log (n) performance .

A

Collections.sort()

38
Q

The sorting algorithm is a tuned quicksort , adapted from Jon L. Bentley and M. Douglas Mcllroy. This algorithm offers n^ * log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance .

A

Arrays.sort()

39
Q

In a _________________ solution, the “basic operationsto be counted are usually performed as part of recursive calls.

A

Divide-and-Conquer

40
Q

It is essential to formulate a recursive definition to “_______” basic operations :

A

count

41
Q

A useful alternative in estimating Big theta complexity is to use the _________________ whenever we have a recurrence relation of the form:

A

Master Theorem

42
Q

The master theorem is:

A

T(n) = a * T(n/b) + f(n)