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 ."...

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

1.png1b.png2.png2b.png3.png4-6.png7.png8-12.png

1.png

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 ."
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 !, " = ? 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 [ ] & = new int [ at ]] ;\
& [ 0] = - 1 ; all] = 1 :`
for lint 1 = 2 ; 1 = = ] ; # 1 ] [
* [1] = all - 21 - 1 + a[1 - 1] + 2 :
return a ;
In Fixs & & 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
"` 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 & = new int *
rectalCASEatall , I )
Int int & = new int [ nit 1]
rachelperla , nj
Int &
a [0] = 0 all] = 0
reCHELperla , !`
int & [ 2 5]
a [0] = 1 all] = - 1
SECUITY
Int & [ZE]
& [ 0] = - 1 a [ 1] =\
return a
int a = new int & [ 25 ]
a [0] = =[ 1] + 2
return IN
int a = new Int [ 1 - 1]
a [a] = a [n - 1] +
LEturn &
Int [ ] & = new int [ n't 1]
all] = =[0] + 2

1b.png

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 & and the value of " 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 " 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 ."
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 " 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 ! " which was called from rectalcasicall _ rec caleAScary will return " back to
run! ! where the array will be printed . It is important to remember , that for each Ain't value , " = ], we must start A In) in
the proper location of the array & so that run! ! can later print &. 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 .
"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 &
* [ 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 & [ ZE]
return & [ 1]
recHelperle , ` = ]]
- 2 =
int &[ ZE ]
return
int !

2.png

2. I'm EXIT aT DIEZ We used & 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 !" Wilma " J. enqueue !'" Pebbles" }.enqueue ! "Fetty " ) .
After Adding the strings to the queue , " Wilma " would be at the front of the queue and " Betty " 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" [
private DILLat < Es millat ;\
public Queue !) ( DLlatKE" 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<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 < E getList ! ! ( return aList ; $
private vold BetList ( List< 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<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

2b.png

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

3.png

3. Six EX IN an MIEZ for A discussion of the D'List _ E_ class . A few definitions before we start :`
alist
A doubly linked list
{List
A singly linked 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 & 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 " [List " or " D'List _ E`" within the code will be renamed to
" SList " and " SList _ E. " 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-6.png

4. We make the required changes for Ex & and now we are ready to begin modifying SList . Which instance Variables should we
Eliminate*?"
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 & 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 & 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 !" Choose all that apply .
A .
Eliminate InData & pData
b .
Eliminate mProv* null*
Eliminate mNext*_ millead
i .
Eliminate millead . In Prev & now Made
Eliminate millead & now Made*
[ .
Eliminate maize + +
{ .
Keep all six of the operations as they Are
&. Of the data structures we studied , which one stares elements following the last - in first-out principle ?"
H .
I'D array
1 .
Array List
Stack
d .
QUEUE
Linked List
I .
Binary Tree
Binary Search Tree*

7.png

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

8-12.png

Continuing with tree I . what integers are stored in the leaf nodes?" 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 ?"
3 7 { } $ 1 1 5 0 4
I T & $ 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 = & was added to { } before the made containing key = $ was
Added .
False
by .
True
WE cannot determine this by examining the BEST

Recently Asked Questions

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
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question