Professional Documents
Culture Documents
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.
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]
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.