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

Practice Question 1: Which is true of stacks? a) Pop followed by push always lea

ID: 3605709 • Letter: P

Question

Practice Question 1: Which is true of stacks? a) Pop followed by push always leaves a stack unchanged in a reference-based implementation, even if the stack was originally empty.

b) Push followed by pop always leave a stack unchanged in an array-based implementation, even if stack was originally full.

c) Push of the same data value on a stack twice has the same effect as pushing that data on the stack once.

d) Peek changes what’s in a stack. e) None of the Above.

Practice Question 2: Supposed that the implementation of an ADT changes, but the interface of the ADT is unchanged. Which statement is true?

a) That can’t happen; if the implementation changes, then the interface must also change.

b) That can only happen if the if the interface has no exceptions.

c) That can only happen if the interface has no public methods.

d) That can happen, but clients will have to be rewritten.

e) That can happen, and clients may continue using the ADT without being rewritten.

Practice Question 3: Which of the following is a reasonable “axiom” about a list that you might test as part of an implementation? (Presented in English to make reading easier.)

a) If you create a new list, then its size is 1.

b) If you remove an item from a non-empty list, then afterward its size decreases by 1.

c) If you remove an item from a non-empty list, then afterward it’s also non-empty.

d) If you add a new item at position k of a list that has more than k elements in it, then the number of items on that list remains the same.

e) If the value that you get for the item at position k of a list is v, then after you add a new item at position k of that list, the value at position k is still v.

Explanation / Answer

Question 1)

Which is true of stacks?

a) Pop followed by push always leaves a stack unchanged in a reference-based implementation, even if the stack was originally empty.

b) Push followed by pop always leave a stack unchanged in an array-based implementation, even if stack was originally full.

c) Push of the same data value on a stack twice has the same effect as pushing that data on the stack once.

d) Peek changes what’s in a stack.

e) None of the Above. - True

Explanation:

a) Pop followed by push always leaves a stack unchanged in a reference-based implementation, even if the stack was originally empty. - For a empty stack, if we pop an item, it will return null or error. Thus then after pushing an item the Stack is changed. So this is false.

b) Push followed by pop always leave a stack unchanged in an array-based implementation, even if stack was originally full - This is not true as for a full stack we cannot push an item as the stack is full. Thus then after popping the item the stack will be changed. So this is False.

c) Push of the same data value on a stack twice has the same effect as pushing that data on the stack once. - False, as we can insert the same data multiple number of times since stack can support duplicates. So this doesn't have the same effect on Stack.

d) The `peek` operation returns the value of the "top" (or "next") element without "consuming" that element, i.e. without removing that element from the data structure, thus it does not change what’s in a stack. Thus not true. False.

e) This will be correct answer as all the other given options are False.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote