complexity

Do you use Big-O complexity evaluation in the 'real world'?

Recently in an interview I was asked several questions related to the Big-O of various algorithms that came up in the course of the technical questions. I don't think I did very well on this... In the ten years since I took programming courses where we were asked to calculate the Big-O of algorithms I have not have one discussion about ...

Is it ever possible to have Big O less than O(1)?

Possible Duplicate: are there any O(1/n) algorithms? Is it ever possible for your code to be Big O less than O(1)? ...

Why is Microsoft source code so complex?

I have been looking at the source code for Microsoft .NET Libraries such as System.Web...... Whenever I look inside the code, I see flags, events, a whole ecosystem of rather complicated code which seems like overkill to do a pretty simple thing. It's filled with absolutely everything. I'm not sure I saw a simple piece of code inside ...

Banker's algorithm calculated time complexity

The Banker's algorithm is used to determine if all requests for resources can be satisfied without leading to a deadlock. m is the total number of resources types n is the total number of processes NEED is an array of size m * n, it defines pending requests for each resources type. E.g.: NEEDij = 2 means that process i is requesting f...

Understanding Ukkonen's algorithm for suffix trees

Hello, I'm doing some work with Ukkonen's algorithm for building suffix trees, but I'm not understanding some parts of the author's explanation for it's linear-time complexity. I have learned the algorithm and have coded it, but the paper which I'm using as the main source of information (linked bellow) is kinda confusing at some parts...

Strings joining and complexity?

When I need to join two strings I use String.Format (or StringBuilder if it happens in several places in the code). I see that some good programmers doesn't give attention to strings joining complexity and just use the '+' operator. I know that using the '+' operator make the application to use more memory, but what about complexity? ...

What is the benefit of Xcode's seemingly over-complicated control/outlet workflow?

I'm new to Objective-C, Cocoa, Xcode and Interface Builder. I've got some C background in the past, as well as a fair amount of RealBASIC experience. I'm working through Mark and LaMarche's iPhone 3 Dev book and I'm really just sort of stunned about how tedious some things are. Maybe someone can shed some light on this for me. My questi...

Complexity of this function ??

void compute(int n) { int h = n; while (h > 1) { for (int i = 0; i < n; i++) { // do some operation } h = h / 2; } } Can anybody please tell me what is the complexity( Big O ) of this function of n ?? This is actually an argument between me and a friend of mi...

Effect of memory usage in the complexity of an algorithm

I am reading Nicolai Josuttis book on C++STL algorithms. For many algorithms such as stable_sort(), he mentions that the complexity of the algorithm n * log(n) if enough memory is available, otherwise it is n * log(n) * log(n). My question is how does the memory usage affects the complexity ? And how does STL detect such a situation? ...

For loop construction and code complexity

My group is having some discussion and strong feelings about for loop construction. I have favored loops like: size_t x; for (x = 0; x < LIMIT; ++x) { if (something) { break; } ... } // If we found what we're looking for, process it. if (x < LIMIT) { ... } But others seem to prefe...

Designing an OO and Unit Test Friendly Query System

I'm working on an application that allows dentists to capture information about certain clinical activities. While the application is not highly customizable (no custom workflows or forms) it does offer some rudimentary customization capabilities; clients can choose to augment the predefined form fields with their own custom ones. Ther...

What is the tersest/densest commonly-used programming language currently available?

I refer you to the following video, which describes how to implement Conway's Game of Life in APL, using a few dozen keystrokes: http://www.youtube.com/watch?v=a9xAKttWgP4 This video was featured prominently in the Return of Uncle Bob Martin podcast, in which Scott Hanselman complains that "his hands hurt" from programming in languages...

How to find all brotherhood strings?

I have a string, and another text file which contains a list of strings. We call 2 strings "brotherhood strings" when they're exactly the same after sorting alphabetically. For example, "abc" and "cba" will be sorted into "abc" and "abc", so the original two are brotherhood. But "abc" and "aaa" are not. So, is there an efficient way t...

Memory-efficient way of computing the median of a large data set?

If one computer can only hold 1 million numbers, how to find out the median number from 100 million numbers? ...

Can a program output a copy of itself

I think this might be a classic question but I am not aware of an answer. Can a program output a copy of itself, and, if so, is there a short program that does this? I do not accept the "empty program" as an answer, and I do not accept programs that have access to there own source code. Rather, I am thinking something like this: int ma...

How can I find the common ancestor of two nodes in a binary tree?

The Binary Tree here is not a Binary Search Tree. Its just a Binary Tree. The structure could be taken as - struct node { int data; struct node *left; struct node *right; }; The maximum solution I could work out with a friend was something of this sort - Consider this binary tree (from http://lcm.csa.iisc.ernet.in/dsa/no...

Avoiding O(n) queries with Django

I've got models like this: class PledgeItem(models.Model): title = models.CharField(...) usd_amount = models.DecimalField(...) class Pledger(models.Model): name = models.CharField(...) ... class Pledge(models.Model): pledger = models.ForeignKey(Pledger) item = models.ForeignKey(PledgeItem) usd_amount = m...

What's the fastest algorithm for sorting a linked list?

I'm curious if n log n is the best a linked list can do. Thanks ...

Number of sequences over {0,1} such that sequence contains at least half ones

How to calculate number of sequences over {0,1} such that each sequence contains at least half ones? ...

Java How do you find a complexity class for algorithms?

Hi I have a question to find a complexity class estimate of a algorithm. The question gives recorded times for an algorithm. So, do I just average out the times based on how it was computed? Sorry, I missed a part. ok, so it recorded time like N = 100, Algorithm = 300, next N = 200, Algorithm = 604, next N = 400 Algorithm = 1196, next...