-
Which of the following are constant in regards to time complexity?
- variable assignments
- accessing an element in an array by index
- searching for an element in an array
- in a loop with only arithmetic operations inside the loop
- arithmetic operations
-
How could you simplify the big O expression of each of the following?
a. O(n + 10) b. O(2n) c. O(1000n + 500n) d. O(5n^2 + 100n + 25) e. O(1000) f. O(n^2 + n^3)
-
What is the time complexity of the following:
a. 5000.times do |i| puts i + i end b. n.times do |i| puts i + i end c. n.times do |i| n.times do |j| puts i * j end end
-
Place the following big O expressions in order from fast to slow:
a. O(log n) b. O(n) c. O(1) d. O(n^2)