Last active
February 26, 2018 23:42
-
-
Save hpoit/defb72cff15a498673ec9c4f6b87abe1 to your computer and use it in GitHub Desktop.
Cormen 1.2.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> i = 1; | |
julia> runningtime1 = 100i^2; | |
julia> runningtime2 = 2^i; | |
julia> while true # is a loop that never terminates, unless there's a break | |
println(i) | |
if runningtime1 < runningtime2 # if condition is true, break | |
break | |
end | |
i += 1 # while condition is false, keep updating variable | |
runningtime1 = 100*i^2 # update variable | |
runningtime2 = 2^i # update variable | |
println(runningtime1) | |
println(runningtime2) | |
end | |
1 | |
400 # runningtime1 | |
4 # runningtime2 | |
2 | |
900 | |
8 | |
3 | |
1600 | |
16 | |
4 | |
2500 | |
32 | |
5 | |
3600 | |
64 | |
6 | |
4900 | |
128 | |
7 | |
6400 | |
256 | |
8 | |
8100 | |
512 | |
9 | |
10000 | |
1024 | |
10 | |
12100 | |
2048 | |
11 | |
14400 | |
4096 | |
12 | |
16900 | |
8192 | |
13 | |
19600 # runningtime1 is greater than | |
16384 # runningtime2 | |
14 | |
22500 # runningtime1 is less than | |
32768 # runningtime2 | |
15 # loop breaks | |
julia> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment