big-o

O(log N) == O(1) - Why not?

Whenever I consider algorithms/data structures I tend to replace the log(N) parts by constants. Oh, I know log(N) diverges - but does it matter in real world applications? log(infinity) < 100 for all practical purposes. I am really curious for real world examples where this doesn't hold. To clarify: I understand O(f(N)) I am cu...

Program Runtime HW Problem

An algo takes .5 ms seconds for an input size of 100, how long will it take to run if the input size is 500 and the program is O(n lg(n))? My book says that when the input size doubles, n lg(n), takes "slightly more than twice as long". That isn't really helping me much. The way I've been doing it, is solving for the constant...

big O homework question

I need to state the big o of the following fragment: sum =0; for (int i=1; i<n; i++) { for (int j=1; j< n/i; j++) { sum = sum +j; } } I know the outer loop is O(n) but I am having a problem analyzing the inner loop. I think it's O(log n). I would appreciate any help. Thank you in advance. ...

O(nlogn) Algorithm - Find three evenly spaced ones within binary string

I had this question on an Algorithms test yesterday, and I can't figure out the answer. It is driving me absolutely crazy, because it was worth about 40 points. I figure that most of the class didn't solve it correctly, because I haven't come up with a solution in the past 24 hours. Given a arbitrary binary string of length n, find th...

Is Big O(logn) log base e?

For binary search tree type of data structures, I see the Big O notation is typically noted as O(logn). With a lowercase 'l' in log, does this imply log base e (n) as described by the natural logarithm? Sorry for the simple question but I've always had trouble distinguishing between the different implied logarithms. ...

Complexity of a given function

When I analyzed the complexity of the code segment below, I found that it is O(n/2). But while searching the internet I discovered that it is probably O(n). I'd like to know who's correct. void function(int n) { int i = 1, k = 100; while (i < n) { k++; i += 2; } } ...

A homework about growth rate of function

Please order the function belows by growth rate n ^ 1.5 n ^ 0.5 + log n n log ^ 2 n n log ( n ^ 2 ) n log log n n ^ 2 + log n n log n n ps: Ordering by growth rate means, as n gets larger and larger, which function will eventually be higher in value than the others. ps2. I have ordered most of the functions: n , n log log n, n log n,...

O Notation Help

I am getting stuck with the class work we got this week and its a subject i really want to learn so for once i thought i would do the additional reading!!!! The method is provided for us and i am just writign some test cases. This is where my knowledge gets a little hazy. If the time increases then i am underestimatign the complexity i ...

Simple Algorithm time complexity Question

Hi, I am working on an assignment for an intro Datamining course. I am trying to figure out the time complexity of an algorithm (see below)? Is it linear/exponential/log/quadratic/polynominal? Any tips on how to approach a question like this would be much appreciated Consider the following algorithm for finding the third smallest elem...

complexity help..O(n^2), 0(nlog) etc

hey there could someone please help me determine the complexity?. An example given in my class was bubble sort int main() { int a[10] = {10,9,8,7,6,5,4,3,2,1}; int i,j,temp; for (j=0;j<10;j++) { for (i=0;i<9;i++) { if (a[i] > a[i+1]) { temp = a[i]; a[i] = a[i+1]; a[i+1] = te...

What is the running time of these mystery?

mystery(int A[1..n], int n) { // pre: n is a power of 2 for i=1..n { for i = 1...n { A[i] = A[i] + 1; } if (n>1) mystery(A, n/2); } } I think the worst case, it runs in O(n), am I right? Edit: This is from another old exam (which has answers for us), but the following algorithm runs...

Sorted array Big o notation

Hello I just have a simple question, why is the big O notation of a sorted array O(log N)? It will be a sorted array. ...

What is the base of the logarithm for the purposes of Algorithms?

While considering O(log(N)) for time complexity, what is the base of log? ...

What is the complexity of this algorithm?

procedure max (a[1..n]: integers) max := a[1] for i := 2 to n if max < a[i] then max := a[i] Is the complexity O(1) or O(n) with the best case scenario? The sequence contains n elements. It is pseudocode. ...

What's my Big O?

My program of sorting values clocks at: 100000 8s 1000000 82s 10000000 811s Is that O(n)? ...

How to add/merge several Big O's into one

If I have an algorithm which is comprised of (let's say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do I theoretically estimate the O() for the entire algorithm? I.e. not clocking it or performing any other practical measurement. Is there...

What is the complexity of inserting into sorted link list in big-O notation?

What is the complexity of inserting into sorted link list in big-O notation? Let say I have 5 elements and what is the complexity to insert all of them. Thank you very much ...

Worst case running time (Big O)

Hi every one. I have this question, and I don't know how to solve it, because I don't understand it. :( The question is: Programs A and B are analyzed and are found to have worst case running times no greater than 150n log n and n2, respectively. Answer the following questions: i) Which program has the better guarantee on...

Find two numbers in a binary search tree that add up to a third number

You are given a BST of numbers. You have to find two numbers (a, b) in it such that a + b = S, in O(n) time and O(1) space. What could be the algorithm? One possible way could be two convert the BST to a doubly linked List and then start from the front and end: if front + end > S then end-- Or: if front + end < S then front++ ...

Graph Adjacency List How to implement O(1) lookup for nodes/vertexes. Array?

I read in the specifications for graphs implemented with Adjacency List that adding edges is done in constant time. BUT that would require a node lookup with O(1). I would like best possible performance. The question here is which datatype would would give me that. Hashmap has been considered, worst case with hashmap is still O(n). Cou...