Connor's- study set 11 13 23

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Select correct inequality for the asymptotic order of growth of the below function. That is, as the value of n becomes very large what is the relation between the two functions. n ____ n2

<

When we say algorithm A is asymptotically more efficient than B, what does that imply?

A will always be a better choice for large inputs

Let W(n) and A(n) denote respectively, the worst case and average case running time of an algorithm executed on an input of size n. which of the following is ALWAYS TRUE?

A(n) = Big O(W(n))

Which of the following correctly defines what a 'recurrence relation' is?

An equation (or inequality) that relates the nth element of a sequence to its predecessors (recursive case). This includes an initial condition (base case).

To find the optimal solution for 0-1 knapsack, what would be dimensions of the extra array that we would need? The knapsack has a capacity of W, and there are total of n items. Assume we are using the approach that was discussed in the exploration.

Array[W+1][n+1]

What is the correct loop invariant for the below code: for i in range(len(A)): # in pseudo-code for i=0,...,len(A)-1 answer += A[i] return answer

At the start of iteration i of the loop, the variable answer should contain the sum of the numbers from the subarray A[0:i-1].

Given two vertices s and t in a connected graph G, which of the two traversals, BFS and DFS can be used to find if there is a path from s to t?

Both BFS and DFS

We use reduction to prove that NP-Completeness of a problem X from A. As a part of reduction we must prove which of the following statements? Assume A is a NP-Hard problem. Statement P: A can be transformed to X in a polynomial time Statement Q: We can obtain solution to A from X in polynomial time

Both P and Q

Which of the two approaches solves the Fibonacci Number problem with a better time complexity?

Both the options

In which of the two approaches we start with the base case and proceed to solve the bigger subproblems?

Bottom-Up Approach

In which of the following approaches we start with the base case and proceed to solve the bigger subproblems?

Bottom-up Approach

A binary search algorithm searches for a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until the target value is found or until a search can no longer be performed. This problem can be solved using which of the techniques?

Divide and Conquer

Prim's and Kruskal's algorithms to find the MST follows which of the algorithm paradigms?

Greedy Approach

If you are given different versions of the same algorithm with the following complexity classes, which one would you select?

Logarithmic

What is the solution of T(n) = 2T(n/2) +n/logn using the Master theorem?

Master Method does not apply

In dynamic programming, the technique of storing the previously calculated values is called

Memoization

Which of the following data structures can be used to implement the Dijkstra algorithm most efficiently?

Min priority queue

What would be the time complexity of the following algorithm? reverse(a): for i = 1 to len(a)-1 x = a[i] for j = i downto 1 a[j] = a[j-1] a[0] = x

O(n^2)

What are the major required aspects in a problem in order to apply Dynamic Programming Technique?

Optimal Substructure and Overlapping subproblems

Can you identify which of the below problems can be solved using the backtracking technique?

Soduko Puzzle, Maze solution, Power set of given set

In the Longest Common Subsequence problem assume we are comparing two strings of lengths m and n. In the bottom-up approach the solution we build a 2-Dimensional array called Cache[m][n]. The final solution was obtained by accessing which element of the cache?

The element in the bottom right corner of the cache[m][n]

Solve the time complexity of an algorithm with the recurrence relation X(n) = 3 * X(n-1) for n > 1 X(1) = 4

Theta(3^n)

What is the running time of the product sum algorithm when solved using the recurrence formula written in the previous question?

Theta(n)

Given the following algorithm foo(n) if n <= 1 return 1 else x = foo(n-1) for i = 1 to n x = x + i return x Determine the asymptotic running time. Assume that addition can be done in constant time.

Theta(n^2)

What is the order of growth of T(n) = 2T(n/2)+n^2 try to solve it using the Master Method.

Theta(n^2)

What is the solution of T(n) = 2T(n/2) +n^2using the Master theorem?

Theta(n^2), Case 3

What would be the time complexity of the following algorithm? int sum = 0;for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { for (k = 0; k < n; k++) { if (i == j == k) { for (l = 0; l < n*n*n; l++) { sum = i + j + k + l; } } } } }

Theta(n^4)

Solve the following recurrence by giving the tightest bound possible. T(n) = 4T(n.4) +4n

Theta(nlogn)

What is the order of growth of T(n) = 2T(n/2)+n try to solve it using the Master Method.

Theta(nlogn)

Backtracking is used to solve which of the problems:

To find all possible solutions

In which of the two approaches we start with the bigger problem and go on solving the subproblems until we reach the base case?

Top-Down Approach

A graph can be represented as a tuple containing two sets. For example: A= ({...},{...}) (T/F)

True

A greedy algorithm is hard to design sometimes as it is difficult to find the best greedy approach (T/F)

True

All possible greedy algorithms, at each step, choose what they know is going to lead to an optimal/near optimal solution. (T/F)

True

Dijkstra is used to solve for a shortest path in a weighted graph with non negative weights.

True

Dynamic programming technique would always return an optimal solution (T/F)

True

Greedy algorithms are efficient compared to dynamic programming algorithms (T/F)

True

If problem A can be solved in polynomial time then A is in NP

True

Is the following a property that holds for all non-decreasing positive functions f and g? (True=Yes/ False=No) If f(n) = O(n2) for c=1 and n0=0 and g(n) = Theta(n2) for n0=0 and c1 =1 and c2=1 then f(n) = O(g(n)).

True

Mark True/False: A graph can have many spanning trees.

True

Removing the maximum weighted edge from a Hamiltonian cycle will result in a Spanning Tree

True

We are given an array of numbers and we are asked to find an optimal solution to maximize the sum of numbers (i.e continuous subsequence that has maximum sum). if the order of the input numbers were altered or if we use a different algorithm, we will always end up with the same combination of numbers as answer.

True

P=NP

Unknown

We can use Divide and Conquer technique to solve a problem in which of the following scenarios?

We can break the problem into several subproblems that are similar to the original problems but smaller in size

What makes the solution for the 'Activity Selection Problem' that we implemented in the exploration, a greedy approach?

We make a best available choice in each iteration and we never look back

The difference between Divide and Conquer Approach and Dynamic Programming is

Whether the sub-problems overlap or not

Can Product Sum problem be solved using Dynamic Programming technique?

Yes

Can the Rod Cutting problem be solved by Dynamic Programming?

Yes

Bubble-sort(a) for i = a.length() downto 0 for j = 0 to i-1 if a[j]>a[j+1] swap(a[j],a[j+1]); end if What parameters does the running time of the BubbleSort algorithm 'generally' depend on (check all that apply)?

a.The programming language use to code this algorithm b.The speed of the computer: CPU c.The size the array

What is the basic operation (that which is executed maximum number of times) in the following code? reverse(a): for i = 1 to len(a)-1 x = a[i] for j = i downto 1 a[j] = a[j-1] a[0] = x

a[j] = a[j-1]

In the o-1 knapsack recurrence formula f(x,i) = max{ vi + f[x-wi , i-1] , f[x , i -1] } The first part vi + f[x-wi , i-1] represents : The second part f[x , i -1] represents:

adding the ith item to the knapsack, not adding the ith item to the knapsack

Which of the following is true for Prim's algorithm? a) It is a greedy algorithm b) It never accepts cycles in the MST c) It can be implemented using a heap

all of the above

Which equations given below best describe the BubbleSort algorithm: Bubble-sort(a) for i = a.length() downto 0 for j = 0 to i-1 if a[j]>a[j+1] swap(a[j],a[j+1]); end if

an2, where a is a constant

In _________________ we start with the base case and build the solution starting from base case. In __________ we start solving the the bigger problem proceed towards the base case.

bottom-up approach, top-down approach

Which of the following equations correctly represent the factorial function. Factorial of a number n is given by: Factorial of n = n * (n-1) (n-2) .... 3*2*1

f(n) = n f(n-1)

Which of the following can be used to compare two algorithms?

growth rates of the two algorithms

Fill in the below pseudocode for activity selection problem using the greedy approach. The function returns the count of the maximum number of activities that can be selected. activitySelection(activities): sortBasedonEndTime(activities) # uses quick sort to sort the activities for activity in activities: if currendEndTime <= activity.startTime: [ Select ] ["result = result + 1", "result.append(activity)"] , [ Select ] ["currentEndTime = activity.endTime", "currentEndTime = activity.startTime"] return result Time complexity for the pseudocode will be [ Select ] ["O(n log n)", "O(n)", "O(n^2)"]

"result = result + 1", "currentEndTime = activity.endTime, "O(n^2)"

What are the steps to approach a problem?

1. Understand the problem 2. Restate the problem in terms of math objects - numbers, arrays, lists, graphs, etc 3.Write an algorithm (Set of instructions that can solve the problem) 4.Prove that the algorithm is correct 5.Analyze how fast the algorithm can run 6.Code the algorithm a programming language

If the solution obtained by an approximation algorithm is : 10 The optimal solution is : 5 What will be the value of the approximation ratio?

2

For an undirected graph G, what will be the sum of degrees of all vertices. (degree of a vertex is the number of edges connected to it.)V: number of vertices, E: number of edges.

2|E|

Consider the graph M with 3 vertices. Its adjacency matrix is shown below. M = [[0, 1, 1], [1, 0, 1], [1, 1, 0]] This graph has ____ number of spanning trees.

3

In the exploration to show that the independent set problem is NP-Complete we have used which of the following NP-Hard problems?

3SAT

Consider the following algorithm 1 Bubble-sort(a) 2 for i = a.length() to 1 3 for j = 1 to i-1 4 if a[j]>a[j+1] 5 swap(a[j],a[j+1]); 6 end if What is its basic operation (write the line number of code which would define the execution time of the code)?

4

Given two integer arrays to represent weights and profits of 'N' items, find a subset of these items that will give us maximum profit such that their cumulative weight is not more than a given number 'C'. Best technique to solve this problem is?

Dynamic Programming

The asymptotic runtime of the solution for the combination sum problem that was discussed in the exploration is ____________.

Exponential

Which of the following recurrence relations is correct representation of the towers of Hanoi problem that was discussed in the exploration?

F(n) = 2F(n-1) + 1

What is the correct recurrence formula for the unbound knapsack problem that was discussed in the exploration? Consider the weight of the items w[1..n], value of the items v[1..n]

F(x) = max{ F[x-wi] + vi }

For every decision problem there is a polynomial time algorithm that solves it. (T/F)

False

Greedy algorithms would always return an optimal solution (T/F)

False

If problem A is in NP then it is NP-complete.

False

If there is a polynomial time reduction from a problem A to Circuit SAT then A is NP-hard.

False

Mark True/False: A spanning tree of a graph should contain all the edges of the graph.

False

When performing the topological sort we always find a unique solution.

False

T/F: Dynamic programming technique would always return an optimal solution

T

What is the solution to following recurrence relation: T(n) = T(n-1) +c2 T(0) = c1

T(n)=nc2+c1

Suppose your algorithm performs multiplication of two numbers x, y. The function takes x , y as inputs. How would you express the running time?

T(x,y)

Rank the following functions by increasing order of growth: log( n! ), 10000n2, log(n3), 2n, n2log(n)

log(n3), log( n! ), 10000n2, n2log(n), 2n


संबंधित स्टडी सेट्स

14 Fundamentals of Electricity: Unit 14 - Magnetic Induction

View Set

World Civ Midterm Multiple Choice Quiz 19

View Set

Division and Classification, ENC1101 Chapter 8, ENC1101 Chapter 13, ENC1101

View Set

3415 Wasting and Stunting Lecture

View Set