What is the formula to prove algorithm A is O(logN) based on given constraints?

  • Thread starter kasper_2211
  • Start date
  • Tags
    Inequalities
In summary, the conversation discusses a formula that can prove the algorithm A is O(logN). The given information includes the fact that A takes two arguments i and j, with the range of 1 ≤ i ≤ j ≤ N. It is also known that j - i < 2^n implies A(i, j) ≤ n and that the algorithm takes 7 "time units" each time it runs, with the last call before termination taking 3 "time units". The solution involves finding a function T(N) and making assumptions based on the given information to show that the algorithm is O(logN).
  • #1
kasper_2211
13
0

Homework Statement


Given an algorithm A i need to figure out a formula that can be used to prove that the algorithm is O(logN). I will try to avoid the details of the algorithm, since i need help with the math only. I think all you need to know is that A takes two arguments i and j. So you would call it like A(i, j).
It is given that: 1 [tex]\leq[/tex] i [tex]\leq[/tex] j [tex]\leq[/tex] N
Also i have proven by induction that j - i < 2^n [tex]\Rightarrow[/tex] A(i, j) [tex]\leq[/tex] n
And lastly i know that every time the algorithm runs it takes 7 "time units". The last call before the algorithm terminates takes 3 "time units". (This is not too important).

Homework Equations


1 [tex]\leq[/tex] i [tex]\leq[/tex] j [tex]\leq[/tex] N
j - i < 2^n [tex]\Rightarrow[/tex] A(i, j) [tex]\leq[/tex] n

The Attempt at a Solution


I will call A with A(1, N), that is i = 1 and j = N, since that is the worst case.

Lets call the function/formula we are looking for T(N). Then, T(N) = 3+7*A(1, N). Now i need to figure out what i can say about A(1, N). I know that N >= j - i + 1. I also know that A(1, N) will terminate in at most n steps if j - i < 2^n. So I assume that's the case.(do i need to make this assumption?) From my assumption i see that N >= 2^n + 1. Now, N / 2^n >= 1 and n - log2N <= 0. So n <= log2N. Now since i need to look at worst case i choose n = log2N. Then T(N)=3+7*log2N. Now it can be easily proven that the algorithm is O(logN). For example choosing 10 for c and 2 for k. Am i on the right track here at all? Thanks.

P.S. By the way, there are probably some fancy ways to do a problem like this but i need to only use what's given here. Especially i would like to use the fact that j - i < 2^n [tex]\Rightarrow[/tex] A(i, j) [tex]\leq[/tex] n
 
Last edited:
Physics news on Phys.org
  • #2
Obviously my "proof" is not correct. Just forget it.
 

FAQ: What is the formula to prove algorithm A is O(logN) based on given constraints?

What is Big O notation and why is it important?

Big O notation is a mathematical notation used to describe the asymptotic behavior or growth rate of a function. It is used in computer science to analyze the time and space complexity of algorithms. It helps to determine the efficiency and scalability of algorithms, making it an important tool for designing and optimizing algorithms.

How is Big O notation related to inequalities?

Big O notation is often used to represent inequalities in terms of asymptotic limits. For example, if an algorithm has a time complexity of O(n), it means that the worst-case running time of the algorithm is proportional to n. This can be represented as an inequality: worst-case running time ≤ Cn for some constant C.

What is the difference between Big O, Omega, and Theta notation?

Big O notation represents the upper bound or worst-case time complexity of an algorithm. Omega notation represents the lower bound or best-case time complexity. Theta notation represents the average-case time complexity. These three notations are used to describe different behaviors of algorithms, but they are all related to the same concept of asymptotic behavior.

How do you determine the time complexity of an algorithm using Big O notation?

To determine the time complexity of an algorithm using Big O notation, you can analyze its code and identify the dominant operations that contribute to the running time. Then, express the running time in terms of the input size (usually denoted as n) and remove any constants or lower-order terms. The resulting expression is the time complexity of the algorithm in Big O notation.

Can Big O notation be used for all types of algorithms?

Big O notation can be used for any algorithm that has a well-defined input size and running time. However, it may not always be the most accurate or useful representation for certain types of algorithms, such as recursive or parallel algorithms. In these cases, other notations, such as Big Theta or Big Omega, may be more appropriate.

Back
Top