View the step-by-step solution to:

# This is Exercise 6 on Midterm Exam 2 . It is duplicated here for reference while you are working on Ex 1 . You do not have to write it .&quot;...

Need help solving my study guide here are some of the questions on there.

This is Exercise 6 on Midterm Exam 2 . It is duplicated here for reference while you are working on Ex 1 . You do not have to write it .&quot;
Consider the sequence of a + 1 integers computed using this formula : \$17 ) = 1.1/ 2 - 17 + 21 + 1.1/ 2 - 21 - 11.`|[0] = _ 1 , and
*[1] = 1 . 1 2 2. Suppose we wish to calculate and print the sequence for 1 = 25 . The output will be :*
1 - 1 . 1 , 1 , 3 , 5 , 1 , 15, 25, 11 , 67 , 109 , 177, 287, 195, TO3, 1210, 1978, 9103, GIFT, \$391, 19420, 21801, 95.121, 57813, 92725, 150^ ]
The sequence can be calculated using an iterative or a recursive algorithm . Here is the iterative approach , where iter called -
Begin ) will compute the A sequence for a given value of !, &quot; = ? and return the sequence in a I D' array of ints .
private vold runny {
I'M' Calculate the A sequence for ! = 25 iteratively and then print out the BEqueNICE*
int iterAbeg = iterCalcAbeg (25; ;\
System . out . printlalArrays . toString literABey ! ] :`
I'M' Calculate the A sequence for ! = 25 recursively and then print out the sequence*
int recAbey = recCalcAGEq ( 25) ;\
System . out . print In [ Arrays . toString ( reCASEY! ) ;`
public int [ ] itercalcAGEglint ! ! I
int [ ] &amp; = new int [ at ]] ;\
&amp; [ 0] = - 1 ; all] = 1 :`
for lint 1 = 2 ; 1 = = ] ; # 1 ] [
* [1] = all - 21 - 1 + a[1 - 1] + 2 :
return a ;
In Fixs &amp; &amp; Final Exam Ex I Isee next page ) your job is to write the methods which will allow us to compute A/nj using
recursion . The code will be partitioned into two methods . The first method is non-recursive reccalcasca! ; which is this
exercise . The code for rellelaur!'; is Final Exam Fx 1 . The template for recCaleAScary is shown below . The same template is
shown in the BE exercise . To complete the exercise , in FB, use use the drag down list box for each of |1 1 - 1 {] to select the proper*
conde piece for that part of the method . When , completed , the entire method will perform as described in the method comments
below . Important notes !
Game of | If-\\ may use the same piece of code . {}.. You might have double in bath blanks (3 ) and 1 1 1 .
2 .
There are more cade choices than are required to complete the method . Some will be unused .*
3 .
Some of | 1 1 - 1 {| may represent cade which should be indented differently than is shown in the template .
1. It may help to know that the instructor indents his cade primarily using KER style, with the JAVA Variant of putting*
the opening left brace of a method on the same line as the method header . Look at cade in the nates for examples
Ignore all semicolons for this exercise . Assume semicolons do not even exist in Java .
I'M' This Is not a recursive method . It declares and createa array all . Stores AID) and Ally in the array a . Then
&quot;` callE recHelper !'; to calculate ALLY , ALL - 1) , A10 - 2) . .... Alas , Storing each calculated value in the array a*
I'M Finally it returns the array all . Ize the drop down Liat boxes to change the code place for blanka [ 1] - public [1] rectalcasey [ [2] ] [
[ 3]
[ 4]
[ 5 ]
[ 6 ]
Choices
InIt
int a = new Int [ n ]
TELCELCASerta , !'
Int I`
Int &amp; = new int *
rectalCASEatall , I )
Int int &amp; = new int [ nit 1]
rachelperla , nj
Int &amp;
a [0] = 0 all] = 0
reCHELperla , !`
int &amp; [ 2 5]
a [0] = 1 all] = - 1
SECUITY
Int &amp; [ZE]
&amp; [ 0] = - 1 a [ 1] =\
return a
int a = new int &amp; [ 25 ]
a [0] = =[ 1] + 2
return IN
int a = new Int [ 1 - 1]
a [a] = a [n - 1] +
LEturn &amp;
Int [ ] &amp; = new int [ n't 1]
all] = =[0] + 2

1 . This exercise continues Ex h an Midterm Exam I, and implements the Second method , recHelper! ! which is called from rec -
CalcAScary .
The parameters are the array &amp; and the value of &quot; for which we are to compute Ally . This is a recursive method which
computers and returns A/nj . For each execution of this method when ! = 2. after computing Ala) , the method will write
All) into the array &quot; at the proper index and will then return the value of A /nj .
The base case occurs when i is less than 2, because for All; and AID; these are our trivial solutions . For the base case*
them , we just have to determine when it occurs and return A In ) when it happens .&quot;
When I = 2, we must calculate AIn ) , stare the value in a and return the value . But note from the definition of A /nj that
in order to determine what A Inj is , we must know what All - 1) and and what Ain - 2 ) are . So, this is where the recursion*
is applicable . When computing AIN ) we already have a method which computes both All - I' and All - 2 ) - it this method
rollelderly . So, just call recHelper! to compute these two values , and when the method returns , we can then calculate*
All) , store it in &quot; at the proper index , and return All ) .
Eventually , the recursion will stop when the base case is reached , and we will return all the way back up the recursion call
tree , to the original method call to reciteper ! &quot; which was called from rectalcasicall _ rec caleAScary will return &quot; back to
run! ! where the array will be printed . It is important to remember , that for each Ain't value , &quot; = ], we must start A In) in
the proper location of the array &amp; so that run! ! can later print &amp;. And do not forget , rec cake AScall already placed AID) and
Ally into a .
Important notes :`
1 .
Some of | 1 1 - 1 11/ may use the same piece of code . E., You might have double in bath blanks ( 2 ) and 1 31 .
2 .
&quot;There are more cade choices than are required to complete the method . Some will be unused .
3 .
Game of | !| - | 11 / may represent code which should be indented differently than is shown in the template .*
4 .
It may help to know that the instructor indents his care primarily using KER style , with the Java Variant of putting*
the opening left brace of' a method on the same line as the method header . Look at code in the mates for examples .
` .
Ignore All semicolons for this exercise . Assume semicolons do not even exist in Java .*
public [ 1] recHelper \$ [21 . [31 1 1)
[ 5]
[ E]
[ 1 1]
Choices
it In _ _ DI
return &amp;
* [ 0]
it In = = 1 1 1
return In
it In * 3 } {
return a [ ]
: [1] -
it ' _ _ ]] [
\$ 10 - 1] -
it In = 2 1
TECHElperl's , ``
. 21
recHelperla , = = 11 + 2)
. I
= [0 # 1] -
it ( =[?] - 0)
recHelperle , ` = 21 +|
- 21 + 1 =\
int
* E + IT*
recHelpert's , ``
reCHELperla , I
* 2
int `
I else I
recHelperla , \$1 . 21
int &amp; [ ZE]
return &amp; [ 1]
recHelperle , ` = ]]
- 2 =
int &amp;[ ZE ]
return
int !

2. I'm EXIT aT DIEZ We used &amp; LILIST_ _ list to store the values at the stack , So we can SAY that our stack is really just A SPIE -
cilic type of linked list where we always and and remove elements from only one end of the list . For this exercise , we wish to
implement a generic queue data structure , which will also use an underlying linked list to start the data in the queue . Our
Queue _ E_ class must implement this public interface :`
[1 ] A default char which initialize the Queue object being constructed . Recall that chars initialize the object by initializing*
some or all of the data members of the object . If the object has an data members to initialize . then the ctor can consist
at just An empty badly .
[ 2) toaqueue [ ` Data : : Cour_ E_ which adds the value plate to the queue . This method must return the Queue Lib -
ject . Thing so permits us to chain together multiple enqueue ! ! method calls . C. B. . .
Queue_String queue = now Queue_ !) .
quique. enqueue !&quot; Wilma &quot; J. enqueue !'&quot; Pebbles&quot; }.enqueue ! &quot;Fetty &quot; ) .
After Adding the strings to the queue , &quot; Wilma &quot; would be at the front of the queue and &quot; Betty &quot; would be At the Year .
(3 ) I dequeue ! ! ! { which removes and returns the value which is at the front of the queue . In this cade , we shall not con -
corn ourselves with runtime exceptions which may occur when we attempt to remove data from an empty queue . We
Assume that the user will not call peck ! ; or dequeue! ! on an Empty queue .*
[ 4 ) + Rock!) . { which returns the date at the front of the queue , without removing it . As with dequeue ! ] , we shall assume
the liset lever calls perkily on an Empty queue .`
We may also change to write other private helper methods as required . Which Queue _ E_ class below is correct_
A .
public Class QUEUECE&quot; [
private DILLat &lt; Es millat ;\
public Queue !) ( DLlatKE&quot; willat = new OILlate !) ; *
public QueueCE; Enqueue ( E plata ) ( mList . appendlydiataj ; return this ; }
public E dequeue ! ) ( E value = mList . removeloy ; return value ; }
public E peek! ! { E value = mList _ getlaj ; return value ; }
bo .
public class QUEUECE; I
private DLlateEs willat ;\
public Queue ! ! I zetLiatinew [Liat ``!) ;\
protected Int indexaffront ! ; ( return O ; }
protected Int Indexoffear ! ! [ return getLiat ! ! _ getSize ! ! - 1 ; }
public Queue&lt;E Enqueue ( E plata ) I getList ( ; . Bet finderof Front( ) , plata ) ; return this ; }
public E dequeue ! ! { E value = getList( ; . remove (index of Heart ! ) ; return value ; }
public E peek ! ! { E value = getList ! ! . get findecaf Front ( ! ) ; return value ; }
private DLiat &lt; E getList ! ! ( return aList ; \$
private vold BetList ( List&lt; E, FList ! ( allat = piList ; }
public [lazz Queue ` E' extends DList* E* *
public Queue ! ! { }
public QueueCE; Enqueue ( E plata) ( prepend (data) ; return this ; }
public E dequeue ! ! I return remove finderof Front ! ! ) ; }
public E peek !'; I return get finderof Front ! ! ) ; \$
private int indexof Front ! ; I return getGizell ; ]
public class Queue` E' extends [Lists E (
public Queue ! ! { }
public Queue&lt;E Enqueue ( E plata) [ appendiplate ) ; return this ; }
public E dequeue ! ! I return remove finderof Front ( ! ) ; }
public E peek!'; I return get linderof Front ! ! ! ; \$
private Int indexofFront ! ! ( return O ; It

e.
public class Queue&lt;E&gt; { // Uses the correct Stack&lt;E&gt; class from ME2 Ex 19
private Stack&lt;E&gt; mStack;
public Queue() { setStack(new Stack &lt;E&gt;()) ; }
public Queue&lt;E&gt; enqueue(E pData) { getStack( ) . push (pData) ; return this; }
public E dequeue( ) { return getStack( ) .pop( ) ; }
public E peek() { return getStack. peek ( ) ; }
private Stack&lt;E&gt; getStack() { return mStack; }
private void setStack(Stack&lt;E&gt; pStack) { mStack = pStack; }
f.
public class Queue&lt;E&gt; extends Stack&lt;E&gt; { // Uses the correct Stack&lt;E&gt; class from ME2 Ex 19
public Queue() { super() ; }
public Queue&lt;E&gt; enqueue(E pData) { push(pData) ; return this; }
public E dequeue( ) { return pop( ) ; }
public E peek() { return peek( ); }

3. Six EX IN an MIEZ for A discussion of the D'List _ E_ class . A few definitions before we start :`
alist
{List
The data type of the data stored in the list*
DIList
The generic DList _ E_ class , including the nested Node _ E class
Nodle
A generic Node _ E class , either for the DList _ E_ or the SList _ E_ class
D'List. Node*
The Node _ E class which is nested within D'List _ {`
SList
The generic SList = E class , including the nested Made _ E_ class
SList . Node*
The Node_ E_ class which is nested within SList = [`
Note that D'List. None has three data members : In Data , InNext , and mirer , all reference variables . Next , see that D'List also
has three data members : willead , maize , and In Jail , with millead and In Tail being reference variables and maize is a Java
int . Recall the difference between an slist and a dlist . Suppose our application does not require &amp; alist . i.e.. it will suffice to
use an slist . In this end , we decide to declare a new generic class SList _ Elie. SList ) with a generic nested Node _ {`
class [i.e., SList. Made ) .
We believe we can save ourselves quite a bit of time from writing SList from scratch by simply making a copy of the DIList
code and renaming it to SList . Of course , any references to &quot; [List &quot; or &quot; D'List _ E`&quot; within the code will be renamed to
&quot; SList &quot; and &quot; SList _ E. &quot; For this exercise , Assume that we have made the copy of D'List And we are not modifying SList .
We start may modify ing SList. Made . What changes would we need to make regarding the instance variables of SList. Made !
A _
WE must remove the declaration for In Data And it's accessur /' mutator methods , then modify the ctor('s ) to eliminate the
initialization at m Data , and finally , modify tostring ! ! to return the empty string .`
1 .
WE must remove the declaration for m Next and it's accessor / mutator methods , then modify the charla ] to eliminate the
initialization of m Next .
WE must remove the declaration for my'rey and it's accessor / mutator methods . then modify the charts ) to eliminate the
initialization of mPrey .*
We must remove the declarations for bath InNext and mPrey , their accessor / mutater methods , and then modify the
charla ) to eliminate the initialization of in Next and mPrev .`
WE must remove the declarations for both In Data and mNext , their accessor ' mutator methods . then modify the ctar('s )
to eliminate the initialization of In Data and mNext , and finally . modify tuString ! ! to return the empty string .
We determine that we can eliminate the entire Made class and just declare m Data in SList .`
We determine that we can eliminate the entire Made class and just declare in Data and in Next in SList
In .
We determine that we can eliminate the entire Made class and just declare mData and meter in SList .
i.
We determine that we can eliminate the entire Made class and just declare in Data , InNext , and mirer in SList .

4. We make the required changes for Ex &amp; and now we are ready to begin modifying SList . Which instance Variables should we
Eliminate*?&quot;
A .
willead and all references to it
Do .
In Tail and all references to it.
misize and All references to it
i .
millead , In Tail and all references to them
millead , msize and all references to them
In Tail , maize and all references to them
E .
We do not eliminate any of them*
In .
We eliminate all of them
{ .
. We need to implement SList functionality so that we can insert &amp; new value into the list at a specific index . In D' List , this is
Accomplished when the list calls addlint plunder . { `Data) . Adding a new node to &amp; I'List is discussed in ST of the Linked
List notes . The lecture video titled D'List Implementation (adding an element ) discusses how to do this so re- view it . Case
number ? in SIT is discussed starting at the 2:35 min mark . In the lecture . I discussed six operations ( live assignment.
operations and incrementing Insize ) which must be performed when the new mode is inserted at index ! . For our SList class.
which , if any , of the following operations must we eliminate !&quot; Choose all that apply .
A .
Eliminate InData &amp; pData
b .
Eliminate mProv* null*
i .
[ .
Eliminate maize + +
{ .
Keep all six of the operations as they Are
&amp;. Of the data structures we studied , which one stares elements following the last - in first-out principle ?&quot;
H .
I'D array
1 .
Array List
Stack
d .
QUEUE
I .
Binary Tree
Binary Search Tree*

T. Shown below is a binary tree T. What wine is stared in the mat. nude? Enter the image? number in the blank in BB. 90 9
960

Continuing with tree I . what integers are stored in the leaf nodes?&quot; Select all that apply .
. I
DO A`
i .
7 .
What is the height of ! !`
10 . We A perform past- order traversal of I. Which of the following choices lists the integers stared in the mades in the order we
visit them As we perform the traversal ?&quot;
3 7 { } \$ 1 1 5 0 4
I T &amp; \$ 1 1 3 5 1 } BIL DT ! ! \$ 3
d .
3 7 5 2 { } \$ 1 1 4
2 8 11 1 BOT } }
\$ 11 1 { { DT } }
11 . Complete this exercise in BB.
12 . Shown below is a FIST named {` The made containing key = &amp; was added to { } before the made containing key = \$ was
False
by .
True
WE cannot determine this by examining the BEST

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents