1. Homepage
  2. Programming
  3. CS271: Data Structures - Project 2: Priority Queues - Minqueue

CS271: Data Structures - Project 2: Priority Queues - Minqueue

Engage in a Conversation
USDenison UniversityCS271Data StructuresMinqueueC++

CS271: Data Structures CourseNana.COM


CourseNana.COM

Project #2 CourseNana.COM

This project is meant to be completed in pairs. You should work in your Unit 1 groups. Solutions should be written in C++ with one submission per group. Submissions should be a compressed file following the naming convention: NAMES cs271 project2.zip where NAMES is replaced by the first initial and last name of each group member. For example, if Dr. Truex and Dr. Amert were in a group they would submit one file titled STruexTAmert cs271 project2.zip. You will lose points if you do not follow the course naming convention. Your .zip file should contain a minimum of 5 files: CourseNana.COM

1. makefile
2. minqueue.cpp
3. test minqueue.cpp 4. usecase.cpp
5. main.cpp CourseNana.COM

Additional files such as a minqueue.h header file or README.md are welcome. The above merely represent the minimum files required for project completion. Details for each are as follows. CourseNana.COM


CourseNana.COM

Specifications Priority Queue CourseNana.COM

Implement a MinQueue priority queue template class using heaps. Your class should have (at a minimum) the following two constructors: CourseNana.COM

MinQueue(): empty constructor initializing an empty minimum priority queue (min heap) CourseNana.COM

MinQueue(T* A, int n): create a minimum priority queue (min heap) of the n elements in A
Correct implementation of both constructors will be necessary to pass testing. In addition, recall that min- CourseNana.COM

priority queues support (at a minimum) the following operations:
insert(x): mq.insert(x) should insert the element x into the priority queue mq. For example: CourseNana.COM

MinQueue<string> mq; mq.insert("hello"); mq.insert("world"); CourseNana.COM

should result in the heap ["hello", "world"] CourseNana.COM

  • min(): mq.min() should return the smallest value in the queue. For example, using the priority queue above:

cout << mq.min() << endl; should result in the printing of the string "hello" CourseNana.COM

  • extract min(): mq.extract min should remove and return the smallest value in the queue. For example, using the priority queue above:

string min = mq.extract_min();
cout << "Removed: " << min << ", new min: " << mq.min() << endl; CourseNana.COM

should result in the printing of the string "Removed: hello, new min: world" CourseNana.COM

  • decrease key(i, k): mq.decrease key(i, k) should decrease the value at index i to the new value k.

For example: CourseNana.COM

MinQueue<int> mq2; mq2.insert(7); mq2.insert(9); mq2.insert(2); mq2.insert(8); mq2.insert(3); mq2.decrease_key(3, 1); CourseNana.COM

should result in the heap [1, 2, 7, 3, 8]
A min-heap should also support (at a minimum) the following operations: CourseNana.COM

  • heapify(i): should maintain the min-heap property by allowing element at index i to “float down” the heap so that, by the conclusion of the method, the subtree rooted at index i is a min-heap.
  • build min heap(): should produce a min-heap from the potentially unordered values in the member array.
  • heapsort(A): should result in the array A containing the values in the min heap member array in ascending order. Your heapsort method should be accessible via a sort method in your MinQueue. For example:

int* A = new int[10];
// populate A with integers MinQueue<int>
mq3(A, 10); mq3.sort(A);
// print A
CourseNana.COM

should result in the printing of the values in A in ascending order. CourseNana.COM

Be sure to include suitable preconditions and postconditions in the comments before each method. Code implementing your MinQueue should be written in the file minqueue.cpp. CourseNana.COM

Unit Testing CourseNana.COM

In addition to the functionality above, you are expected to implement a to string() method which returns a string with the elements in your priority separated by a single space in the order in which they appear in the member array. For example, using the queue mq2 generated in the above specifications: CourseNana.COM

cout << mq2.to_string() << endl;
should result in the printing of the string "1 2 7 3 8". Your to string() method will be required for your class to pass testing. CourseNana.COM

For each method you write, you should also be writing a unit test method in a separate unit test file that thoroughly tests that method. Think, in addition to common cases: what are my boundary cases? edge cases? disallowed input? Each method should have its own test method. CourseNana.COM

An example test file test minqueue example.cpp has been provided and demonstrates (1) a general outline of what is expected in a test file and (2) a guide on how your projects will be tested after submission. The tests included in test minqueue example.cpp are not exhaustive. The unit testing in your test minqueue.cpp file should be much more complete. Additionally, for grading purposes, your code will be put through significantly more thorough testing than what is represented by test minqueue example.cpp. Passing the tests in this example file should be viewed as a lower bound. CourseNana.COM

Documentation CourseNana.COM

The expectation of all coding assignments is that they are well-documented. This means that logic is docu- mented with line comments and method pre- and post- conditions are properly documented immediately after the method’s parameter list. CourseNana.COM

Pre-conditions and post-conditions are used to specify precisely what a method does. However, a pre- condition/post-condition specification does not indicate how that method accomplishes its task (if such com- menting is necessary it should be done through line level comments). Instead, pre-conditions indicate what must be true before the method is called while the post-condition indicates what will be true when the method is finished. CourseNana.COM

Use Case CourseNana.COM

Finally, use your MinQueue to solve the following problem: CourseNana.COM

You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position. Return the min sliding window. CourseNana.COM

Example 1 CourseNana.COM

Input: nums = [1,3,-1,-3,5,3,6,7], k = 3 Output: [-1,-3,-3,-3,3,3]
Explanation: CourseNana.COM

Window Position [13-1]-35367 1[3-1-3]5367 13[-1-35]367 13-1[-353]67 13-1-3[536]7 13-1-35[367] CourseNana.COM

Min -1 -3 -3 -3 3 3 CourseNana.COM

Example 2 CourseNana.COM

Input: nums = [1], k = 1 Output: [1] CourseNana.COM

Your solution should be implemented in usecase.cpp in the
string sliding window(T arr[], int len, int window) CourseNana.COM

where len is the length of the array nums and k is the size of the sliding window. Your sliding window function should return a string with the values in the output of the sliding window problem separated by a single space. For example, the above examples would return the strings "-1 -3 -3 -3 3 3" and "1" from sliding window respectively. In your main.cpp file, your main function should include at least one example test case demon- strating the accuracy of your usecase solution. Note that your use case will only be tested when the template is set to int. CourseNana.COM

Makefile CourseNana.COM

With each project you should be submitting a corresponding makefile. Once unpacking your .zip file, the single command make should create a test executable and a usecase executable. The command ./test should then run all the unit tests in your test minqueue.cpp file evaluating your MinQueue class. The command ./usecase should run the example test case in your main.cpp file demonstrating the accuracy of your sliding window solution. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
US代写,Denison University代写,CS271代写,Data Structures代写,Minqueue代写,C++代写,US代编,Denison University代编,CS271代编,Data Structures代编,Minqueue代编,C++代编,US代考,Denison University代考,CS271代考,Data Structures代考,Minqueue代考,C++代考,UShelp,Denison Universityhelp,CS271help,Data Structureshelp,Minqueuehelp,C++help,US作业代写,Denison University作业代写,CS271作业代写,Data Structures作业代写,Minqueue作业代写,C++作业代写,US编程代写,Denison University编程代写,CS271编程代写,Data Structures编程代写,Minqueue编程代写,C++编程代写,USprogramming help,Denison Universityprogramming help,CS271programming help,Data Structuresprogramming help,Minqueueprogramming help,C++programming help,USassignment help,Denison Universityassignment help,CS271assignment help,Data Structuresassignment help,Minqueueassignment help,C++assignment help,USsolution,Denison Universitysolution,CS271solution,Data Structuressolution,Minqueuesolution,C++solution,