Overview: In this lab you will use the Strategy Design Patter to create a single interface for implementing and analyzing the performance of 3 sorting algorithms (bubble, merge and insertion). This framework will be used as a base in future labs as we continue to grow your algorithm integrations. The project requires no GUI or terminal interface, it should execute completely without human interaction.

Code Requirements:

  • Use a Strategy Pattern with a base class named Algorithm that has the following properties
    • Load [Takes a filename in and can read input data file, can be implemented differently as long as it loads file]
    • Execute [Executes the search algorithm]
    • Display [Prints solution to screen]
    • Stats [Prints algorithm name, execution time and number of records analyzed to screen in a readable format]
    • Select [enum , int, id or string passed as input and loads corresponding algorithm to interface]
    • Save [Saves solution to file path given as input]
  • Create the following sorting algorithms
    • Bubble, merge and insertion
  • All timing stats should be collected using the C++
    • std::chrono::high_resolution_clock class
  • Create the Class Sort which inherits from Algorithm and overrides the base functionality of abstract class
  • Sort should use the concrete implementations of merge, bubble and insertion through composition to complete the Strategy Pattern implementation
  • All classes should be created using both .h and .cpp files (when possible).
  • Create the following data sets of int values with the following size and characteristic and save to file(s)
    • Data Set Sizes: 10; 1,000;
    • Characteristics:
      Random: values are place in complete random order
      Reversed Sorted Order: values are sorted in reverse order
      20 % unique values Data should duplicate numbers, only 20% of values are unique, remaining 80% are duplicates of those and in random order
      Approximately 30% randomized: This is a semi-sorted list, approximately 30% of file is randomized and out of order
    • You will have 8 total data sets, 1 of characteristic for each data set size
  • In main.cpp, loop through all algorithms and data sets to collect the performance timing. Your main.cpp should look similar to (when and how your load data can be different). Overall execution loop can be different, but it should be similar in practice to one loop that executes across different algorithms. cpp should have minimal code, and only need to include your interface class to access the algorithms.
Alorithm Sort;

for (all Algo Sort Types)
for (all Data Types)
Sort.Load(input file type); // Load can be called previous loop
Sort.Execute();
Sort.Stats();
  • You should have files similar to these in your final submission (more are possible and you can adjust naming convention to fit your project/style). Each instantiated non templated class should have a .h/.cpp when relevant. Final code should utilize the Strategy pattern.
    • h, Sort.h/cpp, Bubble.h/cpp, Insertion.h/cpp, Merge.h/cpp, main.cpp
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.