ADS 2
What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree?
O(n) for all
An array consists of n elements. We want to create a heap using the elements. The time complexity of building a heap will be in order of
O(n*n*logn)
What is the worst case complexity of bubble sort?
O(n2)
Average time complexity of Bubble sort is?
O(n^2)
Suppose we have an array with 10 elements: [12, 45, 8, 33, 97, 25, 5, 1, 13, 76]. In case if we need to perform a linear search, which element we get first with the best-case scenario?
12
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
When does merging process start in Merge Sort algorithm?
Once all of subarrays obtain their atomic view
In linked list each node contain minimum of two fields. One field is data field to store the data second field is?
Pointer to node
void fun1(Node head) { if(head == NULL) return; fun1(head.next); printf("%d ", head.data); }
Prints all nodes of linked lists in direct order
On which algorithm is heap sort based on?
Priority queue
The idea of the Enqueue operation in the Queue is
Put the given item to the end of the queue
The idea of the Push operation in the Stack is
Put the given item to the top of the stack
Let's say that you sort 10 items and it takes 1 second. For 20 items it takes 4 seconds. What is you time comlexity?
Quadratic
What is a Big O time complexity of Bubble sort for the worst case?
Quadratic
What is a Big O time complexity of Quick sort for the worst case?
Quadratic
Which of the following algorithms running times is slower for the increasing input (N)?
Quadratic(N*N)
Which of the following data structures is FIFO data structure?
Queque
A pivot element to partition unsorted list is used in
Quick Sort
Imagine a stack, and you have pushed there three strings - ict, aitu, ads in the same order. What will be the result of stack.peek() operation
Retrieve ads
Imagine a queue, and you have enqueued there 12, 56, 92 in the same order. What will be the result of queue.dequeue() operation
Retrieve and remove 12
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
Imagine a stack, and you have pushed there three strings - ict, aitu, ads in the same order. What will be the result of stack.pop () operation
Retrieve and remove ads
Imagine a queue, and you have enqueued there three strings - ict, aitu, ads in the same order. What will be the result of queue.dequeue() operation
Retrieve and remove ict
Imagine a stack, and you have pushed there 12, 56, 92 in the same order. What will be the result of stack.peek() operation
Retrive 92
The idea of the Peek operation in the Queue is
Return the first item from the queue without removing it
The idea of the Peek operation in the Stack is
Return the item from the top of the stack without removing it
The idea of the Top operation in the Stack is
Return the item from the top of the stack without removing it
What problem is solved by Dijkstra's Algorithm?
Single source shortest path
In order traversal of binary search tree will produce
Sorted list
What type of memory Java used to implement Recursion?
Stack
Which data structure is used for implementing recursion?
Stack
Whаt dаtа structurе is hеlpful in visuаlizаtion of rеcursion work?
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 a node with the same key
Which of the following is not required for the doubly linked list in order to traverse it?
Status-visited or not
The idea of the Dequeue operation in the Queue is
Take the first item we have added to the queue
The idea of the Pop operation in the Stack is
Take the last item we have added to the top of the stack
What is the problem with unbalanced binary trees?
The favorable O(logN) running time may even be reduced to O(N) running time
How to find the first node in the linked list
The first node can be found by searching the one which has no pointer on it
Which of the following properties cannot be applied for Red-Black trees
The height of leaf nodes is always equal to zero
Predecessor in a binary search tree is
The largest item in the left subtree
Successor in a binary search tree is
The smallest item in the right subtree
#include <stdio.h> int fun(int n) { if (n == 4) return n; else return 2*fun(n+1); } int main() { printf("%d ", fun(2)); // printing the value return 0; }
16
How many NULL references in a doubly linked list?
2
How many children can a node in binary trees have at most?
2
The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array with improvised version?
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. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?
3
How many swaps are required to sort the given array using bubble sort - { 2, 5, 1, 3, 4}
4
Imagine a binary search tree, and the result of pre-order traversal was 25, 15, 10, 4, 12, 22, 18, 24, 50. Which one in this tree is the item located in the left as far as possible?
4
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
Match numbers with names
5 → root, 6 → right child of root, 4 → a left link, 2,3 → null links, 1,7 → a subtree
Imagine a binary search tree, and the result of pre-order traversal was 25, 15, 10, 4, 12, 22, 18, 24, 50. Which one in this tree is the item located in the right as far as possible?
50
Lets say that you built a min heap inserting 10, 8, 15, 12 one after another. What will be the final representation of your heap as an array
8, 10, 15, 12
Suppose we have an array with 10 elements: [12, 45, 8, 33, 97, 25, 5, 1, 13, 76]. In case if we need to perform a linear search, which element we get first with the worst-case scenario?
95(97)
What is a hash function?
A function that computes the location of the key in the array
Which of the following statement is TRUE?
A hash function takes a message of arbitrary length and generates a fixed length code
What is a hash table?
A structure that maps keys to values
In computer science, a stack and a queque are
Abstract Data Type
What is the difference between data structures and abstract data types?
Abstract data types are the specifications while data structures are the concrete implementations
Asymptotic analysis means that usually we are interested in large sizes so we make some approximations
Agree
Complexity Theory helps to determine the difficulty of a problem, often measured by how much time and space it takes to solve a particular problem
Agree
Considering the fact that the memory is cheap nowadays, do you agree that time complexity is more important than space complexity
Agree
Do you agree that arrays have better cache locality that can make a pretty big difference in performance
Agree
Do you agree the doubly linked list can be traversed in both directions forward and backward?
Agree
Ideally, programmers and data scientists are always trying to achieve the constant time complexity?
Agree
If we remove elements from the beginning, this operation is faster in linked lists comparing with arrays
Agree
In Red-Black trees, each node has an extra bit of information, and that bit is often interpreted as the color (red or black) of the node
Agree
In a binary search tree, every node can have at most two children, left and right
Agree
In an AVL tree, by default, we want the keep the height as as possible
Agree
In order to exit from the recursion the base case must be called
Agree
In the recursion, all calculations continue until the base case is reached
Agree
Linked lists can grow (scale) easily, meaning there is no need to define the size of the linked list in the very beginning
Agree
The main advantage of binary search tree is that on every decision we can get rid of half of the data in which we are searching
Agree
Heap sort is faster than bibble sort.
False
Quick sort is a stable sorting algorithm?
False
package main; class Base { public void Print() { System.out.println("Base"); } } class Derived extends Base { public void Print() { System.out.println("Derived"); } } class Main { public static void DoPrint(Base o) { o.Print(); } public static void main(String[] args) { Base x = new Base(); Base y = new Derived(); Derived z = new Derived(); DoPrint(x); DoPrint(y); DoPrint(z); } } Output Base Base Derived
False
In a binary search tree, if we need to find the greatest node, we have to
Go to the right as far as possible, and get the last leaf node
Dijkstra's algorithm cannot be applied on
Graphs having negative weight function
Time Complexity can be measured by
How many teps an algorithm needs
Space Complexity can be measured by
How much operational memory algorithm needs
Which of the following statement(s) is TRUE? 1.A hash function takes a message of fixed length and generates a code of variable length. 2.A hash function may give the same hash value for distinct messages. 3.A hash function takes a message of arbitrary length and generates a fixed length code.
II and III only
Why it is important to make sure a tree is balanced?
If a tree is balanced, most of the operations will have O(logN) time complexity
Which is not properties of recursive rank()?
If key is not in the table, rank() also returns the number of keys in the table that are smaller than key.
There are three types of traversing for binary search trees, which one is the most used one
In-order traversal
Each node in doubly linked lists does not include
Index of the node
Which of the following traversal outputs the data in sorted order in a Binary Search Tree?
Inorder
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е
Deletion in stack take place at one end called _____________.
top
A queue follows
FIFO structure
A stack follows
FILO structure Which of the listed options are not the application of queues
FIFO structure stands for
FIRST IN FIRST OUT
FILO structure stands for
FIRST IN LAST OUT
If the binary search tree is balanced, the time complexity of search operation is
O(logN)
The running time complexity of search operation in AVL trees in the average case takes
O(logN)
What is the complexity of deletion (removal) operation in a heap
O(logN)
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)
You have a name, and you want to find the person's phone number in the contact list
O(logn)
Find the slowest time
O(n!)
What is the optimal time complexity to count the number of nodes in a linked list?
O(n)
What is the time complexity of insert(index) method in LinkedList?
O(n)
In the deletion operation of max heap, the root is replaced by
last element of the last leve
In which heap the root node must be greatest among the keys present at all of it's children?
max-heap
An important reason that BSTs are widely used is that they allow us to keep the keys in ________.
order
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)
In a heap, how to find the index of the parent node if the left childs index is Ind?
(Ind-1)/2
What is the worst-case runtime of an algorithm that compares two numbers.
. O(1)
In zero-based indexing, the first element of the array is indexed by subscript of
0
There are many three types of indexing in arrays, which one is the most commonly used?
0(zero-based indexing)
Consider a 13 element hash table for which f(key)=key mod 13 is used with integer keys. Assuming linear probing is used for collision resolution, at which location would the key 103 be inserted, if the keys 661, 182, 24 and 103 are inserted in that order?
1
Lets say that you have build you binary search tree with the following numbers 8, 3, 10, 1, 6, 4, 7, 14 (the same order), what will be the result of in-order traversal of the tree
1, 3, 4, 6, 7, 8, 10, 14
Lets say that you have build you binary search tree with the following numbers 8, 3, 10, 1, 6, 4, 7, 14 (the same order), what will be the result of post-order traversal of the tree
1, 4, 7, 6, 3, 14, 10, 8
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
Which one from the considered notations is widely used by computer scientists?
Big Ordo notation
If the elements "C", "D", "B" and "A" are placed in a queue and are deleted one at a time, in what order will they be removed?
CDBA
In order to calculate the height of tree, it is required to
Calculate the length of the path from the root to the deepest node in the tree
Let's say that you sort 10 items and it takes 1 second. For 20 items it takes 1 second as well. What is you time comlexity?
Constant
In order to add items from the end of the array, the time complexity is
Constant time complexity O(1)
In order to remove items from the end of the array, the time complexity is
Constant time complexity O(1)
Lets say we have to swap two number using the third temporary variable. What will be our time complexity?
Constant time 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
If the elements "D", "C", "B" and "A" are placed in a queue and are deleted one at a time, in what order will they be removed?
DCBA
Binary search tree is
Data Structure
In computer science, a linked list is
Data structure
In computer science, an array is
Data structure
Which of the following is not an advantage of optimised bubble sort over other sorting techniques in case of sorted elements?
Detects whether the input is already sorted
What is the difference between directed and undirected graph
Directed graph has interconnection in each edge comparing with undirected graphs
Arrays can grow (scale) easily, meaning there is no need to define the size of the array in the very beginning
Disagree
By default, arrays are dynamic, so the size of the array can be change at compile-time
Disagree
Doubly linked lists are much more memory efficient comparing with singly linked lists and arrays?
Disagree
Every path from a given node to any of its descendant NULL/NONE nodes contains different number of black trees?
Disagree
Ideally, programmers and data scientists are always trying to achieve the quadratic or exponential time complexity?
Disagree
If we remove elements from the end, this operation is faster in linked lists comparing with arrays
Disagree
In linked lists we can use indexes which allows random access to elements
Disagree
In most high level languages, an array or linked lists can be easily implemented either with stacks or queues
Disagree
In the recursion, it is impossible to run out of memory, because the number of open functions is always small
Disagree
Recursive approaches are usual more understandable in terms of the realisation than iterative approaches
Disagree
Recursive approaches can be easily scaled up as iterative approaches
Disagree
The main idea behind of binary search tree is to achieve O(1) time complexity
Disagree
The running time of an algorithm with quadratic complexity O(N*N) is faster than the one with linear time complexity O(N) for the increasing input?
Disagree
Hash function
Distributes keys uniformly to buckets
Imagine a lift in the building: a person have to through all the floors to reach the top, and at the opposite direction. Which data structure reminds you this lift
Doubly linked list
In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?
Inorder successor is always either a leaf node or a node with empty left child
In linked list implementation of queue, if only front pointer is maintained, which of the following operation take worst case linear time?
Insertion, to empty a queque
In the recursion we need a base case because
It helps us to exit from the recursion, so there is no stackoverflow
What is the precise purpose of partition() method in Quick Sort?
It rearranges all elements according to the pivot point
........ form of access is used to add remove nodes from a stack.
LIFO
Which of the following searching techniques do not require the data to be in sorted form
Linear Search
In order to add items to the specific index in the array, the time complexity is
Linear time complexity O(N)
Heap sort worst case time complexity?
Linearithmic
What is a Big O time complexity of Heap sort for the worst case?
Linearithmic
What is a Big O time complexity of Merge sort for the worst case?
Linearithmic
Which of the following are an application of Queue Data Structure?
Load Balancing, When data is transferred asynchronously (data not necessarily received at same rate as sent) between two processes, When a resource is shared among multiple consumers.
Which of the following algorithms running times is faster for the increasing input (N)?
Logarithmic complexity O(logn)
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 position of minimum element in Binary Search Tree?
Most left
Which of these relates to linked list`s disadvantage?
No direct access to elements
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
When we measure time complexity, do we consider the facts such as a new computer is faster than an old one or a super computer is faster than a smartphone?
No, we don't
If all the elements in an input array is equal for example {1,1,1,1,1,1}, What would be the running time of the Insertion Algorithm? the application of the stacks
None of the listed options
Which of the following case does not exist in complexity theory?
Null case
In simple uniform hashing, what is the search complexity?
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)
Whаt is thе timе complеxity of insеrting to stаck?
O(1)
Concatenation of 2 linked list will take a time complexity of?
O(1) if we have address of last node of the lists
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
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
If the binary search tree is unbalanced, the time complexity of search operation is
O(N)
In what time can a binary heap be built?
O(N)
The running in the binary search tree for insert, delete and search operations in the worst case is
O(N)
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; for (i = 0; i < N; i++) { for (j = N; j > i; j--) { a = a + i + j; } }
O(N*N)
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
What are the average, the worst case of Merge algorithm?
O(NlogN)
What is the run time of Merge Sort algorithm in terms of Big O?
O(NlogN)
What is the run time of Quick Sort algorithm in terms of Big O?
O(NlogN)
Why is it good to use data structures in the main?
They can reduce the running time of applications
The Big Omega notation is used to
To describe the best-case running time for an algorithm
The Big Ordo notation is used to
To describe the worst-case running timefor an algorithm
Default constructor must be defined, if parameterized constructor is defined and the object is to be created without arguments.
True
Recursion must solve the same problem on some other input with the goal of simplifying the larger problem input
True
The order in which elements are inserted into a LinkedList is reserved
True
The running times of algorithms on binarysearch trees depend on the shapes of the trees, which, in turn, CS depend on the order in which keys are inserted.
True
class First { public First() { System.out.println("a"); } } class Second extends First { public Second() { System.out.println("b"); } } class Third extends Second { public Third() { System.out.println("c"); } } public class MainClass { public static void main(String[] args) { Third c = new Third(); } } Output a b c
True
The array which includes not only column indexes but also row indexes is also known as
Two-dimensional array
Let's consider the case when you have to construct a binary search tree from a sorted array with the following elements 10, 15, 20, 25, 30. What kind of tree you will get as a results of this operation
Unbalanced tree
Choose the disadvantage of the array?
Wastage of memory if the elements inserted in an array are lesser than the allocated size
Lets say we want to get rid of an item in a binary search tree and the item has one child only, how to perform this operation
We have to update the reference from the node itself to its child
The proper choice of data structure can boost up the algorithms and decrease the running time
Yes
Select the appropriate code that performs bubble sort.
a
In ............................. ; for any node n, every descendant node's value in the left subtree of n is less than the value of n and every descendant node's value in the right subtree is greater than the value n.
binary search tree
How can you improve the best case efficiency in bubble sort?
c
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
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
int fun(int x, int y) { if (y == 0) return 0; return (x + fun(x, y-1)); }
x*y