Find First Place Where F <= 0 in O(log n) Time

Click For Summary

Discussion Overview

The discussion revolves around finding the first index where a strictly decreasing function F: ℕ → ℤ is at or below zero, specifically seeking an O(log n) algorithm for this task. Participants explore the implications of the problem's constraints and the nature of the input size.

Discussion Character

  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses confusion regarding the lack of a finite input size, questioning how to define n in the context of O(n) time complexity.
  • Another participant suggests that n might be constrained by the largest natural number expressible based on the data type of i, raising concerns about the definition of n.
  • Some participants indicate that the problem's statement implies a bounded value for i, which is necessary for the question to make sense.
  • There is a proposal to use a binary search approach after testing a random value to determine the bounds, but uncertainty remains about the initial value selection and its impact on time complexity.

Areas of Agreement / Disagreement

Participants generally express confusion and uncertainty about the problem's constraints and the definition of n, indicating that there is no consensus on how to approach the problem effectively.

Contextual Notes

Limitations include the ambiguity regarding the bounds of i and the implications of defining n in the context of the algorithm's complexity. The problem does not specify data types or constraints on the input size.

Jcampuzano2
Messages
5
Reaction score
0

Homework Statement



Consider a strictly decreasing function F: ℕ → ℤ. We want to find the "first place where f is at or below the horizontal axis." Assume we can compute ƒ(i) for any input i in constant time. Clearly, we can solve the problem in O(n) time by evaluating ƒ(1), ƒ(2), ƒ(3),... until we see a non-positive number. Give an O(log n) algorithm.

Homework Equations


The only given is that ƒ(0) > 0.

The Attempt at a Solution



I'm a little confused on this problem. I don't have a finite input size, so I can't just access the last element in an array like I'm used to on algorithm problems. My only guess so far is that I could could pick a random number and test whether it is less than 0. If it is, then I can say that that can be considered the last element in an set, and perform a binary search to find the first place where the value is less than 0, but what if it takes greater than O(log n) time just to find this initial value?

So for example I test say f(100). if that is less than 0, then my input set can be say 0, 1, ... 100. and do a binary search using this as input. Would this be the correct way to go about this? It's literally the only way I can think of.
 
Physics news on Phys.org
I'm a bit confused. If an algorithm can be said to be O(n), it means that n is defined, that there is a number of input data. If you indeed let i not be constrained, then saying that an algorithm is O(n) doesn't make sense to me.

Could it be that n is constrained by the largest ℕ that can be expressd depending on the data type of i?
 
DrClaude said:
I'm a bit confused. If an algorithm can be said to be O(n), it means that n is defined, that there is a number of input data. If you indeed let i not be constrained, then saying that an algorithm is O(n) doesn't make sense to me.

Could it be that n is constrained by the largest ℕ that can be expressd depending on the data type of i?

That's part of where my confusion comes from as well. This problem isn't given with any data types in its context. I might just have to ask for more info on this one. The only part of the problem I left out because it was explained in the problem is the following sentenct:

We want to find

n = min{ i ∈ ℕ : ƒ(i) ≤ 0} .

But that was explained in the next sentence "first place where f is at or below the horizontal axis." Maybe that helps, but I don't think it does. Correct me if I'm mistaken.
 
Jcampuzano2 said:
Maybe that helps, but I don't think it does.
I'm still as confused. And the more I think about it, the more I'm convinced that the question only makes sense if the value of i is bounded.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
5
Views
2K
Replies
2
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 80 ·
3
Replies
80
Views
10K
  • · Replies 4 ·
Replies
4
Views
2K