Algorithm design and analysis terms and
techniques Questions With Answers
Question 1.
Pseudocode
Correct Answer: Notation for writing algorithms that abstracts away some
practical considerations (memory size, cache, word size,...) but lets us write
unambiguous code that is readable by humans, if not by an actual machine.
CLRS p. 20
See RAM model.
Question 2.
Summation
Correct Answer: Sigma notation is used to sum sequences. CLRS ap. A, C.1.
E.g.: _{1djdn} j = n(n+1)/2
They can be manipulated like integrals -- changing variables, reordering, etc.,
but are easier to envision because they are discrete.
Advice: sum over sets, rather than putting indices above and below the sigma,
because it is easier to manipulate the indices.
Question 3.
Recursive definition
Correct Answer: A definition of X in three parts: base cases identify a few X
items, recursive rules create new X items from known X items, and a closure
rule says the only way to generate X items is to start with the base cases and
apply recursive rules finitely many times.
E.g.: Natural numbers 0 in N; for all k in N, k+1 in N; Closure.
Binary trees: nil is a tree; a root node with pointers to left and right trees is a
tree; closure. CLRS B.5.3
Question 4.
Induction
Correct Answer: A technique for proving that a property is true for all items of
a recursively defined set by handling two cases: Base: proves the property
holds for one or more base cases; IS: proves the property holds for a general
non-base item, assuming that we have already proved it holds for all smaller
items (strong induction). See handout; prereq for CLRS (p.xv)
,Question 5.
Invariant
Correct Answer: A statement that remains true during the execution of an
algorithm. Used to derive and create assertions for correct code implementing
an algorithm.
E.g., Insertionsort: A[1..j-1] have been sorted into increasing order and A[j..n]
are untouched. CLRS p.18
BFS/DFS: gray vertices are in the queue/stack in increasing order of distance d;
parent pointers form a spanning tree on non-white vertices. CLRS p.595.
Question 6.
Recurrence relation
Correct Answer: A recursively defined function (usually on natural numbers or
tuples thereof) that is often used to bound time or space in analysis of an
algorithm or data structure, especially in divide and conquer and dynamic
programming. CLRS 4.3.
E.g., Merge sort recurrence: T(0)=0; T(n) = cn + T(floor(n/2))+T(ceil(n/2))
Question 7.
Recursion tree
Correct Answer: A diagram that helps analyze recurrences. Place the
non-recursive costs in a node, and create a child for each recursive call. The
total of all costs at nodes gives the form of the recurrence that we can prove by
induction. CLRS 4.4.
____ ___s typically fall into one of three types: top-heavy (cost dominated by the
root), leaf-heavy (cost dominated by the many leaves), and even (cost about
the same at each level, so total is lg n * level cost. (Master thm, CLRS 4.5, in a
nutshell.)
Question 8.
Asymptotic notation
Correct Answer: Big-Theta, big-O, and big-Omega suppress constants and lower
order terms
in functions of n. Useful tools in simplifying analysis when we are developing
pseudocode for the RAM model, since those also abstract away details from
actual implementations and hardware. Each has a precise definition, but is
often used as sloppy shorthand. CLRS 3.1, but move all quantifiers in their
definitions to the front.
E.g. 3n^2+n in O(n^2) because there exist c=4 and n_0=1 such that, for all
n>=n_2 3n^2+n <= cn^2.
Question 9.
Incremental
Correct Answer: Maintains the solution to a problem as you add input one by
one. CLRS 2.3. E.g.: Insertion sort, Separate chaining, BST construction
techniques Questions With Answers
Question 1.
Pseudocode
Correct Answer: Notation for writing algorithms that abstracts away some
practical considerations (memory size, cache, word size,...) but lets us write
unambiguous code that is readable by humans, if not by an actual machine.
CLRS p. 20
See RAM model.
Question 2.
Summation
Correct Answer: Sigma notation is used to sum sequences. CLRS ap. A, C.1.
E.g.: _{1djdn} j = n(n+1)/2
They can be manipulated like integrals -- changing variables, reordering, etc.,
but are easier to envision because they are discrete.
Advice: sum over sets, rather than putting indices above and below the sigma,
because it is easier to manipulate the indices.
Question 3.
Recursive definition
Correct Answer: A definition of X in three parts: base cases identify a few X
items, recursive rules create new X items from known X items, and a closure
rule says the only way to generate X items is to start with the base cases and
apply recursive rules finitely many times.
E.g.: Natural numbers 0 in N; for all k in N, k+1 in N; Closure.
Binary trees: nil is a tree; a root node with pointers to left and right trees is a
tree; closure. CLRS B.5.3
Question 4.
Induction
Correct Answer: A technique for proving that a property is true for all items of
a recursively defined set by handling two cases: Base: proves the property
holds for one or more base cases; IS: proves the property holds for a general
non-base item, assuming that we have already proved it holds for all smaller
items (strong induction). See handout; prereq for CLRS (p.xv)
,Question 5.
Invariant
Correct Answer: A statement that remains true during the execution of an
algorithm. Used to derive and create assertions for correct code implementing
an algorithm.
E.g., Insertionsort: A[1..j-1] have been sorted into increasing order and A[j..n]
are untouched. CLRS p.18
BFS/DFS: gray vertices are in the queue/stack in increasing order of distance d;
parent pointers form a spanning tree on non-white vertices. CLRS p.595.
Question 6.
Recurrence relation
Correct Answer: A recursively defined function (usually on natural numbers or
tuples thereof) that is often used to bound time or space in analysis of an
algorithm or data structure, especially in divide and conquer and dynamic
programming. CLRS 4.3.
E.g., Merge sort recurrence: T(0)=0; T(n) = cn + T(floor(n/2))+T(ceil(n/2))
Question 7.
Recursion tree
Correct Answer: A diagram that helps analyze recurrences. Place the
non-recursive costs in a node, and create a child for each recursive call. The
total of all costs at nodes gives the form of the recurrence that we can prove by
induction. CLRS 4.4.
____ ___s typically fall into one of three types: top-heavy (cost dominated by the
root), leaf-heavy (cost dominated by the many leaves), and even (cost about
the same at each level, so total is lg n * level cost. (Master thm, CLRS 4.5, in a
nutshell.)
Question 8.
Asymptotic notation
Correct Answer: Big-Theta, big-O, and big-Omega suppress constants and lower
order terms
in functions of n. Useful tools in simplifying analysis when we are developing
pseudocode for the RAM model, since those also abstract away details from
actual implementations and hardware. Each has a precise definition, but is
often used as sloppy shorthand. CLRS 3.1, but move all quantifiers in their
definitions to the front.
E.g. 3n^2+n in O(n^2) because there exist c=4 and n_0=1 such that, for all
n>=n_2 3n^2+n <= cn^2.
Question 9.
Incremental
Correct Answer: Maintains the solution to a problem as you add input one by
one. CLRS 2.3. E.g.: Insertion sort, Separate chaining, BST construction