1. Theory.
The most obvious way to represent a sequence of objects is simply to list them, one after the other, like this.
|
a |
a |
b |
b |
b |
c |
a |
a |
d |
d |
d |
d |
Note that the same objects often appear many times in a row. This is called a run of those objects. In the example sequence, there is a run of 2 a’s, a run of 3 b’s, a run of 1 c, a run of 2 a’s, and a run of 4 d’s. You can represent a sequence with runs by listing its objects, along with the number of times each object appears. For example, you can represent the sequence shown above like this.
|
a |
b |
c |
a |
d |
|
2 |
3 |
1 |
2 |
4 |
Representing a sequence in this way is called run-length
encoding. If a sequence has long runs, or many runs, then
run-length encoding will represent it more efficiently than simply
listing its objects. However, if a sequence has short runs, or few
runs, then run-length encoding may represent it less
efficiently, because extra space is needed to store the lengths of
the runs.
Since a stack is just a simple kind
of sequence, you can use run-length encoding to implement it. In
this assignment, you will write a Java class called RunnyStack that
implements a stack which uses run-length encoding. Here are some
examples of how it works. Suppose you push an object a on
an empty RunnyStack. Then the stack will look like this, with a run
of 1 a.
|
a 1 |
Now suppose you push b. The stack now looks like this, with a run of 1 b, and a run of 1 a.
|
b 1 |
|
a 1 |
If you push another b on the RunnyStack, then the length of the run on top of the stack is incremented, so the stack looks like this.
|
b 2 |
|
a 1 |
If you push yet another b, then the length of the run at the top of the stack would increase to 3. However, suppose that you pop the RunnyStack instead. Then the length of the run at the top is decremented, so that the stack looks like this.
|
b 1 |
|
a 1 |
If you pop the RunnyStack one more time, then the length of the run on top of the stack is decremented to 0. However, a run of 0 objects is like no run at all, so it vanishes, and the stack looks as it did after the first push.
|
a 1 |
Stacks with run-length encoding are used internally by some compilers and interpreters, because they often push the same objects over and over again.
2. Implementation.
You must write a class called RunnyStack that represents a stack. Your class must implement run-length encoding, as described previously. It must also hold objects of type Base, so it will look like this.
class RunnyStack<Base>
{
⋮
}
Your class must define at least the following methods, as described below. To simplify grading, your methods must have the same names as the ones shown here.
public RunnyStack()
Constructor. Make a new, empty instance of RunnyStack.
public int depth()
Return the depth of the stack: the sum of the lengths of all the runs it holds. This is not necessarily the same as the number of runs it holds, which is returned by the method runs.
public boolean isEmpty()
Test if the stack is empty.
public Base peek()
If the stack is empty, then throw an IllegalStateException. Otherwise, return the Base at the top of the stack.
public void pop()
If the stack is empty, then throw an IllegalStateException. Otherwise, decrement the length of the run on top of the stack. If this leaves a run of zero Base’s on top of the stack, then remove that run.
public void push(Base base)
If the stack is empty, then add a new run of one Base at the top of the stack. If the stack is not empty, then test if base is equal to the object in the run at the top of the stack. If it is, then increment the length of that run. If it isn’t, then add a new run of one base at the top of the stack. Note that base may be null.
public int runs()
Return the number of runs in the stack. This is not necessarily the same as its depth, which is returned by the method depth.
Here are some hints, requirements, and warnings. First, all
these methods must work using O(1) operations, so they are
not allowed to use loops or recursions. You will receive no
points for this assignment if you use loops or recursions in any
way!
Second, your RunnyStack class must
have a private nested class called Run. You must use instances of
Run to implement your stack. Each instance of Run represents a run
of Base’s. You will receive no points for this assignment if
you use arrays in any way! The class Run must have three
private slots that have the following names and types. The slot
base points to the Base that appears in the run. The slot length is
an int that is the length of the run. The slot next points to the
instance of Run that is immediately below this one on the stack, or
to null. It must also have a private constructor that initializes
these slots.
Third, your push method must test
non-null Base’s for equality using their equals methods. It must
use the Java ‘==’ operator only for testing null Base’s. It is
helpful to define an extra private method called isEqual that takes
two Base’s as arguments, and tests if they are equal. If either
Base is null, then isEqual uses ‘==’. If neither Base is null, then
isEqual uses equals.
Fourth, RunnyStack’s methods are not
allowed to print things. If you were writing RunnyStack in the Real
World, then it might be part of some larger program. You don’t know
if that larger program should print things.
In: Computer Science
1.Briefly explain the Pure Expectations Hypothesis (PEH). Explain why a risk premium related to maturity is not consistent with the PEH. Is the historical empirical evidence (historical data) consistent with the PEH?
2.Define and explain Key Rate Durations. Why do we look at Key Rate Durations for portfolios only? How could two portfolios have the same weighted Modified Duration, but very different Key Rate Durations?
3.Use the following information to calculate the no arbitrage price for a Treasury note futures contract. P = 103.65, Coupon Rate = 4.50%, borrowing and lending rate = 3.00%, t = 0.35. The current quoted futures prices for the same contract is 106.20. State whether you would execute a Cash and Carry or Reverse Cash and Carry trade to create arbitrage profit. Calculate the profit per contract from the trade.
4.Explain the difference between Option Adjusted Spread (OAS) and Z-Spread (Static Spread). Separately discuss how a call and a put option impact the relationship between the two spread measures.
5.One of the key functions of a credit analyst is deriving pro forma projections for future financial data. Explain why an analyst runs a pro forma and then runs a downside or "worst case scenario".
6.Briefly explain the major differences between reduced form and structural models of default risk. Include the inputs, outputs, and uses.
In: Finance
In a tennis match, the first serve percentage is a key statistic. Having an accurate (and fast) first serve is seen as an important advantage to winning a match. Let theta be the probability of getting the first serve in on any point in a tennis game. For each of the four situations below, give a prior distribution for theta, explaining each in a sentence. You may assume the winner is determined from the best of three sets, (so the first player to win two sets will win).
(a) The point is the first point of the match.
(b) It is the beginning of the second set and the server has won the first set.
(c) It is the beginning of the second set and the server has lost the first set.
(d) If the server wins the next point, they will win the match.
In: Math
Please Explain!
An urn contains seven chips labeled 1,2,...,7. Three of the chips are black, two are red, and two are green. The chips are drawn randomly one at a time without replacement until the urn is empty. Answer both questions for i = 1,...,7.
a. What is the probability that ith draw is chip 5?
b. What is the probability that ith draw is black?
In: Statistics and Probability
Each unit of A is composed of one unit of B, two units of C, and
one unit of D. C is composed of two units of D and three units of
E. Items A, C, D, and E have on-hand inventories of 20, 10, 20, and
10 units, respectively. Item B has a scheduled receipt of 10 units
in Period 1, and C has a scheduled receipt of 50 units in Period 1.
Lot-for-lot (L4L) lot sizing is used for Items A and B. Item C
requires a minimum lot size of 50 units. D and E are required to be
purchased in multiples of 100 and 50, respectively. Lead times are
one period for Items A, B, and C, and two periods for Items D and
E. The gross requirements for A are 30 in Period 2, 30 in Period 5,
and 40 in Period 8. Find the planned-order releases for all
items.
In: Operations Management
Lower-of-Cost-or-Market Inventory
Data on the physical inventory of Katus Products Co. as of December 31 follows:
| Inventory Item |
Inventory Quantity |
Market Value per Unit (Net Realizable Value) |
||||
| A54 | 37 | $ 56 | ||||
| C77 | 24 | 178 | ||||
| F66 | 30 | 132 | ||||
| H83 | 21 | 545 | ||||
| K12 | 375 | 5 | ||||
| Q58 | 90 | 18 | ||||
| S36 | 8 | 235 | ||||
| V97 | 140 | 20 | ||||
| Y88 | 17 | 744 | ||||
Quantity and cost data from the last purchases invoice of the year and the next-to-the-last purchases invoice are summarized as follows:
| Last Purchases Invoice |
Next-to-the-Last Purchases Invoice |
||||||||||||
| Inventory Item |
Quantity Purchased |
Unit Cost |
Quantity Purchased |
Unit Cost |
|||||||||
| A54 | 30 | $ 60 | 40 | $ 58 | |||||||||
| C77 | 25 | 174 | 15 | 180 | |||||||||
| F66 | 20 | 130 | 15 | 128 | |||||||||
| H83 | 6 | 547 | 15 | 540 | |||||||||
| K12 | 500 | 6 | 500 | 7 | |||||||||
| Q58 | 75 | 25 | 80 | 26 | |||||||||
| S36 | 5 | 256 | 4 | 260 | |||||||||
| V97 | 100 | 17 | 115 | 16 | |||||||||
| Y88 | 10 | 750 | 8 | 740 | |||||||||
Required:
Determine the inventory at cost as well as at the lower of cost or market, using the first-in, first-out method. Record the appropriate unit costs on the inventory sheet, and complete the pricing of the inventory. When there are two different unit costs applicable to an item:
Insert the quantity and unit cost of the last purchase.
On the following line, insert the quantity and unit cost of the next-to-the-last purchase.
Total the cost and market columns and insert the lower of the two totals in the LCM column.
The first item on the inventory sheet has been completed as an example.
| Inventory Sheet December 31 |
|||||||
|---|---|---|---|---|---|---|---|
| Inventory Item |
Inventory Quantity |
Cost per Unit |
Market Value per Unit (Net Realizable Value) |
Total Cost | Total Market | Total LCM | |
| A54 | 37 | 30 | $60 | $56 | $1,800 | $1,680 | |
| 7 | 58 | 56 | 406 | 392 | |||
| 2,206 | 2,072 | $2,072 | |||||
| C77 | 24 | 178 | |||||
| F66 | 30 | 132 | |||||
| 132 | |||||||
| H83 | 21 | 545 | |||||
| 545 | |||||||
| K12 | 375 | 5 | |||||
| Q58 | 90 | 18 | |||||
| 18 | |||||||
| S36 | 8 | 235 | |||||
| 235 | |||||||
| V97 | 140 | 20 | |||||
| 20 | |||||||
| Y88 | 17 | 744 | |||||
| 744 | |||||||
| Total | $ | $ | $ | ||||
In: Accounting
Given below are seven observations collected in a regression
study on two variables, X (independent variable) and Y (dependent
variable).
|
X |
Y |
|
2 |
12 |
|
3 |
9 |
|
6 |
8 |
|
7 |
7 |
|
8 |
6 |
|
7 |
5 |
|
9 |
2 |
a. Develop the least squares estimated regression equation.
b. State the hypotheses to test for the significance of the regression line.
c. Perform an F test to determine whether or not the model is significant. Let α = 0.05.
In: Statistics and Probability
Calculate calorific value of E15 fuel. A car run by gasoline has highway mpg 33, if it runs by E15, calculate the new mpg. Ignore all other effects. If it runs only by ethanol what would be new mpg. (Points 10+10=20)
In: Other
A rocket is fired straight upward, starting from rest with an acceleration of
25.0 m/s2. It runs out of fuel at the end of 4.00 s and continues to coast
upward, reaching a maximum height before falling back to Earth. (a) Find the
rocket’s height when it runs out of fuel; (b) find the rocket’s velocity when it
runs out of fuel; (c) find the maximum height the rocket reaches; (d) find the
rocket’s velocity the instant before the rocket crashes into the ground; and
(e) find the total elapsed time from launch to ground impact.
In: Physics
SPK Industries uses the LIFO inventory costing system, use the following information to calculate the COGS if they sold 50 units in July.
| Date | Purchases | Price per Unit |
| 6/15 | 30 units | $120 |
| 6/30 | 40 units | $130 |
| 7/15 | 20 units | $150 |
In: Finance