exponential

Real-world example of exponential time complexity

百般思念 提交于 2019-12-02 16:46:00
I'm looking for an intuitive, real-world example of a problem that takes (worst case) exponential time complexity to solve for a talk I am giving. Here are examples for other time complexities I have come up with (many of them taken from this SO question ): O(1) - determining if a number is odd or even O(log N) - finding a word in the dictionary (using binary search) O(N) - reading a book O(N log N) - sorting a deck of playing cards (using merge sort) O(N^2) - checking if you have everything on your shopping list in your trolley O(infinity) - tossing a coin until it lands on heads Any ideas? O

Which function grows faster, exponential or factorial?

橙三吉。 提交于 2019-12-02 16:31:16
Which function grows faster, exponential (like 2^n, n^n, e^n etc) or factorial (n!)? Ps: I just read somewhere, n! grows faster than 2^n. n! eventually grows faster than an exponential with a constant base (2^n and e^n), but n^n grows faster than n! since the base grows as n increases. n! = n * (n-1) * (n-2) * ... n^n = n * n * n * ... Every term after the first one in n^n is larger, so n^n will grow faster. n^n grows larger than n! -- for an excellent explanation, see the answer by @AlexQueue. For the other cases, read on: Factorial functions do asymptotically grow larger than exponential

Calculating 2^N in C# with long data type where N is 1929439432949324 [closed]

萝らか妹 提交于 2019-12-02 13:19:19
Currently I need to calculate 2^N , however N can be as large as 1929238932899 and I'm stuck using a long data type which can't hold a number that large. I've currently tried converting to 'BigInt' however I'm still stuck with the long data type restriction from what I've seen as well. I have a function which calculates the power. However, with the long data type, it just returns 0 when the number gets too big. Note that this is just a generic recursive power function. For example, with 2^6 its meant to return 64 and with 2^47 to return 140737488355328. However, when it becomes 2^8489289 , it

exponential fit in ggplot R

元气小坏坏 提交于 2019-12-02 09:41:31
I've been trying to fit an exponential curve to my data using ggplot and geom_smooth. I'm trying to replicate the answer to a similar problem ( geom_smooth and exponential fits ) but keep getting following error message: > exp.model <-lm(y ~ exp(x), df) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in 'x' I don't understand the error, as there is not NA/NaN/Inf values in the dataset: >df x y 1 1981 3.262897 2 1990 2.570096 3 2000 7.098903 4 2001 5.428424 5 2002 6.056302 6 2003 5.593942 7 2004 10.869635 8 2005 12.425793 9 2006 5.601889 10 2007 6.498187 11

Fitting distribution with fixed parameters in SciPy

限于喜欢 提交于 2019-12-02 02:45:26
Is it possible to fix parameters while fitting distributions in SciPy? For example, this code: import scipy.stats as st xx = st.expon.rvs(size=100) print st.expon.fit(xx, loc=0) results in non-zero location ( loc ). When some parameter is provided to the fit function it is considered as an initial guess. And if it is provided to the constructor ( st.expon(loc=0) ) the distribution becomes "frozen" and can not be used for fitting. Warren Weckesser To fix loc , use the argument floc : print st.expon.fit(xx, floc=0) E.g. In [33]: import scipy.stats as st In [34]: xx = st.expon.rvs(size=100) In

Raising number to fractional power java [duplicate]

心不动则不痛 提交于 2019-12-01 17:34:11
问题 This question already has answers here : Division of integers in Java [duplicate] (7 answers) Closed 4 years ago . I used the following code: double pow = 3/7; double num = 85; System.out.println(Math.pow(num, pow)); Expected result: 6.71... The output is 1.0 Any idea why? 回答1: 3/7 is evaluated to 0, since you are dividing two integers, so Math.pow(num, pow) becomes Math.pow(num, 0.0) which is 1.0 . Change it to 3.0/7 in order to get a floating point result. 来源: https://stackoverflow.com

Double precision in C++ (or pow(2, 1000))

杀马特。学长 韩版系。学妹 提交于 2019-12-01 11:16:13
I'm working on Project Euler to brush up on my C++ coding skills in preparation for the programming challenge(s) we'll be having this next semester (since they don't let us use Python, boo!). I'm on #16, and I'm trying to find a way to keep real precision for 2¹°°° For instance: int main(){ double num = pow(2, 1000); printf("%.0f", num): return 0; } prints

Double precision in C++ (or pow(2, 1000))

一笑奈何 提交于 2019-12-01 08:46:54
问题 I'm working on Project Euler to brush up on my C++ coding skills in preparation for the programming challenge(s) we'll be having this next semester (since they don't let us use Python, boo!). I'm on #16, and I'm trying to find a way to keep real precision for 2¹°°° For instance: int main(){ double num = pow(2, 1000); printf("%.0f", num): return 0; } prints

R: approximating `e = exp(1)` using `(1 + 1 / n) ^ n` gives absurd result when `n` is large

折月煮酒 提交于 2019-12-01 08:16:38
So, I was just playing around with manually calculating the value of e in R and I noticed something that was a bit disturbing to me. The value of e using R's exp() command... exp(1) #[1] 2.718282 Now, I'll try to manually calculate it using x = 10000 x <- 10000 y <- (1 + (1 / x)) ^ x y #[1] 2.718146 Not quite but we'll try to get closer using x = 100000 x <- 100000 y <- (1 + (1 / x)) ^ x y #[1] 2.718268 Warmer but still a bit off... x <- 1000000 y <- (1 + (1 / x)) ^ x y #[1] 2.71828 Now, let's try it with a huge one x <- 5000000000000000 y <- (1 + (1 / x)) ^ x y #[1] 3.035035 Well, that's not

For three digit exponents Fortran drops the 'E' in the output

与世无争的帅哥 提交于 2019-11-30 14:04:46
问题 I'm just coming to Fortran90 from Python and, honestly, the hardest part so far has been getting used to the formatting codes for writing output. I've run across a formatting problem that I can't seem to google or fiddle my way out of, I have searched this site for an answer but didn't find anything helpful. I'm doing a calculation and writing the output to file. I'm formatting the results of the calculation with the following code write(file, ('13ES11.2)') kappa Some of the values are very