Assignment 1: Algorithm Complexity Solution

$30.00

Description

General Comments:

  • In CS4310, most assignments will be completed using high-level informal pseudo codes. To avoid confusion and to make sure you’ll receive the best score that your homework deserves, please document in detail all your work clearly.
  • State all your assumptions.
  • No algorithm is complete without its time and space complexities given.
  • When presenting an algorithm,
    1. indicate if it is similar to a well-known algorithm,
    2. describe intuitively how the algorithm works (which may be supported by examples),
    3. give its pseudo code,
    4. finally analyze its time and space complexity.
  • Always describe general idea of the algorithm before giving its pseudo-code. Do not reinvent the wheel, i.e., if a well-known algorithm can be modified to solve a problem efficiently, use that solution and clearly indicate the changes you made. If you just write pseudo-code of a well-known algorithm without indicating how it is applied or modified to the problem at hand, no credit will be given.
  • Do not unnecessarily complicate a solution.

Here comes our first homework assignment.

  1. (20pts) For each of the code snippets below, first derive the time complexity using summation notation, then find the close form and finally express it using tight asymptotic (big-Oh, big-Theta, big-Omega) notation. Assume constant overhead per iteration of a loop. Keep details of your calculation until the last step of expressing your solution using tight asymptotic notation.

 

  1. sum = 0;
    for(i = 1; i n; i++)
    for(j = (n/2); j
    1; j–)
    sum++
    ;
  2. for (i = 1; i < n; i++) {
    y = y + 1;
    for (j = 0; j ≤ 2n; j++)
    x++;
    }
  3. for (i = 1; i ≤ n; i++)
    for (j = 1; j ≤ i; j++)
    for (k = j; k ≤ n; k++)
    x = x + 2;
  4. for (i = 1; i ≤ n; i += 2);
  5. for (i = 1; i ≤ n; i *= 2)
    x = y+2;

 

  1. (20pts) This question concerns the asymptotic relations between functions; you can assume that all logarithmic functions are in base 2. Sort the following functions in an asymptotically non-decreasing order of growth using big-oh and big-theta notations. Again, you must justify your answers, otherwise no credit.

 

  1. (20pts)
    1. Design and analyze an algorithm to find the median, upper quartile and lower quartile from a list of integers (unordered). Your time complexity should be no more than .
    2. Can you improve your algorithm if the input list is sorted? If so, design and analyze such an algorithm. If not, justify why no improvement in time/space complexity can exist.

 

  1. (20pts)

 

    1. Algorithm A uses operations, while algorithm B uses operations. Determine the value n0 such that A is better than B for n ≥ n0.
    2. Are there values of such that B is better than A? If yes, list the ranges. If not, justify why not.
    3. Determine the value n0 such that A is better than B for n ≥ n0, when B uses operations.

 

  1. (20pts) Solve the following recurrence relation:

 

Find a closed form of and then express your solution using tight asymptotic notation.

How to prepare and submit your homework:

Use a word processor (e.g MS Word, LaTeX) that you prefer. Include the original questions in your answer by typing your answers immediately after each question. Proofread your answers several times.

Submit your homework (MS Word or PDF) by uploading it to E-learning Dropbox by the due date.


error: Content is protected !!