How to practice Programming, Data Structures and Algorithms

Attempt a question, record the concept and assumptions, then check the available answer. Rework mistakes after revising the relevant concepts. Topic tags can overlap; review the question context.

Questions 1–10 of 31. Imported answers require independent review unless marked reviewed.

Topic practice 31 questionsPage 1 of 4

Question 15

Open question
DAMCQ1 markNeeds review
Consider that the quick sort algorithm is used to sort an array of

distinct randomly ordered elements. In every call, the pivot is chosen as the first element of the current subarray.
Let

denote the expected time to sort the array. Assume that the time to partition is linear in the size of the current subarray.
Which of the following recurrence relations correctly represents

in this scenario?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 16

Open question
DAMCQ1 markNeeds review
Consider the given Python program.
def append_to_lst(val, lst=[]):
lst.append(val)
return lst
print(append_to_lst(1))
print(append_to_lst(2))
print(append_to_lst(3, []))
Which of the following is the correct output of this program?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 25

Open question
DAMSQ1 markNeeds review
You are given the following Pre-order and In-order traversals of a Binary Tree T with nodes E, F, G, P, Q, R, S.
Pre-order: P Q S E R F G
In-order: S Q E P F R G
Which of the following statements is/are true about the Binary Tree T?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 31

Open question
DANAT1 markNeeds review
Let

be a sorted array containing 1000 distinct integers. You perform a recursive binary search on

to find an element

. Suppose each comparison checks whether the middle element computed during the current recursive step is equal to, less than, or greater than

. The maximum number of comparisons that may have to be performed if

is not an element of

is ________ . (Answer in integer)

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 39

Open question
DAMCQ2 marksNeeds review
A recursive function in Python is given.
def mystery(n):
if n <= 0:
return 1
else:
return mystery(n-1) + mystery(n-2)
Now, consider the following function call:
mystery(4)
Assume that a typical runtime stack is used to manage function calls. Each function call is pushed onto the stack and removed only after it finishes execution.
Which of the following options denotes the total number of function calls (i.e., the total number of stack activations), including the initial call, to compute mystery(4)?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 40

Open question
DAMCQ2 marksNeeds review
Consider a directed graph

, where

is the finite set of vertices and

is the set of directed edges between the vertices.

may contain cycles but there is no self-loop. Further,

may not be strongly connected.
Let

be the graph obtained by reversing the directions of all the edges in

without changing the set of vertices.
Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex

of a graph visits only the reachable vertices from

in that graph.
Which of the following statements must always be true, regardless of the structure of

?
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 49

Open question
DAMSQ2 marksNeeds review
Consider the problem of sorting the given array in ascending order:
P = [1, 2, 3, 5, 4]
Consider two sorting algorithms Bubble Sort (BS) and Insertion Sort (IS).
Let N1 be the total number of comparisons done by BS on the elements of P and N2 be the total number of comparisons done by IS on the elements of P.
Which of the following options is/are correct?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 50

Open question
DAMSQ2 marksNeeds review
Consider the given Python program.
def outer():
x = []
def inner(val):
x.append(val)
return x
return inner
f1 = outer()
f2 = outer()
print(f1(10)) # Line P
print(f1(20)) # Line Q
print(f2(30)) # Line R
print(f1(40)) # Line S
Which of the following options is/are correct?
Your answerSelect all correct options. You can choose more than one.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 58

Open question
DANAT2 marksNeeds review
Consider the given Python program.
def fun(L, i=0):
if i >= len(L)-1:
return 0
if L[i] > L[i+1]:
L[i+1], L[i] = L[i], L[i+1]
return 1+fun(L, i+1)
else:
return fun(L, i+1)

data = [5, 3, 4, 1, 2]
count = 0
for _ in range(len(data)):
count += fun(data)
print(count)
The output of the program is __________. (Answer in integer)

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer

Question 18

Open question
daMCQ1 markNeeds review
Consider a hash table of size 10 with indices

, with the hash function

where linear probing is used to handle collisions. The hash table is initially empty and the following sequence of keys is inserted into the hash table: 1, 4, 5, 6, 14, 15. The indices where the keys 14 and 15 are stored are, respectively
Your answerChoose one option.

Log in to check the answer

You can attempt this question now. Sign in to view the answer key, explanations and discussion.Log in to check answer