3. Algorithm Building Blocks Flashcards

1
Q

What are the general sections in the algorithm template format used by Algorithms in a Nutshell?

A

Name, Input/Output, Context, Solution, Analysis, Variations.

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

What is the Name section of the algorithm template?

A

A descriptive name for the algorithm, which is used to communicate the algorithm concisely to others.

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

What is the Input/Output section of the algorithm template?

A

It describes the expected format of input data to the algorithm and the resulting values computed.

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

What is the Context section of the algorithm template?

A

A description of a problem that illustrates when an algorithm is useful and when it will perform at its best. A description of the properties of the problem/solution that must be addressed and maintained for a successful implementation.

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

What is the Solution section of the algorithm template?

A

The algorithm description using real working code with documentation.

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

What is the Analysis section of the algorithm template?

A

A synopsis of the analysis of the algorithm, including performance data and information that helps to understand the behavior of the algorithm.

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

What is the Variations section of the algorithm template?

A

It presents variations of the algorithm or different alternatives.

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

What is the pseudocode template format of Algorithms in a Nutshell?

A

The pseudocode description is intentionally brief. Keywords and function names are described in boldface text. All variables are in lowercase characters, whereas arrays are capitalized and their elements are referred to using A[i] notation. The indentation in the pseudocode describes the scope of conditional if and looping while and for statements.

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

What is the empirical evaluation format of Algorithms in a Nutshell?

A

The performance of each algorithm is confirmed by executing a series of benchmark problems appropriate for each individual algorithm. To properly evaluate the performance, a test suite is composed of a set of k individual trials (typically k ≥ 10). The best and worst performers are discarded as outliers, the remaining k — 2 trials are aggregated, and the average and standard deviations are computed. Tables are shown with problem instances typically ranging in size from n = 2 to 220.

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

What are some differences in computation between integers and floating-point values?

A

Computers perform basic computations on values stored in registers by the CPU, which are typically 64-bits in size on modern computers. The CPU often supports basic operations—such as ADD, MULT, DIVIDE, and SUB—over integer values stored in these registers. Floating-point units (FPUs) can efficiently process floating-point computations according to the IEEE Standard for Binary Floating-Point Arithmetic (IEEE 754). Mathematical computations over integer-based values have traditionally been the most efficient CPU computations, however, modern CPUs have dramatically improved the performance of floating-point computations relative to their integer counterparts.

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

What are some performance issues of floating-point computation?

A

Despite substantial speed improvements in floating-point computation by processors over time, floating-point computations still tend to be thousands of times slower than their integer counterparts for common mathematical operations (CMP, MULT, DIV), however the differences between different sizes of floating-point values (32-bit, 64-bit, and 128-bit) are considerably less pronounced.

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

How are 32-bit floating-point values (floats) represented?

A

1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa.

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

How are 64-bit floating-point values (doubles) represented?

A

1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa.

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

What is a technique used to achieve the greatest precision with the floating-point representation?

A

The mantissa is always normalized so that the left-most digit is always 1; this bit does not have to actually be stored, but is understood by the floating-point processor to be part of the number.

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

How are floating-point values calculated?

A

(sign)*(mantissa)*2exponent, where the sign is -1 or 1, the mantissa is a value between 0 and 1, and the exponent is a non-negative integer.

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

How are floating-point errors described?

A

The most common way of describing floating-point error is to use the term relative error, which computes the ratio of the absolute error with the desired value. It is quite common for these relative errors to be less than 1 part per million.

17
Q

What is an approach to solving for rounding errors in floating-point computation?

A

One common solution is to introduce a small value δ to determine ≅ (approximate equality) between two floating-point values. Under this scheme, if |xy| < δ, then we consider x and y to be equal. Still, by this simple measure, even when xy and yz, it’s possibly not true that xz. This breaks the principle of transitivity in mathematics and makes it really challenging to write correct code. Additionally, certain problems use signs of the value (0, positive, or negative) to make their decision.

18
Q

What are some uses of special quantities in floating-point representation?

A

Certain values are defined by the IEEE standard are reserved for interpretation as special numbers, and were designed to make it easier to recover from common errors, such as divide by zero, square root of a negative number, overflow of computations, and underflow of computations.

19
Q

What are the special quantities of IEEE 754?

A
  • Positive infinity (exponent = max, mantissa = 0, sign = +)
  • Negative infinity (exponent = max, mantissa = 0, sign = -)
  • Not a number (NaN) (exponent = max, mantissa = non-zero, sign = any)
  • Negative zero (exponent = 0, mantissa = 0, sign = -)
  • Positive zero (exponent = 0, mantissa = 0, sign = +)
20
Q

Which special quantities can be used in computations?

A

Positive zero and negative zero.

21
Q

What are some characteristics of Greedy strategies?

A

A Greedy strategy completes a task of size n by incrementally solving the problem in steps. At each step, a Greedy algorithm will make the best local decision it can given the available information, typically reducing the size of the problem being solved by one. Once all n steps are completed, the algorithm returns the computed solution. Greedy strategies can be identified by the way the subproblems being solved shrink very slowly as an algorithm processes the input.

22
Q

What is the performance of Greedy strategies?

A

When a subproblem can be completed in O(log n) then a Greedy strategy will exhibit O(n log n) performance. If the subproblem requires O(n), then the overall performance will be O(n2).

23
Q

What are some characteristics of Divide and Conquer strategies?

A

A Divide and Conquer strategy solves a problem of size n by dividing it into two independent subproblems, each about half the size of the original problem. Quite often the solution is recursive, terminating with a base case that can be solved trivially. There must be some resolution computation that can determine the solution for a problem when given two solutions for two smaller subproblems.

24
Q

What is the performance of Divide and Conquer strategies?

A

A Divide and Conquer algorithm will exhibit O(n) performance if the resolution step can be accomplished in constant O(1) time. When the resolution step itself requires O(n) computations, then the overall performance will be O(n log n).

25
Q

What are some characteristics of Dynamic Programming?

A

Dynamic Programming is a variation on Divide and Conquer that solves a problem by subdividing it into a number of simpler subproblems that are solved in a specific order. It solves each smaller problem just once and stores the results for future use to avoid unnecessary recomputation. It then solves problems of increasing size, composing together solutions from the results of these smaller subproblems. In many cases, the computed solution is provably optimal for the problem being solved. Dynamic Programming is frequently used for optimization problems where the goal is to minimize or maximize a particular computation.