Data Structures and Algorithms — Homework 8

Due by 11:59pm Wednesday, March 27

Reading

Part 1: Programming Exercises

Download and unzip the folder assign8_files.zip, which contains the starting code for this assignment. This folder also contains the pre-compiled Java program SLLChecker.class. Typing java SLLChecker at the command line will test all of the methods of your LinkedList class and report any problems that it encounters.

  1. Implement the following methods of the LinkedList class:

Part 2: Written Exercises

  1. Suppose algorithm A takes five seconds to handle a dataset of 1,000 elements. If algorithm A has time complexity O(n), approximately how long will it take to handle a dataset of 2,000 elements? Of 10,000 elements? How long would algorithm A take to handle these larger datasets if it has O(n2) time complexity?

  2. Analyze the running times of the code fragments below, assuming that the variable steps has been declared as an int and initialized to zero in each case. Consider the running time to be the total number of loop cycles executed (equal to the final value of steps). Give the running time as a function T(n) of the loop-limit variable n, and state its big-O time complexity. Briefly explain your answer in each case.

    1. for (int i = 0; i < n; i++)
         steps++;
      
    2. for (int i = 0; i < n; i += 2)
         steps++;
      
    3. for (int i = 1; i <= n; i *= 2)
         steps++;
      
    4. for (int i = 0; i < n; i++)
         steps++;
      for (int j = 0; j < n; j++)
         steps++;
      
    5. for (int i = 0; i < n; i++)
         for (int j = 0; j < n; j++)
            steps++;
      
    6. for (int i = 0; i < n; i++)
         for (int j = 0; j < i; j++)
            steps++;
      
    7. for (int i = 0; i < n * n; i++)
         for (int j = 0; j < n; j++)
            steps++;
      

EXTRA CREDIT


Turning in Your Homework

Files to submit:

Submit the above files using the Homework Upload Site. Please include your name and the assignment number in a comment at the top of each Java source code file. You DO NOT need to submit your compiled .class files or any other files.

If you have questions about anything, just ask!