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

1. What should be the name of the following method? public T whatIsMyname() thro

ID: 3744397 • Letter: 1

Question

1. What should be the name of the following method?

public T whatIsMyname() throws EmptyCollectionException

{

if(isEmpty())

throw new EmptyCollectionException("Stack");

return stack[top-1]

}

Select one:

a. Expand

b. pop

c. Push

d. Peek

                    

2. What is an Abstract Data Type

Select one:

a. Group of values and the operations defined on those values

b. Mathematical model for a data type

c. Subset of those classes that support collection

d. Set of programming constructs and techniques used to implement a collection

3. For Stack data structure, what does the following operation do?

public void doSomething (T element){

If(size() == stack.length)

expandCapacity();

stack[top] = element;

top++;

}

Select one:

a. Pop()

b. isEmpty()

c. Push()

d. Peek()

4. We are using stack to evaluate a postfix expression.

If we feed the following values what final values will be stored at the stack? (hint: Use the logic in the book)

2 4 -1 *

Select one:

a. 2 4 -1 *

b. 6

c. 2 -4

d. -8

5. Stacks operate as _______

Select one.

a. First In, First out

b. arrays

c. Last in, First Out

d. Last out, First In

6. What is missing in the following code?

Public T pop() throws EmptyCollectionException

{

If(isEmpty())

Throw new EmptyCollectionException(“Stack”);

              T result = stack[top];

            Stack[top] = null;

               Return result;

               }

Select one;

a. Top++;

b. Top--;

c. Nothing

d. Expand

7. We are using stack to evaluate a postfix expression.

If we feed the following values what final values will be stored at the stack? ( hint: use the logic in the book)

2 4 -1 * +

Select one;

a. -2

b. 2 -4

c. 2 4 -1 * +

d. -8

Given the following sequence: push(8), pop(), push(9)

Assume we have an initial size of 5 for the array implementation. What would the top pointer show?

Select one;

a. 8

b. 0

c. 7

d. 9

9. Pop operation has O(1) time complexity.

Select one;

a. True

b. False

10. What would the following program print?

X. push(new Integer(4));

X. push(new Integer(3));

Integer Y = X.pop();

X.push(new Integer(7));

X.push(new Integer(2));

X.push(new Integer(5));

X.push(new Integer(9));

System.out.print(Y);

Select one:

a. 2

b. 3

c. 7

d. 9

Explanation / Answer

If you post more than 1 question, as per chegg guidelines have to solve only first question.

Ques 1: Answer : (d) Peek

The function is returning the last element, but is not removing it. So, it is a peek operations as in peek operation we just look at the top most element in a stack without removing it.

Also, the if condition is to check for the case if the stack is empty.

Ques 2. Answer : (a) Group of values and the operations defined on those values

An abstract data type is a collectionof set of operations and values which define that particular data type. e.g: classe in object oriented programming.

Ques 3. Answer : (C) Push

In the given function, we are trying to add a new element into the array or the stack. So, it is the push operation.

Also, the if condition is for the case when the stack is full, then we are expanding the array.