List 4 different types of memories according to the hierarchy (lowest to the highest). What is the advantage and disadvantage of each one of them?
In: Computer Science
Implement a priority queue using a DoublyLinkedList
where the node with the highest priority (key) is the right-most
node.
The remove (de-queue) operation returns the node with
the highest priority (key).
If displayForward() displays List (first-->last) : 10 30 40
55
remove() would return the node with key 55.
You will then attach priorityInsert(long key) and priorityRemove() methods). AND Use the provided PQDoublyLinkedTest.java to test your code.
BOTH CODES SHOULD WORK TOGETHER, YOU JUST HAVE TO ADD priorityInsert(int). PLEASE PROVIDE CORRECT CODE.
class Link {
public long dData;
public Link next;
public Link previous;
public Link(long d) {
dData = d;
}
public void displayLink() {
System.out.print(dData + " ");
}
}
class DoublyLinkedList {
private Link first;
private Link last;
public DoublyLinkedList() {
first = null;
last = null;
}
public boolean isEmpty() {
return first == null;
}
public void insertFirst(long dd) {
Link newLink = new Link(dd);
if (isEmpty())
last = newLink;
else
first.previous = newLink;
newLink.next = first;
first = newLink;
}
public void insertLast(long dd) {
Link newLink = new Link(dd);
if (isEmpty())
first = newLink;
else {
last.next = newLink;
newLink.previous = last;
}
last = newLink;
}
public Link deleteFirst() {
Link temp = first;
if (first.next == null)
last = null;
else
first.next.previous = null;
first = first.next;
return temp;
}
public Link deleteLast() {
Link temp = last;
if (first.next == null)
first = null;
else
last.previous.next = null;
last = last.previous;
return temp;
}
public boolean insertAfter(long key, long dd) {
Link current = first;
while (current.dData != key){
current = current.next;
if (current == null)
return false;
}
Link newLink = new Link(dd);
if (current == last) {
newLink.next = null;
last = newLink;
}
else {
newLink.next = current.next;
current.next.previous = newLink;
}
newLink.previous = current;
current.next = newLink;
return true;
}
public Link deleteKey(long key) {
Link current = first;
while (current.dData != key) {
current = current.next;
if (current == null)
return null;
}
if (current == first)
first = current.next;
else
current.previous.next = current.next;
if (current == last)
last = current.previous;
else
current.next.previous = current.previous;
return current;
}
public void displayForward() {
System.out.print("List (first-->last): ");
Link current = first;
while (current != null)
{
current.displayLink();
current = current.next;
}
System.out.println("");
}
public void displayBackward() {
System.out.print("List (last-->first): ");
Link current = last;
while (current != null)
{
current.displayLink();
current = current.previous;
}
System.out.println("");
}
public void insertSorted(long key) {
if (isEmpty() || key < first.dData) {
insertFirst(key);
return;
}
Link current = first;
while (current.next != null) {
if (key >= current.dData && key <=
current.next.dData) {
Link lnk = new Link(key);
lnk.next = current.next;
current.next.previous = lnk;
current.next = lnk;
lnk.previous = current;
return;
}
current = current.next;
}
insertLast(key);
}
}
public class PriorityLinkQueue {
private DoublyLinkedList list;
public PriorityLinkQueue() {
list = new DoublyLinkedList();
}
public void insert(long key) {
list.insertSorted(key);
}
public long remove() {
if (list.isEmpty()) {
throw new RuntimeException("Priority Queue is empty!");
}
return list.deleteLast().dData;
}
public boolean isEmpty() {
return list.isEmpty();
}
public void displayForward() {
list.displayForward();
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
class PQDoublyLinkedTest.JAVA ->>> ONLY FOR TESTING, DO NOT CHANGE ANYTHING IN PQDoublyLinkedTest.JAVA
public class PQDoublyLinkedTest
{
public static void main(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.priorityInsert(22); // insert at front
theList.priorityInsert(44);
theList.priorityInsert(66);
theList.priorityInsert(11); // insert at rear
theList.priorityInsert(33);
theList.priorityInsert(55);
theList.priorityInsert(10);
theList.priorityInsert(70);
theList.priorityInsert(30);
theList.displayForward(); // display list forward
Link2 removed = theList.priorityRemove();
System.out.print("priorityRemove() returned node with key:
");
removed.displayLink2();
} // end main()
} // end class PQDoublyLinkedTest
In: Computer Science
7. As a mass tied to the end of a string swings from its highest point down to its lowest point, it is acted on by three forces: gravity, tension, and air resistance. Which force does (a) positive work? (b) negative work? (c) zero work?
In: Physics
Implement a priority queue using a DoublyLinkedList where the
node with the highest priority (key) is the right-most node.
The remove (de-queue) operation returns the node with the highest
priority (key).
If displayForward() displays List (first-->last) : 10 30 40
55
remove() would return the node with key 55.
Demonstrate by inserting keys at random, displayForward(), call
remove then displayForward() again.
You will then attach a modified DoublyLinkedList.java (to contain
the new priorityInsert(long key) and
priorityRemove() methods), and a driver to
demonstrate as shown above.
Use the provided PQDoublyLinkedTest.java to test your code.
public class PQDoublyLinkedTest
{
public static void main(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.priorityInsert(22); // insert at front
theList.priorityInsert(44);
theList.priorityInsert(66);
theList.priorityInsert(11); // insert at rear
theList.priorityInsert(33);
theList.priorityInsert(55);
theList.priorityInsert(10);
theList.priorityInsert(70);
theList.priorityInsert(30);
theList.displayForward(); // display list forward
Link2 removed = theList.priorityRemove();
System.out.print("priorityRemove() returned node with key: ");
removed.displayLink2();
} // end main()
} // end class PQDoublyLinkedTest
_____________________________________________________________________________________________________________________________________________________
// doublyLinked.java
// demonstrates doubly-linked list
// to run this program: C>java DoublyLinkedApp
class Link
{
public long dData; // data item
public Link next; // next link in list
public Link previous; // previous link in list
public Link(long d) // constructor
{ dData = d; }
public void displayLink() // display this link
{ System.out.print(dData + " "); }
} // end class Link
class DoublyLinkedList
{
private Link first; // ref to first item
private Link last; // ref to last item
public DoublyLinkedList() // constructor
{
first = null; // no items on list yet
last = null;
}
public boolean isEmpty() // true if no links
{ return first==null; }
public void insertFirst(long dd) // insert at front of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() ) // if empty list,
last = newLink; // newLink <-- last
else
first.previous = newLink; // newLink <-- old first
newLink.next = first; // newLink --> old first
first = newLink; // first --> newLink
}
public void insertLast(long dd) // insert at end of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() ) // if empty list,
first = newLink; // first --> newLink
else
{
last.next = newLink; // old last --> newLink
newLink.previous = last; // old last <-- newLink
}
last = newLink; // newLink <-- last
}
public Link deleteFirst() // delete first link
{ // (assumes non-empty list)
Link temp = first;
if(first.next == null) // if only one item
last = null; // null <-- last
else
first.next.previous = null; // null <-- old next
first = first.next; // first --> old next
return temp;
}
public Link deleteLast() // delete last link
{ // (assumes non-empty list)
Link temp = last;
if(first.next == null) // if only one item
first = null; // first --> null
else
last.previous.next = null; // old previous --> null
last = last.previous; // old previous <-- last
return temp;
}
// insert dd just after key
public boolean insertAfter(long key, long dd)
{ // (assumes non-empty list)
Link current = first; // start at beginning
while(current.dData != key) // until match is found,
{
current = current.next; // move to next link
if(current == null)
return false; // didn't find it
}
Link newLink = new Link(dd); // make new link
if(current==last) // if last link,
{
newLink.next = null; // newLink --> null
last = newLink; // newLink <-- last
}
else // not last link,
{
newLink.next = current.next; // newLink --> old next
// newLink <-- old next
current.next.previous = newLink;
}
newLink.previous = current; // old current <-- newLink
current.next = newLink; // old current --> newLink
return true; // found it, did insertion
}
public Link deleteKey(long key) // delete item w/ given key
{ // (assumes non-empty list)
Link current = first; // start at beginning
while(current.dData != key) // until match is found,
{
current = current.next; // move to next link
if(current == null)
return null; // didn't find it
}
if(current==first) // found it; first item?
first = current.next; // first --> old next
else // not first
// old previous --> old next
current.previous.next = current.next;
if(current==last) // last item?
last = current.previous; // old previous <-- last
else // not last
// old previous <-- old next
current.next.previous = current.previous;
return current; // return value
}
public void displayForward()
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginning
while(current != null) // until end of list,
{
current.displayLink(); // display data
current = current.next; // move to next link
}
System.out.println("");
}
public void displayBackward()
{
System.out.print("List (last-->first): ");
Link current = last; // start at end
while(current != null) // until start of list,
{
current.displayLink(); // display data
current = current.previous; // move to previous link
}
System.out.println("");
}
} // end class DoublyLinkedList
class DoublyLinkedApp
{
public static void main(String[] args)
{ // make a new list
DoublyLinkedList theList = new DoublyLinkedList();
theList.insertFirst(22); // insert at front
theList.insertFirst(44);
theList.insertFirst(66);
theList.insertLast(11); // insert at rear
theList.insertLast(33);
theList.insertLast(55);
theList.displayForward(); // display list forward
theList.displayBackward(); // display list backward
theList.deleteFirst(); // delete first item
theList.deleteLast(); // delete last item
theList.deleteKey(11); // delete item with key 11
theList.displayForward(); // display list forward
theList.insertAfter(22, 77); // insert 77 after 22
theList.insertAfter(33, 88); // insert 88 after 33
theList.displayForward(); // display list forward
} // end main()
} // end class DoublyLinkedApp
____________________________________________________________________________________________________________________________________________________
In: Computer Science
Chapter 17 Betty to the Rescue
—T.S. Eliot
Sometimes angels work behind the scenes in secret ways. Betty Mavis was an unsuspected angel for Supervisor Mark Armen of Glacier Hills Township. Glacier Hills was just north of the city of Westminister. Armen had been a political science professor at Ansell College in Westminister, but he was a resident of Glacier Hills, and when the opportunity present itself, he decided a tour of duty in public service was in order. He still had to get elected. Several students helped in his campaign and all were supportive. Particularly helpful was graduate student Paul Turwill. Tur-will took the lead in getting together volunteers to knock on every door in Glacier Hills. He also talked residents into having signs on their lawn. In the true sense of the word, he was a go-getter. After long summer nights of campaigning, Armen and Turwill and those students who were over 21 would gather at the Knolls Tavern to discuss their activities. Betty Mavis often came along, usually with a textbook in hand, and always with a smile.
Armen told Turwill that he would help him get a job with the township if he were to be elected and a job opening was available. The election was a success, and as it happened, the previous, outgoing supervisor had a secretary who indicated she wished to resign when her boss left office. That created an opening for a secretary. Armen approached the township clerk, another elected official who served as personnel director. Armen was told that he could choose anyone he wished to be his secretary. He brought up the possibilities of having Turwill serve instead as his assistant, but with the understanding that Turwill and Armen would take care of all of the secretarial tasks of the supervisor’s office. The clerk had no problem with that arrangement, and at the first meeting led by new Supervisor Mark Armen, the issue was placed in front of the full board, and it was discussed briefly. There was no opposition when it was established that Turwill could type and he had had some clerical work experience. Turwill was hired. He was able to continue with his master’s degree program as all his remaining classes were in the evening. He agreed not to take any class on Monday night, as that was when the township board meetings were.
Political leaders often praise the patronage system. If an official is given the power to make an appointment untied to arms-length merit considerations and open competition, it is considered a plus. This is what Mark Armen had been teaching right out of the textbooks in his political personnel classes. He had his classes read George Washington Plunkitt,1 which explained that the only way you can motivate staff is if you get to select them unhindered by rules and examinations. Patronage was the key to loyalty. When Armen the professor yielded to Armen the political leader, it didn’t seem to work out that way at all. Turwill was a big mistake. He immediately took on a lazy air. He did not show respect to other members of the staff, mostly older women who, while a bit stern in demeanor, had efficiently taken care of township business over the previous 3 decades. Stern was the nature of most workers in the community of German immigrants—many of whom were recent immigrants. Turwill was a bit sloppy in his work. Armen had to have letters retyped, and after a while just took on the task of typing his letters by himself.
Armen was outgoing and liked to joke around with citizens and students alike. He was into jogging, and would tour the township streets in his running outfit two or three mornings a week. He actually used the running to look at sites for rezoning or other issues that had come up in meetings. It was a good way to keep in touch with the citizens. He would wave and smile at constituents and even stop to chat if the occasion called for it. Some of the solid citizens took offense at this style of activity. They were especially critical when they would phone the township and ask for the supervisor only to get Turwill to answer in a sarcastic way that the supervisor was out jogging.
Armen was very concerned when some of Turwill’s college friends would stop by and have closed-door meetings with him. Armen also had an impression that Turwill and his friends would go behind the township hall and participate in recreational drug activity. Armen was well aware that many of the students on campus did drugs, and he had seen Turwill smoking on occasion. The township hall was not the place, and working hours were not the time.
A patronage appointee cannot be easily fired. This is especially the case if he or she earned the job through hard political work. This is the case when someone won an appointment through the recommendation of a close friend. A patronage appointee who knows this may use this. The patronage appointee may take on a feeling that he already paid his dues for the job and he doesn’t have to work as hard as others for their pay. Such was the case with Turwill. Armen pondered solutions, and he knew that any direct action would have costs in friendships on campus, and in respect from his township colleagues who had gone along with his judgment when Turwill was hired. The solution to the problem of Turwill was not easy. Armen’s first thought was to move him to some work outside of the township hall. Armen did let Turwill know that he could not defend him if anyone else saw him smoking marijuana about the premises, and Turwill seemed to understand the warning.
Armen thought about putting Turwill with the township work crews, but that was mostly manual labor, and Armen was not going to make Turwill a supervisor of work crews—where the workers were more skilled than he was. Fortunately the township received a neighborhood development grant for a poor area near the river—Riverdale. The grant entailed hiring crews to clean up the streets, paint houses, and conduct recreational programs. Armen put Turwill in charge of organizing teams to go to the Riverdale area and to work with them. While Turwill thought the work was a bit demeaning, he thought it was less boring that being at township hall all day. He seemed to be doing a satisfactory job in Riverdale. Armen only worried about the fall—in 2 months the Riverdale project would be over—then he would have the Tur-will project on his hands again.
Ah! The day of miracles. One day in August, Turwill came into Armen’s office with a big smile and announced that there was an opening for an assistant public works director in the city of Westminister, and the pay was 40% higher than his current salary. He asked if he should apply.
Armen put on his professor’s hat for a moment and said, “Paul, you know you are welcome here. I owe you this; I know I wouldn’t be here without your work. But the job you have here has to be considered temporary—I am here on a 2-year term; you know my job here is temporary too. You do not have a career job here; there is no career ladder. Westminister is a big city, a post like assistant public works director can have a career ladder. And I can’t raise your salary. Believe me, I know I owe you, and I know you can work hard, and I’ll let the people in Westminister know you are a good student and you can work hard. My professorial advice is simply ‘go for it.’”
Armen made a few inquiries about the position in Westminister, and he found that they wanted a person with a master’s degree and experience, and that they were conducting a national search. His brief moments of thinking that the “Paul problem” was being solved ended. On the other hand, maybe his talk with Turwill could encourage him to look for other jobs, too. But hopes dashed can be hopes revived. Two days later Turwill told the supervisor that he had made the list of ten finalists for the job at Westminister. Armen was indeed a bit dumbfounded.
The next week Turwill was invited for a personal interview. He reported back to Armen with another smile on his face. He had been the first candidate interviewed, because they were talking to people in the local area first. He related that the interview had gone extremely well. In the course of discussions about work experience Turwill had told the Westminister director of public works that he had worked on sidewalk construction crews during summers of his college years. The director asked where, and Turwill replied in Geddes, where he grew up. Geddes was a town of 10,000, forty miles to the west of Glacier Hills.
“You grew up in Geddes?” the director had exclaimed. “So did I. Turwill, your name is? Is that right?”
“Yes, Paul Turwill.”
The director asked, “Do you know Tom Turwill?”
“Of course,” Turwill replied. “That’s my father.”
“I can’t believe it. Your father, wow! You must be that little kid he brought to the class picnics,” the director said. “Your father was my best buddy all though school. The stories I won’t tell you, wow!”
And so went the interview. The director said he would call Turwill in a few days.
The next day the director called Mark Armen. Armen gave Turwill a toned-down good recommendation, but the director sensed something. He asked, “You’re not trying to get rid of him are you?”
Without giving a direct answer, Supervisor Armen repeated the essence of his conversation with Turwill. “I am also Paul’s professor at the college, and I have to reflect on what the job here means and what your job would mean for his career. You are offering a professional public administration post with career opportunities. His job here is simply more limited. He is certainly welcome to stay here, but you are presenting a real professional opportunity and he is capable of taking advantage of it and doing a good job.”
Armen worried that his line of bull might not be effective, but he let it rest, and the director thanked him for his views on Turwill. Turwill got the job.
Armen dropped into the Knolls a few weeks later and Betty Mavis strolled in, books in hand. He asked her how the term was going. She said, “This internship and one more class and I’ve got my degree.”
“Hey, great, tell me about your internship,” Armen said.
Mavis said, “You should know about my internship, you helped set it up last fall.”
Armen sort of remembered and said, “Something to do with personnel, at the county.”
“Right on personnel, but it is the personnel department with the city of Westminister, and let me tell you, I saved your friend Paul’s butt, too.”
Armen inquired as to how she had done that.
Mavis related that the applicants for the assistant public works director were on her desk, and a screening committee had selected ten for interviews. Turwill’s application was in the pile of rejected applications. Mavis said she simply took out the bottom application from the pile of ten and placed Turwill’s into the second spot. Evidently, the director just grabbed the pile of ten and sorted out the locals, and Tur-will was the first one to get an interview call. Mavis heard he had gotten the job, but she hadn’t told anyone how he got the interview. Turwill told her that she had really saved him. She said she thought so because Turwill was always complaining about his township job.
Armen had not thought about Mavis’s graduation, and Mavis had not brought up the subject. But Armen knew she was a waitress at a nice restaurant, the Great Lakes Steakhouse. Armen went into the tavern the week after graduation, and Mavis was there again. This time she was direct.
“Hey, Professor, when you going to take care of me? When do I get a job?”
Armen said, “O.K. Right now, this is your job interview.”
They went though her courses, the jobs she had held, and her skill levels.
Armen said, “Look, I never filled Paul Turwill’s job, and I told the clerk I really didn’t need an assistant, but I know we have a backlog of clerical work, and we could use some organization. You come in tomorrow, and we’ll discuss your job with the clerk.”
The next day Mavis was hired. Armen returned to teaching when his 2-year term ended. Mavis’s new job was a clerical job, but over the next 25 years she grew her position into a professional position. The word in township hall was that she made the place work. Indeed she was even recognized by the Greater Westminister Women’s Club as “Professional Woman of the Year.”
Rethinking patronage—sometimes it can work out O.K.
Questions
In: Economics
2. CEO committment is the highest weighted area of the four evaluated to select the DiversityInc top fifty companies for diversity. Leadership and governance is one of the four dimensions assessed in the Institute of Diversity in Health Management benchmarking survey. Using research findings, testimonies from experts, and logical argument, explain why leadership is key.
In: Operations Management
The goal of health insurance is to:
| 1. |
redistribute income from the sick to the healthy |
|
| 2. |
spread risk over a large group of people |
|
| 3. |
equally distribute the probability of loss over a large number of people |
|
| 4. |
collect sufficient premiums to cover all possible losses |
|
| 5. |
equalize the availability of medical care across population groups |
In: Economics
Let discrete random variable X be the number of flips of a biased coin required to get tails, where P(tails) = 1/3 .
a) Calculate the probability for every value of X from 1 to 10.
b) Sketch a plot of the p.m.f. of X for the first 10 flips.
c) Sketch a plot the c.d.f. of X for the first 10 flips.
In: Statistics and Probability
A box contains 19 large marbles and 18 small marbles. Each marble is either green or white. 9 of the large marbles are green, and 8 of the small marbles are white. If a marble is randomly selected from the box, what is the probability that it is small or green? Express your answer as a fraction or a decimal number rounded to four decimal places.
In: Statistics and Probability
The population of weekly expenditures on alcohol by students has a normal distribution with mean €20 and standard deviation €5. If 100 students will be selected at random, what approximately is the expected number who will have expenditures above €25?
ii) Refer to Questionabove. What is the probability that the mean expenditure of the sample of 100 students will fall between €19 and €20. 5?
In: Statistics and Probability