Fill in Order Details

  • Submit paper details for free using our simple order form

Make Payment Securely

  • Add funds to your account. There are no upfront payments. The writer will only be paid once you have approved your paper

Writing Process

  • The best qualified expert writer is assigned to work on your order
  • Your paper is written to standard and delivered as per your instructions

Download your paper

  • Download the completed paper from your online account or your email
  • You can request a plagiarism and quality report along with your paper

the project description is in the link 1

Due: Tuesday, November 19, before 9:00 pm

Addenda

A new section, Other Operations, has been added. It describes how the merge function is used to implement insertion  and removal. It is required that you use this approach in your project.

You may find the following exercises useful for understanding skew heaps. This was given as an in-class assignment in sections 04 and 07.

skew-heaps.pdf

A minor modification has been made to test0.cpp. The assignment operator was not being tested (s3 would actually be created with the copy constructor).

  • It is an error to attempt to merge two skew heaps with FILLER TEXT priority order.

Objectives

  1. The objectives of this programming assignment are:

Implement a FILLER TEXT is a type of heap data structure that, like a standard max-heap, has efficient insert(), max(), and removeMax() operations, but also allows for efficient merging of heaps. Unlike a standard heap, it is FILLER TEXT, which you were introduced to in Project 3: for any node ww in the tree, the priority of ww must be greater than the priorities of its two children. This property guarantees that the element with highest priority is always in the root node of the tree, and so reading the highest priority element is just a matter of accessing the data in the root node.
The special feature of a skew heap is the FILLER TEXT merge since one of the two trees is empty. We simply return the non-empty tree, which in this case is the green subtree rooted at (5).

Other Operations

  1. The major operations supported by a max-skew heap are insertion of elements, reading the highest priority element, and removing the highest priority element. Reading the highest priority element is just a matter of reading the root node of the heap. The other two operations, insertion and removal, are applications of the merge function:

To insert a new node x into an exiting skew heap H, we treat x as a single-node skew heap and merge it with H.

  • To remove the maximum priority value, we delete the root node and then merge the root’s left and right sub-heaps.

We see, then, that the merge function is key to all of the major skew heap operations. If we can implement merge correctly, insertion and removal are simple.

Supporting Multiple Data Types — Tagged Unions

We would like to create a skewed heap that can store multiple data types (for the purpose of the project, the types will be string and int). One way this can be done is by using a FILLER TEXT The tagged_union variable holds one of two enumerated values, ISSTRING or ISINT, to indicate which type is being stored. The enumerated type is defined in the enum before the Node declaration.

  • Node constructors and a destructor have been provided for you in SkewHeap.h. Study their implementation to understand how the tagged union is used in practice

Function Pointers

So…you’re going to build a skew heap that can hold both strings and integers. We can’t just compare strings and integers, so what are we supposed to use for priority? We’re going to leave that up to the user by allowing them to pass a function pointer to the skew heap constructor. The function pointer is the address of a function that will be used to compute the priority of a node. The function must be able to compute the priority of a string or an integer.

A typedef for the function pointer is provided for you in SkewHeap.h:

  typedef int (*pri_fn)(Node *);

  • This says that pri_fn is a pointer to a function that takes a Node* argument. It must compute the priority from the contents of the node. Sample priority functions and examples of their use are provided in the test programs.

Assignment

Your assignment is to implement the SkewHeap class which implements a skew heap that can store both strings and integers using the tagged union construction. In addition, SkewHeap allows the user to determine how priorities are computed by passing a pointer to a prioritization function to the constructor. In addition, the user can change the prioritization function of an existing skew heap using a setter method, and the class will rebuild the heap using the new prioritization.

You must complete an additional class that uses SkewHeap, the TypedHeap class. The TypedHeap class maintains two skew heaps: an integer heap and a string heap. The user provides a vector of strings to insert, which are processed as follows:

If the string represents an integer (consists only of decimal digits), then convert it to an integer and insert it into the integer skew heap.

If the string does not represent an integer (contains non-digit characters), insert it into the string skew heap.

In addition, the user may request, through a combineHeaps() method, that the string and integer heaps be merged into a third “total” heap. Functions to change the priority function and to dump the skew heaps must also be implemented.

Although several test programs are provided, you are responsible for thoroughly testing your program. It is particularly important that your code run without segmentation faults, memory leaks, or memory errors. Memory leaks are considered as bad as segmentation fault since many segmentation faults are caused by poorly written destructors. A program with a poorly written destructor might avoid some segmentation faults but will leak memory horribly. Memory leaks will incur a penalty similar to that of a segmentation fault.

Following is a list of member functions that must be implemented. Function prototypes are provided in SkewHeap.h and TypedHeap.h. You will need to create the implementation files, SkewHeap.cpp and TypedHeap.cpp.

Public Methods in SkewHeap

A constructor with the signature:   SkewHeap::SkewHeap( pri_fn pri ) ;
The default constructor must create an empty SkewHeap object with the given priority function. The skew heap must be ready for heap operations; even an empty tree should behave properly when its methods are called.

A copy constructor with the signature:   SkewHeap::SkewHeap( const SkewHeap& rhs ) ;
The copy constructor must make a deep copy and create a new object that has its own allocated memory.

A destructor with the signature:   SkewHeap::~SkewHeap() ;
The destructor must completely free all memory allocated for the object. (Use valgrind on GL to check for memory leaks.)

An overloaded assignment operator with the signature:   const SkewHeap& SkewHeap::operator=( const SkewHeap& rhs ) ;
The assignment operator must deallocate memory used by the host object and then make deep copy of rhs.

A function that returns a pointer to the current priority function:   bool SkewHeap::getPriFn() const;        

A function that sets the priority function:   int SkewHeap::setPriFn( pri_fn pri ) ;
Changing the priority function will typically invalidate the current skew heap. This function must rebuild the heap using the new priority function to ensure that the heap is still valid.

A function that returns “true” if the skew heap is emtpy; false otherwise:   bool SkewHeap::empty() const ; 

A function that inserts a string value into the skew heap:   void SkewHeap::insert( string data ) ; 

A function that inserts an integer value into the skew heap:   void SkewHeap::insert( int data ) ; 

A function to access the highest priority element of the skew heap:   Node* SkewHeap::front() const;
Returns a pointer to the highest priority node in the skew heap. Should return nullptr if the heap is emtpy.

A function to remove the highest priority element from the skew heap:   void SkewHeap::removeTop() ;
Should do nothing if the skew heap is empty.

A function to merge two skew heaps:   void SkewHeap::skewHeapMerge( SkewHeap &sh ) ;
When the function completes, *this should contain the merged heap and sh should be empty.

A member function inorder() that performs an inorder traversal and prints the data at each node:   void SkewHeap::inorder() const ;
The inorder() methods visits each node using an inorder traversal and prints out the data. It also prints an open parenthesis before visiting the left subtree and a close parenthesis after visiting the right subtree. Nothing is printed when inorder() is called on an empty tree, not even parentheses. This function may be used for grading and is useful for debugging.

A function dump() that prints all the data in the skew heap:   void SkewHeap::dump() const ;
The dump() function must print the elements of the skew heap in decreasing priority order. See the sample output files for an example of what should be printed by dump().

Public Methods in TypedHeap

A constructor with the signature:   TypedHeap::TypedHeap( pri_fn pri ) ;
The default constructor must create three empty TypedHeaps, one to hold integer data, one to hold string data, and another to hold the combined skew heaps (when requestd by calling combineHeaps()). Each skew heap must be ready for heap operations; even an empty heap should behave properly when its methods are called.

An insertion function with the signature:   TypedHeap::insertToHeaps( vector<string> vec ) ;
The input is a vector of strings. For each string in the vector, the function must determine whether it represents an integer (consists entirely of decimal digits, possibly with leading or trailing spaces) and, if so, insert it into the integer heap; if it does not represent an integer, insert it into the string heap.

  • An function to combine the integer and string heaps:   TypedHeap::combineHeaps() ;
    After combineHeaps() is called, the merged heap will be in totalHeap and the string and integer heaps will be empty.

An function to print the contents of the three heaps:   TypedHeap::printHeaps() const ;
See the sample output files for examples of what should be printed by this function.

A function to change the priority function for all three skew heaps:   TypedHeap::changePriority( pri_fn pri ) ;
This function must change the priority function for each of the three skew heaps, causing the heaps to be re-built with the new prioritization.

Additional Requirements

Requirement: You must use the supplied SkewHeap.h and TypedHeap.h files. You may not modify any of the public method prototypes or private data, although you may add private functions to SkewHeap.h.

  • Requirement: The implementation file for the SkewHeap class must be named SkewHeap.cpp. The implementation file for the TypedHeap class must be named TypedHeap.cpp.

Requirement: If a user attempts to merge two skew heaps with different priority functions, a domain_error exception must be thrown.

Requirement: You must implement the skew heap merge operation as described in the Introduction.

Requirement: The insert() function must implement the merge-based insertion method described in Other Operations.

Requirement: The removeTop() function must implement the merge-based removal methods described in Other Operations.

Requirement: The dump() function must print the elements of the skew heap in decreasing priority order.

Requirement: The max-heap property must hold after any call to insert(), removeTop(), or skewHeapMerge().

Provided Programs

Header files are provided for both classes (SkewHeap.h and TypedHeap.h). You may add private helper functions in SkewHeap.h, but TypedHeap.h should not be modified.

Two test programs, one for SkewHeap and one for TypedHeap are provided, along with sample output from each program. However, it is your responsibility to write additional tests to ensure that your implementation is correct.

Tests of basic SkewHeap functions. Includes sample priority functions.FILLER TEXTtest0.cpp (old test0.cpp)FILLER TEXTSample output: test0.txt (old test0.txt)

Tests of basic TypedHeap functions. Includes sample priority functions.FILLER TEXTtest1.cppFILLER TEXTSample outptu: test1.txt

What to Submit

You must submit the following files to the proj4 directory.

SkewHeap.h

SkewHeap.cpp

TypedHeap.h

TypedHeap.cpp

FILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXT

FILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXTFILLER TEXT

https://userpages.umbc.edu/~cmarron/cs341.f19/projects/proj4.shtml

WHAT OUR CURRENT CUSTOMERS SAY

  • Google
  • Sitejabber
  • Trustpilot
Zahraa S
Zahraa S
Absolutely spot on. I have had the best experience with Elite Academic Research and all my work have scored highly. Thank you for your professionalism and using expert writers with vast and outstanding knowledge in their fields. I highly recommend any day and time.
Stuart L
Stuart L
Thanks for keeping me sane for getting everything out of the way, I’ve been stuck working more than full time and balancing the rest but I’m glad you’ve been ensuring my school work is taken care of. I'll recommend Elite Academic Research to anyone who seeks quality academic help, thank you so much!
Mindi D
Mindi D
Brilliant writers and awesome support team. You can tell by the depth of research and the quality of work delivered that the writers care deeply about delivering that perfect grade.
Samuel Y
Samuel Y
I really appreciate the work all your amazing writers do to ensure that my papers are always delivered on time and always of the highest quality. I was at a crossroads last semester and I almost dropped out of school because of the many issues that were bombarding but I am glad a friend referred me to you guys. You came up big for me and continue to do so. I just wish I knew about your services earlier.
Cindy L
Cindy L
You can't fault the paper quality and speed of delivery. I have been using these guys for the past 3 years and I not even once have they ever failed me. They deliver properly researched papers way ahead of time. Each time I think I have had the best their professional writers surprise me with even better quality work. Elite Academic Research is a true Gem among essay writing companies.
Got an A and plagiarism percent was less than 10%! Thanks!

ORDER NOW


Consider Your Assignments Done

“All my friends and I are getting help from eliteacademicresearch. It’s every college student’s best kept secret!”

Jermaine Byrant
BSN

“I was apprehensive at first. But I must say it was a great experience and well worth the price. I got an A!”

Nicole Johnson
Finance & Economics

Our Top Experts

See Why Our Clients Hire Us Again And Again!


OVER

10.3k
Reviews

RATING
4.89/5
Average

YEARS
13
Mastery

Success Guarantee

When you order form the best, some of your greatest problems as a student are solved!

Reliable

Professional

Affordable

Quick

Using this writing service is legal and is not prohibited by any law, university or college policies. Services of Elite Academic Research are provided for research and study purposes only with the intent to help students improve their writing and academic experience. We do not condone or encourage cheating, academic dishonesty, or any form of plagiarism. Our original, plagiarism-free, zero-AI expert samples should only be used as references. It is your responsibility to cite any outside sources appropriately. This service will be useful for students looking for quick, reliable, and efficient online class-help on a variety of topics.