Question

Multiple choice data structures questions about stacks. Here is an INCORRECT pseudocode for the algorithm which...

Multiple choice data structures questions about stacks.

  1. Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced:
       declare a character stack 
       while ( more input is available)
       {
          read a character
          if ( the character is a '(' ) 
             push it on the stack
          else if ( the character is a ')' and the stack is not empty )
             pop a character off the stack
          else
             print "unbalanced" and exit
        }
        print "balanced"
    
    Which of these unbalanced sequences does the above code think is balanced?
    • A. ((())
    • B. ())(()
    • C. (()()))
    • D. (()))()
  2. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
    • A. 1
    • B. 2
    • C. 3
    • D. 4
    • E. 5 or more
  3. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). What is the maximum number of parentheses that will ever appear on the stack AT ONE TIME during the computation?A. 1 B. 2 C. 3 D. 4 E. 5 or more
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans 1: Option A.  ((())

Ans 2: Option C. 3

Ans 3: Option B. 2

  

Add a comment
Know the answer?
Add Answer to:
Multiple choice data structures questions about stacks. Here is an INCORRECT pseudocode for the algorithm which...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HURRY! I only have 30 minutes for these questions. thank you! Following is an incorrect...

    PLEASE HURRY! I only have 30 minutes for these questions. thank you! Following is an incorrect pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced: declare a character stack while ( more input is available) read a character if ( the character is a) push it on the stack pop a character off the stack print "unbalanced" and exit else if ( the character is a ')' and the stack is not empty)...

  • Stacks and Java 1. Using Java design and implement a stack on an array. Implement the...

    Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...

  • help me answer the following questions please 1. Stack (LIFO) & its application 1. Stack overflow...

    help me answer the following questions please 1. Stack (LIFO) & its application 1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking Exercises: 1) Which of the following applications may use a stack? A. parentheses balancing program. B. Keeping track of local variables at run time. C. Syntax analyzer for a compiler. D. All of the above. 2) Consider the usual algorithm for determining whether a sequence of parentheses is balanced....

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQ...

    Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...

  • This assignment is comprised of 3 parts: ​All files needed are located at the end of...

    This assignment is comprised of 3 parts: ​All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. ​Do Not Worry about these, they are completed. Next, complete the dynamic array and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT