Question 1 | MCQ
THIS IS QUESTION PAPER FOR THE SUBJECT"DIPLOMA LEVEL : PROGRAMMING, DATA
STRUCTURES AND ALGORITHMS USING PYTHON (COMPUTER BASED EXAM)"
ARE YOU SURE YOU HAVE TO WRITE EXAM FOR THIS SUBJECT?
CROSS CHECK YOUR HALL TICKET TO CONFIRM THE SUBJECTS TO BE WRITTEN.
(IF IT IS NOT THE CORRECT SUBJECT, PLS CHECK THE SECTION AT THE TOP FOR THE SUBJECTS REGISTERED BY YOU)
STRUCTURES AND ALGORITHMS USING PYTHON (COMPUTER BASED EXAM)"
ARE YOU SURE YOU HAVE TO WRITE EXAM FOR THIS SUBJECT?
CROSS CHECK YOUR HALL TICKET TO CONFIRM THE SUBJECTS TO BE WRITTEN.
(IF IT IS NOT THE CORRECT SUBJECT, PLS CHECK THE SECTION AT THE TOP FOR THE SUBJECTS REGISTERED BY YOU)
Solution
Inscript
Consider the following Python function:

If the function is called as:
What value will the function return?
Consider the following Python function:
If the function is called as:
What value will the function return?
Solution
Inscript
Consider a connected undirected graph
with
vertices and
edges. What is the minimum number of edges that must be added to
to make it a complete graph?
Consider a connected undirected graph
Solution
Consider the following function:

What is the asymptotic running time of the function?
What is the asymptotic running time of the function?
Solution
We have an input list of two-dimensional points:

We sort these in ascending order by the second coordinate.
Which of the following corresponds to astable sortof this input?
We sort these in ascending order by the second coordinate.
Which of the following corresponds to astable sortof this input?
Solution
Consider the following standard implementation of theInsertion Sortalgorithm:

Suppose you pass a list L containing exactly8 distinct elements(n = 8) into this function. What are the absoluteminimumandmaximumnumber ofswap operationsthat could possibly execute to fully sort the list?
Suppose you pass a list L containing exactly8 distinct elements(n = 8) into this function. What are the absoluteminimumandmaximumnumber ofswap operationsthat could possibly execute to fully sort the list?
Solution
You are given a non-empty list
of
integers with a specific structural property:all odd numbers appear before all even numbers in the list. Within their respective groups, the numbers are not sorted and can appear in any random order.
Furthermore, the exact counts of odd and even numbers arenot given and could be anything (for instance, the list could contain all odds, all evens, or any arbitrary mix of both).
For example:
(where all odds come before all evens).
What is the time complexity of themost efficient algorithmto find the exact count of odd numbers and even numbers in this list?
Furthermore, the exact counts of odd and even numbers arenot given and could be anything (for instance, the list could contain all odds, all evens, or any arbitrary mix of both).
For example:
What is the time complexity of themost efficient algorithmto find the exact count of odd numbers and even numbers in this list?
Solution
Consider the followingpartitionalgorithm used inQuicksort. The algorithm takes a list
and two0-based indices,
and
, and uses thefirst element
as the pivot.

Suppose the partition algorithm is called as:

Afterone complete executionof
, what will be the state of the list
?
Suppose the partition algorithm is called as:
Afterone complete executionof
Solution
LetQbe an initially empty queue that supports the standard queue operationsEnqueueand Dequeue.
The following sequence of operations is performed onQ:

After performing the given sequence of operations, what will be thefrontandrearelements of queueQ?
The following sequence of operations is performed onQ:
After performing the given sequence of operations, what will be thefrontandrearelements of queueQ?
Solution
Consider the following Python function for cycle detection in anundirected graphrepresented using anadjacency list.

The function parameters have the following meanings:
-
is the adjacency list representation of an undirected graph with vertices numbered from
to
.
-
is the starting vertex from which the function is invoked.
-
is
if vertex
has already been visited during the current traversal; otherwise it is
.
-
stores the vertex from which the current vertex
was reached during the traversal. For the initial call,
may be set to
or
.
Assume that:
1.The graph may contain one or more connected components.
2.The function is calledexactly oncefrom a single starting vertex
.
3.There isno outer loopthat invokes the function on other unvisited vertices.
Which of the following statements is true about the graph traversal strategy used and the portion of the graph on which cycle detection is performed?
The function parameters have the following meanings:
-
-
-
-
Assume that:
1.The graph may contain one or more connected components.
2.The function is calledexactly oncefrom a single starting vertex
3.There isno outer loopthat invokes the function on other unvisited vertices.
Which of the following statements is true about the graph traversal strategy used and the portion of the graph on which cycle detection is performed?
Solution
Consider a connected, directed graph
on whichDepth First Search (DFS)is executed. For an
edge
in
, let the following be thepreandpostnumbers computed by DFS.


Which of the following options is correct for edge
?
edge
Which of the following options is correct for edge
Solution
Consider the following functions:
-
-
-
Which of the following is/areTrue?
-
-
-
Which of the following is/areTrue?
Solution
Consider the following linked list structure, where each node is an object of the given class
Which of the following operations can be completed inO(1) (constant) time.
Solution
Let
be a connected, undirected graph, and let
be a Breadth-First Search (BFS) tree generated by running BFS on
starting from a source vertex
. Let
denote the shortest path distance (number of edges) from the source vertex
to any vertex
.
If
is an edge in the original graph
that doesNOTbelong to the BFS tree
(i.e., a cross- edge), which of the following statements regarding their distances from the source vertex
are TRUE? (Select all that apply)
If
Solution
Consider the following Directed Acyclic Graph(DAG):

Identify the valid topological ordering(s)
Identify the valid topological ordering(s)
Solution
Inscript
Consider the following implementation of the
function, which merges two sorted lists into a single sorted list:

Let four sorted lists
and
, each containing5 elements, are merged into a single sorted list using the following two-way merge strategy using above
function:
- Merge
and
to obtain
.
- Merge
and
to obtain
.
- Merge
and
to obtain the final sorted list
.
What is themaximum number of element comparisonsperformed by the
function during the entire process?
Consider the following implementation of the
Let four sorted lists
- Merge
- Merge
- Merge
What is themaximum number of element comparisonsperformed by the
Solution
Inscript
A hash table with8 slots(indexed
to
) uses open addressing withlinear probing(
). After inserting 5 keys, the current state of the table is shown below:

Probe Operation:A probe operation is a single check of a hash table index. Finding a key at the first checked index requires1 probe. If the key is found after checking three indices, it requires3 probes.
Assuming each of the 5 keys currently in the table is searched for exactly once, what is thetotal number of probe operationsrequired to complete all 5 successful searches?
A hash table with8 slots(indexed
Probe Operation:A probe operation is a single check of a hash table index. Finding a key at the first checked index requires1 probe. If the key is found after checking three indices, it requires3 probes.
Assuming each of the 5 keys currently in the table is searched for exactly once, what is thetotal number of probe operationsrequired to complete all 5 successful searches?
Solution
Shape
Thickness [ / ]
3
All colors