Algorithms Quizzes

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Horner's Rule for the polynomial 2x^4 + 6x^3 - 44x^2 + x + 5 is based on which parenthesizing

(((2x + 6)x - 44)x + 1)x + 5

Let n denote number of pages in the web digraph. The concept of PageRank can be formulated with a web surfer who randomly jumps from a page q to an arbitrary page, but with a very small probability; otherwise, randomly clicks on a hyperlink on page q. For damping factor d, these probabilities are given by

(1 - d) /n and d/h(q) where h(q) is the number of of hyperlinks on page q

Consider the array implementation of a complete binary tree in C++. For a node indexed by I the indices the parent, left child and right child are respectively given by

(I - 1)/2, 2*I + 1 , 2*I + 2

The average complexity A(n) of Linear Search assuming the search element is in the list and is equally likely to be in any position is given by:

(n + 1)/2

The coefficient of x in the the Discrete Fourier Transform of x^3 + x for primitive root i is:

0

The PageRank vector is an eigenvector having eigenvalue

1

The coefficient of x in the the Discrete Fourier Transform of x3 + 1 for primitive root i is

1 - i

The number of spanning trees of k10 is

100,000,000

The number of spanning trees of the complete graph of 6 vertices K6 is

1296

The Discrete Fourier Transform of x + 1 for primitive root i is

2 + (1 + i)x + (1 - i)x^3

1 + 1/2 +1/3 + 1/4 + ... + 1/n + ... + 1/(n2 - 1) + 1/n2 is approximately equal to:

2 ln n

A Huffman tree is a:

2-tree

Prefix codes (for unambiguous binary encoding) are generated using a:

2-tree

The number of parenthesizations of a product of n matrices equals the number of

2-trees on n nodes

The worst-case complexity for the right-to-left binary method of computing powers in terms of the number n of binary digits where the basic operation is multiplication is

2n - 2

Quicksort has average complexity A(n) (for a uniform distribution) approximately equal to:

2n ln n

For k = 6, i.e., n = 2k = 64, consider the leaf nodes of the tree of recursive calls for FFT, which we will refer to from left to right as leaf node 0, 1, ..., 63. What is the index i of ai for leaf node 48?

3

Consider symbols a, b, c, d, e having frequencies 10, 20, 30, 40, 50, respectively. Then the length of the Huffman code for a, b, c, d, e is:

3 3 2 2 2

The smallest worst-case complexity for finding both the maximum and minimum elements in a list of even size n:

3n/2 - 2

The smallest worst-case complexity for computing the maximum and minimum elements in a list of even size n is

3n/2 -2

Consider symbols a, b, c, d, e, f having frequencies 10, 20, 30, 40, 50, 60 respectively. Then the length of the Huffman code for a, b, c, d, e, f is:

4 4 3 2 2 2

The number of multiplications involved in the product of matrices of dimensions 5x8 and 8x10 is

400

Consider the fractional Knapsack Problem with 4 objects having values 10, 20, 30, 100 and weights 2, 10, 3, 100, respectively. The value of the optimal Knapsack having capacity 7 is:

44

For k = 6, i.e., n = 2k = 64, consider the leaf nodes of the tree of recursive calls for FFT, which we will refer to from left to right as leaf node 0, 1, ..., 63. What is the index i of ai for leaf node 3?

48

1 + 2 + 3 + ... + 999

499500

Consider the Knapsack Problem with 4 objects having values 10, 20, 30, 100 and weights 2, 10, 3, 100, respectively. The value of the optimal Knapsack having capacity 10 is:

50

Consider the array implementation of a complete binary tree in C++. For a node indexed by I = 101 the indices the parent, left child and right child are respectively given by:

50 203 204

1 + 2 + 3 + ... + 100 equals

5050

The total number of nodes of a 2-tree with 40 leaf nodes is

79

10n + 20n2 ... + 870n87 + 880n88 is strongly asymptotic to (~)

880n^88

Given input (d0,d1,...,dn), the recurrence relation for the number of multiplications mij in an optimal parenthesization of a chained matrix product MiMi+1...Mj where the kth matrix in the product has dimensions dk-1 xdk , k = i, ..., j, is

A

A problem A is NP-complete if

A is in NP and every other NP problem can be polynomially reduced to A

A digraph is defined by

A vertex set V and edge set E where E is a subset of VxV

In order to be able apply Strassen's algorithm for square matrices whose size is not a power of 2, perform the following operation first

Add rows and columns of all zeros to bring the size up to the next power of 2

Given a combine function S = Combine(S1,S2) in Dynamic Programming, an effective proof technique to show that the the Principle of Optimality holds:

Assume that for some optimal solution S at least one of S1 and S2 are suboptimal and obtain a contradiction

see notecard

B

Consider the matrix equation for PageRank R for the (web) digraph W given by R = B^T x R

B is the matrix for a random walk on W

Algorithm for computing shortest paths, i.e., minimum hop-length paths, in graphs or digraphs:

BFS

An algorithm that can be used to compute the diameter of a graph:

BFS

Best algorithm for computing a shortest (minimum hop-length) path in an (unweighted) digraph from u to v, for one given pair of vertices u and v.

BFS

Best algorithm for computing shortest (minimum hop-length) paths in (unweighted) digraphs:

BFS

Which algorithms could be used to compute the diameter of a graph?

BFS and Warshall's algorithm

An algorithm that can be used to compute the connected components of a graph:

BFT

Which is not a major design strategy:

Binary Search

The recurrence relation for an optimal binary search tree Tij with keys Ki, ..., Kj and associated probabilities pi, ..., pj that the search element is in search tree and probability qi, ..., qj+1 it is not, where o-(i, j) =

C

A heap is implemented using

Complete binary tree

The worst-case complexity of Euclid's algorithm for computing the gcd(a,b) occurs when a and b are:

Consecutive Fibonacci numbers

The worst-case complexity of Euclid's algorithm for gcd(a,b) occurs when a and b are:

Consecutive Fibonacci numbers

The proof that there exist NP-complete problems was independently discovered by

Cook and Levin

The fastest known algorithm for computing the product of two nxn matrices is due to

Coppersmith and Winograd

An algorithm that can be used to test whether a graph is connected:

DFS

A topological sort of a DAG can be done efficiently using the following algorithm

DFT

Best algorithm for computing (weighted) shortest paths in a weighted connected graph from a given vertex r to all other vertices v, where the edges have been weighted with positive real numbers.

Dijkstra's algorithm

Best algorithm for computing shortest paths in weighted digraphs:

Dijkstra's algorithm

To compute a shortest (weighted directed) path from a given vertex to all the other vertices in a weighted digraph, where all the weights are positive, which algorithm would do the job most efficiently.

Dijkstra's algorithm

An efficient way to test for cycles when implementing Kruskal's algorithm is to utilize the data structure

Disjoint Sets

An efficient way to test for cycles when implementing Kruskal's algorithm is to utilize:

Disjoint Sets ADT

Which major design strategies can apply to optimization problems?

Dynamic Programming and the Greedy Method

Dynamic Programming and Divide-and-Conquer differ in that

Dynamic Programming involves bottom-up recursion, whereas Divide-&-Conquer involves top-down recursion

An efficient algorithm for computing the greatest common divisor of two integers is:

Euclid's Algorithm

The average complexity of an algorithm is given by:

Expected number of basic operations performed for an input of size n given a probability assignment to the sample space of all inputs of size n.

FFT stands for

Fast Fourier Transform

Which algorithm can be used to compute shortest paths in weighted digraphs where negative weights are allowed by no negative cycles, i.e., directed cycles so that the sum of the weights is strictly negative?

Floyd's algorithm

Which shortest path algorithm can be applied with negative edge weights as long as there is no negative cycle?

Floyd's algorithm

Which are shortest-path algorithms for weighted digraphs?

Floyd-Warshall's and Dijkstra's

Computing a Huffman tree for data compression of text is based on what design strategy:

Greedy Method

Dijkstra's algorithm is based on:

Growing a tree T by adding the smallest-weight edge in Cut(T), where the weight of an edge xy in Cut(T) is Dist[x] + w(xy)

An efficient algorithm for polynomial evaluation is

Horner's rule

Given a combine function S = Combine(S1,S2,...,Sm) in Dynamic Programming, the the Principle of Optimality holds if the following is always true.

If S is optimal then all of S1,S2,...,Sm are optimal

Which traversal outputs the nodes of a binary search tree in sorted order

Inorder Traversal

A sorting algorithm that has the smallest best-case complexity B(n):

Insertionsort

An efficient on-line sorting algorithm (i.e., elements added over time)

Insertionsort

When computing the limit as n goes to infinity of the ratio f(n) / g(n), it is useful to utilize the following rule involving taking the derivative of the numerator and denominator.

L'Hopital's rule.

Which of the following sorting algorithms is not in-place

Mergesort

Which of the following sorting algorithms is not in-place?

Mergesort

NP stands for

Nondeterministic Polynomial

Testing for cycles in Kruskal's algorithm for a graph with n vertices and m edges using the disjoint set ADT takes time

O(m α(m, n))

Two n-digit integers can be multiplied using FFT in time

O(n log n )

Two polynomials of size n can be multiplied using FFT in time

O(n log n )

The computing time (complexity) of the left-to-right binary method for powers in terms of the number n of digits is:

O(n)

An efficient combine operation for divide-and-conquer algorithm for multiplication of two polynomial P(x) and Q(x), where P(x) = P1(x) + xd P2(x), Q(x) = Q1(x) + xd Q2(x).

P1(x) Q1(x) + xd ((P1(x) + P2(x)(Q1(x) + Q2(x)) - P1(x) Q1(x) - P2(x)Q2(x)) + x2dP2(x)Q2(x)

An efficient combine operation for divide-and-conquer algorithm for multiplication of two polynomial P(x) and Q(x), where P(x) = P1(x) + xd P2(x), Q(x) = Q1(x) + xd Q2(x)

P1(x) Q1(x) + xd ((P1(x) + P2(x)(Q1(x) + Q2(x)) - P1(x) Q1(x) - P2(x)Q2(x)) + x2dP2(x)Q2(x)

The application of PageRank to the search engine Google was made by

Page and Brin

An efficient algorithm for multiplying polynomials P(x) and Q(x) of sizes m and n, respectively, where m < n involves

Partition Q(x) into blocks of size m and use distributive law when multiplying by P(x)

Method used to store a binary search tree in a file so it can reconstructed when file is scanned sequentially:

Preorder Traversal

Dijkstra's shortest-path algorithm is similar to

Prim's MST algorithm

Which algorithm is only valid for undirected graphs?

Prim's algorithm

Which algorithm can be used to compute a minimum spanning tree in a weighted connected graph

Prim's and Kruskal's

An important optimization principle applied to effectively solve the problems of finding an optimal parenthesization of a matrix product and the optimal binary search tree is

Principle of Optimality

An important principle applied in Dynamic Programming to effectively solve optimization problems is

Principle of Optimization

BFS utilizes the following data structure:

Queue

A sorting algorithm that is not comparison-based

Radix Sort

A sorting algorithm that is not comparison-based:

Radix Sort

The Recurrence relation for Floyd's algorithm is

S k+1 (i, j) = min {S k (i, j), S k (k, i) + S k (j, k)}, S 0 (i, j) = W(i, j) for all i, j

Which best describes an algorithm

Sequence of steps for solving a problem

Which problem is not NP-complete?

Sorting a List

The worst-case complexity of Quicksort occurs when

The list is already sorted

Binary Search assumes as a precondition that

The list is sorted

Interpolation Search assumes as a precondition that:

The list is sorted

Worst-case complexity of an algorithm is defined as:

The most basic operations performed by the algorithm over all inputs of size n

The worst-case complexity W(n) of a given algorithm is defined as

The most basic operations performed for an input of size n

In order to be able to take the product of two matrices A and B

The number of columns of A must equal the number of rows of B.

Strassen's algorithm is based on the following key result and design strategy

The product of two 2x2 matrices can be computed using 7 multiplications; Divide-and-conquer

Strassen's algorithm is based on the following key result and design strategy:

The product of two 2x2 matrices can be computed using 7 multiplications; Divide-and-conquer

A formal definition of an algorithm uses the following concept:

Turing machine

The formal definition of an algorithm uses the following concept

Turing machine

An efficient combine operation for divide-and-conquer algorithm for multiplication of two integers U and V, where U = U1 + 10d U2, V = V1 + 10d V2

U1V1 + 10^d(( U1+ U2)(V1+ V2) - U1V1 - U2V2 ) + 10^(2d)U2V2

The main operations of the Disjoint Set ADT are:

Union and find

Condition on (web) digraph W to ensure that iteration algorithm for PageRank converges:

W is strongly-connected and aperiodic

The recurrence relation for the worst-case complexity W(n) of Pan's matrix multiplication algorithm is given by

W(n) = 143,640 W(n/70), W(1) = 1

The recurrence relation for the worst-case complexity W(n) of the sorting algorithm Mergesort for n a power of 2 is given by

W(n) = 2W(n/2) + n - 1, Initial Condition W(1) = 0

Recurrence relation for the worst-case complexity W(n) of FFT where the input polynomial size n is a power of 2 is given by

W(n) = 2W(n/2) + n Initial Condition W(1) = 0

The recurrence relation for the worst-case complexity W(n) of Strassen's algorithm is given by

W(n) = 7W(n/2), W(1) = 1

Recurrence relation for the worst-case complexity W(n) of Binary Search (version where no test for equality of midpoint is performed) where the list size n is a power of 2 is given by :

W(n) = W(n/2) + 1, Initial Condition W(1) = 1

An algorithm with worst-case complexity W(n) is said to be polynomial-time if

W(n) E O(n^k ) for some constant k

An algorithm with worst-case complexity W(n) is to be exponential if

W(n) E Ω(a^n ) and W(n) E O(b n ) for some pair of real numbers a and b, 1 < a ≤ b

An algorithm with worst-case complexity W(n) is said to be polynomial-time if

W(n) is O(n^k) for some positive constant k

Euclid's GCD algorithm is called with a = 23498876 and b = 100. After one iteration the new values of a and b are :

a = 100 and 76

If Euclid's GCD algorithm is initially called with a = 100019 and b = 100 after one iteration

a = 100, b = 19

A problem is in NP if it is

a decision problem and a candidate certificate for the problem can be guessed in polynomial time, and it can be verified in polynomial time whether it is a yes-certificate.

Dijkstra's algorithm can be implemented efficiently using

a priority queue of vertices not in the current tree T where the priority of a vertex is Dist[v]

Prim's algorithm can be implemented efficiently using

a priority queue of vertices not in the current tree T where the priority of a vertex is Nearest[v].

Standard implementations of a graph are:

adjacency matrix and adjacency lists

Strassen's algorithm for computing the product of two nxn matrices (where the basic operation is scaler multiplication) has worst-case complexity

approximately n^2.81

A polynomial-time algorithm is one where the worst-case complexity

belongs to O(nk) for some constant k

A decision problem is a problem that

can be posed as a yes-no question of the input values.

The (fractional) knapsack problem is solved using the Greedy method by selecting the objects in:

decreasing order of their densities

The fractional knapsack problem is solved using the Greedy method by selecting the objects in:

decreasing order of their densities

An efficient way to test for cycles when implementing Kruskal's algorithm is to utilize

disjoint sets ADT where the collection of disjoint sets corresponds to the vertex sets of the trees in the forest being grown

A damping factor is necessary when computing PageRank because it

ensures the iterative algorithm for computing PageRank converges

Disjoint Sets ADT can be implemented efficiently using:

forest and its parent array implementation

Longest directed paths joining every pair of vertices in a DAG can be computed by in time O(n^3)

giving each edge the weight -1 and applying Floyd's algorithm

Longest directed paths joining every pair of vertices in a DAG can be computed efficiently

giving each edge the weight -1 and applying Floyd's algorithm

Prim's algorithm is based on

growing a tree t by adding the smallest edge in Cut(T)

A principal eignenvector

has largest eigenvalue

PageRank is based on utilizing the

hyperlink structure of the web

Two primitive 4th roots of unity are

i and -i

Outputting the items of a binary search tree in sorted order can be achieved using:

inorder traversal

The graph ADT can be considered a special case of the digraph ADT because:

it is equivalent to the symmetric digraph obtained by replacing each edge with two edges oriented in opposite directions

The order of complexity of the worst-case complexity of Euclid's GCD algorithms for computing the GCD of a and b, where the input size n is the number of digits of a + b, is

linear in n

The average number of updates (for a uniform distribution) in computing the maximum element in a list is approximately equal to:

ln n

The average number of updates in computing the maximum element in a list of size n for a uniform distribution is approximately:

ln n

The depth of a complete binary tree having n leaf nodes is approximately equal to

log2n

The depth of a complete binary tree on n nodes is approximately equal to

log2n

The minimum depth of a binary tree having n nodes is approximately equal to:

log2n

The number of binary digits of an integer n is approximately equal to

log2n

f(n) satisfies the recurrence relation f(n) = f(n/2) +1, inti. cond. f(1) = 0. Then f(n) has order:

log2n

t(n) satisfies the recurrence relation t(n) = t(n/3) +1, init. cond. t(1) = 0 (where n is a power of 3). Then, t(n) equals

log3n

The number of octal digits of an integer n is approximately equal to:

log8n

The worst-case complexity of BFS for a graph on m edges (with no isolated vertices) has order:

m

The worst-case complexity of Depth-First Traversal for a digraph on m edges (with no isolated vertices) has order:

m

What is the order worst-case complexity of the most efficient algorithm for finding a shortest (minimum-hop length) directed path from u to v for two given vertices u and v in an (unweighted) digraph D having n vertices and m edges implemented using adjacency lists?

m + n

What is the order worst-case complexity of the most efficient algorithm for finding a shortest directed path from u to v for two given vertices u and v in a digraph D having n vertices and m edges implemented using adjacency lists?

m + n

The order of the worst-case complexity of Kruskal's MST algorithm for a graph having n vertices and m edges, implemented using adjacency lists, is:

m log n

What is the order worst-case complexity of Dijkstra's algorithm when the graph G on n vertices and m edges is implemented using adjacency lists and a min-heap is used to implement the priority queue of nodes not in the current tree?

m log n

The order of the worst case complexity of Kruskal's MST algorithm for a graph having n vertices and m edges, implemented using adjacency lists is

mlogn

FFT has order worst-case complexity W(n) given by

n log n

FFT has order worst-case complexity W(n) given by:

n log n

Mergesort has average complexity having order:

n log n

The smallest order worst-case complexity of a comparison-based sorting algorithm is:

n log n

log n! has order

n log n

log n! has order:

n log n

What is the order worst-case complexity of Dijkstra's algorithm when the graph G on n vertices and m edges is implemented using its adjacency matrix and an array is used to implement the priority queue of vertices not in the current tree?

n2

Consider the recurrence relation given by W(n) = 7W(n/2), initial condition W(1) = 1 for n a power of 2. Then W(n) has order

n^(log 2 7)

The number of multiplications performed by Strassen's algorithm to compute the product of two n×n matrices

n^(log 2 7)

Consider the recurrence relation given by W(n) = 10W(n/2), initial condition W(1) = 1 for n a power of 2. Then W(n) has order:

n^(log2 10)

The number of multiplications performed by Strassen's algorithm to compute the product of two n×n matrices:

n^(log2 7)

The Divide-&-Conquer algorithm for polynomial multiplication based on three recursive calls with polynomials half the size has worst-case complexity approximately equal to

n^1.59

Assume a weighted graph G on n vertices is implemented using its adjacency matrix, the order of the the worst-case complexity of Dijkstra's algorithm is:

n^2

Assume a weighted graph G on n vertices is implemented using its adjacency matrix, the order of the the worst-case complexity of Prim's algorithm is:

n^2

Consider the recurrence relation given by W(n) = 4W(n/2), initial condition W(1) = 1 for n a power of 2. Then W(n) has order

n^2

Quicksort has worst-case complexity having order:

n^2

The straightforward algorithm (taught in elementary school) for computing the product of two integers having n digits (where the basic operation is digit multiplication) has order worst-case complexity

n^2

The straightforward algorithm for obtaining the symbolic product of two polynomials of size n by computing every convolution has worst-case complexity

n^2

What is the order worst case complexity of Prim's MST algorithm when the graph G on n vertices is implemented using its adjacency matric

n^2

Assume a weighted graph G on n vertices is implemented using its adjacency matrix, the order of the the worst-case complexity of Kruskal's algorithm is:

n^2log n

Assume a weighted graph G on n vertices is implemented using its adjacency matrix, the order of the worst case complexity of Kruskal's algorithm is

n^2logn

Floyd's algorithm for all-pairs shortest paths for a weighted digraph with n vertices has order worst-case complexity given by

n^3

Floyd's algorithm for all-pairs shortest paths has order worst-case complexity given by:

n^3

The dynamic programming algorithm for computing an optimal binary search tree has order worst-case complexity given by

n^3

The dynamic programming algorithm for optimal parenthesization of a chained matrix product has order worst-case complexity given by

n^3

The straightforward algorithm for computing the product of two nxn matrices (where the basic operation is scaler multiplication) has worst-case complexity

n^3

Consider the recurrence relation given by W(n) = 3W(n/2), initial condition W(1) = 1 for n a power of 2. Then W(n) has order

n^log2,3

The Divide-&-Conquer algorithm for large integer multiplication based on using FFT has worst-case complexity approximately equal to

nlog2n

Strassen's algorithm applies for matrices that are

nxn for n a power of 2

The divide-and-conquer recursion in Strassen's algorithm applies for matrices that are:

nxn for n a power of 2

A deep copy of a binary tree can be implemented by using an algorithm similar to:

preorder traversal

Suppose matrices A and B have dimensions pxq and qxr, respectively. Then the dimensions of their product is

pxr

One interpretation of PageRank is based on

random web surfer

Kruskal's algorithm is based on

sorting the edges and growing a forest by choosing next smallest edge that does not form a cycle

A data structure that can be used to obtain a non-recursive version of a recursive algorithm:

stack

A recursive algorithm can be written as a non-recursive algorithm using the following data structure:

stack

A clique in a graph G is a(n)

subset of vertices such that every pair of distinct vertices in the subset are adjacent.

The diameter of a graph is

the maximum length of a shortest path joining any pair of vertices

The diameter of a graph is:

the maximum length of a shortest path joining any pair of vertices

Consider the matrix equation for PageRank R for the (web) digraph W given by R = B^TR. Then (B^T)i [p][q] equals

the probability that a random web surfer starting at page q reaches page p by following a path of i hyperlinks

A problem is tractable means

there is a polynomial-time algorithm for solving the problem

Input and output for both Kruskal's and Prim's MST algorithms are respectively

weighted connected graph and minimum spanning tree

The sequence of computations in the action of the left-to-right binary method for the power 33 are:

x -> x^2 -> x^4 -> x^8 -> x^16 -> x^33

The sequence of computation involved in the left-right binary method for 57 is

x → x^3 → x^7 → x^14 → x^28 → x^57

Assuming a uniform distribution the worst case and average complexities of Insertion sort are

~n^2 /2 and ~n^2 /4

Assuming a uniform distribution the worst-case and average complexities of Insertion Sort are:

~n^2/2 and ~n^2/4

The smallest worst-case complexity of a comparison-based sorting algorithm is

Θ (n log n)

The worst-case complexity of BFS (breadth-first search) for a graph without isolated vertices having n vertices and m edges implemented using adjacency lists:

Θ(m)

Mergesort has best, average and worst-case complexities, respectively, given by

Θ(n log n) , Θ(n log n), Θ(n log n)

Quicksort has best, average and worst-case complexities, respectively, given by:

Θ(n log n) , Θ(n log n), Θ(n^2 )

Linear Search has worst-case and best-case complexities, respectively:

Θ(n), Θ(1)

The symbol for reducibility is


Ensembles d'études connexes

Chapter 62: Care of Patients with Pituitary and Adrenal Gland Problems

View Set