Big-oh vs big-theta

Big-O is an upper bound. Big-Theta is a tight bound, i.e. upper and lower bound. When people only worry about what’s the worst that can happen, big-O is sufficient; i.e. it says that “it can’t get much worse than this”. The tighter the bound the better, of course, but a tight bound isn’t always easy … Read more

What is O(1) space complexity?

To answer your question, if you have a traversal algorithm for traversing the list which allocate a single pointer to do so, the traversal algorithms is considered to be of O(1) space complexity. Additionally, let’s say that traversal algorithm needs not 1 but 1000 pointers, the space complexity is still considered to be O(1). However, … Read more

What are the differences between NP, NP-Complete and NP-Hard?

I assume that you are looking for intuitive definitions, since the technical definitions require quite some time to understand. First of all, let’s remember a preliminary needed concept to understand those definitions. Decision problem: A problem with a yes or no answer. Now, let us define those complexity classes. P P is a complexity class that represents the set of … Read more

HashMap get/put complexity

It depends on many things. It’s usually O(1), with a decent hash which itself is constant time… but you could have a hash which takes a long time to compute, and if there are multiple items in the hash map which return the same hash code, get will have to iterate over them calling equals on each of them to find a match. … Read more

When will the worst case of Merge Sort occur?

The worst case of merge sort will be the one where merge sort will have to do maximum number of comparisons. So I will try building the worst case in bottom up manner: Suppose the array in final step after sorting is {0,1,2,3,4,5,6,7} For worst case the array before this step must be {0,2,4,6,1,3,5,7} because here left subarray={0,2,4,6} and right … Read more

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