java binary heap operation counts
/*
* Add operation counts to all methods - 4pts
* No other methods/variables should be added/modified
*/
public class A6BH <E extends Comparable<? super E>>
{
private int defaultSize = 4;
private int count = 0;
private E[] heap;
private int opCount = 0;
public int getOpCount()
{
return opCount;
}
public void resetOpCount()
{
opCount = 0;
}
public A6BH()
{
heap = (E[])new
Comparable[defaultSize];
}
public A6BH(int size)
{
heap = (E[])new
Comparable[this.nextSize(size)];
}
public A6BH(E[] items)
{
heap = (E[])new
Comparable[this.nextSize(items.length)];
this.addAll(items);
}
public void addAll(E[] items)
{
//make sure there is room for all
new items
if(count+items.length >=
heap.length)
{
growArray(this.nextSize(count+items.length));
}
for(E item : items)//copy new
items in order
{
count++;
heap[count] =
item;
}
this.buildHeap();//fix heap
order
}
private void buildHeap()
{
for(int i = count >> 1; i
> 0; i--)
{
percolateDown(i);
}
}
public void insert(E val)
{
//make sure we have room for new
item
if(count+1 >= heap.length)
{
growArray();
}
count++;
heap[0] = val;//temporary
storage
percolateUp(count);
}
private void percolateUp(int pos)
{
//pos>>1 = pos/2 - getting to
parent of empty space
for(;heap[pos>>1].compareTo(heap[0]) > 0;pos =
pos>>1)
{
heap[pos] =
heap[pos>>1];//move parent down a level
}
heap[pos] = heap[0];//take value
from initial insert and put in correct pos
}
public E findMin()
{
return (count >
0)?heap[1]:null;
}
public E deleteMin()
{
if(count > 0)
{
E temp =
heap[1];
heap[1] =
heap[count];//moved last value to top
count--;//decrease size
percolateDown(1);//move top value down to final position
return
temp;
}
else
{
return null;//no
items in heap
}
}
private void percolateDown(int pos)
{
int firstChild = pos <<
1;//pos * 2
E temp = heap[pos];
for(;pos<<1 <= count; pos
= firstChild, firstChild = pos<<1)
{
if(firstChild+1
<= count)//there is a second child
{
if(heap[firstChild].compareTo(heap[firstChild+1]) > 0)
{
firstChild++;
}
}
//firstChild is
now the index of the smaller child
if(temp.compareTo(heap[firstChild]) > 0)
{
heap[pos] = heap[firstChild];//move child up to
parent and continue
}
else
{
break;//stop loop because we found correct
position for temp
}
}
heap[pos] = temp;
}
public String toString()
{
String output = "Heap
Size:"+heap.length+"\n";
for(int i = 1; i <= count;
i++)
{
output +=
heap[i]+",";
}
return output;
}
public boolean isEmpty()
{
return count == 0;
}
public void makeEmpty()
{
count = 0;
}
private void growArray()//O(N)
{
growArray(heap.length <<
1);//heap.length * 2
}
private void growArray(int size)
{
//new array that is twice as
big
E[] newArr = (E[])new
Comparable[size];
//Move values to new array
for(int i = 1; i <= count;
i++)//O(N)
{
newArr[i] =
heap[i];
}
//System.out.println(Arrays.toString(newArr));
heap = newArr;//replace small array
with new one
}
private int nextSize(int size)
{
return 1 <<
(Integer.toBinaryString(size).length() + 1);//2^(number of bits to
represent number)
}
}
======================================================================================================
import java.util.Arrays;
import java.util.Random;
public class A6Driver {
public static void main(String[] args) {
Random randGen = new
Random();
randGen.nextInt(10);//better timing
values
long time =
System.nanoTime();//better timing values
A6BH<Integer> heap = new
A6BH<>();
heap.insert(5);//better timing
values
int testCases = 7;
for(int i = 1; i <= testCases;
i++)
{
System.out.println("Test "+i);
int N =
(int)Math.pow(10, i);
Integer[]
randoms = new Integer[N];
time =
System.nanoTime();
for(int j = 0; j
< randoms.length; j++)
{
randoms[j] = randGen.nextInt(N)+1;
}
time =
System.nanoTime() - time;
System.out.println("Generate "+N+" Randoms: "+(time/1000000000.0)+
" seconds");
time =
System.nanoTime();
heap = new
A6BH<>(randoms);
time =
System.nanoTime() - time;
System.out.println("Bulk insert: " + (time/1000000000.0)+"
seconds");
System.out.println("Bulk insert: " + heap.getOpCount()+"
operations");
time =
System.nanoTime();
heap = new
A6BH<>();
for(int j = 0; j
< randoms.length; j++)
{
heap.insert(randoms[j]);
}
time =
System.nanoTime() - time;
System.out.println("Individual insert: " + (time/1000000000.0)+"
seconds");
System.out.println("Individual insert: " + heap.getOpCount()+"
operations");
System.out.println();
}
}
}
In: Computer Science
DNS Query and Web Page Access Time:
Suppose you click on a hyperlink on a webpage you are currently viewing -- this causes a new web page to be loaded and displayed. Suppose the IP address for the host in the new URL is not cached in your local DNS server (AKA local name server), so your Client (browser) makes a DNS query to obtain the IP address before the page can be requested from the web server.
To resolve the DNS (obtain the IP Address for the web server), three separate DNS servers are queried (local DNS Name Server, TLD1 and Authoritative NS). Finally, the local name server returns the IP address of the web server to the Client and the DNS is resolved. The round trip times (RTT) to reach the DNS servers are: RTT0 = 3 msec, RTT1 =40 msec and RTT2 = 20 msec.
The requested Web page contains a base HTML page and no objects. RTTHTTP = 60msec is the time to send an HTTP request to the Web Server hosting the webpage and receive a response is. In other words, it takes 60msecs for the Client to fetch a web page/object from the web server. (Note: RTT = Round Trip Time = the time to send request and receive a response – inclusive, both directions).
Authoritative NS TLD1
With respect to the above information, answer the following questions:
A. DNS
a. Make a list describing in words (not numbers) each step in the DNS resolution:
What does the Client have at the end of this query?
Local Name Server
b. How much time in total is spent on the DNS query (show your numbers)?
B. Accessing the Web Page
c. Now that the client has the IP address of the web server, what
step must the Client do before
sending the HTTP request? How long does this step take?
How long does it take to retrieve the base web page from the web server? (include step c)
How much total time IN TOTAL elapses from the instant the client first clicks on the hyperlink until the web page is displayed? This time includes (b),(c) and (d). (Assume 0 seconds transmission time for the web page – makes the problem easier, but not really true for large files!)
C. New Page / New Objects
Now suppose you request another page on the same web server: a base HTML page and 4 small objects. Neglecting transmission time, how much time elapses from the instant the new link is clicked until the entire page can be displayed? Assume the local DNS server has cached the IP address of the web server. Show your work. Assume persistent connection and pipelining.
In: Computer Science
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following:
Read through the "Lesson: Object-Oriented Programming Concepts" on The Java™ Tutorials website.
Download the linked Bicycle class, or cut-and-paste it at the top of a new Java™ project named BicycleDemo.
Download the linked BicycleDemo class, or cut-and-paste it beneath the Bicycle class in the BicycleDemo.java file.
Optionally, review this week's Individual "Week One Analyze Assignment," to refresh your understanding of how to code derived classes.
Adapt the Bicycle class by cutting and pasting the class into the NetBeans editor and completing the following:
Using the NetBeans editor, adapt the BicycleDemo class as follows:
Comment each line of code you add to explain what you added and why. Be sure to include a header comment that includes the name of the program, your name, PRG/421, and the date.
Rename your JAVA file to have a .txt file extension.
Submit your TXT file.
*******************CODE**************************
class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println("cadence:" + cadence + " speed:" + speed + " gear:" + gear); } }
***********************************SECOND CLASS********************************************
class BicycleDemo { public static void main(String[] args) { // Create two different // Bicycle objects Bicycle bike1 = new Bicycle(); Bicycle bike2 = new Bicycle(); // Invoke methods on // those objects bike1.changeCadence(50); bike1.speedUp(10); bike1.changeGear(2); bike1.printStates(); bike2.changeCadence(50); bike2.speedUp(10); bike2.changeGear(2); bike2.changeCadence(40); bike2.speedUp(10); bike2.changeGear(3); bike2.printStates(); } }
In: Computer Science
im applying for a customer service clerk job as a student who just graduated college please send an example on how to do this.
In: Operations Management
This case is based entirely on hypothetical information –please use only the information in the case and do not use any information about the products/brands through other sources. Ensure that you study Chapter 2 of the textbook for the BCG Growth Share Matrix and Diversification Analysis/Market Product strategies and Matrix. Please do internet based research to understand the concepts of Harvest, Invest, and Divest)
The firm Johnson-Evinrude Inc (or JE, to keep it short) has been in existence for more than two decades. However it is confronted by a changing technological and market environment.
While it is well known for the manufacture and sale of two stroke boat motors that have enjoyed a positive reputation, it is now facing increasing competition from four stroke boat motors. In terms of market growth the highest growth rates are being experienced for four stroke-high horse power motors; Johnson is testing motors of this type but their products seem to have multiple defects. The same type of motors of Japanese brands are flawless. It is true that in traditional two-stroke high horse power motors Johnson has a high market share –almost 65%, but this type of motor has almost no growth in the industry as a whole.
In the low horse power, 2 stroke market Johnsons share is minor and in the industry it is low horse power four stroke motors that have a rapidly growing market. JE do not have any of their own products in this category. Many Chinese manufacturers make these as generic unbranded products and the Chinese products are of low cost and good quality
JE has also been marketing trolling electric motors. The JE design is very well regarded in industry and with fishing gaining popularity as a sport trolling motors is a growth area. However, Johnson’s share is not as high as it could be because of inexpensive Chinese substitutes. While the Chinese products take advantage of lower manufacturing costs they lack the design sophistication of JE products.
Questions: Discuss the above from the perspective of :
1. Product portfolio management (the BCG or Growth Share Matrix approach)-for this classify the different types of motors in terms of the BCG Matrix – Rate of Growth of the Industry and Market Share of the Firm; Cash Cows, Dogs, Stars, Question Marks; make sure that you do this for every type and category of motor.
2. Try to analyze the portfolio/different motor categories in terms of the diversification or product –market matrix
3. Make suggestions for the overall marketing strategy for JE. You may like to ‘classify’ products (whether current or planned) and then develop your approach for them.
4. Discuss the possible problems that the comp
In: Operations Management
Review Question 9 in Chapter 12 of the textbook.
The Company you work for is in the process of determining whether to have an information security audit (ISA) performed. Even though the Company is not (yet) required to have an ISA for compliance purposes with laws, rules, and/or regulations, they are very aware of the benefits such audit can provide. However, they also know how pricy these specialized audits are. Would you be inclined to advise your Company go through such type of audit, yes or no? Explain your position.
Response parameters:
The initial post should be between 250 and 350 words
The initial post must demonstrate effective communication skills and analysis that is thoughtful and objective
You must support your responses by searching beyond the chapter (i.e., IT literature and/or any other valid external source). Include examples, as appropriate, to evidence your case point
Use APA formatting (including working web links) to cite all of your sources
Plagiarism
You are expected to write primarily in your own voice, using paraphrase, summary, and synthesis techniques when integrating information from class and outside sources. Use an author’s exact words only when the language is especially vivid, unique, or needed for technical accuracy. Failure to do so may result in charges of Academic Dishonesty.
Overusing an author’s exact words, such as including block quotations to meet word counts, may lead your readers to conclude that you lack appropriate comprehension of the subject matter or that you are neither an original thinker nor a skillful writer.
In: Operations Management
a) A car is driven along a curve at a speed of 38 m/s. If the car
In: Physics
The purpose of creating an abstract class is to model an abstract situation.
Example:
You work for a company that has different types of customers: domestic, international, business partners, individuals, and so on. It well may be useful for you to "abstract out" all the information that is common to all of your customers, such as name, customer number, order history, etc., but also keep track of the information that is specific to different classes of customer. For example, you may want to keep track of additional information for international customers so that you can handle exchange rates and customs-related activities, or you may want to keep track of additional tax-, company-, and department-related information for business customers.
Modeling all these customers as one abstract class ("Customer") from which many specialized customer classes derive or inherit ("InternationalCustomer," "BusinessCustomer," etc.) will allow you to define all of that information your customers have in common and put it in the "Customer" class, and when you derive your specialized customer classes from the abstract Customer class you will be able to reuse all of those abstract data/methods.This approach reduces the coding you have to do which, in turn, reduces the probability of errors you will make. It also allows you, as a programmer, to reduce the cost of producing and maintaining the program.
In this assignment, you will analyze Java™ code that declares one abstract class and derives three concrete classes from that one abstract class. You will read through the code and predict the output of the program.
Read through the linked Java™ code carefully.
Predict the result of running the Java™ code. Write your prediction into a Microsoft® Word document, focusing specifically on what text you think will appear on the console after running the Java™ code.
In the same Word document, answer the following question:
CODE:
/**********************************************************************
* Program: PRG/421 Week 1 Analyze Assignment
* Purpose: Analyze the coding for an abstract class
* and two derived classes, including overriding methods
* Programmer: Iam A. Student
* Class: PRG/421r13, Java Programming II
* Instructor:
* Creation Date: December 13, 2017
*
* Comments:
* Notice that in the abstract Animal class shown here, one method is
* concrete (the one that returns an animal's name) because all animals can
* be presumed to have a name. But one method, makeSound(), is declared as
* abstract, because each concrete animal must define/override the makeSound() method
* for itself--there is no generic sound that all animals make.
**********************************************************************/
package mytest;
// Animal is an abstract class because "animal" is conceptual
// for our purposes. We can't declare an instance of the Animal class,
// but we will be able to declare an instance of any concrete class
// that derives from the Animal class.
abstract class Animal {
// All animals have a name, so store that info here in the superclass.
// And make it private so that other programmers have to use the
// getter method to access the name of an animal.
private final String animalName;
// One-argument constructor requires a name.
public Animal(String aName) {
animalName = aName;
}
// Return the name of the animal when requested to do so via this
// getter method, getName().
public String getName() {
return animalName;
}
// Declare the makeSound() method abstract, as we have no way of knowing
// what sound a generic animal would make (in other words, this
// method MUST be defined differently for each type of animal,
// so we will not define it here--we will just declare a placeholder
// method in the animal superclass so that every class that derives from
// this superclass will need to provide an override method
// for makeSound()).
public abstract String makeSound();
};
// Create a concrete subclass named "Dog" that inherits from Animal.
// Because Dog is a concrete class, we can instantiate it.
class Dog extends Animal {
// This constructor passes the name of the dog to
// the Animal superclass to deal with.
public Dog(String nameOfDog) {
super(nameOfDog);
}
// This method is Dog-specific.
@Override
public String makeSound() {
return ("Woof");
}
}
// Create a concrete subclass named "Cat" that inherits from Animal.
// Because Cat is a concrete class, we can instantiate it.
class Cat extends Animal {
// This constructor passes the name of the cat on to the Animal
// superclass to deal with.
public Cat(String nameOfCat) {
super(nameOfCat);
}
// This method is Cat-specific.
@Override
public String makeSound() {
return ("Meow");
}
}
class Bird extends Animal {
// This constructor passes the name of the bird on to the Animal
// superclass to deal with.
public Bird (String nameOfBird) {
super(nameOfBird);
}
// This method is Bird-specific.
@Override
public String makeSound() {
return ("Squawk");
}
}
public class MyTest {
public static void main(String[] args) {
// Create an instance of the Dog class, passing it the name "Spot."
// The variable aDog that we create is of type Animal.
Animal aDog = new Dog("Spot");
// Create an instance of the Cat class, passing it the name "Fluffy."
// The variable aCat that we create is of type Animal.
Animal aCat = new Cat("Fluffy");
// Create an instance of (instantiate) the Bird class.
Animal aBird = new Bird("Tweety");
//Exercise two different methods of the aDog instance:
// 1) getName() (which was defined in the abstract Animal class)
// 2) makeSound() (which was defined in the concrete Dog class)
System.out.println("The dog named " + aDog.getName() + " will make this sound: " + aDog.makeSound());
//Exercise two different methods of the aCat instance:
// 1) getName() (which was defined in the abstract Animal class)
// 2) makeSound() (which was defined in the concrete Cat class)
System.out.println("The cat named " + aCat.getName() + " will make this sound: " + aCat.makeSound());
System.out.println("The bird named " + aBird.getName() + " will make this sound: " + aBird.makeSound());
}
}
In: Computer Science
Select 5 international brands and make a swot analysis.word count should be 4000 words.please dont copy.ill check the plagiarism.Can u please do it fast.
In: Operations Management
a) Determine whether or not the following nuclide is likely to be stable: Hg-199. Why
b) Determine whether or not the following nuclide is likely to be stable: Y-88. Why?
In: Chemistry
How to print output vertically in the code attached below:
import operator with open ('The Boy .txt',encoding='utf8') as my_file: contents=my_file.read() l = contents.strip() words = l.split() newdict = dict() for i in words: if i in newdict: newdict[i] = newdict[i] + 1 else: newdict[i] = 1 newly = dict() sorted_Dict = sorted(newdict.items(), key=operator.itemgetter(1), reverse=True) for n in sorted_Dict: newly[n[0]] = n[1] print(newly) with open('freqs.txt','w', encoding='utf8') as final: final.write(str(newly))
In: Computer Science
Let T : V → V be a linear map. A vector v ∈ V is called a fixed point of T if Tv = v. For example, 0 is a fixed point for every linear map T. Show that 1 is an eigenvalue of T if and only if T has nonzero fixed points, and that these nonzero fixed points are the eigenvectors of T corresponding to eigenvalue 1
In: Advanced Math
Demand for oil changes at Garcia's Garage has been as follows:
Month |
Number of Oil Changes |
January |
47 |
February |
41 |
March |
63 |
April |
47 |
May |
57 |
June |
44 |
July |
52 |
August |
71 |
a. Use simple linear regression analysis to develop a forecasting model for monthly demand. In this application, the dependent variable, Y, is monthly demand and the independent variable, X, is the month. For January, let
Xequals=1;
for February, let
Xequals=2;
and so on.
The forecasting model is given by the equation
Yequals=nothingplus+nothingX.
(Enter your responses rounded to two decimal places.)
In: Operations Management
using c language:
Add two vectors of doubles. Name this function vect_add(). Subtract two vectors of doubles. Name this function vect_sub(). Multiplies element by element two vectors. Name this function vect_prod(). Compute and return the dot product of two vectors. Name this function vect_dot_prod(). The dot product operation is the result of taking two vectors(single dimension arrays) and multiplying corresponding element by element and then adding up the sum of all the products. For example, if I have 2 vectors of length 3 that have the following values {l, 2, 3} and {3, 2, l} the dot product of these two vectors is: 1*3+2*2+3*1 = 10 Compute and return the mean of a single vector. Name this function vect_mean(). Compute and return the median of a single vector. Name this function vect_median(). First sort the array. If the length of the sorted array is odd, then the median is the middle element. If the length is odd, the median is the average of the middle two elements. Compute and return the maximum element of a vector. Name this function vect_max(). Compute and return the minimum element of a vector. Name this function vect_min(). Write a function that reverses the elements in a given array. This function will change the original array, passed by reference. Name this function vect_reverse().
In: Computer Science