Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, we will create two variants of the BufferArray class; BufferArrayNoDups and BufferArrayWithDups. As the name implies, the first class does not allow

In this assignment, we will create two variants of the BufferArray class; BufferArrayNoDups and BufferArrayWithDups. As the name implies, the first class does not allow the insertion of duplicate values, while the second one does. The BufferArrayNoDups class should look like the BufferArray class in Assignment 1. Only the insert operation has to change. Both remove functions should assume that there is never more than one copy of a value. For this assignment I would also like the distinction between the two remove functions to be more clear. So please rename the remove as fastRemove and leave the other one with the same name stableRemove.
The BufferArrayWithDups class should also look like the class in BufferArray class in Assignment 1. This time, do not change the insert function, and implement both remove functions as for the NoDups case. But, in addition, add three new methods, called findAll, fastRemoveAll, and stableRemoveAll. The findAll function should return an int with the number of elements that have the same value as the target value, while the two removeAll functions should remove all copies of the target value. Have both removeAll functions return an int with the number of values that were actually removed. For this assignment, we will make two more changes. First, omit the BUFFER_SZ constant, and instead have the __init__ take an integer argument for the size.
If possible implement these two new classes as child classes of the BufferArray class.
Sorted Array Buffers with and Without Duplicates
In this assignment, we will also create two variants of the classes from Assignment 1; SortedBufferArrayNoDups and SortedBufferArrayWithDups. As the name implies, the first class is a sorted array and does not allow the insertion of duplicate values, while the second one does. The SortedBufferArrayNoDups class should look like the BufferArrayNoDups class from above. Only the insert operation has to change. Insert has to insert in order. Here there is only one remove function which is stableRemove that has to be slightly altered so that you dont have to go until the end of the array to find the integer. You can stop when you have reached a value greater than the value being passed in. For example if your array contains integers [1,3,5,7,9] and you are asked to remove integer 4, you can stop once you reach 5 as you know 4 cannot be found now. Change locationOf to reflect the fact that the array is sorted.
The SortedBufferArrayWithDups class should also look like the class in SortedBufferArrayWithNoDups class in previous section. This time, change the insert function that allows duplicates but needed to be inserted in order. Now implement the findAll and stableRemoveAll. The findAll function should return an int with the number of elements that have the same value as the target value, while the stableRemoveAll function should remove all copies of the target value. Have the stableRemoveAll function return an int with the number of values that were actually removed.
Here findAll and stableRemoveAll become easier. For findAll once you find the first one you need to look at the next element. If its the same keep going until you find an element which is a greater value and you stop searching. And Similarly for stableRemoveAll as you know the number of occurrences and now if you find the locationOf the first one you can stop looking and remove starting from that index to the number of occurrences. So for example if you have an integer array [1,3,5,5,5,7,9] and you are asked to remove 5, location of first 5 is 2 and number of occurrences for 5 is 3. So you need to remove from index 2 to 4(3 occurrences). For this assignment, like the non sorted BufferArray have the __init__ take an integer argument for the size and do not use a default.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago