complexity

Can OSGi help reduce complexity?

I saw lots of presentations on OSGi and i think it sounds promising for enforcing better modularization. Apparently "hotdeployment" and "running different versions of x in parallel" are mayor selling points too. I wonder whether what OSGi promises to solve is even an issue...? It reminded me of the early days of OO when similar claims w...

Understanding Big O

Given the following code, what is the complexity of 3. and how would I represent simple algorithms with the following complexities? O(n²+n) O(n²+2n) O(logn) O(nlogn) var collection = new[] {1,2,3}; var collection2 = new[] {1,2,3}; //1. //On foreach(var i in c1) { } //2. //On² foreach(var i in c1) { foreach(var j in c1) { } } ...

When do you favor the use of state machines over linear workflows

State machines can reduce complexity of workflows when there are multiple loops and branching or logic when the workflow must "react" to answers supplied by users. This would be an event-driven workflow. In what circumstances have you elected to use a state machine and what type of pain did reduce in terms of time and complexity? ...

Do functional languages cope well with complexity?

I am curious how functional languages compare (in general) to more "traditional" languages such as C# and Java for large programs. Does program flow become difficult to follow more quickly than if a non-functional language is used? Are there other issues or things to consider when writing a large software project using a functional lan...

Complexity running times LAB and fibonacci numbers (java)

Hi, have been looking the page and lots of great people helping outhere so i have a Lab Assignment and i know i have to do a method concerning the fibonacci numbers to caclulate the number in the position n, but im not quite sure what do put inside the method i know is what i have to think about hope you can give and idea. Having trouble...

Big-O complexity of c^n + n*(logn)^2 + (10*n)^c

I need to derive the Big-O complexity of this expression: c^n + n*(log(n))^2 + (10*n)^c where c is a constant and n is a variable. I'm pretty sure I understand how to derive the Big-O complexity of each term individually, I just don't know how the Big-O complexity changes when the terms are combined like this. Ideas? Any help wo...

No guarantees for Arrays.BinarySearch?

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Arrays.html Sun does not mention any complexity for their binary-search implemention. Is this a mistake? I know it should be O(logn), but it makes me nervous when they don't state this explicitly. They do for some of their algoritms, like Arrays.sort. Does any of you have any knowledge ...

Can the bigO of an algorithm be found programmatically by analyzing its perfs?

Note that I don't have a "problem" and I'm not looking for "another way to find the big O of my algorithm". What I'd like to know is if it would be possible write a program to which you'd pass data points that would all be perfs measurements of an algorithm for various input size: (n,time taken to solve problem for n) and that would the...

How to find the first item according to a specific ordering using LINQ in O(n)?

Suppose I have a list of items (e.g., Posts) and I want to find the first item according to some non-trivial ordering (e.g., PublishDate and then CommentsCount as a tie-breaker). The natural way to do this with LINQ is like this: posts.OrderBy(post => post.PublishDate).ThenBy(post => post.CommentsCount).First() However, the micro-opti...

Binary tree to get minimum element in O(1)

I'm accessing the minimum element of a binary tree lots of times. What implementations allow me to access the minimum element in constant time, rather than O(log n)? ...

Is premature optimization in SQL as "evil" as it is in procedural programming languages?

I'm learning SQL at the moment and I've read that joins and subqueries can potentially be performance destroyers. I (somewhat) know the theory about algorithmic complexity in procedural programming languages and try to be mindful of that when programming, but I don't know how expensive different SQL queries can be. I'm deciding whether I...

Way to store a large dictionary with low memory footprint + fast lookups (on Android)

I'm developing an android word game app that needs a large (~250,000 word dictionary) available. I need: reasonably fast look ups e.g. constant time preferable, need to do maybe 200 lookups a second on occasion to solve a word puzzle and maybe 20 lookups within 0.2 second more often to check words the user just spelled. EDIT: Lookups...

Data structures question

This question is from an exam I had, and I couldn't solve it and wanted to see what the answer is (this is not homework, as it will not help me in anything but knowledge). We need to create a data structure for containing elements whose keys are real numbers. The data structure should have these functions: Build(S, array): Builds the da...

Complexity Of Recursive Factorial Program

What's the complexity of a recursive program to find factorial of a number n? My hunch is that it might be O(n) ...

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

Calculate the cosine of a sequence

Hi, I have to calculate the following: float2 y = CONSTANT; for (int i = 0; i < totalN; i++) h[i] = cos(y*i); totalN is a large number, so I would like to make this in a more efficient way. Is there any way to improve this? I suspect there is, because, after all, we know what's the result of cos(n), for n=1..N, so maybe there's so...

Big O complexity of the basic arithmetic operations

What Big-O complexity have most widespread algorithms for the basic arithmetic operations like multiplication, square root, logarithm, scalar and matrix product? Do exist some exotic algorithms which are the most effective in terms of Big-O complexity but for some reasons not very widespread in practical solutions (e.g. not implemented i...

What is O(log* N)?

What is O(log* N)? I found it online with no description. edit: I know big-Oh, the log* was the question ...

Unexpected complexity in a matlab function

Hello i am developing a program in c#, and thanks to the matlab .net builder, i am using a matlab maping toolbox fucntion "polybool", which in one of it's options calculate the diffrence of 2 polygons in 2-D. The problem is that the fucntions takes about 0.01 seconds to finish in which is bad for me because i call it a lot. And this does...

How many additional function calls does fib(n) require if "LINE 3" is removed?

I just got this question on an interview and had no idea how to calculate the answer. How many additional function calls does fib(n) require if "LINE 3" is removed? The answer should be in terms on n. int fib(int n) { if(n == 0) return 0; if(n == 1) return 1; if(n == 2) return 1; //LINE 3 HERE <--- return fib(n - 1) + fib(n - 2...