When a hash table is resized (rehashed), the operation takes O(n) time. Why is this generally considered acceptable?
Blog
Because a heap maintains the “Complete Binary Tree” property…
Because a heap maintains the “Complete Binary Tree” property, the height of a heap with n entries is guaranteed to be:
In the Merge-Sort algorithm, which lines of code are *direct…
In the Merge-Sort algorithm, which lines of code are *directly* responsible for its O(n) auxiliary space complexity? public void merge(K[] S, K[] S1, K[] S2, Comparator comp) { // … merge logic … } public void mergeSort(K[] S, Comparator comp) { int n = S.length; if (n < 2) return; // Base case int mid = n / 2; K[] S1 = Arrays.copyOfRange(S, 0, mid); // LINE A K[] S2 = Arrays.copyOfRange(S, mid, n); // LINE B mergeSort(S1, comp); // LINE C mergeSort(S2, comp); // LINE D merge(S, S1, S2, comp); // LINE E }
Identify the missing step in the removeMin method below: pu…
Identify the missing step in the removeMin method below: public E removeMin() { if (heap.isEmpty()) return null; E min = heap.get(0); int lastIndex = heap.size() – 1; // MISSING LINE HERE heap.remove(lastIndex); if (!heap.isEmpty()) { downheap(0); } return min; }
True or False: Bubble Sort is a stable sorting algorithm, me…
True or False: Bubble Sort is a stable sorting algorithm, meaning equal elements retain their relative order.
class Entry { private final K key; private V value; public E…
class Entry { private final K key; private V value; public Entry(K k, V v) { key = k; value = v; } // … } Why is the key field marked as final in the Entry class snippet above?
What is the worst-case time complexity of Quick-Sort, and wh…
What is the worst-case time complexity of Quick-Sort, and when does it occur?
What is the time complexity of this insert method in a Heap…
What is the time complexity of this insert method in a Heap Priority Queue? public void insert(E key) { heap.add(key); // Step 1 upheap(heap.size() – 1); // Step 2 }
What is the auxiliary bspace/b complexity of the standard Me…
What is the auxiliary bspace/b complexity of the standard Merge-Sort algorithm, and why?
Why is sorting data a critical prerequisite for algorithms l…
Why is sorting data a critical prerequisite for algorithms like Binary Search?