Exercises

  1. The following are some growth-rate functional forms. Can you arrange them in the order of slower to faster performance?
    • 10n3
    • 3(log e n)2
    • 10n
    • 100n
    • Log2n2
    • Log2n3
    • Log3n2
    • Log3n3
    • n1.5
  2. Answer the following questions:
    • How can we evaluate the total memory currently being used by a given R environment? What is the purpose of garbage collection (GC) in the context of R?
    • Which occupies more size-a matrix with 10 numbers of categorical attributes, or a dataframe with 10 numbers of corresponding factors?
    • Can you evaluate and plot the memory allocation for dataframes and matrices with an increment of five observations for a fixed number of attributes (15 columns)?
    • Why does data.table occupy more memory than data.frame?
  3. Is data.table scalable in terms of performance (faster execution of operations) related to data pre-processing and transformations?

    (Hint: microbenchmark using large number of variables and observations with a higher number of iterations for each scenario).

  4. What are the best, worst, and average-case scenarios for the factorial n (n!)?
  5. Consider two computing systems A and B, where B is 100 times faster than A. Suppose an algorithm requires 100,000 iterations in system A in a given time t. The following are the functional forms which represent system runtime:
    • 10nlog2 n
    • 5n3
    • 8log3 n2

    Calculate the following:

    • Time required by system B to complete 100,000 iterations
    • Number of iterations processed by system B in the given time t
  6. Determine the relationship between the following functional forms f(n) and g(n) based on the asymptotic analysis using suitable limits for the input size n.
    • f(n)= nlog n ; g(n) = n2log n
    • f(n)= n2 ; g(n) = 2n
    • f(n)= 25 ; g(n) = 210
    • f(n)= 2n ; g(n) = 3n
    • f(n)= nlog n ; g(n) = (log n)2
  7. Evaluate Big θ for the following code snippets:
    • First snippet:
                     for(i in 1:100)
                     {
                       a = i*10
                       b = a+50}
      
    • Second snippet:
                     i=1; a=0
                     while(i<100)
                     {
                       a = c(a,i)
                       i=i+1}
      
    • Third Snippet:
                     a= data.frame(i=0, j=0)
                     for(i in 1:100){
                     for(j in 1:100)
                     {a[i,1] = i
                       a[j,2] = j}}
      
    • Fourth snippet:
                     a=50
                     for(i in 1:100)
                     {
                       if(i <= a)
                       print("i is less than or equal to a")" else print("i  
                       is greater than a")}"
      
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset