complexity

What is the worst case time complexity for this algorithm?

procedure matrixvector(n:integer); var i,j:integer; begin for i<-1 to n do begin B[i] = 0; C[i] = 0; for j<-1 to i do B[i]<- B[i]+ A[i,j]; for j<-n down to i+1 do C[i]<-C[i] + A[i,j] end end; ...

In Complexity Analysis why is ++ considered to be 2 operations?

In my Computer Science II class, the professor considers ++,--,*=, etc. to be 2 operations. However, at the Assembly level this is not really two operations. Can someone explain or is this just for the sake of simplicity? ...

What are some of Drupal's shortcomings?

Drupal is very much a "Do Everything" CMS. There are modules that allow you to add almost any functionality, which is great. However, it feels like a lot of the features (v5 and v6) seem scattered around and unintuitive for the user. As a developer, I'm left with the feeling of having patched a site together using bubble gum and string. ...

Are there O(1) random access data structures that don't rely on contiguous storage?

The classic O(1) random access data structure is the array. But an array relies on the programming language being used supporting guaranteed continuous memory allocation (since the array relies on being able to take a simple offset of the base to find any element). This means that the language must have semantics regarding whether or n...

Network theory and MVC

I've designed an MVC that doesn't allow communication between Views (forms). If a form needs to communicate with another form, it raise an event on the controller, which other forms can subscribe to. The general idea is to keep paths of communication to a minimum, helping keep complexity down. Each View communicates with the RootContr...

What is the O time in determining if a value is in a sorted array?

I have a sorted array of 5000 integers. How fast can I tell if a random integer is a member of the array? An answer in general, C and Ruby would be nice. The array values are of the form c*c+1 where c can be any integer from 1 to 5000 i.e. [2, 5, 10, 17, 26, 37, 50 ...] ...

Programmatically obtaining Big-O efficiency of code

I wonder whether there is any automatic way of determining (at least roughly) the Big-O time complexity of a given function? If I graphed an O(n) function vs. an O(n lg n) function I think I would be able to visually ascertain which is which; I'm thinking there must be some heuristic solution which enables this to be done automatically....

Using multiple languages in one project

From discussions I've had about language design, it seems like a lot of people make the argument that there is not and will never be "one true language". The alternative, according to these people, is to be familiar with several languages and to pick the right tool for the job. This makes perfect sense at the level of a whole project o...

Unit tests to verify time complexity

Hi, Does anyone use unit tests to verify the time/space complexity of code? Thanks Hugo ...

Plain English explanation of Big O

What is a plain English explanation of Big O? With as little formal definition as possible and simple mathematics. ...

complexity of algorithm

Hi All, I would have quite general question. Have you ever had to really compute(e.g on the paper) complexity of an algorithm except at school as a programmer? And if.. can you give me an example please. thank you :) ...

Databases vs. plain text

When dealing with small projects, what do you feel is the break even point for storing data in simple text files, hash tables, etc., versus using a real database? For small projects with simple data management requirements, a real database is unnecessary complexity and violates YAGNI. However, at some point the complexity of a database...

Equal sum subsets hybrid

The problem is the following: You are given a set of positive integers { a1 , a2 , a3 , ... , an } in which there are no same numbers ( a1 exists only once ,a2 exists only once,...) eg A = {12 , 5 ,7 ,91 }. Question: Are there two disjoint subsets of A , A1 = { b1,b2,...,bm } and A2 = { c1,c2,...,ck} so that b1+b2+...+bm = c1+c2+.....

Memory Allocation in std::map

I am doing a report on the various C++ dictionary implementations (map, dictionary, vectors etc). The results for insertions using a std::map illustrate that that the performance is O(log n). There are also consistent spikes in the performance. I am not 100% sure what's causing this; I think they are caused by memory allocation but I ...

Time complexity of nested for loop

Hi, I need to calculate the time complexity of the following code: for(i=1; i<=n; i++) { for(j=1; j<=i; j++) { // Some code } } Is it O(n^2)? ...

Complexity of a function

What is the time and space complexity of: int superFactorial4(int n, int m) { if(n <= 1) { if(m <= 1) return 1; else n = m -= 1; } return n*superFactorial4(n-1, m); } It runs recursively by decreasing the value of n by 1 until it equals 1 and then it will either decrease the va...

Non-exponential solution to maze problem?

Given a n*n-sized multi-headed acyclic graph where each node has at most three children and three parents, is there an non-exponential algorithm to identify whether a n-length path exists where no two nodes share the same value, and every value of a set is accounted for? Basically, I have an n*n maze where each space has a random value ...

NP-Complete reduction (in theory)

I want to embed 3 NP-Complete problems(2 of them are known to be NP-Complete, 1 of them is my own idea). I saw "this question" and got idea about reinterpreting embedding problems in theory: The Waiter is The Thief. Tables are store. Foods are valued items which has different weight. Thief know all the items' price and weight before th...

Are games the most complex / impressive applications?

I was thinking today about what could be the most complex / impressive application ever written. So I started thinking of what I am comfortable with and use everyday, databases. Then I went into the field of the unknown (to most of us I guess), the government. I can only imagine the complexity of NASAs applications that allow them to co...

Complexity calculation

What is the complexity of: int f4(int n) { int i, j, k=1, count = 0; for(i = 0; i < n; i++) { k *= 3; for(j = k; j; j /= 2) count++; } return count; } I know it is O(n^2) but how do you calculate this? and why isn't it n*log n? ...