What is the meaning of “exclusive” and “inclusive” when describing number ranges?

The following function prints the powers of 2 from 1 through n (inclusive). This means that the function will compute 2^i where i = 1, 2, …, n, in other words, i can have values from 1 up to and including the value n. i.e n is Included in Inclusive If, on the other hand, your book had said: The following function prints the powers of … Read more

Shortest possible depth of a leaf in decision tree (comparison sorting algorithm)

The absolute best case happens when we just check every element and see that the data’s already sorted. This will result in n-1 comparisons and thus the leaf will have a depth of n-1. Practically, this happens for insertion sort (which isn’t all that good otherwise though). Does it change depending on the algorithm? Absolutely. The best case of an … Read more

Trying to understand max heapify

Here’s what MAX-HEAPIFY does: Given a node at index i whose left and right subtrees are max-heaps, MAX-HEAPIFY moves the node at i down the max-heap until it no longer violates the max-heap property (that is, the node is not smaller than its children). The longest path that a node can take before it is in the proper position … Read more

When should I use Kruskal as opposed to Prim (and vice versa)?

Use Prim’s algorithm when you have a graph with lots of edges. For a graph with V vertices E edges, Kruskal’s algorithm runs in O(E log V) time and Prim’s algorithm can run in O(E + V log V) amortized time, if you use a Fibonacci Heap. Prim’s algorithm is significantly faster in the limit when you’ve got a really dense graph with many … Read more

longest increasing subsequence(O(nlogn))

Let’s first look at the n^2 algorithm: Now the improvement happens at the second loop, basically, you can improve the speed by using binary search. Besides the array dp[], let’s have another array c[], c is pretty special, c[i] means: the minimum value of the last element of the longest increasing sequence whose length is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)