Homework 7
Document last modified: 

Overview

The text presents algorithms and analysis of an Insertion and Quick sort. The assignment seeks to verify empirically the accuracy of those analysis's by profiling the execution of each algorithm under specific conditions.

Profiling program execution provides detailed empirical data on algorithm performance at different levels of granularity and measures.

The assignment uses a profiling system to acquire runtimes of the two sorting algorithms under varying problem sizes and initial orderings (sorted or random).

Purpose of Assignment

Assignment Software

Profiling using Visual Studio

Assignment

  1. Complete implementation of the Quick sort algorithm from Cormen, Chapter 7.1

    In driver.cpp, comment out the #include to select between Insertion and Quick sorts.
     

  2. Create an Excel table:
     
    1 2 3 4 5 6 7 8 9
    Sorting
    Algorithm
    Random,
    Ascending
    or Descending
    # Items
    Sorted
    Number of Calls Elapsed
    Exclusive Time
    Elapsed
    Inclusive Time
    Time Spent
    per item
    Math
    Function
    Ratio
    Col #6/#8

     

  3. For each run, record a row in the Excel table the following information:
  4. Executions 
    1. run Insertion sort on 5 different sets of integers ascending order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
    2. run Insertion sort on 5 different sets of integers in random order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
    3. run Insertion sort on 5 different sets of integers descending order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
    4. run Quick sort on 5 different sets of integers in ascending order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
    5. run Quick sort on 5 different sets of integers in random order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
    6. run Quick sort on 5 different sets of integers in descending order, the set sizes are: 
      7500, 15000, 30000, 60000, 120000
       
  5. Compute the following in Excel using the collected data:
  1. Time spent per item.
  2. Math functions constructed by you that takes the number of items sorted as its only parameter and produces as a result an approximation to the "Elapsed Inclusive Time" spent in the operation. These functions should correspond to the behavior elicited by the different data orderings. The Excel math function, where cell C11 contains the number of items sorted, could be similar to: =0.123*C11*C11. Note that exactly the same function should be used for each group of five sets, 7500 to 120000.
  3. The ratio of the recorded "Elapsed Inclusive Time" to result of the math function.  Repeatedly rework the function in 2. above in an attempt to drive the ratio to 1.0, meaning they agree. Note that, due to variations in inclusive execution times of the five sets, the ratio will not be exactly 1.0; 0.95 to 1.05 is certainly acceptable.

Analysis of results

  1. In an Excel spreadsheet, a table containing:
    1. the 3 Insertion sort results.
    2. the 3 Quick sort results.
    3. Insertion and Quick sort on descending data results.
    4. Insertion and Quick sort on random data results.
    5. Insertion and Quick sort on ascending data results.
       
      • x axis = size of the data (Column #3)
      • y axis = total time spent (Column #6)
  2. In a Word document, make observations and explanations of:

    Note: a significant portion of the grade for this project depends on what you write in response to these questions.

  3. In the Word document, answers to these questions:

What to Turn In: