Analysis of average-case efficiency for either algorithm

Assignment Help C/C++ Programming
Reference no: EM131475225

Summary

In the first assignment you learned how to analyse an algorithm experimentally, by implementing it as an executable program, measuring the program's run-time characteristics, and comparing the results with theoretical predictions for the algorithm. In this assignment you will undertake a similar exercise, but this time the aim is to directly compare two different algorithms that both perform the same function but may have different efficiencies. In particular, you must ensure that both programs are analysed under exactly the same conditions, to ensure that the results are meaningfully comparable. As in the first assignment, you will be required to count the number of basic operations performed, measure execution times, and produce a clear report describing your findings. (An example report is available on the CAB301 BlackBoard site.)

Tasks

To complete this assignment you must submit a written report, and accompanying evidence, describing the results of your experiments to compare the efficiency of two given algorithms. The steps you must perform, and the corresponding (brief) summaries required in your written report, are as follows.

1. You must ensure you understand the algorithms to be analysed.
- Your report must briefly describe the two algorithms.

2. You must define a common basis for meaningful comparison of the two algorithms, in terms of basic operations and the size of inputs.

- Your report must describe your choice of ‘basic operation' applicable to both algorithms.

- Your report must describe your choice of ‘problem size' applicable to both algorithms.

- Your report must summarise the predicted (theoretical) time efficiency of the two algorithms, as far as possible. For the purposes of this assignment we are interested in average-case efficiency only.

3. You must describe the methodology you used for performing the experiments.

- Your report must describe your choice of computing environment.

- Your report must describe your C++ implementation of the given algorithms. You must ensure that the correspondence between features of the algorithms and the corresponding program code is clear, to confirm the validity of the experiments. The program code should replicate the structure of the algorithms as faithfully as possible.

- Your report must explain how you showed that your programs work correctly. Thorough testing would normally be sufficient.

- Your report must explain clearly how you produced test data for the experiments, or chose cases to test, as appropriate. Usually this will involve generating random data for different sizes of input. In particular, it is important that both algorithms are tested using the same data, to ensure that the comparative results are meaningful.

- Your report must explain clearly how you counted basic operations, e.g., by showing the relevant program code for maintaining ‘counter' variables. In particular, it should be easy to see that the method used is accurate with respect to the original algorithms.

- Your report must explain clearly how you measured execution times, e.g., by showing the relevant program code augmented with calls to ‘clock' or ‘time' procedures. Since it is often the case that small program fragments execute too quickly to measure accurately, you may need to time a large number of identical tests and divide the total time by the number of tests to get useful results.

4. You must describe the results of your experiments.

- Your report must briefly explain how you proved that your programs work correctly. This would normally be done through testing.

- Your report must show in detail the results of comparing the number of basic operations performed by the two algorithms for different sizes of inputs. The results should be plotted as one or more graphs which make it easy to see how the two algorithms compare. You must produce enough data points to show a clear ‘trend' in the outcomes. It must be clear how many individual data points contributed to the lines shown and how many individual tests contributed to each data point. You must briefly explain what the results reveal about the comparative efficiency of the two algorithms.

- Your report must show in detail the results of comparing the execution times of the two programs for different sizes of inputs. The results should be plotted as one or more graphs which make it easy to see how the two algorithms compare. You must produce enough data points to show a clear ‘trend' in the outcomes. It must be clear how many individual data points contributed to the lines shown and how many individual tests contributed to each data point. You must briefly explain what the results reveal about the comparative efficiency of the two programming language implementations of the algorithms.

5. You must produce a brief written report describing all of the above steps.

- Your report should be prepared to a professional standard and must not include errors in spelling, grammar or typography.

- You are free to consult any legitimate reference materials such as textbooks, web pages, etc, that can help you complete the assignment. However, you must appropriately acknowledge all such materials used either via citations to a list of references, or using footnotes. (Copying your assignment from one of your classmates is not a legitimate process to follow, however. Note the comments below concerning plagiarism.)

- Your report must be organised so that it is easy to read and understand. The main body of the report should summarise what you did and what results you achieved as clearly and succinctly as possible. Supporting evidence, such as program listings or execution traces, should be relegated to appendices so that they do not interrupt the ‘flow' of your overall argument.

- There should be enough information in your report to allow another competent programmer to fully understand your results. This does not mean that you should include voluminous listings of programs, execution traces, etc. However, you should include the important parts of the code, and brief, precise descriptions of your experimental methodology.

6. You must provide all of the essential information needed for someone else to duplicate your experiments in electronic form, including complete copies of program code (because the written report will normally contain code extracts only). As a minimum this data must include:
- An electronic copy of your report;
- The complete source code for your C++ implementations of the algorithms; and
- The complete source code for the test procedures used in your experiments.

Optionally you may also include electronic versions of the data produced by the experiments. In all cases, choose descriptive folder and file names.

Algorithms

Levitin presents the following algorithm for finding the distance between the two closest elements in an array of numbers [Ex. 1.2(9), p. 18].

Algorithm MinDistance(A[0..n - 1])

//Input: Array A[0..n - 1] of numbers

//Output: Minimum distance between two of its elements

dmin ← ∞

for i to n - 1 do

for j 0 to n - 1 do

if i ≠ j and  A[i] - A[j] < dmin

dmin ← |A[i] - A[j]|

return dmin

He then asks if there is a more efficient algorithm to do this task. One possible answer is as follows.

Algorithm MinDistance2(A[0..n - 1])

//Input: An array A[0..n - 1] of numbers

//Output: The minimum distance d between two of its elements

dmin ← ∞

for i 0 to n - 2 do

for j ← i + 1 to n - 1 do

temp |A[i] - A[j]|

if temp < dmin

dmin temp

return dmin

This version would appear to be more efficient because it compares the same pair of numbers only once, and avoids recomputing the same expression in the innermost loop. Can your empirical analysis confirm the claim that MinDistance2 is more efficient than MinDistance on average?

Since the optimisation in MinDistance2 is motivated by a desire to reduce the number of expressions that access elements of array A, you may want to use this principle to justify your choice of basic operation. (When counting basic operations for algorithm MinDistance, be careful to consider whether or not the second conjunct is evaluated when index i equals index j.)

Unfortunately, Levitin does not give an analysis of average-case efficiency for either algorithm. Nevertheless, it is obvious from inspection that the best- and worst-case behaviours for both algorithms are quadratic with respect to the length of the array. (Why?) Thus their average-case efficiencies must be quadratic as well. (Why?) However, although both algorithms belong to the same efficiency class, your experiments should reveal that algorithm MinDistance's average-case efficiency function has a significantly larger ‘constant multiplier' than that of MinDistance2.

Reference no: EM131475225

Questions Cloud

The emperors new clothes : Through this article review, you will learn how to determine whether an employee empowerment initiative is driven by Model I values or Model II values.
Kinds of legal issues : What kinds of legal issues do you think stem cell research and genetic therapies will present in the coming years? [Shewalten 2015)
Experience and internship enabled you to better : How has your work experience and internship enabled you to better solve problems?
External and internal environments : Choose an industry you have not yet written about in this course, and one publicly traded corporation within that industry. Research the company on its own.
Analysis of average-case efficiency for either algorithm : CAB301 Algorithms and Complexity Assignment 2 - Empirical Comparison of Two Algorithms - analysis of average-case efficiency for either algorithm
Find the output and next state sequence : For the flow table shown below: Find the output and next state sequence for the input sequence.
Leadership by a successful leader : Select a book about leadership by a successful leader whom you believe has adopted leadership as a vocation.
How can knowledge management systems : How can knowledge management systems help an organization increase profits and reduce costs? The response should be between 250-300 words with all citations.
Formulate the conversation you would have with the employe : Formulate the conversation you would have with the employee.Summarize the conversation you would have with the employee's male co-worker.

Reviews

len1475225

4/26/2017 8:05:01 AM

Quality of written report Very good (4) The report contains no significant errors in spelling, grammar or typography All reference materials used for the project are cited comprehensively The computing environment used to develop the programs and perform the experiments is described clearly The report is well organised into sections and contains helpful navigational aids for the reader (headings, cross references, etc) which make the overall ‘story’ easy to follow Marks awarded (out of 4): Very good (15-18) The functional correctness of the programs was tested or verified in a clear and appropriate way, including ‘normal’ and ‘extreme’ input cases It is clear how many data points contributed to the graphs of results and how many tests contributed to each data point The way that basic operations are counted is clear and accurate (with respect to the basic operations identified for these algorithms) for both algorithms Experiments to count the algorithms’ basic operations produced clear trends which could be compared meaningfully and the results are explained clearly

len1475225

4/26/2017 8:04:29 AM

Description of algorithms and theoretical predictions Very good (7-8) The algorithms are described clearly, succinctly and accurately The choices of basic operation and input size are clearly identified, well justified, and suitable for both algorithms The algorithms’ predicted average-case efficiencies are explained clearly, succinctly and accurately Marks awarded (out of 8): Implementation of the algorithm Very good (7-8) The programs implement the algorithms faithfully, and the correspondences between features of the algorithms and their programming language implementations are either self-evident or are explained clearly, succinctly and accurately Marks awarded (out of 8):

len1475225

4/26/2017 8:04:06 AM

The specific criteria by which your assignment will be assessed are detailed in the Marking Schema and Feedback Sheet for this assignment. Assessment will be based primarily on your written report. However, if there is some concern about the originality of your work or the quality of your experimental results you may be asked to give a practical demonstration of your program. Submission Your assignment solution should be submitted electronically via Blackboard before 11:59 pm. Your submission should be a zip file. The file name should contain your student number and include the following items: • All source code of your algorithm implementations • A detailed report on your empirical analysis of both algorithms - the structure of your detailed report must be the same with that of the sample assignment • Statement of completeness including the percentage contribution of each student

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd