Question

In: Computer Science

(java) Create a specification(your choice) of a data abstraction , decide a rep for the data...

(java)

Create a specification(your choice) of a data abstraction , decide a rep for the data abstraction. Write the abstraction function and the rep invariant for the rep.

Note* add comments for explanation..

Solutions

Expert Solution

Rep invariant is some sort of protection on state(s) against operations that have the capacity to`modify`. Therfore, Heap sort on array is great example to show the rep invarirant. where array is used to store elements in such a manner when converted to binary tree parent is max/min than both children.

thus, abstract function would be heapify function where each parent node’s key >= children’s keys.

Its given below -

//sort applied on array (can be abstracted)
public void sort(int arr[])
{
int n = arr.length;
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);

for (int i=n-1; i>=0; i--)
{
int temp = arr[0];
arr[0] = arr[i];
arr[i] = temp;

heapify(arr, i, 0);
}
}

//rep invariancy condition
void heapify(int arr[], int n, int i)
{
int largest = i;
int l = 2*i + 1;
int r = 2*i + 2;

if (l < n && arr[l] > arr[largest])
largest = l;

if (r < n && arr[r] > arr[largest])
largest = r;

if (largest != i)
{
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;

heapify(arr, n, largest);
}
}


Related Solutions

PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
Run the following R code (copy and paste) to create some data: out1 <- rep( c(0,0,1),...
Run the following R code (copy and paste) to create some data: out1 <- rep( c(0,0,1), 3 ) out2 <- rep( c(1,0,1), 3 ) counts <- c(18,17,15,20,10,20,25,13,12) This is a variation on the data in the first example on the “glm” help page in R. The counts variable is our response variable and will be modeled as a Poisson variable, the out1 predictor variable will measure the difference between outcomes 2 (baseline) and 3, and out2 will measure the difference...
a/  write  4 numbers from your choice b/ Write a java code to create a linked list containing...
a/  write  4 numbers from your choice b/ Write a java code to create a linked list containing the 4 numbers
Create a game of your choice that involves the following concepts:
C++ PROJECTCreate a game of your choice that involves the following concepts:STL library. (Maps, Sets, Lists, Stacks and Queues), with Iterators and AlgorithmsShow especially Especially Algorithm/Iterators/Containers in the STLMinimum of 750 linesInclude Full documentation
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
This week, we learned that there are four levels of abstraction of a data model. They...
This week, we learned that there are four levels of abstraction of a data model. They are contextual, conceptual, logical, and physical. Briefly explain each level with a focus on the differences between them. When working on the final project for this course, many students go directly to the physical model. What would you say to these students? Why would you say so?
Given the data below, a lower specification of 78.2, and an upper specification of 98.9, what...
Given the data below, a lower specification of 78.2, and an upper specification of 98.9, what is the long term process performance (Ppk)? Data 101.4791 94.02297 95.41277 106.7218 90.35416 86.9332 94.87044 95.91265 93.98042 108.558 86.17921 85.01441 96.14778 92.59247 92.49536 87.4595 104.3463 90.57274 99.38992 80.61536 82.31772 97.05331 87.64293 103.3648 98.09292 87.72921 110.1765 86.76847 87.22422 94.88148 86.01183 91.43283 104.0907 97.77132 98.69138 95.55565 106.2402 95.96255 88.05735 100.2796 99.00995 86.18458 95.41366 99.32314 95.75733 88.82675 93.39986 98.34077 94.72198 99.14256 92.37767 94.94969 89.63531 87.56148 88.02731 97.57498...
Given the data below, a lower specification of 62.6, and an upper specification of 101.8, what...
Given the data below, a lower specification of 62.6, and an upper specification of 101.8, what is the long term process performance (ppk)? Data 66.06284 82.57716 78.64111 92.72893 76.18137 71.46201 76.24239 74.83622 69.87486 77.90479 82.39439 79.18856 84.34492 77.32829 80.50536 83.36017 97.34745 84.56226 87.95131 65.64412 70.73183 74.28879 89.07007 78.50745 77.51397 89.04946 73.75787 91.30598 87.12589 89.29855 81.398 86.52962 84.33249 80.48321 81.87089 83.54964 71.19464 80.02001 90.00112 82.29257 77.55125 88.07639 88.95467 83.92542 88.33509 84.36723 77.89679 82.38985 67.81415 80.68263 87.25767 81.1521 82.15546 72.52171 67.58353 86.11663...
Create a context diagram and a DFD for a system of your choice (or a system...
Create a context diagram and a DFD for a system of your choice (or a system to book appointments in a hospital).Your system should at least contains 4 processes. Steps: • Identify the processes that you want your system to accomplish. • Identify the external entities that may interacts with your system. •( Create context diagram (Level 0 DFD • Create DFD
Question 1. Your task is to create a full program for a Restaurant of your choice....
Question 1. Your task is to create a full program for a Restaurant of your choice. You will have the output appear at first saying Welcome to ______ Restaurant where the _____ will be whatever you name your restaurant Today’s choices are 1.__________ 2._________ 3._______ 4.________ NOTE each _____ will say an item and its price for example pizza 2.99 Please choose 1 of the choices. In each case, as the user picks a choice It will calculate the total...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT