Computer Knowledge
Data Structures and Algorithms
1,518 Questions
Data Structures and Algorithms form the core of computer science, focusing on arrays, linked lists, trees, and sorting mechanisms. These concepts are essential for solving complex computational problems efficiently. Test takers preparing for technical and administrative IT exams will find these questions highly relevant.
Array OperationsLinked List ApplicationsSorting AlgorithmsTree Data StructuresMultilevel IndexingAlgorithm Time Complexity
Data Structures and Algorithms Questions
-
Genetic algorithm
-
Drill down
-
Roll up
-
Data visualization
-
KDD
D
Correct answer
Explanation
It makes it possible for the analyst to gain a deeper, more intuitive understanding of the data.
-
Pfam
-
ProDom
-
MUMmer
-
KEGG
-
TIGRFAMs
C
Correct answer
Explanation
MUMmer is a bioinformatics software system for sequence alignment. It is based on the suffix tree data structure and is one of the fastest and most efficient systems available for this task, enabling it to be applied to very long sequences.
-
Queue
-
Stack
-
Tree
-
Heap
-
List
B
Correct answer
Explanation
A stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push and removal of an entity, known as pop. The relation between the push and pop operations is such that the stack is a Last-In-First-Out (LIFO) data structure. It is the best data for checking the balancing of parenthesis.
-
LIFO
-
FIFO
-
GIGO
-
PIPO
-
WYSIWYG
B
Correct answer
Explanation
FIFO stands for First In First Out. A queue is a FIFO data structure.
-
Sequential pattern
-
Clustering / segmentation
-
Association
-
EIther Sequential pattern or Clustering / segmentation
-
None of these
C
Correct answer
Explanation
An association function is an operation against this set of records, which returns affinities or patterns that exists among the collection of items.
-
$\theta(n^2)$
-
$\theta(nlogn)$
-
$\theta(n)$
-
$\theta(logn)^2$
A
Correct answer
Explanation
To solve this question, the user needs to know the concept of time complexity and how to analyze the time complexity of a given algorithm.
The given function fun() contains two nested loops that iterate over the range of n and j respectively. The outer loop runs n times, and the inner loop runs from i to 1. Therefore, the total number of iterations is the sum of the first n positive integers, which is n*(n+1)/2.
Since the number of iterations is proportional to n^2, the time complexity of the function is $\theta(n^2)$.
Therefore, the correct answer is:
The Answer is: A. $\theta(n^2)$
-
A(n) = $\omega$ W(n)
-
A(n) = $O$ W(n)
-
A(n) = $\theta$ W(n)
-
A(n) = o W(n)
B
Correct answer
Explanation
By definition, the worst-case running time W(n) is the upper bound for any input, including the average case. Therefore, A(n) is always O(W(n)).
-
A(n) = $\Omega$ W(n)
-
A(n) = $O$ W(n)
-
A(n) = $\Theta$ W(n)
-
A(n) = o W(n)
B
Correct answer
Explanation
Average-case running time $A(n)$ is bounded above by the worst-case running time $W(n)$ for all inputs of size $n$, because the average value of a set cannot exceed its maximum. Therefore, $A(n) = O(W(n))$ always holds. The other options are false because the average case can be asymptotically strictly smaller than the worst case.
-
$O (n)$
-
$O (n logn)$
-
$O (n^2)$
-
$O (logn)^2$
C
Correct answer
Explanation
The function contains two nested loops, each iterating over the entire array of size $n$. This requires $n \times n = n^2$ operations, leading to a quadratic time complexity of $O(n^2)$. Distractors represent linear, logarithmic, or linearithmic complexities.
-
$O(2^n)$ for both fun1() and fun2()
-
$O(n)$ for fun1() and $O(2^n)$ for fun2()
-
$O(2^n)$ for fun1() and $O(n)$ for fun2()
-
$O(n)$ for both fun1() and fun2()
B
Correct answer
Explanation
To solve this question, the user needs to know how to determine the time complexity of recursive functions based on the recurrence relation.
Let's analyze the time complexity of each function:
fun1(n): This function has a recurrence relation of T(n) = T(n-1) + c, where c is a constant representing the time it takes to execute the base case. By repeatedly substituting T(n-1) with T(n-2) and so on, we get T(n) = T(n-k) + kc. When the base case is reached, we have T(n-k) = 1, so T(n) = k + c. Since k is proportional to n, the time complexity of fun1(n) is O(n).
fun2(n): This function has a recurrence relation of T(n) = 2T(n-1) + c, where c is a constant representing the time it takes to execute the base case. By repeatedly substituting T(n-1) with 2T(n-2), 4T(n-3), and so on, we get T(n) = 2^n * T(0) + c * (2^n - 1). Since T(0) = 1, the time complexity of fun2(n) is O(2^n).
Therefore, the answer is:
The Answer is: B. O(n) for fun1() and O(2^n) for fun2().
-
Exhibits the worst case performance when the initial array is sorted in reverse order.
-
Worst case and average case performance is Ο(n2)
-
Can be compared to the way a card player arranges his card from a card deck.
-
None of the above!
-
$O(n), O(1)$
-
$O(1), O(1)$
-
$O(1), O(n)$
-
$O(n), \theta(1)$
B
Correct answer
Explanation
A queue implemented with an array using front and rear pointers allows both enqueue and dequeue operations to be performed in O(1) time.
-
sorted
-
unsorted
-
in a heap
-
popped out of stack
A
Correct answer
Explanation
The correct answer is A. sorted. For a binary search algorithm to work correctly, the array (or list) must be sorted in ascending or descending order. This allows the algorithm to efficiently divide the search space in half at each step, reducing the number of elements to be searched. If the array is unsorted, the binary search algorithm may not produce the correct results.
-
$Ο(n^2)$
-
$O(log_2n)$
-
$O(n logn)$
-
$O(log logn)$
B
Correct answer
Explanation
Binary search repeatedly halves the search interval, resulting in a worst-case time complexity of $O(\log_2 n)$. Distractors like $O(n^2)$ and $O(n \log n)$ represent much slower, non-logarithmic algorithms, whereas $O(\log \log n)$ is too fast.
-
It uses stack instead of queue.
-
Every recursive call has to be stored.
-
Both 1 & 2 are true.
-
None of the above are true.
B
Correct answer
Explanation
Recursion requires the system to store the state of each function call on the call stack until the base case is reached, consuming memory proportional to the recursion depth.