質問

Yeah, this is for a homework assignment, but I hope that you'll humor me anyway. I am asked to design an algorithm that finds the natural logarithm of a number. This would be straightforward, but I'm not allowed to use strategies that involve integration, bit manipulation, approximation formulas, or Taylor Series. Instead, we're asked to generate an array of values where at least one of them will be the answer, and then to find the correct value in that array. There must be some kind of established algorithm for this, but this and other resources haven't been helpful. I'm stuck. What should I be thinking about here?

役に立ちましたか?

解決

Suppose you have an array $A = [e^0, e^1, e^2, \dots]$. You do a search in this array, and try to find the biggest value in the array that's smaller than or equal to $x$.

  1. You find this value at position $n$. What is the value of $A[n]$?

  2. What can you say about $\ln(x)$ in relation to $n$?

  3. Can you find the correct $n$ quickly? Does it help that $A$ is sorted?

ライセンス: CC-BY-SA帰属
所属していません cs.stackexchange
scroll top