time-complexity

Time Complexity confusion

Ive always been a bit confused on this, possibly due to my lack of understanding in compilers. But lets use python as an example. If we had some large list of numbers called numlist and wanted to get rid of any duplicates, we could use a set operator on the list, example set(numlist). In return we would have a set of our numbers. Thi...

What are the "hardest" problems which can be solved in polynomial time?

Recently I read a seminar work which says: The matching algorithm [for general graphs] can be extended to the weighted case, which appears to be one of the "hardest" combinatorial optimization problems that can be solved in polynomial time. Immediately the following question came to my mind: Do you know other "P-hard" pro...

Union/find algorithm without union by rank for disjoint-set forests data structure

Here's a breakdown on the union/find algorithm for disjoint set forests on wikipedia: Barebone disjoint-set forests... (O(n)) ... with union by rank ... (now improved to O(log(n)) ... with path compression (now improved to O(a(n)), effectively O(1)) Implementing union by rank necessitates that each node keeps a rank field for com...

Recommended Complexity Theory Book(s)

I'd like to start off by saying that I have no formal training in computer science. I have several years of programming experience but I'm entirely self-taught. Additionally, I have a relatively good grasp of common algorithms and their performance (e.g., time vs. space) characteristics. Since I lack formal training, however, I feel lik...

Is there an O(n) integer sorting algorithm?

The last week I stumbled over this paper where the authors mention on the second page: Note that this yields a linear running time for integer edge weights. The same on the third page: This yields a linear running time for integer edge weights and O(m log n) for comparison-based sorting. And on the 8th page: In particular...

Where should the line between property and method be?

Possible Duplicate: Properties vs Methods For many situations it is obvious whether something should be a property or a method however there are items that might be considered ambiguous. Obvious Properties: "name" "length" Obvious Methods: "SendMessage" "Print" Ambiguous: "Valid" / "IsValid" / "Validate" "InBounds...

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? ...

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...

The limits of parallelism (job-interview question)

Is it possible to solve a problem of O(n!) complexity within a reasonable time given infinite number of processing units and infinite space? The typical example of O(n!) problem is brute-force search: trying all permutations (ordered combinations). ...

How do I find the median of numbers in linear time using heaps?

Wikipedia says: Selection algorithms: Finding the min, max, both the min and max, median, or even the k-th largest element can be done in linear time using heaps. All it says is that it can be done, and not how. Can you give me some start on how this can be done using heaps? ...

Time complexity of Sieve of Eratosthenes algorithm

From Wikipedia: The complexity of the algorithm is O(n(logn)(loglogn)) bit operations. How do you arrive at that? That the complexity includes the loglogn term tells me that there is a sqrt(n) somewhere. Suppose I am running the sieve on the first 100 numbers (n = 100), assuming that marking the numbers as c...

How should I change my Graph structure (very slow insertion)?

Hi, This program I'm doing is about a social network, which means there are users and their profiles. The profiles structure is UserProfile. Now, there are various possible Graph implementations and I don't think I'm using the best one. I have a Graph structure and inside, there's a pointer to a linked list of type Vertex. Each Vertex ...

What is order notation f(n)=O(g(n))?

Two questions: Question 1: Under what circumstances would O(f(n)) = O(k·f(n)) be the most appropriate form of time-complexity analysis? Question 2: Working from mathematical definition of O notation, how to show that O(f(n)) = O(k·f(n)), for positive constant k? My view: For the first one I think it is average case and worst case form...

what is average case analysis?

Hello again guys, question 1: why is average case analysis more difficult to carry out than the worst case analysis. got to think of alteast 4 points, thought of 1, am i right? answer: Algorithm exist for which no such analysis has been possible question 2: what is elementary operation in terms of time measure? and why is time-demand...

Time complexity of a sorting algorithm

The two programs below get n integers from file and calculates the sum of ath to bth integers q(number of question) times. I think the upper program has worse time complexity than the lower, but I'm having problems calculating the time complexity of these two algorithms. [input sample] 5 3 5 4 3 2 1 2 3 3 4 2 4 [output sample] 7 5 9 ...

What data is actually stored in a B-tree database in CouchDB?

I'm wondering what is actually stored in a CouchDB database B-tree? The CouchDB: The Definitive Guide tells that a database B-tree is used for append-only operations and that a database is stored in a single B-tree (besides per-view B-trees). So I guess the data items that are appended to the database file are revisions of documents, no...

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...

TreeMap - Search Time Complexity

What is the time complexity of a get() and put() in a TreeMap? Is the implementation same as a Red-Black Tree? ...

Java: Calculate distance between a large number of locations and performance

I'm creating an application that will tell a user how far away a large number of points are from their current position. Each point has a longitude and latitude. I've read over this article http://www.movable-type.co.uk/scripts/latlong.html and seen this post http://stackoverflow.com/questions/837872/calculate-distance-in-meters-when-...

Longest Common Subsequence

Consider 2 sequences X[1..m] and Y[1..n]. The memoization algorithm would compute the LCS in time O(m*n). Is there any better algorithm to find out LCS wrt time? I guess memoization done diagonally can give us O(min(m,n)) time complexity. ...