WorksheetsCSD203
Total questions: 186
Worksheet time: 2hrs 33mins
What is the value of the Shift Folding Hash Function if K = 723-203-541-213-24 and table size = 1000?
A. 704
B. 24
C. 723
D. 1704
Given a graph in the figure, the depth first traversal from node D is (visit nodes in ABC order):
A. D. C. B. A. E
B. D, C, E, A, B
C. D. A. B. C. E
D. D. E. A. B. С
Given an array as follows: [6, 1, 5, 3, 7]. What is the number of key comparisons done to check if 9 is in the array or not by using linear search?
A. 0
B. 1
C. 5
D. 6
The average number of key comparisons done in a successful linear search in an array of length n is
A. n
B. n/2
C. n*n
D. (n+1)/2
What will be the output of the following code?
def func(n):
if (n > 0):
print(n%2)
func(int(n/2)
-----------------------------
func(11)
A. 11
B. 1011
C. 1101
D. 0
A chained hash table has an array size of 100 (separate chaining for solving collision). What is the maximum number of elements that can be placed in the table?
A. 100
B. 99
C. There is no limit
D. 98
What is the output of the following program?
txt = "1546a"
x = txt.isascii()
print(x)
A. Error
B. 1
C. True
D. False
What distinguishes an AVL tree from other binary search trees?
A. It is always balanced.
B. It allows duplicate keys.
C. It does not support deletions.
D. It has a fixed height.
In a hash table, an element with key k is stored at index
A. k
B. Log k
C. H(k)
D. k*k
What is a tree in python?
A. A set of nodes connected by edges
B. A set of nodes
C. A set of edges
D. A set of vertices
Given a graph in the figure, the adjacency matrix of the graph is (visit nodes in ABCD order):
A. [[0. 1. 0. 1], [0, 0, 1.0], [0, 0, 0, 0], [0, 1, 1.0]]
B. [[0. 2. 0, 0]. [0.0, 7. 0], [0, 0, 0, 0], [0, 4, 8, 0]]
C. [[0. 1. 0. 1]. [1. 0. 1. 1]. [0. 1. 0. 1]. [1. 1. 1.0]]
D. [[0. 2. 0. 9]. [0. 0. 7. 4]. [0. 7. 0. 8]. [9. 4. 8.0]]
Which sorting technique will be most appropriate to sort 1 GB of data with only 100 MB of available main memory?
A. Insertion sort
B. Heap sort
C. Merge sort
D. Quick sort
The complexity of Linear search algorithm is
A. O(n)
B. O(log n)
C. O(n2)
D. O(n log n)
(Choose 1 answer) Given a binary search tree as follows: What is the output of In-order traversal?
A. 40 20 50 10 30
B. 40 20 50 30 10
C. 10 20 30 40 50
D. 50 40 20 30 10
What is the worst-case time complexity of QuickSort?
A. O(n^2)
B. O(n log n)
C. O(n)
D. O(2^n)
What are incident edges on vertex V?
A. a, b, d
B. d
C. a
D. b
Given a string S = "ABCDEFABCD and a pattern P = "CD". What is KMP algorithm returns? (the string is indexed from 0)
A 2
B. 3
C. 1,7
D. 2,8
A. 12345
B. 2345
C. 1234
D. 54321
Which is sorting algorithms that maintain two sub-lists, one sorted and one to be sorted?
A. Selection Sort
B. Merge Sort
C. Quick Sort
D. None of these
A. -4
B. 4
C. -12
D. 12
Given an empty stack S and a sequence of the following operations: Push(F); Push(P); Pop(); Push(T); Pop(); Push(U); What does the stack look like? (visit from bottom to top)
A. FU
B. FPTU
C. TU
D. FP
A. Insert a new node to the front of a linked list
B. Calculate the size of a linked list
C. Traverse the linked list
D. Insert a new node to the end of the linked list
A recursive function is
A. A function that calls other functions
B. A function that calls itself
C. A function that has arguments
D. None of these
A. The base case
B. The conductive case
C. Function call
D. Nothing
A sorting algorithm that uses the divide and conquer technique is?
A. Quick sort
B. Selection sort
C. Bubble sort
D. Insertion sort
Given a graph in the figure, the adjacency matrix of the graph is:
A. [10. 2. 0. 0. 4]. [2. 0. 7. 0. 0]. [0. 7. 0. 8. 0], [0, 0, 8. 0. 5].[4. 0. 0. 5.0]]
B. [[0, 1, 0.0, 1]. [1, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 1].[1. 0, 0, 1, 0]]
C. [10. 2. 0. 1. 4]. [1. 0. 1. 0. 0]. [0. 7. 0. 8. 5]. [9. 0. 8. 0. 5].[4. 0. 0. 5, 0]]
D. [[1. 0. 1. 0. 0]. [0. 1. 0. 1. 1]. [1. 0. 1. 0. 1]. [0, 1, 0. 1. 0].[0. 1. 1. 0. 1]]
Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5
A. 1
B. 5
C. 10
D. 15
Best Case Time Complexity of Linear Search is
A. O(1)
B. O(n)
C. O(n*n)
D. O(nlogn)
What method is used to remove an element from a Queue?
A. dequeue()
B. enqueue()
C. push()
D. pop()
A. 1
B. 5
C. 15
D. 16
Given a graph in the figure, the weighted matrix of the graph is (visit nodes in ABC order):
A. [[0, 2.0.0], [0, 0. 7.0]. [0.0.0.0]. [0.4.8.0]]
B. [[0. 2. 0. 9]. [0.0, 7.0]. [0. 0. 0. 0]. [0, 0, 8.0]]
C. [[0. 1. 0. 1]. [1. 0. 1. 1]. [0. 1. 0. 1]. [1. 1. 1.0]]
D. [[0. 1. 0. 1]. [0. 0. 1. 0]. [0.0.0.0]. [0.0.1.0]]
What happens when an imbalance occurs in an AVL tree after an insertion?
A. The imbalance is corrected by rotating the affected subtree.
B. The tree is automatically rebuilt from scratch.
C. The tree is rebalanced by converting it to a red-black tree.
D. A new node is created to fix the imbalance.
A linked list is a series of connected
A. ADTS
B. Nodes
C. vectors
D. head
Given a graph in the figure, the weighted matrix of the graph is:
A. [[1. 0. 1. 0, 0]. [0. 1. 0. 1. 1]. [1. 0, 1, 0, 1]. [0, 1, 0, 1, 0].[0. 1. 1. 0.1]]
B. [[0, 2. 0. 1. 4]. [1. 0. 1. 0. 0]. [0. 7. 0, 8, 5]. [9. 0. 8. 0. 5].[4. 0. 0. 5.0]]
C. [[0, 1. 0. 1. 1]. [1, 0, 1, 0, 0], [0, 1, 0. 1. 0]. [1. 0. 1. 0. 1].[1, 0, 0, 1, 0]]
D. [[0. 2. 0. 0. 4]. [2. 0. 7. 0. 0], [0. 7. 0. 8. 0]. [0. 0. 8. 0. 5].[4. 0. 0. 5.0]]
Given a graph in the figure, the breadth first traversal from node C is (in ABC order):
A. C. B, A, D, E
B. C, B, E, A, D
C. C. E. E.A.B
D. C, E, B, D, A
Given a binary search tree as follows: What are the Internal nodes?
A. 30, 40, 50
B. 30,50
C. 25, 35, 45, 60
D. 40
Given a binary search tree as follows: What is the output of In-order traversal?
A. 50, 25, 10, 5, 35, 30, 75, 65, 72, 100
B. 5, 10, 30, 35, 25, 72, 65, 100. 75, 50
C. 5, 10, 25, 30, 35, 50, 65, 72, 75, 100
D. 50, 25, 75, 10, 35, 65, 100, 5, 30, 72
What is the time complexity for access an element in Arrays?
A. O(n)
B. O(1)
C. O(n*n)
D. O(n+1)
Given a hash table of size S and a division hash function h(), an element with key k is stored at index
A. k
B. k/S
C. k% S
D. h(k/S)
What is the output of the following program?
txt = "acbd"
x = txt.istitle()
print(x)
A. Error
B. 1
C. True
D. False
Given a binary search tree as follows:
What is the sibling of node 25?
A. 10
B. 75
C. 35
D 50
What is the output of the following code?
my_list=["Hello", "Python"]
print("-" join(my_list))
A. HelloPython-
B. Hello-Python
C. -HelloPython
D. HelloPython
The data structure required for Breadth First Traversal on a graph is?
A. Stack
B. Queue
C. Array
D. Linked list
For the given hash table size of 100 and folding method is used with length equals 2. What location will be the key 2844267 be hashed using probing?
A. 5
B. 7
C. 67
D. 105
The following circular queue can accommodate a maximum six elements with the following data
front 2 rear = 4
queue=__;L;M;N__;__
What are the values of front and rear after add O operation takes place?
queue = __;L, M, N, O,__
A. front 2, rear = 5
B. front 3, rear = 5
C. front 1, rear = 4
D. front 3, rear = 4
A. Base case
B. Recursive calls
C. Recall case
D. Nothing
A graph in which exists a path between any two nodes is called
A. Complete graph
B. Connected graph
C. Digraph
D. In-directed graph
How to access to the value part of a singly linked list node x?
Given a pointer h points to the first node of a singly linked list. Which one is used to remove the list?
What is the shortest path from node A to node E?
A. A. B. C. E
B. A. G. E
C. A.B.E
D. A. C. E
Given the sequential representation of the binary tree T (a one-dimensional array is used to store the elements of the tree T) and the root node of the tree T is the node 15)
What is the left child of the node 10?
A. 12
B. 5
C. 7
D. 3
Given a binary search tree as follows: What would be the output of In-order traversal?
A. 25, 35, 30, 45, 60, 50, 40
B. 40, 30, 50, 25, 35, 45, 60
C. 40. 30, 25, 35, 50, 45, 60
D. 25, 30, 35, 40, 45, 50, 60
Given a binary search tree as follows: What are the descendants of node 25 of the tree?
A. 10.35
B. 5, 10, 30, 35
C. 75
D 50
What is visited first in Post-order traversal of binary tree?
A. The left subtree
B. The right subtree
C. The root
Given a binary search tree as follows: What is the output of Breadth First traversal?
A. 5, 10, 30, 35, 25, 72, 65, 100, 75, 50
B. 50, 25, 10, 5, 35, 30, 75, 65, 72, 100
C. 5, 10, 25, 30, 35, 50, 65, 72, 75, 100
D. 50, 25, 75, 10, 35, 65, 100, 5, 30, 72
Given a binary tree as follows:
The leaves of tree are
A. E, F, G, H
B. G. H
C. B. G. H
D. G.H.F
Assume that a Binary Trees T is represented as Array-Based Representation (root is stored at index 1) and a node X is stored at index 3. What is position of the left child of X?
A. 3
B. 5
C. 6
D. 7
What will be the output of the following code?
x = hex(12);
print(x)
A. Oxa
B. Oxb
C. Oxc
D. Oxd
A. It finds the middle node of the linked list in O(n) time.
B. It finds the middle node of the linked list in O(logn) time.
C. It finds the length of the linked list in O(n) time.
D. It finds the middle node of the linked list in O(n2) time.
What is the time complexity to insert a new node at the end of a singly linked list if the tail pointer is not maintained?
A. O(1)
B. O(n)
C. O(log n)
D. O(nlog n)
What will be the output of the following code?
a=[1, 2, 3, 4, 5]
b=a[2:4]
print(b)
A. [2, 3, 4]
B. [2,4]
C. [3, 4, 5]
D. [3, 4]
What will be the output of the following code?
student = { 1: "Tuan", 2. "Hoa" 3: "Nam' }
x = student.keys()
print(x)
A. dict_keys([1, 2, 3])
B. dict_values(['Tuan', 'Hoa', 'Nam'])
C. [1: "Tuan", 2: "Hoa", 3: "Nam"]
D. 3
A. 135
B. 2345
C. 1234
D. 54321
How to delete the first element of a non-empty linked list that is pointed by pointer Head?
A. Head = None;
B. Head = tail;
C. Head = Head.next
D. Head = tail.next
What is the primary benefit of using a circularly linked list?
A. It allows circular traversal without reaching the end of the list.
B. It allows easier removal of the first element.
C. It eliminates the need for a tail pointer.
D. It supports multiple pointers to the same node.
A hash function h defined h(key)=key mod 10, linear probing is used to insert sequentially the keys 2, 4, 7, 17 into a hash table indexed from 0 to 9. What will the location of the key 8 be?
A. 0
B. 1
C. 7
D. 9
Given a 11-entry hash table and a hash function, h(i)=(3i+5) mod 11, to hash the keys 2, 12, 15, and 1, assuming no collision is handled. Where is 1 hashed?
A. 1
B. 2
C. 8
D. collision
Which of the following method is not a collision resolution strategy for open addressing in hash table?
A. Linear probing.
B. Quadratic probing.
C. Double hashing.
D. Chaining.
A chained hash table has an array size of N (separate chaining for solving collision). What is the maximum number of elements that can be placed in the table?
A. N
B. N+1
C. N-1
D. There is no limit
Given a hash table T with 10 slots that stores 5 elements, the load factor a for T is
A. 10
B. 5
C. 50
D. 0.5
The number of elements in the weighted matrix of a graph having 5 vertices is?
A. 5
B. 16
C. 25
D. 36
Given a graph in the figure, the breadth first traversal from node A is (in ABC order):
A. A. D. E. C. B
B. A, B, C, D, E
C. A, B. D. C. E
D. A. B. C. D. E
The total number of edges that connect to node u is called
A. In-degree
B. Out-degree
C. Degree
D. Order
Given a graph in the figure, the Breadth first traversal from node 5 is (in 1.2.3 order):
A. 5, 7, 8, 6. 2. 1.3.4
B. 5, 4, 1, 6, 7, 8. 3. 2
C. 5, 1, 2, 6, 7. 8.3.4
D. 5. 1,7,2,3,4.8.6
What will be the output of the following code?
from queue import LifoQueue
S= LifoQueue(maxsize=5)
S.put('A')
S.put('B')
S.get()
S.put('C')
print(S.qsize())
A. 5
B. 1
C. 2
D. 3
Process of inserting an element in stack is called
A. Add
B. Insert
C. Push
Pop
What does the following algorithm do?
Algorithm add last(L,e):
newest=Node(e)
newest.next = None
L.tail.next = newest
L.tail = newest
A. Inserting a new node at the end of a singly linked list.
B. Inserting a new node at the head of a singly linked list.
C. Removing a node at the end of a singly linked list.
D. Removing a node at the head of a singly linked list.
What will be the output of the following code?
from queue import LifoQueue
S= LifoQueue(maxsize=3)
S.put('A')
S.put('B')
S.put('C')
print(S.get())
A. ['A', 'B', 'C']
B. ['C', 'B', 'A']
C. A
D. C
Consider the following operation performed on a stack of size 5.
Push(1);
Push(2);
Push(3);
Pop();
Push(4);
Pop();
Pop();
Push(5);
After the completion of all operations, the number of elements present on stack are
A. 1
B. 2
C. 3
D. 4
Given a string S = "1234512345" and a pattern P = "123". What is brute-force algorithm returns? (the string is indexed from 0)
A. 0
B. 1
C. 5
D. 0,5
Prefix notation is also known as
A. Reverse Polish Notation
B. Reverse Notation
C. Polish Notation
D. Polish Reverse Notation
The concept of prefix and suffix is used in which of the following algorithms?
A. KMP
B. Boyer-Moore
C. Brute Force
D. Advanced Brute Force
Given a string S = "12312345" and a pattern P = "123". What is KMP algorithm returns? from 0)
A. 0
B. 3
C. 1,4
D. 0,3
Given an array as follows: [6, 1, 5, 3, 7]. What is the number of key comparisons done to check if 3 is in the array or not by using linear search?
A. 1
B. 2
C. 3
D. 4
The number of swappings needed to sort the numbers 2, 7, 8, 9, 1 in ascending order, using bubble sort is
A. 2
B. 3
C. 4
D. 5
Which of the following algorithm divides the list?
A. Linear search
B. Binary search
C. Binary tree building
D. Heap Sort
Given an array A = (6, 7, 4, 1, 2, 9) and Quick Sort is used to sort the aray A in increasing order. What is the sequence after the first phase, the pivot is 4?
Α. 674129
Β. 214769
C. 124769
D. 124679
The worst case occurs in linear search algorithm when
A. Item is somewhere in the middle of the array
B. Item is not in the array at all
C. Item is the last element in the array
D. Item is the last element in the array or is not there at all
Given an array X = [3, 1, 2, 7, 9, 6], Selection sort is used to sort X in an ascending order. After 2 steps, how does the array look like?
A. [1, 2, 3, 7, 9, 6]
B. [3, 1, 2, 7, 9, 6]
C. [1, 3, 2, 7, 9, 6]
D. [1, 2, 3, 6, 7, 9]
A. yhn
B. Ptn
C. ytn
D. oht
E. yirvn P
Which search algorithm is best for a large ordered list?
A. A for each loop
B. Sequential search
C. Binary search
D. None of these
A. Base case
B. Recursive calls
C. Anchor case
D. Nothing
A. 4
B. 0
C. 10
D. Error
A. 4
B. 1
C. 10
D. 6
A. good good good good
B. good
C. 16
D. 4
A. 10
B. 4
C. 2
D. 1
What is visited first in Pre-order traversal?
A. The left subtree
B. The right subtree
C. The root
D. The leaf
Given the sequential representation of the binary tree T (a one-dimensional array is used to store the elements of the tree T) and the root node of the tree T is the node 15):
The left subtree of the node 10 is
A. 7, 17, 35
B. 3, 23, 37
C. 7,3
D. 20
Given a binary search tree as follows:
What is this tree?
A. Full tree
B. Complete tree
C. Perfect tree
D. B-tree
A. Traverse the tree in Pre-order
B. Traverse the tree in Post-order
C. Traverse the tree in In-order
D. Traverse the tree in BFT
A. 12345
B. 2345
C. 1234
D. 54321
What will be the output of the following code?
b=[1] *5
print(b)
A. 0
B. 5
C. [1, 1, 1, 1, 1]
D. Error
What is the output of the following list operation?
alist[10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
A. [30, 40, 50]
B. [20, 30, 40]
C. [30, 40, 50, 60]
D. [20, 30, 40, 50]
A. Create a node of singly linked list
B. Create a node of circular linked list
C. Create a node of doubly linked list
D. None of these
List A is defined as follows:
A = ['a', 'b', 'c']
Which of the following statements adds 'd' and 'e' to the end of A, so that it then equals ['a', 'b', 'c', 'd', 'e']:
A. A extend(['d', 'e'])
B. A.append(['d', 'e'])
C. A[-1] = ['d', 'e']
D. A.append('d', 'e')
What is the output of the following program?
a=[5, 4, 7, 2, 9]
print(a.index(4))
A. 0
B. 1
C. 2
D. 9
A hash function h defined h(key)=key mod 10, quadratic probing is used to insert sequentially the keys 2, 4, 7, 17 into a hash table indexed from 0 to 9. What will the location of the key 17 be?
A. 0
B. 1
C. 7
D. 8
A chained hash table has an array size of 255. What is the maximum number of elements that can be placed in the table?
A. There is no limit
B. 254
C. 255
D. 256
A hash function h defined h(key)=key mod 5, with Quadratic probing, is used to insert the keys 1, 10, 11, 12 into a table indexed from 0 to 4. What will be the location of key 12?
A. 4
B. 3
C. 0
D. 1
What is the shortest path from node A to node D?
A. A, B, F, D
B. A, B, E, D
C. A, C, E, D
D. A, G, D
Given a graph in the figure, the Depth first traversal from node A is (in ABC order):
A. A, B, D, C, E
B. A, B, C, E, D
C. A, D, B, E, C
D. A, D, B, C, E
The number of elements in the weighted matrix of a graph having 8 vertices is?
A. 8
B. 16
C. 49
D. 64
Given a graph in the figure, the weighted matrix of the graph is (visit nodes in ABC order):
A. [[0, 1, 0, 1), [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 1, 0]]
B. [[0, 1, 0, 0], [0, 0, 10, 0], [0, 1, 1, 0], [0, 0, 0, 0]
C. [[0, 5, 0, 40], [0, 0, 10, 0], [0, 10, 0, 10], [0, 0, 0, 0]]
D. [[0, 1, 0, 1), (1, 0, 1, 1], [0, 1, 0, 1], [1, 1, 1, 0]]
What does the function S.discard(e) do?
A. Remove element e from the set, if present.
B. Add element e to the set
C. Return True if the set contains element e
D. Generate an iteration of all elements of the set
What will be the output of the following code?
from collections import deque
S = deque()
S.append(1)
S.append(2)
S.pop()
S.append(3)
S.pop()
print(S)
A. deque([1])
B. deque ([1, 2, 3])
C. 3
D. 1
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as a?
A. Queue
B. Stack
C. Tree
D. Linked list
Given an empty queue Q and a sequence of the following operations:
Enqueue(5)
Enqueue(15)
Enqueue(25)
Dequeue();
Dequeue()
The value of the front element is:
A. 0
B. 5
C. 15
D. 25
The brute-force pattern matching algorithm compares the pattern P containing n characters with the text T containing m characters. What is the time complexity of it?
A. O(n*m)
B. O(n+m)
C. O(n)
D. O(m)
Given a string S = "ABCDEFABCD" and a pattern P = "BC". What is brute-force algorithm returns? (the string is indexed from 0)
A0
B. 1
C. 7
D. 1,7
Given the length of input data is 8 and the length of output data is 4. What is the data compression rate in this case?
A. 8
B. 4
C. 1
D. 0.5
The number of swappings needed to sort the numbers 8, 22, 7, 9, 31 in ascending order, using bubble sort is____
A. 2
B. 3
C. 4
D. 5
Which of the following cases occurs when searching an array using linear search the value to be searched is equal to the last element of the array?
A. The best case
B. The worst case
C. The average case
D. The amortized case
The worst case occurs in linear search algorithm when
A. Item is somewhere in the middle of the array
B. Item is not in the array at all
C. Item is the last element in the array
D. Item is the last element in the array or is not there at all
Given an array as follows: [1, 3, 4, 5, 6, 8, 9] What is the number of key comparisons done to find 5 using binary search?
A. 1
B. 2
C. 3
D. 4
What is the condition for applying binary search in an array?
A. The array should not be too long
B. The array should not be short long
C. The array should be sorted
D. The array should not be sorted
Given a definition as follows: "A unique type of recursion where the last procedure of a function is a recursive call What is this?
A. Tail-Recursion
B. NonTail-Recursion
C. Recursion
D. None of these
By default, what is the maximum depth of recursion?
A. 10000
B. 1000
C. 100
D. 10
A5
B. 4
C. 3
D. 2
A 11
B. 1011
C. 1101
D0
What is advantage of Recursion?
A. Recursive functions make the code look clean and elegant
B. Recursive calls are inefficient as they take up less of memory
C. Recursive calls are inefficient as they take up less of time
D. None of the others
What is true about AVL tree?
A. Heights of the children of a node can differ by at most 1
B. Every node has a color either red or black
C. Heights of the children of a node can differ by at least 1
D. All leaves have the same depth
Given an unbalanced tree as follows: What kind of rotation should be used to make AVL tree
A. Up
B. Down
C. Left
D. Right
What is visited first in Breadth First Traversal of a tree?
A. The left subtree
B. The right subtree
C. The root
D. The leaf
What are properties of a tree
A. One node is marked as Root node
B. Every node other than the root is associated with one parent node
C. Each node can have an arbiatry number of child node
D. All of the others
What will be the output of the following code?
b=[1, 2, 3, 4, 5]
print(b[-3;-1])
A. [1]
B. [2, 3]
C. [3, 4]
D. Error
What is the output of the following list assignment?
alist = [4, 8, 12, 16]
alist[1:4] = [20, 24, 28]
print(aList)
A. [4, 20, 24, 28, 8, 12, 16]
B. [4, 20, 24, 28]
C. [4, 8, 12, 16]
D. [20, 24, 28]
In hashing, what is direct addressing?
A. Distinct array position for every possible key
B. Fewer array positions than keys
C. Fewer keys than array positions
D. Same array position for all keys
Given a hash table T with 20 slots that stores 1000 elements, the load factor a for T is
A. 20
B. 1000
C. 50
D. 0.02
What is the hash function used in the division method?
A. h(k) = k / m
B. h(k) = k mod m
C. h(k) = m / k
D. h(k) = m mod k
What is simple uniform hashing?
A. Every element has equal probability of hashing into any of the slots
B. A weighted probabilistic method is used to hash elements into the slots
C. Elements has Random probability of hashing into array slots
D. Elements are hashed based on priority
Hash function is used
A. to converts each key k into an index in the hash table.
B. to converts each index in the hash table into a key.
C. to find a key in the hash table.
D. to calculate a key k.
Given a hash table with size 100 and Division hashing method is used, in what location will the key 124 be hashed?
A. 24
B. 1
C. 4
D. 12
Which of the following is longest proper prefix which is also suffix of "ABCA"?
A. "ABCA"
B. "ABC"
C. "AB"
D. "A"
What does the function s.find(pattern) do?
A. Return the index starting the leftmost occurrence of pattern; else -1
B. Return the index starting the rightmost occurrence of pattern; else -1
C. Return 1 as occurrence of pattern; else -1
D. Return the length of pattern
What is the best case for sorting in Merge Sort?
A. O(n*n)
B. O(n)
C. O(nlogn)
D. O(logn)
Which of the following algorithms has a logarithmic runtime complexity?
A. Binary search
B. Linear search
C. Merge sort
D. Selection sort
Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general?
A. Heap Sort
B. Selection Sort
C. Insertion Sort
D. Merge Sort
The complexity of Binary search algorithm is
A. O(n)
B. O(log n)
C. O(n^2)
D. O(n log n)
Given a definition as follows: "a recursive function in which the first statement is a recursive call and then the other operations are performed What is this?
A. Tail-Recursion
B. NonTail-Recursion
C. Recursion
D. None of the others
Recursion calls are stored on the memory in which data structure?
A. Heap
B. Tree
C. Stack
D. Queue
What is recursion used for?
A. Recursion is used to create loops in languages where other loops are not available.
B. We use recursion only to implement mathematical formulas in code.
C. Recursion is used to iterate through sequences of files and directories.
D. Recursion lets us tackle complex problems by reducing the problem to a simpler one.
What are the advantages of recursive programming over iterative programming?
A. Recursion provides a clean and simple way to write code
B. The recursive program has greater space requirements than the iterative program
C. The recursive program has greater time requirementsthan the iterative program
D. None of the others
What is degree of vertex V?
A. 0
B. 1
C. 3
D. 5
What is the maximum number of children a node can contain in an n-ary tree?
A n
B. 2
C. 1
D. п-1
If you insert the sequence of numbers [10, 8, 3, 20, 25, 15, 1, 0) sequentially into a binary search tree (BST), what would be the height of the tree?
A. 4
B. 3
C. 5
D. 6
Consider the AVL tree created by sequentially adding the numbers (20, 5, 25, 9, 10, 4, 35). What is the difference in the number of nodes between the right and left subtrees of the root node? A. 2 B. 1 C. 0 D 3
A. 2
B. 1
C. 0
D 3
What property is guaranteed in a balanced binary search tree (BST)?
A. The height of the tree is O(log n)
B. Every level of the tree is fully populated
C. The tree can be unbalanced but still maintain BST properties
D. Each node has at most two children
What is the MAXIMUM number of nodes in a binary search tree with height=3?
A. 15
B. 16
C. 8
D. 7
Which of the following is a disadvantage of AVL trees?
A. They are not balanced
B. They require additional space for storing balance factors
C. They do not support in-order traversal
D. They are balanced
What is the main advantage of a doubly linked list over a singly linked list?
A. Easier insertion at the beginning of the list
B. Ability to traverse the list in both directions
C. Reduced memory usage
D. Faster access to elements by index
In a doubly linked list, what does the prev pointer of the head node point to?
A. The next node in the list
B. The previous node in the list
C. It points to NULL
D. It points to the last node in the list
In a circularly linked list, what does the next pointer of the last node point to?
A. NULL
B. The head node
C. The previous node
D. Itself
List A is defined as follows: A = [1, 2, 3, 4, 5] Select all of the following statements that remove the middle element 3 from A so that it equals [1, 2, 4, 5]:
A del A[2]
B. A[2] = []
C. A[2:2] = []
D. A[2].remove()
What is the time complexity of searching for an element in a linked list with 'n' elements in the worst case?
A. O(n)
B. O(log n)
C. O(1)
D. O(n^2)
What data structure is used to implement a hash table?
A. Arrays
B. Linked Lists
C. Trees
D. Graphs
What is the main goal of collision resolution in hash tables?
A. To decrease the size of the hash table.
B. To handle cases where multiple keys map to the same index
C. To increase the complexity of the hash function
D. To sort the keys in the hash table
What is the main disadvantage of using chaining to handle collisions?
A. Increased memory usage
B. Increased complexity of hash function
C. Decreased average search time
D. Difficulty in implementing
What effect does a higher load factor have on the efficiency of a hash table?
A. Higher load factors decrease efficiency
B. Higher load factors have no effect on efficiency
C. Higher load factors increase efficiency
D. Efficiency is unrelated to load factor
In the worst-case scenario, what is the time complexity of a search operation in a hash table with separate chaining?
A. O(n)
B. O(logn)
C. O(1)
D. O(n^2)
What does an adjacency list represent in a graph data structure?
A. It represents the vertices of the graph.
B. It represents the edges of the graph.
C. It stores the adjacent vertices for each vertex.
D. It stores the weights of the edges in the graph.
What is the minimum spanning tree (MST)?
A. Spanning subgraph
B. Spanning tree
C. Spanning tree of a weighted graph with minimum total edge weight
D. Shortest path
What data structure follows the Last in, First Out (LIFO) principle?
A. Queue
B. Stack
C. Linked List
D. Tree
In a stack implementation, what is the primary difference between the "pop" and "peek" operations?
A. "Pop" removes the top element, while "peek" only returns its value:
B. "Peek" removes the top element, while "pop" only returns its value.
C. Both "pop" and "peek" remove the top element but have different return values.
D. Both "pop" and "peek" return the top element but have different removal behaviors.
A. [[1, 5], [2, 6], [3, 4]]
B. [4, 5, 6, 3, 2, 1]
C. [1, 3, 5, 2, 4, 6]
D. The code will raise an error
What is the main advantage of using Huffman coding over fixed-length coding?
A. Easier to implement
B. Uses less memory
C. Faster encoding and decoding
D. Reduces the average code length, saving space
What is the load factor in the context of hash tables?
A. The ratio of the number of elements to the total available slots.
B. The average number of probes required for each search
C. The number of collisions that have occurred.
D. The number of slots available for new elements.
In which sorting, elements in the array are compared with a pivot value?
A Bubble Sort
B Selection Sort
C. Merge Sort
D. Quick Sort
Which sorting algorithm use the divide-and-conquer approach?
A. Quick Sort
B. Insertion Sort
C. Bubble Sort
D. Selection Sort
A sorted array contains 8 items. Using binary search, the maximum number of comparisons to search for an item in this array is
A. 1
B. 2
C. 3
D. 4
Which of the following problems is least likely to benefit from recursion?
A. Tower of Hanoi
B. Calculating Fibonacci numbers
C. Summing elements of a list
D. Traversing a directory structure
Which technique can be used to eliminate tail recursion?
A. Dynamic programming
B. Memoization
C. Iteration
D. Breadth-first search
A sorted array contains 16 items. Using binary search, the maximum number of comparisons to search for an item in this array is
A 1
B. 4
C. 8
D. 16
What is the time complexity for access an element in Arrays?
A. O(n)
B. O(1)
C. O(n*n)
D. O(n+1)
Which search algorithm would be best to use with ordered data?
A. A binary search
B. Either binary search or a linear search
C. A linear search
D. Neither binary search nor a linear search
In which sorting, consecutive adjacent pairs of elements in the array are compared with each other?
A Bubble sort
B. Selection sort
C. Merge sort
D. Quick sort
