big-o

Big O, how do you calculate/approximate it?

Most people with a degree in CS will certainly know what Big O stands for. It helps us to measure how (in)efficient an algorithm really is and if you know in what category the problem you are trying to solve lays in you can figure out if it is still possible to squeeze out that little extra performance.* But I'm curious, how do you calc...

An O(1) Sort ~~~

Before you stone me for being a heretic, There is a sort that proclaims to be O(1), called "Bead Sort" (http://en.wikipedia.org/wiki/Bead_sort) , however that is pure theory, when actually applied I found that it was actually O(N * M), which is pretty pathetic. That said, Lets list out some of the fastest sorts, and their best case and ...

Where can I find the time and space complexity of the built-in sequence types in Python

I've been unable to find a source for this information, short of looking through the Python source code myself to determine how the objects work. Does anyone know where I could find this online? ...

Big-O for Eight Year Olds?

I'm asking more about what this means to my code. I understand the concepts mathematically, I just have a hard time wrapping my head around what they mean conceptually. For example, if one were to perform an O(1) operation on a data structure, I understand that the amount of operations it has to perform won't grow because there are mor...

What is the time complexity of indexing, inserting and removing from common data structures?

There is no summary available of the big O notation for operations on the most common data structures including arrays, linked lists, hash tables etc. ...

What is Big O notation? Do you use it?

What is Big O notation? Do you use it? I missed this university class I guess :D Does anyone use it and give some real life examples of where they used it? See also: Big-O for Eight Year Olds? Big O, how do you calculate/approximate it? Did you apply computational complexity theory in real life? ...

Which list<Object> implementation will be the fastest for one pass write, read, then destroy?

What is the fastest list implementation (in java) in a scenario where the list will be created one element at a time then at a later point be read one element at a time? The reads will be done with an iterator and then the list will then be destroyed. I know that the Big O notation for get is O(1) and add is O(1) for an ArrayList, while ...

Balanced Distribution Algorithm

Hello, I'm working on some code for a loosely coupled cluster. To achieve optimal performance during jobs, I have the cluster remap its data each time a child enters or exits. This will eventually be made optional, but for now it performs its data balancing by default. My balancing is basically just making sure that each child never has...

Algorithm to determine if array contains n...n+m?

I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions: Write a method that takes an int array of size m, and returns (True/False) if the array consists of the numbers n...n+m-1, all numbers in that range a...

Is there a master list of the Big-O notation for everything?

Is there a master list of the Big-O notation for everything? Data structures, algorithms, operations performed on each, average-case, worst-case, etc. ...

Constant Amortized Time

What is meant by "Constant Amortized Time" when talking about time complexity of an algorithm? ...

Efficient traversal of a changelist

I have a list of changes to a list - Adds and Deletes. The list could be huge - say 10'000 items. I want to know the state of the list after change 9'000. I could walk the list from the start all the way to change 9'000. That seems a bit long-winded to me. I could keep a list of items and record when they're added and when they're de...

Recursion and Big O

I've been working through a recent Computer Science homework involving recursion and big-O notation. I believe I understand this pretty well (certainly not perfectly, though!) But there is one question in particular that is giving me the most problems. The odd thing is that by looking it, it looks to be the most simple one on the homewor...

Big O Notation Homework--Code Fragment Algorithm Analysis?

For homework, I was given the following 8 code fragments to analyze and give a Big-Oh notation for the running time. Can anybody please tell me if I'm on the right track? //Fragment 1 for(int i = 0; i < n; i++) sum++; I'm thinking O(N) for fragment 1 //Fragment 2 for(int i = 0; i < n; i+=2) sum++; O(N) for fragment 2 as ...

multiset, map and hash map complexity

Hallo everybody, I would like to know the complexity in Big O notation of the STL multiset, map and hash map classes when: inserting entries accessing entries retrieving entries comparing entries ...

Is list::size() really O(n)?

Recently, I noticed some people mentioning that std::list::size() has a linear complexity. According to some sources, this is in fact implementation dependent as the standard doesn't say what the complexity has to be. The comment in this blog entry says: Actually, it depends on which STL you are using. Microsoft Visual Studio V6 ...

How to find the kth largest element in an unsorted array of length n in O(n)?

I believe there's a way to find the kth largest element in an unsorted array of length n in O(n). Or perhaps it's "expected" O(n) or something. How can we do this? Cheers! p.s. this is not for homework. ...

What is the best solution for the 'Students and Lockers' problem?

I thought that it would be fun to present some classic CS problems and let people show their algorithm optimization skills. The hope is that we get to see some clever techniques to solve abstract problems that we may be able to implement in practice. Ideally solutions would be presented in pseudo code with a big O classification. Proof ...

Feasibility of LinkedList vs. Array for sorted vs. unsorted data?

Comparing LinkedLists and Arrays while also comparing their differences with sorted and unsorted data Adding Removing Retrieving Sorting Overall speed Overall memory usage Actual questions Discuss the feasibility of implementing an unsorted data set as a linked list rather than an array. What would the tradeoffs be in terms of...

A range intersection algorithm better than O(n)?

Range intersection is a simple, but non-trivial problem. Its has been answered twice already: http://stackoverflow.com/questions/224878/find-number-range-intersection http://stackoverflow.com/questions/143552/comparing-date-ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of cours...