DoA Flashcards
Time complexity of merge sort
O(nlogn)
Time complexity of Binary search
O(logn)
Time complexity of insertion sort
O(n^2)
Give a recurrence T (n) = · · · for the worst-case running time of Binary search
T(n) = T(n/2) + ϴ(1)
T(1) = ϴ(1)
Give a recurrence T (n) = · · · for the worst-case running time of Merge sort
T(n) = 2T(n/2) + ϴ(n)
T(1) = ϴ(1)
Give a recurrence T (n) = · · · for the worst-case running time of Insertion sort
T(n) = T(n-1) + ϴ(n)
T(1) = ϴ(1)
Radix
Instead of using countingsort to sort digitals in the radixsort, one can use any in-place sorting algorithm
and the radixsort will still sort correctly. TRUE or FALSE? Why?
False
Radix sort relies on stable sorting algorithms for each digit place. While it’s true that you can use any stable sorting algorithm, not every in-place sorting algorithm is stable.
Explain Binary search tree (BST)
A BST is a hierarchical data structure consisting of nodes, where each node has a key, and at the most 2 children.
The keys in the left subtree of a node are less than its key, and the keys in the right subtree are greater than its key.
Explain AVL-tree
An AVL tree is a self-balancing binary search tree that maintains a height-balanced property, ensuring that the height difference between the left and right subtrees of any node (called the balance factor) is at most 1.
Explain min-heap
And shortly how to make insertions in it.
A tree where every node is smaller than its children.
The tree is always filled up from left to right.
Insertions happens into the next empty space and if the inserted node is smaller than its parent: swap
Explain max-heap
And shortly how to make insertions in it.
A tree where every node is greater than its children.
The tree is always filled up from left to right.
Insertions happens into the next empty space and if the inserted node is greater than its parent: swap
True or false?
2n + n^3 = O(2n).
False
Instead it is:
2n + n^3 = O(n^3).
Time complexity of counting sort
O(n+k)
Where ‘n’ Represents The Number Of Elements And ‘k’ Represents The Range Of The Inputs.
Time complexity of radix sort
O(nd)
where ‘n’ is the size of the array and ‘d’ is the number of digits in the largest number
Give a recurrence T (n) = · · · for the worst-case running time of selection sort
T(n) = T(n-1) + O(n)
T(1) = O(1)