0% found this document useful (0 votes)
17 views18 pages

DSA 9

Uploaded by

Hemchandru MK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views18 pages

DSA 9

Uploaded by

Hemchandru MK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

11/2/24, 10:44 PM Questions

Q1

In a flowchart, what does a rectangle symbolize?

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

How do you access the first element in an array of size 4?

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?

Until scope ends


Until manually deallocated

127.0.0.1:5500/sa/index.html 1/18
11/2/24, 10:44 PM Questions

Until program ends


Until function returns

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

What will be the output of the pseudocode:


a = 3;
b = 5;
if a > b then print a;
else print b;

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?

To create a new instance of the class.


To refer to the superclass of the class.
To invoke static methods of the class.
To refer to the current instance of the class.

Q20

What is the output of the given pseudocode:

sum = 0;
for i = 1 to 3;
sum = sum + i;
print(sum);

3
6
7
9

Q21

Which sorting technique is used in the below pseudo-code?


repeat
set a flag to False
for each pair of keys
if the keys are in the wrong order then
swap the keys
set the flag to True
end if
next pair
until flag is not set

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)?

O(1), O(log n), O(nlogn), O(n), O(n!), O(n^n)


O(1), O(n), O(log n), O(nlogn), O(n^n), O(n!)
O(1), O(n), O(nlogn), O(log n ), O(n!), O(n^n)
O(1), O(log n), O(n), O(nlogn), O(n!), O(n^n)

Q23
You are given a graph of 5 nodes. How will you detect whether the graph is also a tree?

if the number of nodes is less than 8

if there are not one or more cycles in the graph.


if the graph is a directed graph.
if the graph has 0 or more incoming nodes.

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

What does the following pseudo-code do?

CREATE array c having size = array length a + array length b


SET aIdx to 0
SET bIdx to 0
SET cIdx to 0
WHILE aIdx < length of a - 1 and bIdx < length of b - 1IF a [aIdx] < b [bIdx] THENSET c[cIdx] to a[aIdx]
INCREMENT aIdx
INCREMENT cIdx
ELSESET c[cIdx] to b[bIdx]
INCREMENT bIdx
INCREMENT cIdx
ENDIF
ENDWHILE

WHILE aIdx < length of a - 1SET c[cIdx] to a[aIdx]


INCREMENT aIdx
INCREMENT cIdx
ENDWHILE

WHILE bIdx < length of b - 1SET c[cIdx] to b[bIdx]


INCREMENT bIdx
INCREMENT cIdx
ENDWHILE

RETURN c

127.0.0.1:5500/sa/index.html 6/18
11/2/24, 10:44 PM Questions

Merge two sorted arrays

Sequential search

Summing the array

Traversing the array

Q26

When two keys result in having the same hash value, the condition is called?

Collapsing
Collision
Chaining
Matching

Q27

Consider the following algorithm-


Begin
if top = -1 then stack empty
item = stack[top]
return item
End

It is given that symbols and variables have usual meanings.

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.

Allows adding or removing the elements from the front or back


Allows addition of elements to only one end and removal from the other
Allows deletion of elements from both ends, but restriction of input from only one end
Allows taking input at both ends, but restricts the output to be made from only one end

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.

A. Make the first pointer point to the new node.

B. Allocate a new node from the heap.

C. Store the required data in data element of the node.

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

What will the below code help to do?


int solve(Queue *Queue)
{
Stack st;
while (!isEmpty(Queue))
{
push(st, deQueue(Queue));
}
while (!isEmpty(st))
{
enQueue(Queue, pop(st));
}
}

Removes the last from Queue.


Keeps the queue the same as it was before the call.
Makes the queue empty.

127.0.0.1:5500/sa/index.html 9/18
11/2/24, 10:44 PM Questions

Reverse the Queue.

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

Select the appropriate code that performs Insertion sort.

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

Consider the following Python code:


tuple1 = (0, 1, 2, 3)
tuple1[0] = 4
print(tuple1)

What would be the output of this code?

( 0 , 1 , 2 , 3)

(4 , 1 , 2 , 3)

error

( unindentified , 1 , 2 , 3)

Q41

Given the statement:


print(type(type(int)))

What would be the output for this?

<type ‘int’ >


0 (NULL)

<class ‘type’>

127.0.0.1:5500/sa/index.html 11/18
11/2/24, 10:44 PM Questions

Error

Q42

What would be the output of the following code snippet?


a = 7
if a > 4:
def globalabc():
global a
a = 8
print(a)
print(a)

8
7

7
8

7
7

8
8

Q43

Let us say you have the Fibonacci series in two lists:

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?

(Select all that apply)

Fib1.append(Fib2)

Fib2.extend(Fib1)

Fib1.extend(Fib2)

Fib1.cat()

Q44

What will be the output of the given Python code snippet?

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

if a < 10 and not b % a:


result = b // a
else:
result = a * 2

What is the value of "result" after executing the code snippet?

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)

After the code execution, what will be the value of "result"?

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

What would be the output of the following code snippet?

def add_numbers(x, y):


return x+y
nums = [1, 2]
print(add_numbers(*nums))

[1, 2]
12
3
Error: Undefined Variable

Q50

What is the output of the following code?


a = [1,2,[3,4],[5,[6,7],8]]
b = []
for i in a:
if type(i) == list:
for j in i:
b.append(j)
else:
b.append(i)
print(b)

[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]

After the code execution, what will be the value of "result"?

127.0.0.1:5500/sa/index.html 14/18
11/2/24, 10:44 PM Questions

105
120
65
75

Q52

What will be the output of the following set operation in Python?


set('abc') | set('bcd')

{'a','c','d'}
{'a','b','c'}
{'a','b','c','d'}
{'b','c','d'}

Q53

The following code is executed in python.

Select the correct output.


>>message="doselect is the best platform"
>>type(message)

< class 'str' >

< class 'int' >

< class 'float' >

< class 'void' >

Q54
L = [11, 54, 65, 99, 132, 143]
x = list(filter(lambda a: a % 11 == 0, L))

What is the value of x?

[132, 143]

[11, 99, 132, 143]

[11, 54, 65, 99, 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.

Why is this so?

They slow down execution.

They confuse the interpreter.

They are used to indicate global variables.

They are used to indicate private variables of a class.

Q56

The following code is executed in Python.

Choose the correct output


class Person:
self.name = name
self.age = age

def myfunc(self):
print("The best platform is " + self.name)

p1 = Person("Doselect", 36)
p1.myfunc()

The best platform is Doselect

The best platform is

Doselect

Error

Q57

What is the output of the following code?


with open("file.txt", "w") as f:
f.write("Hello World")

with open("file.txt", "r") as f:


print(f.read())

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

Which of the following statements is true about Python's exception-handling mechanism?

It is used to handle both runtime errors and syntax errors.


It involves the use of try-except blocks to catch and handle exceptions.
It is not necessary to include a finally block in a try-except block.
It is recommended to use the base Exception class to catch all exceptions.

Q59
x = "Hello"
y = "World"
z = x[2:] + y[:3]
print(z)

What will be the output of the following code snippet?

HelloWorld
lloWor
lloWorld
HelloWor

Q60

Problem Statement
Write a program that takes a list of integers and returns the largest integer

from that list.

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

The list [4, 7, 1, 0, 6] has the largest element 7.

127.0.0.1:5500/sa/index.html 18/18

You might also like