You are on page 1of 7

A.

MCQ Question
1. If a is an array then a[-1] points to its.
Ans. Last element
2. If a is an array then a.remove(1) will remove
Ans. First occurrence of 1
3. a = arr.array('i', [1, 2, 3,9, 4, 7,5, 6,810]) print(a[3:8]) This Python code will
Ans. Element from 3rd to 7th index.
So, the code will be print the element at indices 3,4,5,6 and 7from the array ‘a’.
1. using double hashing we stored three keys 27, 42, and 692 In a hash table if the first hash
function is h1(key) = key%7, the second hash function is h2(key) = 1 + (key % 5) and the size
of the hash table is 7 then the index number where a new key 72 will store.
Ans. To find the index where a new key (72) will be stored using double hashing, we can use the
following formula:
Index = (h1(key)+I.h2(key)) mod table_size
Let’s calculate it step by step:
1. h1(72) = 72 mod 7 = 2
2. h2(72) = 1+(72 mod 5) = 1+2=3
Now, we can use the formula:
Index = (2+i.3) mod 7
For i = 0, index = 2
For i = 1, index = (2+3) mod 7=5.
For i = 2, index = (2+2.3) mod 7=1.
For i = 3, index = (2+3.3) mod 7=4.
So, the new key 72 will be stored at index 4.
Therefore, the answer is 4.
2. Time complexity of insertion sort is
Ans. O(n2).
3. In which linked list the last node points to the head of the linked list a) Single linked list b)
double linked list c) circular linked list d) none of the above,
Ans. Circular linked list
4. Recursion is a process of.
Ans. A function calling itself.
5. Which data structure is used for implementing recursion?
Ans. Stack.
9.What is the value of the postfix expression 6 5 2 4 + – *?
Ans. Scan the expression from left to right.
Encounter "-": Pop the top two elements (5 and 6), subtract them, and push the result (-1) onto
the stack.
Encounter "*": Pop the top two elements (6 and -1), multiply them, and push the result (-6) onto
the stack.
Encounter "+": Pop the top two elements (4 and 2), add them, and push the result (6) onto the
stack.
Encounter 2: Push 2 onto the stack.
Encounter 4: Push 4 onto the stack.
Encounter 5: Push 5 onto the stack.
Encounter 6: Push 6 onto the stack.
The final result is on the top of the stack, which is -6.
Therefore, the correct answer is:
10.Which data structure is used in cryptography.
Ans. Hash
11. Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n
elements. Assume that the insertion and deletion operation are carried out using REAR and FRONT
as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue
full and queue empty are
Ans. Full: (REAR + 1) mod n==Front, empty: REAR == Front.
12. Which data structure in python follows the last In, First out(LIFO) Principal?
Ans. Stack.
13. What is the time complexity of the quicksort algorithm in the best-case scenario?
Ans. O(n log n)
14. Which search algorithm does not require the list to be sorted?
Ans. Linear search.
15. Which data structure uses the FIFO (first In, First Out) Principal?
Ans. Queue
16. What is the worst-case time complexity of the insertion operation in a binary search tree(BST)?
Ans. O(log n)
17. Which sorting algorithm has a time complexity of O(n^2) in the worst-case scenario?
Ans. Bubble sort.
18. Which of the following is not a type of tree traversal?
Ans. Inorder instead of midorder.
19. Which data structure is typically used to implement a LIFO (Last In, First Out) mechanism?
Ans. Stack.
20. Which of the following is not a searching algorithm?
Ans. Bubble Sort.
21. What is the purpose of dynamic programming?
Ans. Solving problems by breaking them down into smaller subproblems.
22. In a binary tree, what is the maximum number of nodes at level 3?
Ans. 8.

One word answer………..


(i). What is the difference between a stack and an Array?
Ans. Array: Direct(random) access to element using an index.
Stack: LIFO (Last In, First Out) access pattern with push and pop operations.
(ii). What are the disadvantage of circular list?
Ans. Circular lists are complex as compared to singly linked lists.
(iii). Which data structure is used to perform recursion?
Ans. Stack (LIFO) data structure is one of the famous data structure used for implanting recursion.
(iv). Given a Tree, is it possible to find the greatest and least among leaves in linear time?
Ans. Depends on the tree structure. Linear solution exists.
(v). Is it necessary to sort a file before searching a particular item?
Ans. Arranging things in a short manner makes it easier to analyze and search for a particular
element among the collection of elements.
(vi). What is spanning Tree?
Ans. A spanning tree is a subset of graph G, which has all the vertices covered with minimum
possible number of edges.
(vii). Is it possible to implement 2 stacks in an array?
Condition: None of the stack should indicates an overflow until every slot of an array is used.
Ans. Condition: None of the stock should indicates an overflow until every slot of an array is used. 2
stack can be implemented if the given condition is applied only for 1 stack.
(viii). How many stacks are required to implement a Queue.
Ans. 2 stacks.
(ix). Parenthesis is never required in postfix or prefix expressions. Why?
Ans. The order of the operators in the postfix and prefix expression determines the actual order of
operation in evaluating the expression.
(x). What action are performed when a function is called?
Ans. Using the function name, followed by a set of parentheses containing the data to be the
function.
(xi). What do you mean by free pool?
Ans. The heap, the pool of free memory available for all allocation throughout the program.
(xii). What is Dangling pointer and how to avoid it?
Ans. The dangling pointer happens when the user does not delete the memory allocated for an
object in the past.

5 marks questions.
1. Write down a python code and the output to add these given polynomials using array: 5+10x
2+ 6x 3 and 1+ 2x +3x 2
Ans. def add_polynomials(p1, p2):
return [sum(x) for x in zip(p1, p2)]

p1 = [5, 10]
p2 = [2, 6]
p3 = [3, 1, 2, 3]
p4 = [2, 2, 2, 2]

result = add_polynomials(p1, p2)


result = add_polynomials(result, p3)
result = add_polynomials(result, p4)

print(result)
result: -
24,13,6,8
2. How many types of linked list are there? Explain in details.
Ans. There are four types of linked list: -
 Single linked list: -
Each node in the list contains data and a reference (link) to the next node in the
sequence.
The last node’s reference is typically set to null, indicating the end of the list.
 Doubly linked list: -
A doubly linked list is a bi-directional linked list.
its nodes contain one extra pointer called the previous pointers.
 Circular linked list: -
Similar to a singly or doubly linked list, but the last node points back to the first node
(forms a loop).
Useful for scenarios where continuous cycling through the list is required.
 Circular doubly linked list: -
A doubly circular linked list (DCL) is a variation of the standard doubly linked list.
The first and last nodes are linked together, forming a circle.

3.Difference between stack and queue.


Ans.
Stack Queue
-Follows the Last In, First Out (LIFO) -Follows the First In, First Out (FIFO)
principle. principle.
-The last element added is the first -The first element added is the first
one to be removed. one to be removed.
-Insert operation is called push operation. -Insert operation is called enqueue
-Stack is used in solving problems work on operation.
recursion. -Queue is used in solving problem having
-Stack does not have any types sequential processing.
-Queue is of three types- (i). circular Queue
(ii). Priority Queue (iii). Double-ended
Queue.

4. Write an algorithm to convert an in-fix expression to a post-fix expression.


Ans. converting an infix expression to a postfix expression involves rearranging the expression based
on the order of operations. Here's an algorithm to achieve this using a stack:
 Initialize an empty stack to hold operators.
 Initialize an empty string to store the postfix expression.
 Iterate through each symbol (operand or operator) in the infix expression
from left to right.
-If the symbol is an operand, append it to the postfix string.
-If the symbol is an operator:
-Pop operators from the stack and append them to the postfix string until the stack is empty,
the top of the stack is an opening parenthesis '(', or the current operator has lower
precedence than the operator at the top of the stack.
-Push the current operator onto the stack.
-If the symbol is an opening parenthesis '(', push it onto the stack.
-If the symbol is a closing parenthesis ')':
-Pop operators from the stack and append them to the postfix string until an opening
parenthesis '(' is encountered. Pop and discard the opening parenthesis.

5.Write a python code to implement queue.


Ans. queue = []
queue.append('a')
queue.append('b')
queue.append('c')
print("Initial queue")
print(queue)
print("\nElements dequeued from queue")
print(queue.pop(0))
print(queue.pop(0))
print(queue.pop(0))
print("\nQueue after removing elements")
print(queue)
6.What do you mean by Binary search tree? Construct a binary search tree using the given
data 20 26 200 343 322 444 221 664 343 322.
Ans. Binary Search Tree is a node-based binary tree data structure which has the following
properties:
 The left subtree of a node contains only nodes with keys lesser than the node’s key.
 The right subtree of a node contains only nodes with keys greater than the node’s
key.
 The left and right subtree each must also be a binary search tree.
20
\
26
\
200
\
221
/\
200 343
\
322
\
444
\
664

You might also like