SlideShare a Scribd company logo
1 of 23
1
Part I: written exercises.
1. Using the Red-Black Tree applet, you input the following
numbers into the Red-Black tree, keep all red-black rules ( see
the red-black rule on the bottom of the exercise ) either using
color changes or rotation. The result graph should be height
balance and red-black correct.
You need to follow the rules, randomly color change and
rotation will result in zero credit even the result could be red-
black correct.
Attach your results of screen shots for every question.
a. Insert 50, 70, 20, 90
b. Insert 50, 70, 20, 90, 99
c. Insert 50, 70, 20, 90, 80
d. Insert 50, 70, 20, 80, 60, 90, 75, 95
e. Insert 50, 70, 20, 90, 60, 55, 65, 68
Red-Black Rules
When inserting (or deleting) a new node, certain rules, which
we call the red-black rules, must be followed. If they’re
followed, the tree will be balanced. Let’s lookbriefly at these
rules:
1. Every node is either red or black.
2. The root is always black.
3. If a node is red, its children must be black (although the
converse isn’t necessarily true).
4. Every path from the root to a leaf, or to a null child, must
contain the same
number of black nodes.
2. Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and
a hash function h(x) = x %10 (table size is 10), showing the
resulting
a. Separate chaining hash table
b. Open addressing hash table using linear probing.
c. Open addressing hash table using quadratic probing.
d. Open addressing hash table with second hash function h2(x)
= 7- (x %7)
3. Draw the figures to show steps how to convert the binary tree
to a heap using the Heapify algorithm.
(
4
5
2
6
7
3
1
)
4. Using the diagrams (see the attached example of heap sort) to
trace the action of heapsort on the list of 1, 7, 2, 6, 3, 5, 4, give
every state of your tree such as finishing a heapify or removing
the root.
Part II: programming exercise
Implement the PriorityQ class in the priorityQ.java program
(Listing 4.6) using
a heap instead of an array. You should be able to use the Heap
class in the
heap.java program (Listing 12.1) without modification. Make it
a descending
queue (largest item is removed).
Listing 4.6
The priorityQ.java Program
// priorityQ.java
// demonstrates priority queue
// to run this program: C>java PriorityQApp
////////////////////////////////////////////////////////////////
class PriorityQ
{
// array in sorted order, from max at 0 to min at size-1
private int maxSize;
private long[] queArray;
private int nItems;
//-------------------------------------------------------------
public PriorityQ(int s) // constructor
{
maxSize = s;
queArray = new long[maxSize];
nItems = 0;
}
//-------------------------------------------------------------
public void insert(long item) // insert item
{
int j;
if(nItems==0) // if no items,
queArray[nItems++] = item; // insert at 0
else // if items,
{
for(j=nItems-1; j>=0; j--) // start at end,
{
if( item > queArray[j] ) // if new item larger,
queArray[j+1] = queArray[j]; // shift upward
else // if smaller,
break; // done shifting
} // end for
queArray[j+1] = item; // insert it
nItems++;
} // end else (nItems > 0)
} // end insert()
//-------------------------------------------------------------
public long remove() // remove minimum item
{ return queArray[--nItems]; }
//-------------------------------------------------------------
public long peekMin() // peek at minimum item
{ return queArray[nItems-1]; }
//-------------------------------------------------------------
public boolean isEmpty() // true if queue is empty
{ return (nItems==0); }
//-------------------------------------------------------------
public boolean isFull() // true if queue is full
{ return (nItems == maxSize); }
//-------------------------------------------------------------
} // end class PriorityQ
////////////////////////////////////////////////////////////////
class PriorityQApp
{
public static void main(String[] args) throws IOException
{
PriorityQ thePQ = new PriorityQ(5);
thePQ.insert(30);
thePQ.insert(50);
thePQ.insert(10);
thePQ.insert(40);
thePQ.insert(20);
while( !thePQ.isEmpty() )
{
long item = thePQ.remove();
System.out.print(item + “ “); // 10, 20, 30, 40, 50
} // end while
System.out.println(“”);
} // end main()
//-------------------------------------------------------------
} // end class PriorityQApp
Listing 12.1
// heap.java
// demonstrates heaps
// to run this program: C>java HeapApp
import java.io.*;
////////////////////////////////////////////////////////////////
class Node
{
private int iData; // data item (key)
// -------------------------------------------------------------
public Node(int key) // constructor
{ iData = key; }
// -------------------------------------------------------------
public int getKey()
{ return iData; }
// -------------------------------------------------------------
public void setKey(int id)
{ iData = id; }
// -------------------------------------------------------------
} // end class Node
////////////////////////////////////////////////////////////////
class Heap
{
private Node[] heapArray;
private int maxSize; // size of array
private int currentSize; // number of nodes in array
// -------------------------------------------------------------
public Heap(int mx) // constructor
{
maxSize = mx;
currentSize = 0;
heapArray = new Node[maxSize]; // create array
}
// -------------------------------------------------------------
public boolean isEmpty()
{ return currentSize==0; }
// -------------------------------------------------------------
public boolean insert(int key)
{
if(currentSize==maxSize)
return false;
Node newNode = new Node(key);
heapArray[currentSize] = newNode;
trickleUp(currentSize++);
return true;
} // end insert()
// -------------------------------------------------------------
public void trickleUp(int index)
{
int parent = (index-1) / 2;
Node bottom = heapArray[index];
while( index > 0 &&
heapArray[parent].getKey() < bottom.getKey() )
{
heapArray[index] = heapArray[parent]; // move it down
index = parent;
parent = (parent-1) / 2;
} // end while
heapArray[index] = bottom;
} // end trickleUp()
// -------------------------------------------------------------
public Node remove() // delete item with max key
{ // (assumes non-empty list)
Node root = heapArray[0];
heapArray[0] = heapArray[--currentSize];
trickleDown(0);
return root;
} // end remove()
// -------------------------------------------------------------
public void trickleDown(int index)
{
int largerChild;
Node top = heapArray[index]; // save root
while(index < currentSize/2) // while node has at
{ // least one child,
int leftChild = 2*index+1;
int rightChild = leftChild+1;
// find larger child
if(rightChild < currentSize && // (rightChild exists?)
heapArray[leftChild].getKey() <
heapArray[rightChild].getKey())
largerChild = rightChild;
else
largerChild = leftChild;
// top >= largerChild?
if( top.getKey() >= heapArray[largerChild].getKey() )
break;
// shift child up
heapArray[index] = heapArray[largerChild];
index = largerChild; // go down
} // end while
heapArray[index] = top; // root to index
} // end trickleDown()
// -------------------------------------------------------------
public boolean change(int index, int newValue)
{
if(index<0 || index>=currentSize)
return false;
int oldValue = heapArray[index].getKey(); // remember old
heapArray[index].setKey(newValue); // change to new
if(oldValue < newValue) // if raised,
trickleUp(index); // trickle it up
else // if lowered,
trickleDown(index); // trickle it down
return true;
} // end change()
// -------------------------------------------------------------
public void displayHeap()
{
System.out.print(“heapArray: “); // array format
for(int m=0; m<currentSize; m++)
if(heapArray[m] != null)
System.out.print( heapArray[m].getKey() + “ “);
else
System.out.print( “-- “);
System.out.println();
// heap format
int nBlanks = 32;
int itemsPerRow = 1;
int column = 0;
int j = 0; // current item
String dots = “...............................”;
System.out.println(dots+dots); // dotted top line
while(currentSize > 0) // for each heap item
{
if(column == 0) // first item in row?
for(int k=0; k<nBlanks; k++) // preceding blanks
System.out.print(‘ ‘);
// display item
System.out.print(heapArray[j].getKey());
if(++j == currentSize) // done?
break;
if(++column==itemsPerRow) // end of row?
{
nBlanks /= 2; // half the blanks
itemsPerRow *= 2; // twice the items
column = 0; // start over on
System.out.println(); // new row
}
else // next item on row
for(int k=0; k<nBlanks*2-2; k++)
System.out.print(‘ ‘); // interim blanks
} // end for
System.out.println(“n”+dots+dots); // dotted bottom line
} // end displayHeap()
// -------------------------------------------------------------
} // end class Heap
////////////////////////////////////////////////////////////////
class HeapApp
{
public static void main(String[] args) throws IOException
{
int value, value2;
Heap theHeap = new Heap(31); // make a Heap; max size 31
boolean success;
theHeap.insert(70); // insert 10 items
theHeap.insert(40);
theHeap.insert(50);
theHeap.insert(20);
theHeap.insert(60);
theHeap.insert(100);
theHeap.insert(80);
theHeap.insert(30);
theHeap.insert(10);
theHeap.insert(90);
while(true) // until [Ctrl]-[C]
{
System.out.print(“Enter first letter of “);
System.out.print(“show, insert, remove, change: “);
int choice = getChar();
switch(choice)
{
case ‘s’: // show
theHeap.displayHeap();
break;
case ‘i’: // insert
System.out.print(“Enter value to insert: “);
value = getInt();
success = theHeap.insert(value);
if( !success )
System.out.println(“Can’t insert; heap full”);
break;
case ‘r’: // remove
if( !theHeap.isEmpty() )
theHeap.remove();
else
System.out.println(“Can’t remove; heap empty”);
break;
case ‘c’: // change
System.out.print(“Enter current index of item: “);
value = getInt();
System.out.print(“Enter new key: “);
value2 = getInt();
success = theHeap.change(value, value2);
if( !success )
System.out.println(“Invalid index”);
break;
default:
System.out.println(“Invalid entryn”);
} // end switch
} // end while
} // end main()
//-------------------------------------------------------------
public static String getString() throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
//-------------------------------------------------------------
public static char getChar() throws IOException
{
String s = getString();
return s.charAt(0);
}
//-------------------------------------------------------------
public static int getInt() throws IOException
{
String s = getString();
return Integer.parseInt(s);
}
//-------------------------------------------------------------
} // end class HeapApp
Brazil has long been known as a country of soccer, Carnival and
beautiful beaches, a tropical paradise where people go to get
away from it all and enjoy the sights and sounds of Rio or
Salvador. However, Brazil has recently come into the global
spotlight as a member of the BRIC which is a group of countries
projected to grow economically and become some of the most
economically powerful global agents. Brazil has seen this
economic growth over the past few decades with its tourism
industry and oil reserves. As technological advancements in
Brazil are on the rise, the country's natural resources are
quickly becoming a source of wealth which is putting this
country on the map for more reasons than one. With this rise in
popularity, the country has been offered two of the most
prestigious international events in the world: the 2014 World
Cup and the 2016 Summer Olympics, two events which are both
very costly, but would also bring a lot of attention to the
country and be a chance to let Brazil flex its new global
muscles. But just how much does an event like the world cup or
the Olympics really cost? Between a complete overhaul of
transportation systems, construction of new airports, renovation
and construction of stadiums and any number of other
necessities, the current price tag is running around one trillion
dollars at the moment according to Zimbalist (2013). But is it
really worth it? After all, what is the social cost of these
sporting events?
In June 2013, there was an uprising of Brazilians against the
outrageous government spending for these events. Brazilians
took to the streets in protest of what was being sacrificed in
order to host these events. Much as has been the global trend,
this taking to the streets has been widely televised and
criticized. Powerful images of the widening income gap in
Brazil have been everywhere and the people are demanding that
the government reconsider what it is prioritizing. Overall,
Brazilians are asking the government to think most importantly
about education, corruption and the costs of living and how all
of these are suffering at the hands of a single sporting event.
In Brazil, the literacy rate sits comfortably around 97 percent.
Education is free all the way up through university and many
students are even offered the chance to study abroad in the USA
through government partnerships. Although this may seem
idyllic, the reality is much more grim. While is is no secret that
private schools are the most prestigious schools to attend this is
because many public schools in Brazil are beyond run down,
sometimes not even having enough resources to put a floor in
the school according to the Economist (2009). Roofs leak,
students use old books and technological education falls by the
wayside. Students who attend these schools almost never get
the opportunity to attend a federal college (the most
prestigious) due to their lack of competitive edge. In an effort
to quell these tensions, the board of education has implemented
enrollment quotas for federal universities but these two are very
controversial and seem to be a temporary bandage for a very
large and serious problem. While fixing this problem is
possible, it would be very expensive. This begs the question; is
it more important to have an educated and stable population or a
very nice soccer stadium? I think the answer is obvious.
Education should always be a top priority in every country.
Brazil has also been known for its vast network of corruption.
From ex-president da Silva to the more recent Mensalão
scandal, corruption has been a constant issue in the Brazilian
government and the citizens' perception of it. Even in looking
at the enormous price tag for the current projects, Brazilians
and those watching the developments from around the world can
never be completely sure of what money is going to productive
causes and what money is lining the pockets of greedy
politicians and business men. But how can corruption be
stopped? Through legislation. And how can legislation be
passed? Through political action. And at the root of all
political action is money, the driving force. In considering this,
would it not be in the best interest of the country and the people
to invest in stopping corruption so that money might be used
more efficiently? This might even save them a significant
amount of money in the long run and even short term when it
comes to expenses for the World Cup and Olympic Games.
Finally, Brazilians are protesting the increase in the cost of
living. As the wealth of Brazil increases, so widens the income
gap. According to the Associated Press (2013)The rich are
getting richer and the poor are getting poorer. One of the main
reasons the current protests began in the first place was due to a
proposed increase to the cost of public transportation, the main
source of transportation for more than half of the population.
But the more serious problem at hand is why this disparity
exists in the first place. In fact, the reason can be found back in
education and government spending. The poor stay poor for the
same that the rich stay rich: access to education and
infrastructure. By paying more attention to and investing more
in these things the country would be setting itself up for a
country which is successful beyond the closing ceremony of the
2016 Olympic Games.
With the costs of hosting the 2014 World Cup and the 2016
Olympic Games sitting around one trillion dollars, Brazilians
are asking their government to consider their spending and how
it is affecting the people, particularly in the realms of
education, corruption and standard of living. By investing more
in these basic necessities and less in an event which will
become obsolete in 3 years, the Brazilian government can be
true to its people and invest in their futures by overhauling
these systems and making them not only more efficient, but also
more practical, Brazil will be setting its people up for a life
which promises a bright future instead of an increasing income
gap and more of the same corruption the people have been
fighting for years.
Works Cited
Associated Press."Brazil's income gap continues wide in
Brazil."Bloomberg Business Week. N.p., 16
Nov. 2011. Web. 1 July 2013.
<http://www.businessweek.com/ap/financialnews/D9R1VHPO0.
htm>.
"Brazil's poor schools: Still a lot to learn."The Economist. N.p.,
4 June 2009. Web. 1 July 2013.
<http://www.economist.com/node/13782570>.
Zimbalist, Andrew. "Can Brazil build the massive infrastructure
it needs to host the Olympics and the
World Cup?."Americas Quarterly. N.p., 2013. Web. 1 July 2013.
<http://www.americasquarterly.org/zimbalist>.
Outline for a persuasive paper
Title: Avoiding car accidents
Speaker:
Specific Purpose: To inform the audience on the dangers of
irresponsible driving and persuade them not to.
I. Introduction
A. Attention getter: What is happening in this photograph?
Answer: Wedding. Most couples have big plans for the future,
including establishing a family and investing.
B. Establishment of Ethos (credibility): Hi, my name is
………., and the couple in this photo was my friends Mike
Drauch and Laura Stevens who I grew up with. Three years ago,
in their second year of marriage, the couple was involved in a
greasy road accident. The couple was hit by an over speeding
car as it was crossing an intersection on foot.
C. Thematic Statement: So today I want to tell you about the
dangers of irresponsible driving and persuade you not to do it. I
will tell you how you can prevent what happened to Mike and
Laura from happening to you.
(Translation- I will tell you how responsible driving can save
your life just like Mike and Laura’s lives could have been
saved)
II. Need
A. About 1.24 million people die each year as a result of road
traffic crashes with road traffic injuries being the leading cause
of death among young people, aged 15–29 years.
B. According to the American Tracking Association, 2013, in
about 9 out of 10 clashes, the primary failure is a driver error.
Indeed, as observed from the above data, the overwhelming
majority of car accidents are caused by only human driver
factors.
C. In America, the top three causes of car accidents and car
accident deaths are impaired driving, speeding and distracted
driving.
D. Speeding is a serious offense when it comes to accidents and
deaths related to cars. The US Department of Transportation
has speculated that almost 1 in 3 car accidents has some factor
of speeding involved.
E. In 2011, the National Safety Council released a study stating
that 1.6 million crashes involved a driver distracted on a cell
phone each and every year.
F. According to World Health Organization, road traffic injuries
cause considerable economic losses to victims, their families,
and to nations as a whole. These losses arise from the cost of as
well as reduced/lost productivity for those killed or disabled by
their injuries, and for family members who need to take time off
work to care for the injured.
(Internal summary- all these show that road accidents are a
reality and if no action is taken, our economy will be headed for
a downfall)
(Transition-Now that we have explored the problem, it is
important that we provide a solution)
III. Satisfaction
A. The US needs strategies to cab the ever rising rates of road
accidents.
B. Intoxicated driving can be avoided by choosing a designated
driver or calling a taxi when it becomes apparent to you or the
people around you that driving could make you put the lives of
some people in danger.
C. Laws that establish blood alcohol concentrations (BACs) of
0.05g/dl or below are effective at reducing the number of
alcohol-related crashes. The world Health Organization
contends that enforcing sobriety checkpoints and random breath
testing can lead to reductions in alcohol-related crashes of about
20% and have shown to be very cost-effective.
D. There are speed limits posted on the American roads. Proper
rules and regulations should be designed and implemented to
ensure that the speeds are followed to the latter. By observing
the speed limits we can make the roads a safer place, especially
since the faster you go, the greater the force of impact and the
more destructive or deadly power your vehicle will have.
E. While there is little concrete evidence yet on how to reduce
distractions from mobile phone use while driving, the
government needs to be proactive. Actions that can be taken
include adopting legislative measures, launching public
awareness campaigns, and regularly collecting data on
distracted driving to better understand the nature of this
problem.
F. The increased accident rates are enough motivation as to why
these solutions should be adopted with immediate effect.
(Internal summary- all these are potential solutions to road
accidents. This means that in deed we can avoid unnecessary
deaths and injuries if we really wanted to)
(Transition-Having established that there is a solution to road
accidents, the almost immediate question is, Why should we as
Americans get involved? And what is our role as individuals?)
IV. Visualization
A. Of course we don’t want to lose any more lives in our roads.
Moreover the economic losses resulting from road accidents are
too much to bear.
B. Each one of us has a role to play. Together, we can
significantly reduce these accidents.
C. Some rules that can be implemented to cab road accidents
may seem harsh in the beginning. However, if we could
perceive the value of human life, only then can we embrace
these measures whole heartedly.
(Internal summary-It is now evident that road accidents can
actually be prevented. However, that is only if we could join
hands and work together and in corporation with all relevant
stakeholders)
(Transition to conclusion- How do we as Americans maintain a
culture of safety?)
V. Action
A. Road accidents are a reality. Every day, it continues to take
innocent lives. Unless something is done, road accidents will
continue to claim lives, our economy will continue being
adversely impacted and worse still our individual ambitions and
goals like the ones Mike and Laura had will be crashed.
B. The good thing is that there is hope. Something can be done
to end the situation. But that is only if we will embrace the
solutions explored above. By doing this, we will save lives as
well as our economy.
C. Here is Mike and Laura’s photo again. A young and happily
married couple, about to embark on the journey of a married life
and full of great adventure. Think about it
D. As drivers, let’s not compromise anybody else’s bright
future. Let’s drive responsibly.
References
American Tracking Associations, 2013. Relative
Contribution/Fault in Car-Truck Crashes.
Kostyniuk LP, Streff FM, Zakrajsek J., 2002. Identifying
Unsafe Driver Actions that Lead to Fatal Car-Truck Crashes.
Washington DC: AAA Foundation for TrafficSafety.
http://www.who.int/mediacentre/factsheets/fs358/en/
Screenshot 2014-06-24 at 11.58.57 PM.png
Screenshot 2014-06-24 at 11.58.49 PM.png
Screenshot 2014-06-24 at 11.58.36 PM.png
Screenshot 2014-06-24 at 11.56.14 PM.png
Screenshot 2014-06-24 at 11.56.02 PM.png
Brazil Protests
Introduction
· Brazil is well known as a country for fun and tourism
· Brazil has been growing economically and is part of the BRIC
· Brazil has been offered the 2014 World Cup and 2016 Summer
Olympics
· These programs have cost the country about one trillion
dollars
Protests
· June 2013 saw protests against government spending
· Brazilians think the sacrifice is to great for the small benefit
of the games
· Brazilians want the government to reconsider what they find
to be important
· “Overall, Brazilians are asking the government to think most
importantly about education, corruption and the costs of living
and how all of these are suffering at the hands of a single
sporting event.”
Education
· Brazil has a 97 percent literacy rate
· Education is free in Brazil
· There is a huge divide between public and private schools
· Many schools in Brazil are very run down and are not able to
provide students with adequate education
· This is a very serious problem and there is no solution as of
yet
· The solution will require a lot of money to fix
· Education should be a priority in every country
Corruption
· Brazil has a long history of corruption
· This has been an ongoing issue
· The money being invested in the games probably has some
deal of corruption associated with it
· by fighting this corruption more money can go back to the
people
· Corruption can be stopped through legislation
· Legislation can be passed by money
· Doing this in a timely manner can decrease further corruption
in spending for games
Cost of Living
· Income gap is huge and increasing
· Brazil should be concerned with setting itself up for success
even after the games
Conclusion
· Government needs to consider how this spending is affecting
the people and what they are giving up to have these games
· Investing in people is a better long term strategy
Works Cited
Associated Press."Brazil's income gap continues wide in
Brazil."Bloomberg Business Week. N.p., 16
Nov. 2011. Web. 1 July 2013.
<http://www.businessweek.com/ap/financialnews/D9R1VHPO0.
htm>.
"Brazil's poor schools: Still a lot to learn."The Economist. N.p.,
4 June 2009. Web. 1 July 2013.
<http://www.economist.com/node/13782570>.
Zimbalist, Andrew. "Can Brazil build the massive infrastructure
it needs to host the Olympics and the
World Cup?."Americas Quarterly. N.p., 2013. Web. 1 July 2013.
<http://www.americasquarterly.org/zimbalist>.

More Related Content

Similar to 1 Part I written exercises.1. Using the Red-Black Tre.docx

Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
fashiongallery1
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
aromanets
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
hendriciraida
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
admin463580
 
T sql denali code Day of .Net
T sql denali code Day of .NetT sql denali code Day of .Net
T sql denali code Day of .Net
KathiK58
 
ContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docxContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docx
dickonsondorris
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
Kenny Gryp
 

Similar to 1 Part I written exercises.1. Using the Red-Black Tre.docx (20)

Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
 
React table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilterReact table tutorial project setup, use table, and usefilter
React table tutorial project setup, use table, and usefilter
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Php my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.netPhp my sql - functions - arrays - tutorial - programmerblog.net
Php my sql - functions - arrays - tutorial - programmerblog.net
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
I need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docxI need help with implementing the priority queue data structure with a.docx
I need help with implementing the priority queue data structure with a.docx
 
TP2 Big Data HBase
TP2 Big Data HBaseTP2 Big Data HBase
TP2 Big Data HBase
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
What is new in java 8 concurrency
What is new in java 8 concurrencyWhat is new in java 8 concurrency
What is new in java 8 concurrency
 
Mapfilterreducepresentation
MapfilterreducepresentationMapfilterreducepresentation
Mapfilterreducepresentation
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
 
T sql denali code Day of .Net
T sql denali code Day of .NetT sql denali code Day of .Net
T sql denali code Day of .Net
 
Java Generics
Java GenericsJava Generics
Java Generics
 
ContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docxContentsCOSC 2436 – LAB4TITLE .............................docx
ContentsCOSC 2436 – LAB4TITLE .............................docx
 
Reducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQLReducing Risk When Upgrading MySQL
Reducing Risk When Upgrading MySQL
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 

More from mercysuttle

1 Question Information refinement means taking the system requi.docx
1 Question Information refinement means taking the system requi.docx1 Question Information refinement means taking the system requi.docx
1 Question Information refinement means taking the system requi.docx
mercysuttle
 
1 R120V11Vac0Vdc R2100VC13mE.docx
1 R120V11Vac0Vdc R2100VC13mE.docx1 R120V11Vac0Vdc R2100VC13mE.docx
1 R120V11Vac0Vdc R2100VC13mE.docx
mercysuttle
 
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
mercysuttle
 
1 Politicking is less likely in organizations that have· adecl.docx
1 Politicking is less likely in organizations that have· adecl.docx1 Politicking is less likely in organizations that have· adecl.docx
1 Politicking is less likely in organizations that have· adecl.docx
mercysuttle
 
1 page2 sourcesReflect on the important performance management.docx
1 page2 sourcesReflect on the important performance management.docx1 page2 sourcesReflect on the important performance management.docx
1 page2 sourcesReflect on the important performance management.docx
mercysuttle
 
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
mercysuttle
 
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
mercysuttle
 
1 Objectives Genetically transform bacteria with for.docx
1 Objectives Genetically transform bacteria with for.docx1 Objectives Genetically transform bacteria with for.docx
1 Objectives Genetically transform bacteria with for.docx
mercysuttle
 
1 of 8 Student name ……………. St.docx
1 of 8 Student name …………….               St.docx1 of 8 Student name …………….               St.docx
1 of 8 Student name ……………. St.docx
mercysuttle
 
1 MATH 106 QUIZ 4 Due b.docx
1 MATH 106 QUIZ 4                                 Due b.docx1 MATH 106 QUIZ 4                                 Due b.docx
1 MATH 106 QUIZ 4 Due b.docx
mercysuttle
 
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
mercysuttle
 
1 NAME__________________ EXAM 1 Directi.docx
1 NAME__________________ EXAM 1  Directi.docx1 NAME__________________ EXAM 1  Directi.docx
1 NAME__________________ EXAM 1 Directi.docx
mercysuttle
 
1 Name .docx
1 Name                                                 .docx1 Name                                                 .docx
1 Name .docx
mercysuttle
 
1 Lab 3 Newton’s Second Law of Motion Introducti.docx
1 Lab 3 Newton’s Second Law of Motion  Introducti.docx1 Lab 3 Newton’s Second Law of Motion  Introducti.docx
1 Lab 3 Newton’s Second Law of Motion Introducti.docx
mercysuttle
 
1 Marks 2 A person can be prosecuted for both an attempt and .docx
1 Marks 2 A person can be prosecuted for both an attempt and .docx1 Marks 2 A person can be prosecuted for both an attempt and .docx
1 Marks 2 A person can be prosecuted for both an attempt and .docx
mercysuttle
 
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
mercysuttle
 
1 List of Acceptable Primary Resources for the Week 3 .docx
1 List of Acceptable Primary Resources for the Week 3 .docx1 List of Acceptable Primary Resources for the Week 3 .docx
1 List of Acceptable Primary Resources for the Week 3 .docx
mercysuttle
 

More from mercysuttle (20)

1 Question Information refinement means taking the system requi.docx
1 Question Information refinement means taking the system requi.docx1 Question Information refinement means taking the system requi.docx
1 Question Information refinement means taking the system requi.docx
 
1 pageApaSourcesDiscuss how an organization’s marketing i.docx
1 pageApaSourcesDiscuss how an organization’s marketing i.docx1 pageApaSourcesDiscuss how an organization’s marketing i.docx
1 pageApaSourcesDiscuss how an organization’s marketing i.docx
 
1 R120V11Vac0Vdc R2100VC13mE.docx
1 R120V11Vac0Vdc R2100VC13mE.docx1 R120V11Vac0Vdc R2100VC13mE.docx
1 R120V11Vac0Vdc R2100VC13mE.docx
 
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
1 PSYC499SeniorCapstoneTheImpactoftheSocial.docx
 
1 Politicking is less likely in organizations that have· adecl.docx
1 Politicking is less likely in organizations that have· adecl.docx1 Politicking is less likely in organizations that have· adecl.docx
1 Politicking is less likely in organizations that have· adecl.docx
 
1 page2 sourcesReflect on the important performance management.docx
1 page2 sourcesReflect on the important performance management.docx1 page2 sourcesReflect on the important performance management.docx
1 page2 sourcesReflect on the important performance management.docx
 
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
1 of 402.5 PointsUse Cramer’s Rule to solve the following syst.docx
 
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx1 of 6  LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
1 of 6 LAB 5 IMAGE FILTERING ECE180 Introduction to.docx
 
1 Objectives Genetically transform bacteria with for.docx
1 Objectives Genetically transform bacteria with for.docx1 Objectives Genetically transform bacteria with for.docx
1 Objectives Genetically transform bacteria with for.docx
 
1 of 8 Student name ……………. St.docx
1 of 8 Student name …………….               St.docx1 of 8 Student name …………….               St.docx
1 of 8 Student name ……………. St.docx
 
1 MATH 106 QUIZ 4 Due b.docx
1 MATH 106 QUIZ 4                                 Due b.docx1 MATH 106 QUIZ 4                                 Due b.docx
1 MATH 106 QUIZ 4 Due b.docx
 
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
1 MN6003 Levis Strauss Case Adapted from Does Levi St.docx
 
1 NAME__________________ EXAM 1 Directi.docx
1 NAME__________________ EXAM 1  Directi.docx1 NAME__________________ EXAM 1  Directi.docx
1 NAME__________________ EXAM 1 Directi.docx
 
1 Name .docx
1 Name                                                 .docx1 Name                                                 .docx
1 Name .docx
 
1 pageapasources2Third Party LogisticsBriefly describe .docx
1 pageapasources2Third Party LogisticsBriefly describe .docx1 pageapasources2Third Party LogisticsBriefly describe .docx
1 pageapasources2Third Party LogisticsBriefly describe .docx
 
1 Pageapasources2Review the Food Environment Atlas maps for.docx
1 Pageapasources2Review the Food Environment Atlas maps for.docx1 Pageapasources2Review the Food Environment Atlas maps for.docx
1 Pageapasources2Review the Food Environment Atlas maps for.docx
 
1 Lab 3 Newton’s Second Law of Motion Introducti.docx
1 Lab 3 Newton’s Second Law of Motion  Introducti.docx1 Lab 3 Newton’s Second Law of Motion  Introducti.docx
1 Lab 3 Newton’s Second Law of Motion Introducti.docx
 
1 Marks 2 A person can be prosecuted for both an attempt and .docx
1 Marks 2 A person can be prosecuted for both an attempt and .docx1 Marks 2 A person can be prosecuted for both an attempt and .docx
1 Marks 2 A person can be prosecuted for both an attempt and .docx
 
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
1 Marks 1 Post Traumatic Stress Disorder (PTSD)Choose one .docx
 
1 List of Acceptable Primary Resources for the Week 3 .docx
1 List of Acceptable Primary Resources for the Week 3 .docx1 List of Acceptable Primary Resources for the Week 3 .docx
1 List of Acceptable Primary Resources for the Week 3 .docx
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

1 Part I written exercises.1. Using the Red-Black Tre.docx

  • 1. 1 Part I: written exercises. 1. Using the Red-Black Tree applet, you input the following numbers into the Red-Black tree, keep all red-black rules ( see the red-black rule on the bottom of the exercise ) either using color changes or rotation. The result graph should be height balance and red-black correct. You need to follow the rules, randomly color change and rotation will result in zero credit even the result could be red- black correct. Attach your results of screen shots for every question. a. Insert 50, 70, 20, 90 b. Insert 50, 70, 20, 90, 99 c. Insert 50, 70, 20, 90, 80 d. Insert 50, 70, 20, 80, 60, 90, 75, 95 e. Insert 50, 70, 20, 90, 60, 55, 65, 68 Red-Black Rules When inserting (or deleting) a new node, certain rules, which we call the red-black rules, must be followed. If they’re followed, the tree will be balanced. Let’s lookbriefly at these rules: 1. Every node is either red or black.
  • 2. 2. The root is always black. 3. If a node is red, its children must be black (although the converse isn’t necessarily true). 4. Every path from the root to a leaf, or to a null child, must contain the same number of black nodes. 2. Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x %10 (table size is 10), showing the resulting a. Separate chaining hash table b. Open addressing hash table using linear probing. c. Open addressing hash table using quadratic probing. d. Open addressing hash table with second hash function h2(x) = 7- (x %7) 3. Draw the figures to show steps how to convert the binary tree to a heap using the Heapify algorithm. ( 4 5 2 6 7 3 1
  • 3. ) 4. Using the diagrams (see the attached example of heap sort) to trace the action of heapsort on the list of 1, 7, 2, 6, 3, 5, 4, give every state of your tree such as finishing a heapify or removing the root. Part II: programming exercise Implement the PriorityQ class in the priorityQ.java program (Listing 4.6) using a heap instead of an array. You should be able to use the Heap class in the heap.java program (Listing 12.1) without modification. Make it a descending queue (largest item is removed). Listing 4.6 The priorityQ.java Program // priorityQ.java // demonstrates priority queue // to run this program: C>java PriorityQApp //////////////////////////////////////////////////////////////// class PriorityQ {
  • 4. // array in sorted order, from max at 0 to min at size-1 private int maxSize; private long[] queArray; private int nItems; //------------------------------------------------------------- public PriorityQ(int s) // constructor { maxSize = s; queArray = new long[maxSize]; nItems = 0; } //------------------------------------------------------------- public void insert(long item) // insert item { int j; if(nItems==0) // if no items, queArray[nItems++] = item; // insert at 0 else // if items, { for(j=nItems-1; j>=0; j--) // start at end, { if( item > queArray[j] ) // if new item larger, queArray[j+1] = queArray[j]; // shift upward else // if smaller, break; // done shifting } // end for queArray[j+1] = item; // insert it nItems++; } // end else (nItems > 0) } // end insert() //------------------------------------------------------------- public long remove() // remove minimum item { return queArray[--nItems]; } //------------------------------------------------------------- public long peekMin() // peek at minimum item { return queArray[nItems-1]; }
  • 5. //------------------------------------------------------------- public boolean isEmpty() // true if queue is empty { return (nItems==0); } //------------------------------------------------------------- public boolean isFull() // true if queue is full { return (nItems == maxSize); } //------------------------------------------------------------- } // end class PriorityQ //////////////////////////////////////////////////////////////// class PriorityQApp { public static void main(String[] args) throws IOException { PriorityQ thePQ = new PriorityQ(5); thePQ.insert(30); thePQ.insert(50); thePQ.insert(10); thePQ.insert(40); thePQ.insert(20); while( !thePQ.isEmpty() ) { long item = thePQ.remove(); System.out.print(item + “ “); // 10, 20, 30, 40, 50 } // end while System.out.println(“”); } // end main() //------------------------------------------------------------- } // end class PriorityQApp Listing 12.1
  • 6. // heap.java // demonstrates heaps // to run this program: C>java HeapApp import java.io.*; //////////////////////////////////////////////////////////////// class Node { private int iData; // data item (key) // ------------------------------------------------------------- public Node(int key) // constructor { iData = key; } // ------------------------------------------------------------- public int getKey() { return iData; } // ------------------------------------------------------------- public void setKey(int id) { iData = id; } // ------------------------------------------------------------- } // end class Node //////////////////////////////////////////////////////////////// class Heap { private Node[] heapArray; private int maxSize; // size of array private int currentSize; // number of nodes in array // ------------------------------------------------------------- public Heap(int mx) // constructor { maxSize = mx; currentSize = 0; heapArray = new Node[maxSize]; // create array } // ------------------------------------------------------------- public boolean isEmpty() { return currentSize==0; }
  • 7. // ------------------------------------------------------------- public boolean insert(int key) { if(currentSize==maxSize) return false; Node newNode = new Node(key); heapArray[currentSize] = newNode; trickleUp(currentSize++); return true; } // end insert() // ------------------------------------------------------------- public void trickleUp(int index) { int parent = (index-1) / 2; Node bottom = heapArray[index]; while( index > 0 && heapArray[parent].getKey() < bottom.getKey() ) { heapArray[index] = heapArray[parent]; // move it down index = parent; parent = (parent-1) / 2; } // end while heapArray[index] = bottom; } // end trickleUp() // ------------------------------------------------------------- public Node remove() // delete item with max key { // (assumes non-empty list) Node root = heapArray[0]; heapArray[0] = heapArray[--currentSize]; trickleDown(0); return root; } // end remove() // ------------------------------------------------------------- public void trickleDown(int index) { int largerChild;
  • 8. Node top = heapArray[index]; // save root while(index < currentSize/2) // while node has at { // least one child, int leftChild = 2*index+1; int rightChild = leftChild+1; // find larger child if(rightChild < currentSize && // (rightChild exists?) heapArray[leftChild].getKey() < heapArray[rightChild].getKey()) largerChild = rightChild; else largerChild = leftChild; // top >= largerChild? if( top.getKey() >= heapArray[largerChild].getKey() ) break; // shift child up heapArray[index] = heapArray[largerChild]; index = largerChild; // go down } // end while heapArray[index] = top; // root to index } // end trickleDown() // ------------------------------------------------------------- public boolean change(int index, int newValue) { if(index<0 || index>=currentSize) return false; int oldValue = heapArray[index].getKey(); // remember old heapArray[index].setKey(newValue); // change to new if(oldValue < newValue) // if raised, trickleUp(index); // trickle it up else // if lowered, trickleDown(index); // trickle it down return true; } // end change() // ------------------------------------------------------------- public void displayHeap()
  • 9. { System.out.print(“heapArray: “); // array format for(int m=0; m<currentSize; m++) if(heapArray[m] != null) System.out.print( heapArray[m].getKey() + “ “); else System.out.print( “-- “); System.out.println(); // heap format int nBlanks = 32; int itemsPerRow = 1; int column = 0; int j = 0; // current item String dots = “...............................”; System.out.println(dots+dots); // dotted top line while(currentSize > 0) // for each heap item { if(column == 0) // first item in row? for(int k=0; k<nBlanks; k++) // preceding blanks System.out.print(‘ ‘); // display item System.out.print(heapArray[j].getKey()); if(++j == currentSize) // done? break; if(++column==itemsPerRow) // end of row? { nBlanks /= 2; // half the blanks itemsPerRow *= 2; // twice the items column = 0; // start over on System.out.println(); // new row } else // next item on row for(int k=0; k<nBlanks*2-2; k++) System.out.print(‘ ‘); // interim blanks } // end for System.out.println(“n”+dots+dots); // dotted bottom line
  • 10. } // end displayHeap() // ------------------------------------------------------------- } // end class Heap //////////////////////////////////////////////////////////////// class HeapApp { public static void main(String[] args) throws IOException { int value, value2; Heap theHeap = new Heap(31); // make a Heap; max size 31 boolean success; theHeap.insert(70); // insert 10 items theHeap.insert(40); theHeap.insert(50); theHeap.insert(20); theHeap.insert(60); theHeap.insert(100); theHeap.insert(80); theHeap.insert(30); theHeap.insert(10); theHeap.insert(90); while(true) // until [Ctrl]-[C] { System.out.print(“Enter first letter of “); System.out.print(“show, insert, remove, change: “); int choice = getChar(); switch(choice) { case ‘s’: // show theHeap.displayHeap(); break; case ‘i’: // insert System.out.print(“Enter value to insert: “); value = getInt(); success = theHeap.insert(value); if( !success )
  • 11. System.out.println(“Can’t insert; heap full”); break; case ‘r’: // remove if( !theHeap.isEmpty() ) theHeap.remove(); else System.out.println(“Can’t remove; heap empty”); break; case ‘c’: // change System.out.print(“Enter current index of item: “); value = getInt(); System.out.print(“Enter new key: “); value2 = getInt(); success = theHeap.change(value, value2); if( !success ) System.out.println(“Invalid index”); break; default: System.out.println(“Invalid entryn”); } // end switch } // end while } // end main() //------------------------------------------------------------- public static String getString() throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = br.readLine(); return s; } //------------------------------------------------------------- public static char getChar() throws IOException { String s = getString(); return s.charAt(0); }
  • 12. //------------------------------------------------------------- public static int getInt() throws IOException { String s = getString(); return Integer.parseInt(s); } //------------------------------------------------------------- } // end class HeapApp Brazil has long been known as a country of soccer, Carnival and beautiful beaches, a tropical paradise where people go to get away from it all and enjoy the sights and sounds of Rio or Salvador. However, Brazil has recently come into the global spotlight as a member of the BRIC which is a group of countries projected to grow economically and become some of the most economically powerful global agents. Brazil has seen this economic growth over the past few decades with its tourism industry and oil reserves. As technological advancements in Brazil are on the rise, the country's natural resources are quickly becoming a source of wealth which is putting this country on the map for more reasons than one. With this rise in
  • 13. popularity, the country has been offered two of the most prestigious international events in the world: the 2014 World Cup and the 2016 Summer Olympics, two events which are both very costly, but would also bring a lot of attention to the country and be a chance to let Brazil flex its new global muscles. But just how much does an event like the world cup or the Olympics really cost? Between a complete overhaul of transportation systems, construction of new airports, renovation and construction of stadiums and any number of other necessities, the current price tag is running around one trillion dollars at the moment according to Zimbalist (2013). But is it really worth it? After all, what is the social cost of these sporting events? In June 2013, there was an uprising of Brazilians against the outrageous government spending for these events. Brazilians took to the streets in protest of what was being sacrificed in order to host these events. Much as has been the global trend, this taking to the streets has been widely televised and criticized. Powerful images of the widening income gap in Brazil have been everywhere and the people are demanding that the government reconsider what it is prioritizing. Overall, Brazilians are asking the government to think most importantly about education, corruption and the costs of living and how all of these are suffering at the hands of a single sporting event. In Brazil, the literacy rate sits comfortably around 97 percent. Education is free all the way up through university and many students are even offered the chance to study abroad in the USA through government partnerships. Although this may seem idyllic, the reality is much more grim. While is is no secret that private schools are the most prestigious schools to attend this is because many public schools in Brazil are beyond run down, sometimes not even having enough resources to put a floor in
  • 14. the school according to the Economist (2009). Roofs leak, students use old books and technological education falls by the wayside. Students who attend these schools almost never get the opportunity to attend a federal college (the most prestigious) due to their lack of competitive edge. In an effort to quell these tensions, the board of education has implemented enrollment quotas for federal universities but these two are very controversial and seem to be a temporary bandage for a very large and serious problem. While fixing this problem is possible, it would be very expensive. This begs the question; is it more important to have an educated and stable population or a very nice soccer stadium? I think the answer is obvious. Education should always be a top priority in every country. Brazil has also been known for its vast network of corruption. From ex-president da Silva to the more recent Mensalão scandal, corruption has been a constant issue in the Brazilian government and the citizens' perception of it. Even in looking at the enormous price tag for the current projects, Brazilians and those watching the developments from around the world can never be completely sure of what money is going to productive causes and what money is lining the pockets of greedy politicians and business men. But how can corruption be stopped? Through legislation. And how can legislation be passed? Through political action. And at the root of all political action is money, the driving force. In considering this, would it not be in the best interest of the country and the people to invest in stopping corruption so that money might be used more efficiently? This might even save them a significant amount of money in the long run and even short term when it comes to expenses for the World Cup and Olympic Games. Finally, Brazilians are protesting the increase in the cost of living. As the wealth of Brazil increases, so widens the income
  • 15. gap. According to the Associated Press (2013)The rich are getting richer and the poor are getting poorer. One of the main reasons the current protests began in the first place was due to a proposed increase to the cost of public transportation, the main source of transportation for more than half of the population. But the more serious problem at hand is why this disparity exists in the first place. In fact, the reason can be found back in education and government spending. The poor stay poor for the same that the rich stay rich: access to education and infrastructure. By paying more attention to and investing more in these things the country would be setting itself up for a country which is successful beyond the closing ceremony of the 2016 Olympic Games. With the costs of hosting the 2014 World Cup and the 2016 Olympic Games sitting around one trillion dollars, Brazilians are asking their government to consider their spending and how it is affecting the people, particularly in the realms of education, corruption and standard of living. By investing more in these basic necessities and less in an event which will become obsolete in 3 years, the Brazilian government can be true to its people and invest in their futures by overhauling these systems and making them not only more efficient, but also more practical, Brazil will be setting its people up for a life which promises a bright future instead of an increasing income gap and more of the same corruption the people have been fighting for years. Works Cited Associated Press."Brazil's income gap continues wide in Brazil."Bloomberg Business Week. N.p., 16 Nov. 2011. Web. 1 July 2013. <http://www.businessweek.com/ap/financialnews/D9R1VHPO0. htm>.
  • 16. "Brazil's poor schools: Still a lot to learn."The Economist. N.p., 4 June 2009. Web. 1 July 2013. <http://www.economist.com/node/13782570>. Zimbalist, Andrew. "Can Brazil build the massive infrastructure it needs to host the Olympics and the World Cup?."Americas Quarterly. N.p., 2013. Web. 1 July 2013. <http://www.americasquarterly.org/zimbalist>. Outline for a persuasive paper Title: Avoiding car accidents Speaker: Specific Purpose: To inform the audience on the dangers of irresponsible driving and persuade them not to. I. Introduction A. Attention getter: What is happening in this photograph? Answer: Wedding. Most couples have big plans for the future, including establishing a family and investing. B. Establishment of Ethos (credibility): Hi, my name is ………., and the couple in this photo was my friends Mike Drauch and Laura Stevens who I grew up with. Three years ago, in their second year of marriage, the couple was involved in a greasy road accident. The couple was hit by an over speeding car as it was crossing an intersection on foot. C. Thematic Statement: So today I want to tell you about the dangers of irresponsible driving and persuade you not to do it. I will tell you how you can prevent what happened to Mike and Laura from happening to you. (Translation- I will tell you how responsible driving can save your life just like Mike and Laura’s lives could have been saved) II. Need A. About 1.24 million people die each year as a result of road
  • 17. traffic crashes with road traffic injuries being the leading cause of death among young people, aged 15–29 years. B. According to the American Tracking Association, 2013, in about 9 out of 10 clashes, the primary failure is a driver error. Indeed, as observed from the above data, the overwhelming majority of car accidents are caused by only human driver factors. C. In America, the top three causes of car accidents and car accident deaths are impaired driving, speeding and distracted driving. D. Speeding is a serious offense when it comes to accidents and deaths related to cars. The US Department of Transportation has speculated that almost 1 in 3 car accidents has some factor of speeding involved. E. In 2011, the National Safety Council released a study stating that 1.6 million crashes involved a driver distracted on a cell phone each and every year. F. According to World Health Organization, road traffic injuries cause considerable economic losses to victims, their families, and to nations as a whole. These losses arise from the cost of as well as reduced/lost productivity for those killed or disabled by their injuries, and for family members who need to take time off work to care for the injured. (Internal summary- all these show that road accidents are a reality and if no action is taken, our economy will be headed for a downfall) (Transition-Now that we have explored the problem, it is important that we provide a solution) III. Satisfaction A. The US needs strategies to cab the ever rising rates of road
  • 18. accidents. B. Intoxicated driving can be avoided by choosing a designated driver or calling a taxi when it becomes apparent to you or the people around you that driving could make you put the lives of some people in danger. C. Laws that establish blood alcohol concentrations (BACs) of 0.05g/dl or below are effective at reducing the number of alcohol-related crashes. The world Health Organization contends that enforcing sobriety checkpoints and random breath testing can lead to reductions in alcohol-related crashes of about 20% and have shown to be very cost-effective. D. There are speed limits posted on the American roads. Proper rules and regulations should be designed and implemented to ensure that the speeds are followed to the latter. By observing the speed limits we can make the roads a safer place, especially since the faster you go, the greater the force of impact and the more destructive or deadly power your vehicle will have. E. While there is little concrete evidence yet on how to reduce distractions from mobile phone use while driving, the government needs to be proactive. Actions that can be taken include adopting legislative measures, launching public awareness campaigns, and regularly collecting data on distracted driving to better understand the nature of this problem. F. The increased accident rates are enough motivation as to why these solutions should be adopted with immediate effect. (Internal summary- all these are potential solutions to road accidents. This means that in deed we can avoid unnecessary deaths and injuries if we really wanted to) (Transition-Having established that there is a solution to road accidents, the almost immediate question is, Why should we as
  • 19. Americans get involved? And what is our role as individuals?) IV. Visualization A. Of course we don’t want to lose any more lives in our roads. Moreover the economic losses resulting from road accidents are too much to bear. B. Each one of us has a role to play. Together, we can significantly reduce these accidents. C. Some rules that can be implemented to cab road accidents may seem harsh in the beginning. However, if we could perceive the value of human life, only then can we embrace these measures whole heartedly. (Internal summary-It is now evident that road accidents can actually be prevented. However, that is only if we could join hands and work together and in corporation with all relevant stakeholders) (Transition to conclusion- How do we as Americans maintain a culture of safety?) V. Action A. Road accidents are a reality. Every day, it continues to take innocent lives. Unless something is done, road accidents will continue to claim lives, our economy will continue being adversely impacted and worse still our individual ambitions and goals like the ones Mike and Laura had will be crashed. B. The good thing is that there is hope. Something can be done to end the situation. But that is only if we will embrace the solutions explored above. By doing this, we will save lives as well as our economy. C. Here is Mike and Laura’s photo again. A young and happily married couple, about to embark on the journey of a married life and full of great adventure. Think about it
  • 20. D. As drivers, let’s not compromise anybody else’s bright future. Let’s drive responsibly. References American Tracking Associations, 2013. Relative Contribution/Fault in Car-Truck Crashes. Kostyniuk LP, Streff FM, Zakrajsek J., 2002. Identifying Unsafe Driver Actions that Lead to Fatal Car-Truck Crashes. Washington DC: AAA Foundation for TrafficSafety. http://www.who.int/mediacentre/factsheets/fs358/en/ Screenshot 2014-06-24 at 11.58.57 PM.png Screenshot 2014-06-24 at 11.58.49 PM.png Screenshot 2014-06-24 at 11.58.36 PM.png Screenshot 2014-06-24 at 11.56.14 PM.png Screenshot 2014-06-24 at 11.56.02 PM.png Brazil Protests Introduction · Brazil is well known as a country for fun and tourism · Brazil has been growing economically and is part of the BRIC · Brazil has been offered the 2014 World Cup and 2016 Summer Olympics
  • 21. · These programs have cost the country about one trillion dollars Protests · June 2013 saw protests against government spending · Brazilians think the sacrifice is to great for the small benefit of the games · Brazilians want the government to reconsider what they find to be important · “Overall, Brazilians are asking the government to think most importantly about education, corruption and the costs of living and how all of these are suffering at the hands of a single sporting event.” Education · Brazil has a 97 percent literacy rate · Education is free in Brazil · There is a huge divide between public and private schools · Many schools in Brazil are very run down and are not able to provide students with adequate education · This is a very serious problem and there is no solution as of yet · The solution will require a lot of money to fix · Education should be a priority in every country
  • 22. Corruption · Brazil has a long history of corruption · This has been an ongoing issue · The money being invested in the games probably has some deal of corruption associated with it · by fighting this corruption more money can go back to the people · Corruption can be stopped through legislation · Legislation can be passed by money · Doing this in a timely manner can decrease further corruption in spending for games Cost of Living · Income gap is huge and increasing · Brazil should be concerned with setting itself up for success even after the games Conclusion · Government needs to consider how this spending is affecting the people and what they are giving up to have these games · Investing in people is a better long term strategy Works Cited
  • 23. Associated Press."Brazil's income gap continues wide in Brazil."Bloomberg Business Week. N.p., 16 Nov. 2011. Web. 1 July 2013. <http://www.businessweek.com/ap/financialnews/D9R1VHPO0. htm>. "Brazil's poor schools: Still a lot to learn."The Economist. N.p., 4 June 2009. Web. 1 July 2013. <http://www.economist.com/node/13782570>. Zimbalist, Andrew. "Can Brazil build the massive infrastructure it needs to host the Olympics and the World Cup?."Americas Quarterly. N.p., 2013. Web. 1 July 2013. <http://www.americasquarterly.org/zimbalist>.