complexity-theory

C++0x issue: Constant time insertion into std::set

风流意气都作罢 提交于 2019-12-04 02:47:14
According to this page , I can achieve constant time insertion if I use iterator std::set::insert ( iterator position, const value_type& x ); and the position iterator I provide directly "precedes" the proper (in-order) insertion point. Now the case I'm concerned with is if I know that the value I'm inserting goes at the end (since it's the largest), e.g.: set<int> foo = {1, 2, 3}; foo.insert(4); // this is an inefficient insert According to the above criterion I should pass the last element foo.end()-1 to insert not foo.end() . Is my understanding correct? What happens if I pass foo.end() ?

Fast algorithm for counting the number of acyclic paths on a directed graph

喜夏-厌秋 提交于 2019-12-04 02:24:04
In short, I need a fast algorithm to count how many acyclic paths are there in a simple directed graph. By simple graph I mean one without self loops or multiple edges. A path can start from any node and must end on a node that has no outgoing edges. A path is acyclic if no edge occurs twice in it. My graphs (empirical datasets) have only between 20-160 nodes, however, some of them have many cycles in them, therefore there will be a very large number of paths, and my naive approach is simply not fast enough for some of the graph I have. What I'm doing currently is "descending" along all

What's the asymptotic complexity of GroupBy operation?

橙三吉。 提交于 2019-12-04 01:09:10
问题 I am interested in the asymptotic complexity (big O) of the GroupBy operation on unindexed datasets. What's the complexity of the best known algorithm and what's the complexity for algorithms that SQL servers and LINQ are using? 回答1: Ignoring the base SQL that the group by is working on, when presented to the GROUP BY operation itself, the complexity is just O(n) since the data is scanned per-row and aggregated in one pass. It scales linearly to n (the size of the dataset). When Group By is

Does Big O Measure Memory Requirments Or Just Speed?

旧巷老猫 提交于 2019-12-03 22:27:25
I often here people talk about Big O which measures algorithms against each other Does this measure clock cycles or space requirements. If people want to contrast algorithms based on memory usage what measure would they use If someone says "This algorithm runs in O(n) time", he's talking about speed. If someone says "This algorithm runs in O(n) space", he's talking about memory. If he just says "This algorithm is O(n)", he's usually talking about speed (though if he says it during a discussion about memory, he's probably talking about memory). If you're not sure which one someone's talking

Convert string to number & vice versa complexity

狂风中的少年 提交于 2019-12-03 17:36:55
问题 What would be the complexity of converting a string to its equivalent number or vice versa? Does it change depending on programming language? On the face of it, one needs to traverse the entire string to convert it to a number, so it is O(n) , or is some typecasting used? This doubt came about when I was writing a routine to check if a given number is a palindrome or not. One approach would be to keep dividing the number by the base (here 10), accumulate digits, and put them together at the

Complexity of a Lucene's search

二次信任 提交于 2019-12-03 16:58:31
问题 If I write and algorithm that performs a search using Lucene how can I state the computational complexity of it? I know that Lucene uses tf*idf scoring but I don't know how it is implemented. I've found that tf*idf has the following complexity: O(|D|+|T|) where D is the set of documents and T the set of all terms. However, I need someone who could check if this is correct and explain me why. Thank you 回答1: Lucene basically uses a Vector Space Model (VSM) with a tf-idf scheme. So, in the

Calculating the Recurrence Relation T(n)=T(n-1)+logn

天大地大妈咪最大 提交于 2019-12-03 16:35:25
We are to solve the recurrence relation through repeating substitution: T(n)=T(n-1)+logn I started the substitution and got the following. T(n)=T(n-2)+log(n)+log(n-1) By logarithm product rule, log(mn)=logm+logn, T(n)=T(n-2)+log[n*(n-1)] Continuing this, I get T(n)=T(n-k)+log[n*(n-1)*...*(n-k)] We know that the base case is T(1), so n-1=k -> k=n+1, and substituting this in we get T(n)=T(1)+log[n*(n-1)*...*1] Clearly n*(n-1)*...*1 = n! so, T(n)=T(1)+log(n!) I do not know how to solve beyond this point. Is the answer simply O(log(n!)) ? I have read other explanations saying that it is Θ(nlogn)

Complexity of Binary Search

断了今生、忘了曾经 提交于 2019-12-03 15:01:19
I am watching the Berkley Uni online lecture and stuck on the below. Problem : Assume you have a collection of CD that is already sorted. You want to find the list of CD with whose title starts with "Best Of." Solution : We will use binary search to find the first case of "Best Of" and then we print until the tile is no longer "Best Of" Additional question : Find the complexity of this Algorithm. Upper Bound : Binary Search Upper Bound is O(log n), so once we have found it then we print let say k title. so it is O(logn + k) Lower Bound : Binary Search lower Bound is Omega(1) assuming we are

How much to log within an application and how much is too much?

笑着哭i 提交于 2019-12-03 14:15:40
Just wondering how much people log within their applications??? I have seen this: "I typically like to use the ERROR log level to log any exceptions that are caught by the application. I will use the INFO log level as a "first level" debugging scheme to show whenever I enter or exit a method. From there I use the DEBUG log level to trace detailed information. The FATAL log level is used for any exceptions that I have failed to catch in my web based applications." Which had this code sample with it: Public Class LogSample Private Shared ReadOnly Log As log4net.ILog = log4net.LogManager

Is “house coloring with three colors” NP?

匆匆过客 提交于 2019-12-03 13:34:23
问题 Consider the problem described here (reproduced below.) Can some better known NP-complete problem be reduced to it? The problem: There are a row of houses. Each house can be painted with three colors: red, blue and green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. You have to paint the houses with minimum cost. How would you do it? Note: The cost of painting house 1 red is different