Pre Flashcards

1
Q

What is bandwidth?

A

bandwidth describes the “Data transfer rate”. That is, the amount of bits transfered from one place to another in within a second.

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

How algorithms are analyzed?

A

Occasionally, resources such as memory, communication bandwidth and computer hardware are of primary concern, but most often it is computational time that we want to measure.

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

Which operations are considered to be O(1)?

A
  • Arithmetic operations.*
  • data movement operations - load, store, copy*
  • control operations - conditional and unconditional brance, subroutine call and return*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When analyzing we assume a limit on the size of each word of data, explain that

A

When working with inputs of size n, we assume that integers are represented by clogn bits, where c>=1. The upper bound makes sure n can be represented so we can index the input integers. C is a constant so that the word size don’t grow arbitrarily.

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

What about “shift” operations are exponent operations, how much time do they take?

A

Here we enter a grey area because both shift and exponent take several operations. But if we assume the real numbers are relatively small, we consider it O(1).

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

What does input size mean?

A

It can mean two different things, which depends on the problem being analyzed:

  • The number of items in the input
    • Sometimes described by two numbers, like with graphs, vertices & edges
  • The number of bits required to represent the input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe running time

A

We look at it in the following way; a constant time is required to execute each line of our pseudocode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  • Describe insertion sort.*
  • Describe the best case and worst case in terms of run-time.*
A

Worst case:

  • Array is sorted in reverse order. This way the inner loop work as much as possible
  • O(n^2)

Best case:

  • Array is already sorted. This way the inner loops doesn’t work at all.
  • O(n)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe divide and conquer method:

  • Divide - ?
  • Conquer - ?
  • Combine - ?

How merge sort uses this method?

A
  • Divide the problem to subproblems
  • Conquer the subproblems by solving them recursively. When they are small enough, solve them in a straightforward manner.
  • Combine the solutions to the subproblems to reach the solution for the problem.

Merge sort:

  • Divide the n array problem into two n/2 subproblems.
  • Sort the two arrays recursively using merge sort
  • Merge the two sorted sequences to have the original sequence sorted.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does merge sort work?

A
  • Input: two sorted arrays of sizes: q-p+1 and r-p
  • Operation:
    • choose the smallest element of the two arrays to be the next element in the new created array
    • In each array, the last element is infinity. That’s how we maintain these procedure.
  • Output:
    • New sorted array of the two combined, of size r-q+1.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Explain the run time of merge sort

A
  • Recursively:*
  • T(n)=2T(n/2)+O(n)*
  • 2T(n/2) - two new sub problems of size n/2
  • O(n) - time it takes to merge
  • division to sub problems is O(1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Describe the assymptotic relation between logarithmic, polynomial and exponential functions.

What is the relation between ln(1+x) and x?

A

For a>0

log^b(n) = o(n^a)

For any a>1

n^b = o(a^n)

ln and x

Attached

n! < n^n

n! > 2^n

log(n!) = nlogn

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

Which methods do we have for finding assymptotic bounds on recursive formulas?

A

The substitution method - guess a bound and use mathematical induction to prove

The recursion-tree method - create a tree whose nodes represent the costs at each division. Then use techniques for bounding summations

The master method - provide bound for formulas of the form: T(n) = aT(n/b) + f(n)

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

a^(log(b)) = ?

A

b^log(a)

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

Memorize

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

To be memorized

A