Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

.Help with multiple choice: 1. Suppose that items A, B, C, D and E are pushed, i

ID: 3718718 • Letter: #

Question

.Help with multiple choice:

1. Suppose that items A, B, C, D and E are pushed, in that order, onto an initially empty stack S. S is then popped four times; as each item is popped off, it is inserted into an initially empty queue. If two items are then removed from the queue, what is the next item that will be removed from the queue?

2. If the binary tree below is printed by a preorder traversal, what will the result be?

Suppose that items A, B, C, D and E are pushed, in that order, onto an initially empty stack S. S is then popped four times, as each item is popped off, it is inserted into an initially empty queue. If two items are then removed from the queue, what is the next item that will be removed from the queue? B. C. tem A Item B item C Item D item E E. 2. If the binary tree below is printed by a preorder traversal, what will the result be? 9 4 16 12 A. B. C. D. E. 9 4 17 16 12 11 6 9 17 6 4 16 22 12 69 17 4 16 22 12 6 17 22 9 4 16 12 6 17 9 4 22 16 12 3. Given the array of integers arr shown below 19 66 12 48 6 23| 39| 2 | 18 what is the output of the following statements? int[] a2 = arr; a2 [3] = arr[2]; arr[2] = arrf31: arr[3] = a2[31 System.out.println(arr[2] + " " + arr[3]); 6 12 12 6 6 6 12 12 none of the above E.

Explanation / Answer

1)

step 1: initial queue is empty

step 2 :ABCD inserted so

Ele Add this side ->DCBA<- ele remove this side

A removed then Queue contain DCB

B removed then Queue Contain DC

next item of queue is C for remove

So Ans is :option C  

................................................................................................

2) Preoder of tree

step1 :print data of node

step 2 :if node has left node then visit then go step 1

step3:if node has right node then visit step 1

end :when tree end

So Ans is (E):6,17,9,4,22,16,12

.................................................................................................

3) arr[]={5 ,19,6,12,48,6,23,39,2,18 }

line 1: int []a2=arr;

a2 array point to arr array(its means a2 stored address od arr)

line 2:

a2[3]=arr[2];

here arr[2]=6 is assigned to a2[3]

i.e a2[3]=6;

line 3: arr[2]=arr[3]

here arr[3]=12 is assigned to arr[2]

i.e arr[2]=12;

line 4: arr[3]=a2[3];

here a2[3]=6 // we calculated above in line 2

So arr[3]=6

finally

it will print arr[2]=12

arr[3]=6

Ans is B: 12,6