wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

221 quiz questions exam 2 prep

Total questions: 26

Worksheet time: 14mins

Name
Class
Date
1.

What is the recurrence relation for the code below?

a)

T(n) = T(n-1) + O(1) and T(1)=0

b)

 T(n) = T(n-1) + O(n) and T(1)=0

c)

T(n) = 2T(n-1) + O(1) and T(1)=0

d)

T(n) = 2T(n-1) + O(n) and T(1)=0

2.

How many recursive problems are solved by the Recur_fun(int n) for n=3?

a)

5

b)

8

c)

7

d)

6

3.

How many recursive problems are solved for n>0?

a)

n

b)

2n

c)

2n - 1

d)

2n

4.

How many recursive steps are required to reach the base case (the solutions to n=0)?

a)

n

b)

log2n

c)

n/2

d)

nlog2n

5.

How can you classify this algorithm using the big-O asymptotic notation?

a)

O(n)

b)

O(log2n)

c)

O(2n)

d)

O(n2)

6.

Is this recursive function correct?

a)

True

b)

False

7.

What is the purpose of postfix form for algebraic expression?

a)

The postfix form is used for find syntax errors of an algebraic expression.

b)

The postfix form provides a more readable form of an algebraic expression.

c)

The postfix form speeds up the evaluation process of an algebraic expression.

d)

The postfix form decreases the arithmetic operations.

8.

What is the postfix form for the expression:  x+y-z+t

a)

x y + z - t +

b)

x y z + t + -

c)

x y + - z t +

d)

x y + z t - +

9.

What is the purpose of using the stack data structure during the conversion from infix to postfix forms for an arithmetic expression?

a)


To push the operands (numbers or variables) into the postfix form in the reverse order.

b)

To push the arithmetic operators before enqueuing them in the right order into the postfix form.

c)

A stack is used only to detect the end of an expression.

d)

A stack is redundant during the conversion to postfix form and it should not be used.

10.

Assume that an expression consists of one digit numbers and arithmetic operations on them and it is given in postfix form:  4 3 1 + / 2 *

What is the value of the expression?

a)

-1

b)

0

c)

1

d)

2

11.

How many times is the push operation called by the algorithm for the evaluation of the expression in the postfix form:  4 3 1 + / 2 * from the previous question?

a)

4

b)

5

c)

6

d)

7

12.

How many times is the pop operation called by the algorithm for the evaluation of the expression in the postfix form: 4 3 1 + / 2 * from the previous question?

a)

2

b)

3

c)

4

d)

5

e)

6

13.

Consider the quick sort algorithm to sort n consecutive integers and the middle element is selected as the pivot at each recursive call.

What is the recurrence relation that describes the quick sort algorithm on this input?

a)

T(n)=2T(n/2) + n and T(1)=0

b)

T(n)=T(n/2) + n and T(1)=0

c)

T(n)=T(n-1) + n and T(1)=0

14.

Consider the quick sort algorithm to sort n consecutive integers and  the middle element is selected as the pivot at each recursive call.

What is the running time of the quick sort algorithm expressed in terms of the big-O asymptotic notation on this input?

a)

O(nlog_2(n))

b)

O(n^2)

c)

O(n)

15.

Which case of the quick sort algorithm cannot be solved by the Master method?

a)

best

b)

worst

c)

average

16.

The efficiency of the quick and merge sort algorithms expressed in the terms of the Big-O asymptotic notation is the same for

a)

worst and best cases of the quick sort

b)

worst and average cases of the quick sort

c)

best and average cases of the quick sort

17.

The merge sort algorithm reaches the base case after a certain number of recursive steps. Select the number of recursive steps for the merge sort.

a)

nlog_2(n)

b)

log_2(n)

c)

n

d)

2^n

18.

How many recursive subproblems are solved by the merge sort algorithm applied to a sequence of n elements?

a)

2^(n/2)

b)

2^log_2(n) -1

c)

2^n - 1

d)

n/2

19.

What is the recurrence relation equation for the merge sort algorithm?

a)

T(n) = T(n/2) +O(n) and T(1) = 0

b)

T(n) = T(n/2) +O(n log2n) and T(1) = 0

c)

T(n) = 2T(n/2) +O(n) and T(1) = 0

d)

T(n) = 2T(n/2) +O(n log2n) and T(1) = 0

20.

Which recurrence relation cannot be solved by the Master method?

a)

T(n) = T(n/2) + O(n) and T(1) = 0

b)

T(n) = T(n/16) + O(1) and T(1) = 0

c)

T(n) = T(n/2) + O(log2(n)) and T(1) = 0

d)


T(n) = T(n-2) + O(n) and T(1) = 0

21.

Is the merge sort an in-place algorithm?

Select: True for Yes and False for No.

a)

True

b)

False

22.

Which statement is true about a singly linked list?

a)

A linked list uses less memory to store data than an array

b)

The insert operation does not change addresses of existing nodes within a linked list.

c)

A linked list provides a direct access to data

d)

A sorted linked list is a perfect data structure for implementing the binary search algorithm.

23.

Which operation can be done in a constant time (O(1)) on singly linked list when we are at the node pointed to by (pointer) P?

a)

Delete a node pointed to by P.

b)

Insert a new node after the node pointed to by P.

c)

Insert a new node before the node pointed to by P.

24.

An insertion of a new node at the beginning of a singly linked list should update explicitly or implicitly how many pointers?

a)

Three pointers

b)

Two pointers

c)

Four pointers

d)

One pointer

25.

Assume that the queue data structure is implemented based on a singly linked list. The enqueue operation takes a constant time when the following information is provided:

a)

The address of (pointers to) the middle node

b)

The address of (pointer to) the first node.

c)

The queue size, number of nodes in a queue.

d)

The address of (pointer to) the last node

26.

We use the definition of type Link below to create an object of this type initialized with the string "Hello". Which statement is correct?

a)

Link obj = Link('Hello');

b)

Link* obj = Link("Hello");

c)

Link obj = new Link("Hello");

d)

Link obj = Link("Hello");