Question

1) Recall that within theArrayBoundedStackthetopIndexvariable holds the index of theelementsarray where the current top of stack...

1) Recall that within theArrayBoundedStackthetopIndexvariable holds the index of theelementsarray where the current top of stack is stored. If a stack is empty, then itstopIndexvariableis:

a) -1

b) 0

c) 1

d) DEFCAP  

e) None of above

8) Evaluate the following postfix expression:  6  4 + 3  10  * 2 2 2 - +  * +

What is the highest number of elements on our stack at any one time?  

a) 2

b) 3

c) 4  

d) 5

e) None of above

Homework Answers

Answer #1
1)  a) -1
when stack is empty, then top is -1

2)  d) 5
6 4 + 3 10 * 2 2 2 - + * +
--------------------------------
stack: []
push 6
stack: [6]
push 4
stack: [6 4]
pop, 6 and 4, push 6+4 = 10
stack: [10]
push 3
stack: [10 3]
push 10
stack: [10 3 10]
pop, 3 and 10, push 3*10 = 30
stack: [10 30]
push 2
stack: [10 30 2]
push 2
stack: [10 30 2 2]
push 2
stack: [10 30 2 2 2]
pop, 2 and 2, push 2-2 = 0
stack: [10 30 2 0]
pop, 2 and 0, push 2+0 = 2
stack: [10 30 2]
pop, 30 and 2, push 30*2 = 60
stack: [10 60]
pop, 10 and 60, push 10+60 = 70
stack: [70]

value of this expression is 70
and we can see that maximum size of stack is 5
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Evaluate the following postfix expression: 6 4 + 3 10 * 2 2 2 - +...
Evaluate the following postfix expression: 6 4 + 3 10 * 2 2 2 - + * + What is the highest number of elements on our stack at any one time? can you please explain the answer for me ?
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These...
in Java In this exercise, you'll write a Java version of the infix-to-postfix conversion algorithm. These same mechanisms can be used as a part of writing a simple compiler. Write class InfixToPostfixConverter co convert an ordinary infix arithmetic expression (assume a valid expression is entered) with single-digit integers (to make things easier) such as (6 + 2) • 5 - 8 / 4 to a postfix expression. The postfix version (no parentheses are needed) of this infix expression is 6...
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log...
1.A stack implemented with an array has what performance? Select one: a. O(n3) b. O(n log n) c. O(n) d. O(n2) 2. A stack uses the first in first out insertion and deletion method. Select one: True False 3. Match the following stack operations with their meaning. object pop(); boolean isEmpty(); push (object); integer size(); object top(); meanings are: - returns the number of elements stored -just removes the last inserted elements - returns the last inserted elements without removing...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression Evaluator as described in section 7-3b of the book. The program should ask the user for a string that contains a Postfix Expression. It should then use the string's split function to create a list with each token in the expression stored as items in the list. Now, using either the stack classes from 7.2 or using the simulated stack functionality available in a...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
Question 1 Consider the following grammar G: S ➝ A B C | A C |...
Question 1 Consider the following grammar G: S ➝ A B C | A C | A | B A ➝ a B B ➝ b C | a C ➝ c D D ➝ d A Recall that a non-terminal A is reachable if there is a derivation starting from S in which A appears: S ⇒* x A y holds for some x and y which are sequences of terminals and non-terminals (possibly empty). For example, if there...
Something is either messed up in my operator overload <<, covertopostfix function, or my main output....
Something is either messed up in my operator overload <<, covertopostfix function, or my main output. Cannot figure it out. please help. Please comment your changes too. Program below is supposed to be outputting like this: InFix is:   A+B-C Post fix is:   A B + C - InFix is:   A+C Post fix is:   A C + InFix is:   x*(y+z)-(w+t) Post fix is:   x y z + * w t + - InFix is:   A+B*(C+D)-E/F+G+H Post fix is:   A B C...
Use the following algorithm: (1) Create three stacks of characters: stk1, stk2, stk3. (2) Read the...
Use the following algorithm: (1) Create three stacks of characters: stk1, stk2, stk3. (2) Read the input infix expression one character at a time and push every character read ( other than ')' ) onto stk1. Do not push the character read if it is ')'. (3) As long as stk1 is not empty, do the following:            Fetch the top character ( call it c ) of stk1 and pop stk1.            if c is an alphabetic character (a-z),...
2. Assume that purchasing power parity holds real exchange rates close to E(f/d) = 1. Suppose:...
2. Assume that purchasing power parity holds real exchange rates close to E(f/d) = 1. Suppose: a. The nom exchange rate e(EUR/CAD) is decreasing. Where is inflation higher?___________ b. The nom exchange rate e(GBP/CAD) is increasing. Where is inflation higher?____________ c. Using the information in a and b, where is inflation highest? Europe or Canada or Great Britain
1. Which of the following statements is FALSE? a. A transformer operation changes the object (e.g....
1. Which of the following statements is FALSE? a. A transformer operation changes the object (e.g. list.add(element) changes the list by adding an element) b. An observer operation may also modify the object (e.g. list.isFull( ) may increase the size of the list if no more elements can be added) c. An observer operation returns information about an object (e.g. list.size() returns the number of elements in the list) d. A transformer operation may or may not return a value....