0% found this document useful (0 votes)
30 views19 pages

Dsa 7

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)
30 views19 pages

Dsa 7

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/ 19

11/2/24, 10:42 PM Questions

Q1
Uninitialized static/global variables go in

Stack
Heap
Data
BSS

Q2
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.

Q3

Based on the pseudo code, under which condition should a packet be retransmitted?
If acknowledgmentNotReceivedWithin(timeout) {
retransmitPacket()
}

After receiving a negative acknowledgment


Immediately after sending the original packet
If the acknowledgment is not received within a specified timeout
If the packet size exceeds the network's MTU

Q4
Which of these statements is NOT executable?

Function call
Preprocessor directive
Conditional block
Loop

Q5

What does a parallelogram represent in flowcharts?

Process
Input/Output
Decision
Start/End

127.0.0.1:5500/js/index.html 1/19
11/2/24, 10:42 PM Questions

Q6

How many times will the loop run?


i = 1;
while (i < 5) {
i += 1;
}

3
4
5
Infinite

Q7
Which of the following paradigms typically involves writing code that performs a sequence of steps, with
a focus on control flow?

Object-Oriented Programming
Functional Programming
Procedural Programming
Declarative Programming

Q8
How many return values can a function have?

One
Multiple
Zero
Depends on context

Q9
What section stores global variables?

Stack
Heap
Data
Text

Q10

How do you access the last element of an array of size n?

Use index 0
Use index 1
Use index n

127.0.0.1:5500/js/index.html 2/19
11/2/24, 10:42 PM Questions

Use index n-1

Q11
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

Q12
Can a function have no parameters and still return a value?

No
Yes
Depends on language
Only for built-ins

Q13

What is the result of calling obj.display() in the following code?


class Counter {
private static int count = 0;

Counter() {
count++;
}

void display() {
System.out.println(count);
}
}

Counter obj1 = new Counter();


Counter obj2 = new Counter();
obj1.display();

1
2
3
Error

Q14
What is the primary benefit of modular programming using procedures and functions?

Reusability
Less code
Fewer bugs

127.0.0.1:5500/js/index.html 3/19
11/2/24, 10:42 PM Questions

Direct memory access

Q15

Based on the pseudo code, what is the type of the variable age?

age = 30

String
Integer
Boolean
Float

Q16
If an array is copied into another variable and the first element of the copy is modified, what happens to
the original array?

The original array remains unchanged


The original array also gets modified (shallow copy)
A new array is created
Only the copy is modified

Q17

Which shape represents a decision in flowcharts?

Rectangle
Diamond
Oval
Parallelogram

Q18

What does the following pseudo code describe in the context of memory management?

If requestedMemory <= availableMemory:


Allocate memory
Else:
Put process in waiting queue

Segmentation
Paging
Dynamic memory allocation
Memory swapping

Q19

127.0.0.1:5500/js/index.html 4/19
11/2/24, 10:42 PM Questions

What is an argument in a function call?

Variable in function
Actual value passed
Memory location
Function's output

Q20
What is a key characteristic of an interpreter in the context of interpreted languages?

It compiles the entire source code into machine code before execution.
It translates source code into intermediate code or directly into machine code and executes it
immediately.
It optimizes code performance by compiling it once and running it multiple times.
It only executes code that has been pre-compiled.

Q21

Consider a stack of integers. The stack is allocated 6 memory cells.

STACK: 1, 1, 1, 2, 5, _.

Now, consider the following operations:

1) PUSH (STACK, 10)

2) PUSH (STACK, 1010)

3) PUSH (STACK, 101010)

4) POP( STACK , ITEM1)

What is the maximum number of operations that can be performed in any sequence from amongst the
above operations, such that no overflow/underflow condition is encountered?

2
3
4
1

Q22
Given a binary max heap that contains 'n' numbers, what is the time complexity to find the smallest
element?

O(n)

O(logn)
0(loglogn)
0(1)

127.0.0.1:5500/js/index.html 5/19
11/2/24, 10:42 PM Questions

Q23
In the balanced binary tree in the below figure, how many nodes will become unbalanced when a node is
inserted as a child of the node “g”?
a
/ \
b e
/ \ /
c d f
/
g

1
2
3
4

Q24
What is the worst-case time complexity of the linear search algorithm?

O(1)
O(N)
O(logN)
O(N^2)

Q25

If the stack is implemented using an array arr = {2, 5, 13, 4, 15, 6, 7, 8, 9} (0-based indexing).

Which element would be at the top of stack, if the last element of the array is inserted first in the stack?

13
5
2
9

Q26
Which algorithm is primarily used for traversing trees?

Dijkstra's Algorithm
Kruskal's Algorithm

Prim's algorithm

Depth-First Search

Q27

Consider a stack of integers. The stack is allocated 5 memory cells.


127.0.0.1:5500/js/index.html 6/19
11/2/24, 10:42 PM Questions
STACK: 3, 8, 1, 5, _.

The following operations are performed on the stack-

1) POP( STACK , ITEM1)


2) PUSH (STACK, ITEM1)
3) POP( STACK , ITEM1)
4) PUSH (STACK, ITEM1)
5) POP( STACK , ITEM1)
6) PUSH (STACK, ITEM1)
7) POP( STACK , ITEM1)
8) PUSH (STACK, ITEM1)
9) POP( STACK , ITEM1)
10) PUSH (STACK, ITEM1)
11) POP( STACK , ITEM1)
12) PUSH (STACK, ITEM1)
13) POP( STACK , ITEM1)
14) PUSH (STACK, ITEM1)

Identify the topmost element of the stack after all the operations are performed.

POP(STACK , x)

means the topmost element is popped from the stack and stored in x.

5
8
1
3

Q28
A priority queue is a data structure in every element has priority associated with it. What is the minimum
number of queues needed to build priority queue.

1
2
3
4

Q29

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.


127.0.0.1:5500/js/index.html 7/19
11/2/24, 10:42 PM Questions

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


Makes the queue empty.
Reverse the Queue.

Q30

Consider the following statements and choose the correct option:

A) Last In First out mechanism is supported by Queues.

B) The Prev link of the first node and Next link of the last node of a doubly linked list is NULL.

C) A Singly Linked list can be traversed from both ends.

D) Last In First out mechanism is supported by Stacks.

A and B are true

A and C are true

B and D are true

C and D are true

Q31

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/js/index.html 8/19
11/2/24, 10:42 PM Questions

Reverse the Queue.

Q32

Which of the following statements is true for Binary Trees?

(Select all correct options)

Keeps keys in sorted order for sequential traversing


Uses a hierarchical index to minimize the number of disk reads
Uses partially full blocks to speed insertions and deletions

None of the above

Q33

From the following options, select the type of linked list that is described by the following points.

Each node has two links.


One node points to the previous node, or a null value or an empty list in case it is the first node.
One node points to the next, or a null value or empty list in case it is the last node.

Singly linked list


Multi linked list
Doubly linked list
Circularly linked list

Q34

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)

Q35
Which of the following traversals is sufficient to construct BST from given traversals
1) Inorder
2) Preorder
3) Postorder

1 and 3
2 and 3
127.0.0.1:5500/js/index.html 9/19
11/2/24, 10:42 PM Questions

Either 2 or 3 is sufficient
Any one of the given three traversals is sufficient

Q36
How are the elements in the circular linked list pointed to each other?

The pointer from the last element in the list, points back to the first element
The pointer from the first element in the list, points back to the last element
The pointer from the last element in the list, points to the tail of the list
The pointer from the first element in the list, points to the head of the list

Q37

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

Q38
Which type of algorithm uses a priority queue?

DFS
BFS
Dijkstra's Algorithm
Kruskal's Algorithm

Q39
From the following options, select the type of linked list that is described by the following points:

Each node has two links.


One node points to the previous node, or a null value or an empty list in case it is the first node.
One node points to the next, or a null value or empty list in case it is the last node.

Singly linked list


Multi linked list
Doubly linked list

127.0.0.1:5500/js/index.html 10/19
11/2/24, 10:42 PM Questions

Circularly linked list

Q40
Which algorithm, among the ones listed below, offers the most efficient time complexity for determining
the shortest path between two nodes in a weighted graph?

DFS
BFS
Dijkstra's Algorithm
Bellman-Ford Algorithm

Q41

What is the difference between a class method and an instance method in Python OOP?

A class method is called on the class itself, whereas an instance method is called on an instance of
the class.
A class method can access instance variables, whereas an instance method cannot.
A class method is defined using the @classmethod decorator, whereas an instance method is not.
A class method is used for object instantiation, whereas an instance method is used for object
manipulation.

Q42
arr = [10, 3, 7, 1, 9]

What is the value of arr after sorting it in descending order using Python's built-in sort() method?

[10, 9, 7, 3, 1]
[1, 3, 7, 9, 10]
[9, 10, 7, 3, 1]
None of the above

Q43

Which of the following Python expressions is functionally identical to the provided code snippet that
manipulates a dictionary named count?

if key in count:
count[key] = count[key] + 1
else:
count[key] = 1

127.0.0.1:5500/js/index.html 11/19
11/2/24, 10:42 PM Questions

count[key] = count.get(key,0) + 1

count[key] = count.get(key,-1) + 1

count[key] = (key in count) + 1

count[key] = (count[key] * 1) + 1

Q44

A university is analyzing the student database system to get the names of the students who have
participated in the annual events this academic year. The condition is to be met that if the name of the
student "Steve" matches, then the program should end running.

Choose the correct Python code snippet from the options for getting the following

Output:

Mark

Jacob

Jasmin

Leonard

Steve

#code_start_python

students = ["Mark", "Jacob", "Jasmin" , "Leonard" , "Steve" , "Alex" , "Johnson"]


for x in students:
print(x)
if x == "Steve":
continue

#code_end

#code_start_python

students = ["Mark", "Jacob", "Jasmin" , "Leonard" , "Steve" , "Alex" , "Johnson"]


for x in students:
print(x)
if x == "Steve":
break

#code_end

#code_start_python

students = ["Mark", "Jacob", "Jasmin" , "Leonard" , "Steve" , "Alex" , "Johnson"]


while x in students:
print(x)
if x == "Steve":
break

127.0.0.1:5500/js/index.html 12/19
11/2/24, 10:42 PM Questions

#code_end

#code_start_python

students = ["Mark", "Jacob", "Jasmin" , "Leonard" , "Steve" , "Alex" , "Johnson"]


if x in students = true
print(x)
if x == "Steve":
break

#code_end

Q45

What is the output of the following code snippet?

my_set = {1, 2, 3, 4, 5}

my_set.add(6)

my_set.remove(2)

print(my_set)

{1, 2, 3, 4, 5, 6}
{1, 3, 4, 5}
{1, 3, 4, 5, 6}
{2, 3, 4, 5, 6}

Q46

A student management system is implemented using Python. One of the functionalities is the printing of
all student details, along with the stu1 name having the value 'Abc'. The student array consists of stu1,
stu2, stu3, and stu4. The following code is written to fulfill this requirement:
#code_start_python
studs = ['stu1', 'stu2', 'stu3']
for _ in studs:
print('Studentdetails')
for st in studs:
print(st)
stu1name = 'Abc'
for x in stu1name:
print(x)
#code_end

What will happen when the given code is executed?

Studentdetails
Studentdetails
Studentdetails
Studentdetails
Studentdetails
127.0.0.1:5500/js/index.html 13/19
11/2/24, 10:42 PM Questions

Studentdetails
Studentdetails
Studentdetails
Studentdetails
stu1
stu2
stu3
A
b
c
stu1
stu2
stu3
Abc
Studentdetails
stu1stu2stu3
Abc
Studentdetails
Studentdetails
Studentdetails
stu1
stu2
stu3
A
b
c

Q47

What is the output of the following code snippet?


a = [1, 2, 3]
b = a
print(a is b)

True
False
TypeError
None of the above

Q48
In Python, which statement is used to execute a block of code repeatedly as long as a given condition is
true?

if statement
for loop
while loop
else statement

Q49

127.0.0.1:5500/js/index.html 14/19
11/2/24, 10:42 PM Questions
for i in range(3):
for j in range(2):
if j == 1:
break
print(i, j)
else:
print("End")

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

00
10
20
End
00
10
20
End
00
01
02
End

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

Q51

What is the output of the following code?


d = {}
for i in range(5):
d[i] = i**2
d

127.0.0.1:5500/js/index.html 15/19
11/2/24, 10:42 PM Questions

{0, 1, 2, 3, 4}
{0: 0, 1: 1, 2: 4, 3: 9, 4: 16}
{0: 1, 1: 2, 2: 3, 3: 4, 4: 5}
{1: 0, 2: 1, 4: 2, 9: 3, 16: 4}

Q52

What is the output of the following code?


def function(x):
if x<2:
return 1
else:
return function(x-1) + function(x-2)
print(function(6))

21
8
34
13

Q53

What is the output of the following code snippet?


x = 3
y = 5
z = 7
result = (x * y + z) // x % y
print(result)

2
3
4
5

Q54
for i in range(3):
if i == 2:
break
else:
x = "Done"

What will be the value of x?

0
2
"Done"
NameError

127.0.0.1:5500/js/index.html 16/19
11/2/24, 10:42 PM Questions

Q55

What is the difference between the 'finally' and 'except' clauses in a try-except block?

finally' is always executed, regardless of whether an exception is raised or not, whereas 'except' is
only executed if an exception is raised.
There is no difference - they both handle errors in the same way.
finally' is only executed if an exception is raised, whereas 'except' is always executed whether an
exception is raised or not.
finally' and 'except' are only used in different types of try-except blocks, depending on the type of error
being handled.

Q56

What will be the output of the code snippet below?

d = {}
d['name'] = 'abc'
d['age'] = 20
d['address'] = 'not found'
print(d)

{name: abc, age: 20, address: not found}

{'name': abc, 'age': 20, 'address': not found}

{name: 'abc', age: 20, address: 'not found'}

{'name': 'abc', 'age': 20, 'address': 'not found'}

Q57

What is the output of the following code?


my_list = [1, 2, 3, 4]
new_list = []
for i in range(len(my_list)):
if i%2 == 0:
new_list.append(my_list[i])
else:
new_list.insert(0, my_list[i])

print(new_list)

[1, 2, 3, 4]

[4, 2, 1, 3]

[2, 4, 1, 3]
[3, 1, 4, 2]

127.0.0.1:5500/js/index.html 17/19
11/2/24, 10:42 PM Questions

Q58

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]

Q59

Consider the following Python code snippet:

class MyClass:
def __init__(self, x):
self.x = x
def my_method(self):
print(self.x)

obj = MyClass(10)
obj.my_method()

What would be the output of this code?

10
0

Syntax Error

None of the Above

Q60

What is the output of the following code?


my_list = [10, 20, 30, 40, 50]
print(my_list[-2:-5:-1])

[40, 30, 20]


127.0.0.1:5500/js/index.html 18/19
11/2/24, 10:42 PM Questions

[50, 40, 30]


[50, 40, 30, 20]
[30, 40, 50]

Q61

Problem Statement

In the DoSelect Coding Community, people use a language called Coderita, which contains only
lowercase English letters.

In Coderita, the transformation of a string goes like this:

If the string ends with s then simply append es at the end of the string, else simply append s.

Input Format

Given a string S.

Constraints

1<=|S|<=1000
S consists of only lowercase English letters.

Output Format

Print the string after modification.

Evaluation Parameters

Sample Input
employee

Sample Output
employees

Explanation

As string does not end with s so we have to simply append s at the end of the string.

127.0.0.1:5500/js/index.html 19/19

You might also like