Final Exam Review (Quizzes)

Ace your homework & exams now with Quizwiz!

In this sequence, 11 4 20 45 32 60 98 70, which element seems to be the pivot?

20

Which Master's Theorem case does it belong: T(n)=16T(n/4) + n

Case 1

Dynamic programming is typically applied to

Optimization problems

Consider the recurrence T (n)= 2T (n/2) + 17) + n Make a good guess of the solution (Substitution method Step 1) :

T (n)= O(n lg n)

The Average case complexity of Insertion sort is:

О(n^2)

Consider the strings "PQRSTPQRS" and "PRATPBRQRPS". What is the length of the longest common subsequence?

7

Given an array, A = <5, 2,4, 6,1, 3>, what is the sequence of elements after the third step, if INSERTION-SORT is applied on it?

<2,4,5,6,1,3>

What do you mean by "Programming" in the context of Dynamic Programming?

A tabular method

How is the safe edge chosen and added to set A in Kruskal's algorithm ?

Always a least-weight edge

Which Master's Theorem case does it belong to: T(n)=7T(n/2) + n^3

Case 3

The following array is a max heap: [10, 3, 5, 1, 4, 2].

False

Which colored vertices represent the frontier between discovered and undiscovered vertices?

Gray

Given an unsorted array. The array has this property that every element in an array is at most k distance from its position in the sorted array where k is a positive integer smaller than the size of an array. Which sorting algorithm can be easily modified for sorting this array and what is the obtainable time complexity?

Heap Sort with time complexity O(nLogk)

The algorithm design techniques for simple insertion sort algorithm used in the book is...

Incremental approach

You have to sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?

Merge sort

What is NOT the property of a Greedy Algorithm ?

Non Overlapping sub problems

What is the running time of heapsort?

O( n lg n)

The time required to compute the hash value h(k) is

O(1)

The complexity of Dijkstra's algorithm is :

O(V lg V + E)

What is the complexity of adding an element to the heap?

O(log n) & O(h)

What is meant by a degree of a vertex in an undirected graph?

The number of edges incident on it

Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10 Which statement is correct?

The pivot could be either the 7 or the 9

A dynamic-programming algorithm solves each sub-problem just once and then saves its answer in a table, thereby avoiding the work of recomputing the answer every time it solves each sub problem.

True

A recursion tree is best used to generate a good guess, which you can then verify by the substitution method

True

Will Dijkstra's algorithm work for an undirected graph?

Yes, if an un directed edge is viewed as combination of two edges directed at opposite directions

Rank the following functions by increasing order of growth; that is, find an arrangement g1, g2, g3, g4 of the functions satisfying: g1 = O(g2), g2 = O(g3), g3 = O(g4). f1=n^(logn) f2=sqrt{n} f3=n^(3+sin(n)) f4=log n^n

f2 ,f4, f3, f1

Which of the following statement(s) is TRUE? i. A hash function takes a message of arbitrary length and generates a fixed length code. ii. A hash function takes a message of fixed length and generates a code of variable length. iii. A hash function may give the same hash value for distinct messages.

i and iii only

Which is the correct order of the following algorithms with respect to their time Complexity in the best case ?

insertion sort < Quick sort < Merge sort < selection sort

In chaining, we place all the elements that hash to the same slot into the same

linked list

An edge is a light edge satisfying a given property if its weight is the

minimum of any edge satisfying the property

Which of the following two schemes to design good hash functions provide good performance?

multiplication

In practice, merge sort beats insertion sort for...

n > 30

An alternative method for resolving collisions, is called

open addressing

LCS for input Sequences "ABCDGH" and "AEDFHR" is

"ADH" of length 3

Dynamic programming approach is used when : 1. It provides optimal solution 2. The solution has optimal substructure 3. The given problem can be reduced to any problem 4. It's faster than Greedy

2

Suppose we are sorting an array of eight integers using heapsort, and we have just finished some heapify (either maxheapify or minheapify) operations. The array now looks like this: 16 14 15 10 12 27 28 How many heapify operations have been performed on the root of the heap?

2

When developing a dynamic-programming algorithm, we follow a sequence of steps, Choose the correct ones from below: 1. Characterize the structure of an non optimal solution. 2. Recursively define the value of an optimal solution. 3. Compute the value of an optimal solution, typically in a bottom-down fashion. 4. Construct an optimal solution from computed information.

2 & 4

There are n people, each in possession of a different rumour. They want to share the news with each other by sending electronic messages. What is the minimum number of messages they need to send to guarantee that every one of them gets all the rumours?

2n - 2

Select from the following methods which can be used to solve the longest common subsequence problem? 1. Recursion 2. Dynamic programming 3. Both recursion and dynamic programming 4. None of the mentioned

3

What is the time complexity of the brute force algorithm used to find the longest common subsequence? 1. O(n) 2. O(n2) 3. O(n3) 4. O(2n)

4

Consider a hash table of size 11 where hashing function is (h(item)=item%11). Insert the following , according to the type of hash table below: 54, 26, 93, 17, 77, and 31.

77 _ _ _ 26 93 17_ _ 31 54

What is the hash key value of 'Donaldson' if you assign each letter its corresponding number in the alphabet (ie f = 6) and if you use 9 as the divisor?

8

Which Master's Theorem case does it belong to: T(n)=2T(n/2) + n log n

Case 2

Which search technique explores the edges out of the most recently discovered vertex that still has unexplored edges leaving it. Once all of 's edges have been explored, the search "backtracks" to explore edges leaving the vertex from which was discovered

Depth-first search

What is the below approach known as : Break the problem into several subproblems that are similar to the original problem but smaller in size, solve the subproblems recursively and then combine these solutions to create a solution to the original problem

Divide-and-conquer

The following paradigm can be used to find the solution of the problem in minimum time: Given a set of non-negative integer, and a value K, determine if there is a subset of the given set with sum equal to K:

Dynamic programming

Dijkstra's algorithm may not terminate if the graph contains negative-weight edges.

False

An undirected graph G has n nodes. Its adjacency matrix is given by an n × n square matrix whose (i) diagonal elements are 0's and (ii) non-diagonal elements are 1's. which one of the following is TRUE?

Graph G has multiple distinct MSTs, each of cost n-1

Which algorithm would work best to sort data as it arrives, one piece at a time, perhaps from a network?

Insertion sort

Which of the following sorting algorithms for a typical implementation gives the best performance when applied on an array which is sorted or almost sorted?

Insertion sort

Which of these sorting algorithms (Merge or Insertion) could easily be parallelized? (Given any number of extra computers to help with the task, which would require the least extra programming to have them work together to sort the list)?

Merge

Which algorithm closely follows the divide-and-conquer paradigm?

Merge sort

The running time of Prim's algorithm using a Fibonacci heap is...

O(E + V lg V )

An array consists of n elements. We want to create a heap using the elements. The time complexity of building a heap will be in the order of

O(n*log n)

Quick sort uses...

Partitioning

For an edge (u,v) , a process of of testing whether we can improve the shortest path to v found so far by going through u and, if so, updating shortest-path estimate (v.d ) is called

Relaxation

A shortest path from u to v is a path of minimum weight from u to v. The shortest- path weight from u to v is defined as δ(u,v) = min{w(p) :p is a path from u to v}.

True

Does heap exhibit the property of a binary tree?

True

For any two functions f (n) and g(n), we have f (n) = theta(g(n) ) if and only if f (n) = O(g (n)) and f (n)= omega (g(n)).

True

In a DFS of an undirected graph G, every edge of G is either a tree edge or a back edge.

True

With hashing, the element is stored in slot h(k) that is,in order to compute the slot from the key k we use

a hash function h

The Master Theorem applies to recurrences of the following form: T (n) = aT (n/b) + f(n) In what form should the constants a and b be?

a ≥ 1 and b > 1

Consider the problem of computing min-max in an unsorted array where min and max are minimum and maximum elements of array. Algorithm A1 can compute min-max in a1 comparisons without divide and conquer. Algorithm A2 can compute min-max in a2 comparisons by scanning the array linearly. What could be the relation between a1 and a2 considering the worst case scenarios?

a1 > a2

When we have only an asymptotic upper bound, we use...

big-oh notation

One of the simplest collision resolution technique is called

chaining

In case of hashing, two keys may hash to the same slot. We call this situation a

collision

Quick sort, like merge sort, applies the

divide-and-conquer paradigm

We say that g(n) is an asymptotically tight bound for f (n), if

f (n)=Θ( g(n) )

The worst-case running time of an algorithm

gives us an upper bound on the running time for any input

We say that an element with key k hashes to slot h(k),we also say that h(k) is the

hash value of key k

In regards to the design of good hash functions, two of the schemes which are heuristic in nature are...

hashing by division and hashing by multiplication

Dynamic programming thus uses additional memory to save computation time; it serves an example of a

time-memory trade-off

Despite this slow worst-case running time, quicksort is often the best practical choice for sorting because it is remarkably efficient on the average: its expected running time is

Θ(n lg n)

Solving T(n) = 2T(n/2) +cn, where c> 0 is constant using recursion

Θ(n lg n)

The merge sort has a time complexity of...

Θ(n lg n)

Consider the recurrence T(n) = 4T(n/2) + n Use masters method to solve T(n)

Θ(n^2)

On an input array of n numbers ,the quicksort algorithm has a worst-case running time of

Θ(n^2)

The insertion sort has a worst-case running time of...

Θ(n^2)

In a hash table of size 13 which index positions would the following two keys map to? 27, 130

1, 0

What are the correct intermediate steps of the following data set when it is being sorted with the Quick sort? 15,20,10,18

10, 20,15,18 -- 10,18,15,20 -- 10,15,18,20

The recurrence relation T(n) = 4T(n/2) + n2 /lg n can be best solved using Master Method

False

Suppose we have an O(n) time algorithm that finds the median of an unsorted array. Now consider a QuickSort implementation where we first find the median using the above algorithm, then use median as a pivot. What will be the worst case time complexity of this modified QuickSort?

O(nLogn)

Breadth-first search is so named because it expands the frontier between discovered and undiscovered vertices uniformly across the breadth of the frontier.

True

Dijkstra's algorithm solves the single-source shortest-paths problem on a weighted, directed graph G= (V ,E) for the case in which all edge weights are non negative.

True

Is the following statement valid about shortest paths? Given a graph, suppose we have calculated shortest path from a source to all other vertices. If we modify the graph such that weights of all edges become double of the original weight, then the shortest path remains same only the total weight of path changes.

True

Like insertion sort, heapsort sorts in place: only a constant number of array elements are stored outside the input array at any time.

True

The two algorithms for solving the minimum spanning-tree problem are Kruskal's algorithm and Prim's algorithm.

True

What is the second step in the substitution method for solving recurrences which comprise of two steps:

Use mathematical induction to find the constants and show that the solution works

We say that an edge (u,v) ϵ E crosses the cut (S, V - S ) if one of its endpoints is in S and the other is in

V - S

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true? i. 9679, 1989, 4199 hash to the same value ii. 1471, 6171 has to the same value iii. All elements hash to the same value iv. Each element hashes to a different value

i and ii only

The running time of an algorithm on a particular input is the number of...

primitive operations or "steps" executed

Consider the problem of searching an element x in an array A of size n. The problem can be solved in O(Logn) time if. 1) Array is sorted 2) Array is reversely sorted 3) Array is unsorted

Both 1 & 2

Which of the following statements is/are TRUE for undirected graphs? P: Number of odd degree vertices is even. Q: Sum of degrees of all vertices is even.

Both P and Q

In an undirected graph, self-loops are possible.

False

Prim's algorithm executed on a planar graph will perform best when the priority queue is implemented using an array.

False

Can you solve the following recurrence using Master's Theorem: T(n)=2T(n/2)+n/log(n) ?

No

Let G be an undirected connected graph with distinct edge weight. Let emax be the edge with maximum weight and emin the edge with minimum weight. Which of the following statements is false?

No minimum spanning tree contains emax

A data structure for maintaining a set S of elements, each with an associated value called a key.

Priority queue

Heap can be used as

Priority queue

To implement Dijkstra's shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:

Queue

What is the model of the implementation technology for analyzing an algorithm?

Random-access machine model

What is recurrence for worst case of QuickSort and what is the time complexity in Worst case?

Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n^2)

A mergesort works by first breaking a sequence in half a number of times so it is working with smaller pieces. When does it stop breaking the list into sublists?

When each sublist has one element

"Big-omega" provides the

asymptotic lower bound

A ________________ of a connected graph is a minimal set of edges whose removal separate the graph into two components.

cut

In BFS , if (u,v) belongs to E and vertex u is black, then vertex is either gray or black; that is, all vertices adjacent to black vertices have been

discovered

In DFS, each vertex is initially white, is grayed when it is _ _ _ _ _ _ _ _ _ in the search, and is blackened when it is _ _ _ _ _ _ _ _ _ _, that is, when its adjacency list has been examined completely.

discovered, finished

Let P be a QuickSort Program to sort numbers in ascending order using the first element as pivot. Let t1 and t2 be the number of comparisons made by P for the inputs {1, 2, 3, 4, 5} and {4, 1, 5, 3, 2} respectively. Which one of the following holds?

t1 > t2

In general, the time taken by an algorithm grows with the size of the input, so it is traditional to describe the running time of a program as a function of

the size of its input

MST Algorithms works on which of the following type(s) of graph:

weighted ,connected, undirected

To keep track of progress, breadth-first search colors each vertex

white, gray, or black

T(n) = T(sqrt{n}) + Θ(Log Log n) What is the value of recurrence?

Θ( (Log Log n) ^ 2)

In a hash table in which collisions are resolved by chaining, an unsuccessful search takes average-case time

Θ(1+ α)

The running time of DFS is :

Θ(V + E)


Related study sets

The Integumentary System (the skin)

View Set

Modules 13 - 14: Layer 2 and Endpoint Security

View Set

LS CH2 - Managerial Accounting and Cost Concepts

View Set