What are the differences between segment trees, interval trees, binary indexed trees and range trees?

All these data structures are used for solving different problems: Segment tree stores intervals, and optimized for “which of these intervals contains a given point” queries. Interval tree stores intervals as well, but optimized for “which of these intervals overlap with a given interval” queries. It can also be used for point queries – similar … Read more

How to determine the longest increasing subsequence using dynamic programming?

OK, I will describe first the simplest solution which is O(N^2), where N is the size of the collection. There also exists a O(N log N) solution, which I will describe also. Look here for it at the section Efficient algorithms. I will assume the indices of the array are from 0 to N – … Read more

Given a number, find the next higher number which has the exact same set of digits as the original number

You can do it in O(n) (where n is the number of digits) like this: Starting from the right, you find the first pair-of-digits such that the left-digit is smaller than the right-digit. Let’s refer to the left-digit by “digit-x”. Find the smallest number larger than digit-x to the right of digit-x, and place it … 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 … Read more

Are there any cases where you would prefer a higher big-O time complexity algorithm over the lower one?

There can be many reasons to prefer an algorithm with higher big O time complexity over the lower one: most of the time, lower big-O complexity is harder to achieve and requires skilled implementation, a lot of knowledge and a lot of testing. big-O hides the details about a constant: algorithm that performs in 10^5 … Read more

Skip List vs. Binary Search Tree

Skip lists are more amenable to concurrent access/modification. Herb Sutter wrote an article about data structure in concurrent environments. It has more indepth information. The most frequently used implementation of a binary search tree is a red-black tree. The concurrent problems come in when the tree is modified it often needs to rebalance. The rebalance … Read more

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