complexity

A good tutorial for order of complexity?

Does anyone know of some good tutorial on order of complexity that can explain it at an advanced level? probably with some examples and tricky cases? ...

Big O complexity of simple for not always linear?

I'm sure most of you know that a nested loop has O(n^2) complexity if the function input size is n for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ ... } } I think that this is similar, by a analogous argument, but i'm not sure can anyone confirm? for(int i = 0, max = n*n; i < max; i++{ ... } If so i guess that there is some...

Dictionary Lookup (O(1)) vs Linq where

What is faster and should I sacrifice the Linq standard to achieve speed (assuming Dictionary lookup is truly faster)? So let me elaborate: I have the following: List<Product> products = GetProductList(); I have a need to search for a product based on some attribute, for example, the serial number. I could first create a dictionary...

How is schoolbook long division an O(n^2) algorithm?

Premise: This Wikipedia page suggests that the computational complexity of "Schoolbook" long division is O(n^2). Deduction: Instead of taking two n-digit numbers, if I take one n-digit number and one m-digit number, then the complexity would be O(n*m). Contradiction: Suppose you divide 100000000 (n digits) b...

Best jQuery/Prototype book for complex ajax?

I've been working on a complex app with one main dashboard. I don't particularly like the design because it tries to do too much on one page. So the lead developer thought it would be a good idea to use ajax - because the page is so big. Refreshing part of it is far faster than loading it again. Problem is there's several ways data c...

What is the complexity of the below code with respect to memory ?

Hi, I read about Big-O Notation from here and had few questions on calculating the complexity.So for the below code i have calculated the complexity. need your inputs for the same. private void reverse(String strToRevers) { if(strToRevers.length() == 0) { return ; } else { ...

What would be the time complexity of counting the number of all structurally different binary trees?

Using the method presented here: http://cslibrary.stanford.edu/110/BinaryTrees.html#java 12. countTrees() Solution (Java) /** For the key values 1...numKeys, how many structurally unique binary search trees are possible that store those keys? Strategy: consider that each value could be the root. Recursively find the size of the le...

Time complexity for Search and Insert operation in sorted and unsorted arrays that includes duplicate values.

1-)For sorted array I have used Binary Search. We know that the worst case complexity for SEARCH operation in sorted array is O(lg N), if we use Binary Search, where N are the number of items in an array. What is the worst case complexity for the search operation in the array that includes duplicate values, using binary search?? Will it...

Can NP-Intermediate exist if P = NP?

My understanding is that Ladner's theorem is basically this: P != NP implies that there exists a set NPI where NPI is not in P and NPI is not NP-complete What happens to this theorem if we assume that P = NP rather than P != NP? We know that if NP Intermediate doesn't exist, then P = NP. But can NP Intermediate exist if P = NP?...

Suggest a good method with least lookup time complexity

I have a structure which has 3 identifier fields and one value field. I have a list of these objects. To give an analogy, the identifier fields are like the primary keys to the object. These 3 fields uniquely identify an object. Class { int a1; int a2; int a3; int value; }; I would be having a list of say 1000 object of th...

How to calculate order (big O) for more complex algorithms (ie quicksort)

I know there are quite a bunch of questions about big O notation, I have already checked Plain english explanation of Big O , Big O, how do you calculate/approximate it?, and Big O Notation Homework--Code Fragment Algorithm Analysis?, to name a few. I know by "intuition" how to calculate it for n, n^2, n! and so, however I am completely...

Is there a shorthand term for O(n log n)?

We usually have a single word for most complexities we encounter in algorithmic analysis: O(1) == "constant" O(log n) == "logarithmic" O(n) == "linear" O(n^2) == "quadratic" O(n^3) == "cubic" O(2^n) == "exponential" We encounter algorithms with O(n log n) complexity with some regularity (think of all the algorithms dominated by sort ...

Whats the best data-structure for storing 2-tuple (a, b) which support adding, deleting tuples and compare (either on a or b))

Hi So here is my problem. I want to store 2-tuple (key, val) and want to perform following operations: keys are strings and values are Integers multiple keys can have same value adding new tuples updating any key with new value (any new value or updated value is greater than the previous one, like timestamps) fetching all the keys wit...

Amazing families of algorithms over implicit graphs

Dynamic programming is, almost by definition, to find a shortest/longest path on an implicit dag. Every DP algorithm just does this. An Holographic algorithm can be loosely described as something that counts perfect matchings in implicit planar graphs. So, my question is: are there any other families of algorithms that use well-known a...

Analysis of algorithms (complexity)

How are algorithms analyzed? What makes quicksort have an O(n^2) worst-case performance while merge sort has an O(n log(n)) worst-case performance? ...

Should I consider memmove() O(n) or O(1) ?

Hello, this may be a silly question, but I want to calculate the complexity of one of my algorithms, and I am not sure what complexity to consider for the memmove() function. Can you please help / explain ? void * memmove ( void * destination, const void * source, size_t num ); So is the complexity O(num) or O(1). I suppose it's O(...

Complexity in using Binary search and Trie

given a large list of alphabetically sorted words in a file,I need to write a program that, given a word x, determines if x is in the list. Preprocessing is ok since I will be calling this function many times over different inputs. priorties: 1. speed. 2. memory I already know I can use (n is number of words, m is average length of the...

Given a set of points, find if any of the three points are collinear

Hi, What is the best algorithm to find if any three points are collinear in a set of points say n. Please also explain the complexity if it is not trivial. Thanks Bala ...

Linear complexity and quadratic complexity

I'm just not sure... If you have a code that can be executed in either of the following complexities: A sequence of O(n), like for example: two O(n) in sequence O(n) The preferred version would be the one that can be executed in linear time. Would there be a time such that the sequence of O(n) would be too much and that O(n) would b...

What guarantees are there on the run-time complexity (Big-O) of LINQ methods?

I've recently started using LINQ quite a bit, and I haven't really seen any mention of run-time complexity for any of the LINQ methods. Obviously, there are many factors at play here, so let's restrict the discussion to the plain IEnumerable LINQ-to-Objects provider. Further, let's assume that any Func passed in as a selector / mutator /...