ads final
What is a hash function?
. A function that computes the location of the key in the array
From the given example, find a value placed at index '2'. Given: hash(x)= x %(mod) 10
12
The number of different binary trees with 6 nodes is
132
Which of the following statement is TRUE?
A hash function takes a message of arbitrary length and generates a fixed length code
If several elements are competing for the same bucket in the hash table, what is it called?
Collision
........ form of access is used to add remove nodes from a stack.
LIFO
What searching algorithm starts at the beginning of the list and check every element in the list?
Linear search
In order to add items to the specific index in the array, the time complexity is
Linear time complexity O(N)
What is the position of minimum element in Binary Search Tree?
Most left node
The time taken by binary search algorithm to search a key in a sorted array of n elements is
O ( log n )
In simple uniform hashing, what is the search complexity?
O(1)
Find the slowest time
O(n!)
Which of the following standard algorithms is not Dynamic Programming based.
Prim's Minimum Spanning Tree
Which of the following data structures is FIFO data structure?
Queue
What is the best sorting algorithm to use for the elements in array are more than 1 million in general?
Quick sort
What is recurrence for worst case of QuickSort and what is the time complexity in Worst case?
a. Recurrence is T(n) = T(n-1) + O(n) and time complexity is O(n^2)
If we remove elements from the end, this operation is faster in linked lists comparing with arrays
disagree
The main idea behind of binary search tree is to achieve O(1) time complexity
disagree
Deletion in stack take place at one end called
top
Which of the following data structures is non-linear?
trees
Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments
true
A binary search tree is generated by inserting in order the following integers: 50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24, 49 The number of nodes in the left subtree and right subtree of the root respectively is
(8, 4)
Whаt аlgorithm is dеscribеd bеlow? 1. аdd thе еlеmеnt to thе bottom lеvеl of thе hеаp аt thе most lеft. 2. Compаrе thе аddеd еlеmеnt with its pаrеnt; if thеy аrе in thе corrеct ordеr, stop. 3. If not, swаp thе еlеmеnt with its pаrеnt аnd rеturn to thе prеvious stеp.
. Insеrtion to а hеаp
Which of these relates to linked list`s disadvantage?
. No direct access to elements
Whаt is thе timе complеxity of insеrting to stаck?
. O(1)
The average case occurs in the Linear Search Algorithm when
. The item to be searched is in some where middle of the Array
Consider a complete binary tree with 7 nodes. Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root. The value of |A-B| is
1
What does the following function print for n = 25? void fun(int n) { if (n == 0) return; printf("%d", n%2); // printing the value fun(n/2); }
10011
Given a hash table T with 25 slots that stores 3000 elements, the load factor α for T is
120
Consider the following recursive function fun(x, y). What is the value of fun(4, 3) int fun(int x, int y) { if (x == 0) return y; return fun(x - 1, x + y); }
13
The number of structurally different possible binary trees with 4 nodes is
14
Four matrices M1, M2, M3 and M4 of dimensions pxq, qxr, rxs and sxt respectively can be multiplied is several ways with different number of total scalar multiplications. For example, when multiplied as ((M1 X M2) X (M3 X M4)), the total number of multiplications is pqr + rst + prt. When multiplied as (((M1 X M2) X M3) X M4), the total number of scalar multiplications is pqr + prs + pst. If p = 10, q =100, r =20, s =5, and t=80, then the number of scalar multiplication needed is ..?
19000
From the given example, find index of '12'. Given: hash(x)= x %(mod) 10
2
How many NULL references in a doubly linked list?
2
How many children can a node in binary trees have at most?
2
How many sub arrays does the quick sort algorithm divide the entire array into at each iteration?
2
What is the index of node`s right child in Heap if node locates at position k
2k+2
The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16, 7. What is the height of the binary search tree ? (Hint: Height = 'Number of Layers' - 1)
4
Suppose you are given a binary tree with n nodes, such that each node has exactly either zero or two children. What will be the maximum height of the tree?
?(n−1)/2
What is a hash table?
A structure that maps keys to values
Which of the following statements about Linear Search is TRUE?
All of the options in this question are TRUE . linear search compares each array element with a search key it's just as likely that the value will be found in the first element as the last. . In order to check if a value is not in the array, the algorithm must compare the search key to every element in the array. on average, the algorithm must compare the search key with half the array elements
Which of the following is required to apply Binary Search algorithm?
Array must be sorted in ascending order
Which of these searching algorithms consider all neighbors first and not suitable for decision making trees used in games?
BFS
In order to add items to the end in the array, the time complexity is
Constant complexity O(1)
In order to remove items from the end of the array, the time complexity is
Constant complexity O(1)
Lets say we have to swap two number using the third temporary variable. What will be our time complexity?
Constant complexity O(1)
If the elements "A", "B", "C" and "D" are placed in a stack and are deleted one at a time, in what order will they be removed?
DCBA
Which of the following algorithm design technique is used in merge sort?
Divide and Conquer
In which data structure a hash function is used?
HashTable
Which of the following traversal outputs the data in sorted order in a Binary Search Tree?
Inorder
recursion is similar to which of the following?
Loop
Which of the following sorting algorithms has the lowest worst-case complexity?
Merge Sort
What is the best time complexity of bubble sort?
N
Which of these relates to linked list`s advantage?
No need to pre-allocate memory (No buffer)
Heap is basically a binary tree, can a heap be unbalanced
No, it cannot be unbalanced
What is the worst-case runtime of an algorithm that compares two numbers
O(1)
What would be the asymptotic time complexity to add a node at the beginning of singly linked list, if the reference is initially referencing to the head of the list?
O(1)
n simple uniform hashing, what is the search complexity?
O(1)
Given a sorted array of integers, what can be the minimum worst case time complexity to find ceiling of a number x in given array? Ceiling of an element x is the smallest element present in array which is greater than or equal to x. Ceiling is not present if x is greater than the maximum element present in array. For example, if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then output should be 100.
O(Logn)
Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?
O(M+N)
What is the time, space complexity of following code : int a = 0, b = 0; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { a = a + j; } } for (k = 0; k < N; k++) { b = b + k; }
O(N * N) time, O(1) space
What is the time, space complexity of following code : int a = 0, b = 0; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { a = a + j; } } for (k = 0; k < N; k++) { b = b + k; }
O(N * N) time, O(1) space
What is the time, space complexity of following code : int a = 0, b = 0; for (i = 0; i < N; i++) { a = a + rand(); } for (j = 0; j < M; j++) { b = b + rand(); } Assume that rand() is O(1) time, O(1) space function.
O(N + M) time, O(1) space
Whаt is а timе complеxity of аn аlgorithm thаt finds thе sizе of Linkеd List?
O(N)
What is the time complexity of the following code : int a = 0; or (i = 0; i < N; i++) { for (j = N; j > i; j--) { a = a + i + j; } }
O(N*N)
If n elements are sorted in a balanced binary search tree. What would be the asymptotic complexity to search a key in the tree?
O(logn)
Search a binary search tree costs?
O(logn)
What is the time complexity of recursive Binary Search algorithm?
O(logn)
What the time complexity of LinearSearch algorithm?
O(n)
What would be the asymptotic time complexity to add a node at the end of singly linked list, if the reference is initially referencing to the head of the list?
O(n)
the run time for traversing all the nodes of a binary search tree with n nodes and printing them in an order is
O(n)
What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree?
O(n) for all
Average time complexity of Bubble sort is?
O(n^2)
What does the following function do for a given Linked List with first node as head? void fun1(Node head) { if(head == NULL) return; fun1(head.next); printf("%d ", head.data); }
Prints all nodes of linked list in reverse order
Imagine a stack, and you have pushed there 12, 56, 92 in the same order. What will be the result of stack.peek() operation
Retrieve 92
Imagine a stack, and you have pushed there 12, 56, 92 in the same order. What will be the result of stack.pop () operation
Retrieve and remove 92
Whаt аlgorithm is dеscribеd bеlow? 1. Swаp thе root of thе hеаp with thе lаst еlеmеnt of thе hеаp. 2. Compаrе thе nеw root with its childrеn; if thеy аrе in thе corrеct ordеr, stop. 3. If not, swаp thе еlеmеnt with onе of its childrеn аnd rеturn to thе prеvious stеp.
Rеmoving thе root from а hеаp
How the process of finding a particular element of an array is called?
Searching
Which data structure is used for implementing recursion?
Stack
How to insert a new node to Binary Search Tree?
Starting from the root go to the right or left child of each node according to the new node`s key recursively till it finds an empty position
Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10
The pivot could be either the 7 or the 9.
How to get an index of list (chain) from the hash code of a HashTable Node (M - number of chains/bins)
Using modulo operator (hashcode % M)
The subset-sum problem is defined as follows. Given a set of n positive integers, S = {a1 ,a2 ,a3 ,...,an} and positive integer W, is there a subset of S whose elements sum to W? A dynamic program for solving this problem uses a 2-dimensional Boolean array X, with n rows and W+1 columns. X[i, j],1 <= i <= n, 0 <= j <= W, is TRUE if and only if there is a subset of {a1 ,a2 ,...,ai} whose elements sum to j. Which of the following is valid for 2 <= i <= n and ai <= j <= W?
X[i, j] = X[i - 1, j] V X[i - 1, j - ai]
Considering the fact that the memory is cheap nowadays, do you agree that time complexity is more important than space complexity
agree
if we remove elements from the beginning, this operation is faster in linked lists comparing with arrays
agree
If the last node of a linked list references back to the head node instead of containing the null reference we call it________.
circular linked list
The in-order and pre-order traversal of a binary tree are d b e a f c g and a b d e c f g respectively. The post order traversal of a binary tree is...?
d e b f g c a
Given references of the head and the tail of a Linked List. Which of the following functions are dependent on the number of nodes in the Linked List?
function that deletes the last element
what kind of data structure uses BFS
graph
what kind of data structure uses DFS
graph
An array that stores pointers to records corresponding to a given phone number or type of data that sores key-value pairs
hash table
Consider a full binary tree with n internal nodes, internal path length i, and external path length e. The internal path length of a full binary tree is the sum, taken over all nodes of the tree, of the depth of each node. Similarly, the external path length is the sum, taken over all leaves of the tree, of the depth of each leaf. Which of the following is correct for the full binary tree?
i = e + 2n
In the deletion operation of max heap, the root is replaced by
last element of the last level
The time complexity of computing the transitive closure of a binary relation on a set of n elements is known to be:
o (n^3)
what is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size n?
o(log2(n))
the following algorithms is relied to which sorting algorithms? algorithms We choose an element from the list, called the pivot. We'll use it to divide the list into two sub-lists. We reorder all the elements around the pivot - the ones with smaller value are placed before it, and all the elements greater than the pivot after it. After this step, the pivot is in its final position. This is the important partition step. We apply the above steps recursively to both sub-lists on the left and right of the pivot.
quick sort
Whаt is thе optimаl wаy to gеt prеdеcеssor's vаluе in а Linkеd List?
storе а pointеr to thе prеvious nodе
We use dynamic programming approach when
the solution has optimal substructure
What does the following function do? int fun(int x, int y) { if (y == 0) return 0; return (x + fun(x, y-1)); }
x*y
Is it possible for a binary search tree to become unbalanced?
yes