Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.18 KB

time_complexity_quiz.md

File metadata and controls

42 lines (32 loc) · 1.18 KB

Time Complexity Quiz

  1. Which of the following are constant in regards to time complexity?

    1. variable assignments
    2. accessing an element in an array by index
    3. searching for an element in an array
    4. in a loop with only arithmetic operations inside the loop
    5. arithmetic operations
  2. 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)             
    
  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
    
  4. 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)
    

Click here for solutions