DSA 9
DSA 9
Q1
Start/End
Input/Output
Decision
Process
Q2
What is a default parameter in a function?
A mandatory argument
Predefined value
Function result
Data type of input
Q3
Use index 0
Use index 1
Use index 2
Use index 3
Q4
What is the primary benefit of modular programming using procedures and functions?
Reusability
Less code
Fewer bugs
Direct memory access
Q5
What is returned if a function has no return statement?
0
Error
Undefined
Garbage value
Q6
What is the lifetime of a dynamically allocated variable?
127.0.0.1:5500/sa/index.html 1/18
11/2/24, 10:44 PM Questions
Q7
Which programming paradigm is commonly associated with programming languages like Prolog and is used for
rule-based logic and reasoning?
Logic Programming
Functional Programming
Procedural Programming
Declarative Programming
Q8
Which programming paradigm involves expressing computations in terms of mathematical functions and avoids
changing state?
Logic Programming
Functional Programming
Procedural Programming
Declarative Programming
Q9
How are arguments typically passed to a function?
By reference
By value
By name
By copy
Q10
Which programming paradigm focuses on defining how to accomplish tasks by describing the control flow and
sequence of operations?
Logic Programming
Functional Programming
Procedural Programming
Declarative Programming
Q11
Which paradigm is used when the programming model is based on mathematical functions, and output depends
solely on input?
Logic Programming
Functional Programming
Procedural Programming
Declarative Programming
Q12
127.0.0.1:5500/sa/index.html 2/18
11/2/24, 10:44 PM Questions
What is the value of arr[2] in the following array?
int[] arr = {3, 7, 1, 9, 5};
System.out.println(arr[2]);
3
7
1
9
Q13
Which of the following best describes the purpose of the break statement in loops?
To skip the current iteration and continue with the next iteration
To exit the loop immediately and skip the remaining iterations
To reset the loop counter
To pause the loop execution temporarily
Q14
Which paradigm is characterized by a focus on describing what the program should accomplish rather than how
to accomplish it?
Object-Oriented Programming
Functional Programming
Procedural Programming
Declarative Programming
Q15
Which of the following concepts allows a class to be used as a template for creating objects?
Class
Interface
Object
Method
Q16
3
5
Error
None
Q17
127.0.0.1:5500/sa/index.html 3/18
11/2/24, 10:44 PM Questions
Which flowchart symbol is used to denote the start or end of a program?
Oval
Diamond
Rectangle
Parallelogram
Q18
In pseudocode, what does x := 5 mean?
Compare x with 5
Increment x by 5
Assign 5 to x
Print x
Q19
What is the purpose of the this keyword in object-oriented programming?
Q20
sum = 0;
for i = 1 to 3;
sum = sum + i;
print(sum);
3
6
7
9
Q21
127.0.0.1:5500/sa/index.html 4/18
11/2/24, 10:44 PM Questions
Insertion Sort
Bubble sort
Selection sort
Merge sort
Q22
Set the following in increasing order of their complexity O(log n), O(n!), O(n^n), O(nlogn), O(1), O(n)?
Q23
You are given a graph of 5 nodes. How will you detect whether the graph is also a tree?
Q24
Consider a given array of 7 elements arr [ 7 ] = { 10,20,30,25,5,40,35}. Satyam wants to find out the preorder
traversal of the heap binary tree that is going to be constructed using the given array.
Note that each element in the tree will be greater than or equal to its child elements. Which is the correct
preorder representation of the binary tree?
127.0.0.1:5500/sa/index.html 5/18
11/2/24, 10:44 PM Questions
10 25 5 40 20 35 30
40 10 25 5 20 35 30
40 10 5 25 20 30 35
40 25 10 5 35 20 30
Q25
RETURN c
127.0.0.1:5500/sa/index.html 6/18
11/2/24, 10:44 PM Questions
Sequential search
Q26
When two keys result in having the same hash value, the condition is called?
Collapsing
Collision
Chaining
Matching
Q27
Identify the correct statement about the operation being performed by the above algorithm.
The algorithm returns the top element of the stack without deleting it.
The algorithm returns the top element of the stack and deletes it from the stack.
The algorithm returns the top element of the queue and deletes it from the queue.
None of these.
Q28
Select the option that describes the head-tail linked list.
127.0.0.1:5500/sa/index.html 7/18
11/2/24, 10:44 PM Questions
Q29
Given an array that contains the numbers 1 through 8 in ascending order, identify the longest subsequence where
the product of its elements, when divided by 8, yields a remainder of exactly 1.
1357
12357
1246
1568
Q30
Consider the following traversal methods for a binary tree: 1. Breadth-First Search (BFS) 2. Depth-First Search
(DFS). Which of these methods begins the traversal from the root node of the tree?
1 only
2 only
Both 1 and 2
Neither 1 nor 2
Q31
The steps to write a function in C language that adds a single new node at the start of any linked list are given in
a jumbled order. Select the option that denotes the correct sequence of steps.
D. Make the new node point to the current first node of the list.
A, B, C, D
C, B, D, A
B, C, D, A
B, A, D, C
Q32
How many levels are needed to represent a tree with 7 nodes in the best case using a Binary Search Tree?
2
3
5
6
Q33
An intelligent thief started thieving in a new place, where the houses were arranged like a binary tree. The thief
can only enter through the root. Apart from the root, each house has only one parent house.
The thief had to be careful about the burglar system installed there. It would automatically contact the police if
two directly linked houses were robbed on the same night. You are given the binary tree. Find the maximum
amount of money the thief can rob without altering the police.
127.0.0.1:5500/sa/index.html 8/18
11/2/24, 10:44 PM Questions
310
305
330
345
Q34
How many subarrays have to be searched to find the element 0 in the given below array when the Binary search
algorithm is applied?
A = {0,1,2,3,4,5,12,13,15}
2
3
1
0
Q35
127.0.0.1:5500/sa/index.html 9/18
11/2/24, 10:44 PM Questions
Q36
When executing a quick sort algorithm on an unsorted array, if Joseph consistently selects the largest element as
the pivot for partitioning the array, what time complexity scenario will he encounter?
Best case
Average case
Worst case
Either 1 or 2
Q37
What is the complexity of finding the maximum element in an unsorted array?
O(1)
O(n)
O(log n)
O(n^2)
Q38
for(i=1;i<=count;i++){
temp=number[i];
j=i+1;
while((temp<number[j])&&(j>0)){
number[j+1]=number[j];
j=j-1;
}
number[j+1]=temp;
}
for(i=1;i<=count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])||(j>0)){
number[j-1]=number[j];
j=j-1;
}
number[j+1]=temp;
}
for(i=1;i<=count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])||(j!=0)){
number[j+1]=number[j];
j=j+1;
}
number[j+1]=temp;
}
127.0.0.1:5500/sa/index.html 10/18
11/2/24, 10:44 PM Questions
for(i=1;i<=count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])&&(j>=0)){
number[j+1]=number[j];
j=j-1;
}
number[j+1]=temp;
}
Q39
A Priority-Queue is implemented as a Max-Heap. Initially, it has 5 elements. The level-order traversal of the
heap is given below: 10, 8, 5, 3, 2 Two new elements ”1‘ and ”7‘ are inserted in the heap in that order. The level-
order traversal of the heap after the insertion of the elements is:
10, 8, 7, 5, 3, 2, 1
10, 8, 7, 2, 3, 1, 5
10, 8, 7, 3, 2, 1, 5
10, 8, 7, 1, 2, 3, 5
Q40
( 0 , 1 , 2 , 3)
(4 , 1 , 2 , 3)
error
( unindentified , 1 , 2 , 3)
Q41
<class ‘type’>
127.0.0.1:5500/sa/index.html 11/18
11/2/24, 10:44 PM Questions
Error
Q42
8
7
7
8
7
7
8
8
Q43
Fib1=[1,1,2,3,5,8]
Fib2=[13,21,34]
How will you create a list in python that has all the above elements in one list?
Fib1.append(Fib2)
Fib2.extend(Fib1)
Fib1.extend(Fib2)
Fib1.cat()
Q44
count = 0
while True:
if count % 4 == 0:
127.0.0.1:5500/sa/index.html 12/18
11/2/24, 10:44 PM Questions
print(count, end = ', ')
if count > 15:
break
count += 1
Infinite Loop
0,4,8,12,16,
TRUE
0,2,4,6,8,10,12,14,16,
Q45
a, b = 7, 14
2
4
14
28
Q46
Which of the following exceptions is raised when a program tries to access an item at an index that is out of
range?
KeyError
ValueError
IndexError
TypeError
Q47
data = [3, 5, 8, 2]
result = 1
for i in data:
result += (i*2)
result -= len(data)
31
33
22
28
127.0.0.1:5500/sa/index.html 13/18
11/2/24, 10:44 PM Questions
Q48
Which access modifier in Python is used to indicate that a method or property is intended for internal use only?
public
private
protected
internal
Q49
[1, 2]
12
3
Error: Undefined Variable
Q50
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, [6, 7], 8]
[1, 2, [3, 4], 5, [6, 7], 8]
[1, 2, [3, 4], 5, 6, 7, 8]
Q51
data = [1, 5, 8, 2, 10, 3, 7]
result = 0
for i in range(len(data)):
for j in range(i+1, len(data)):
if data[i] > data[j]:
result += data[j]
else:
result += data[i]
127.0.0.1:5500/sa/index.html 14/18
11/2/24, 10:44 PM Questions
105
120
65
75
Q52
{'a','c','d'}
{'a','b','c'}
{'a','b','c','d'}
{'b','c','d'}
Q53
Q54
L = [11, 54, 65, 99, 132, 143]
x = list(filter(lambda a: a % 11 == 0, L))
[132, 143]
[54 ,65]
127.0.0.1:5500/sa/index.html 15/18
11/2/24, 10:44 PM Questions
Q55
When defining local variable names in a Python code, the use of underscore(_) as the first character [e.g
_value] doesn't pose any errors, yet this practice is discouraged.
Q56
def myfunc(self):
print("The best platform is " + self.name)
p1 = Person("Doselect", 36)
p1.myfunc()
Doselect
Error
Q57
127.0.0.1:5500/sa/index.html 16/18
11/2/24, 10:44 PM Questions
with open("file.txt", "a") as f:
f.write("!")
Hello World
Hello World!
!
None of the above
Q58
Q59
x = "Hello"
y = "World"
z = x[2:] + y[:3]
print(z)
HelloWorld
lloWor
lloWorld
HelloWor
Q60
Problem Statement
Write a program that takes a list of integers and returns the largest integer
Input Format
First line will contain an integer, N.
The next N lines will have an integer.
Constraints
1 <= N <= 10
0 <= |arri| <= 100
Output Format
127.0.0.1:5500/sa/index.html 17/18
11/2/24, 10:44 PM Questions
Print largest number from that list
Evaluation Parameters
input
5
4
7
1
0
6
Output
7
Explanation
127.0.0.1:5500/sa/index.html 18/18