Question

3. Given to you are some of the applications of linear data structures: Matching braces/paranthesis in a program Managing fun
0 0
Add a comment Improve this question Transcribed image text
Answer #1

3. Matching braces/ paranthesis in a program

Matching braces/ paranthesis in a program i.e checking whether the program has valid paranthesis or not depending on rules of production. Matching paranthesis checks that whether there is a proper matching of the braces like every braces should be closed by braces of same category, also each braces should exist in pair and the order of opening of braces should be reverse of order of closing.

This type of checking can be easily performed using a linear data structure stack. Stack is a linear data structure with the Last in First out (LIFO) property. It supports two types of operations a push ( in which a token is pushed to Stack) and a pop ( in which the top of stack is popped out).

For understanding how it actually performs the braces matching task, Let's consider a basic example of checking balanced paranthesis in an input expression.

Suppose the input string is [{( a+b)*c} *d]

Now define a Stack S

The steps to check for balanced paranthesis will be,

  • Start reading the input string from the first position, if the token is an opening brace then push it on stack
  • If the token is a closing brace then match the top of stack with the closing brace, if there's a match pop the top and continue reading token.
  • If the top of stack doesn't match the closing brace, then the input does not have balances paranthesis
  • If after processing each tokens in input string, the stack isn't empty and have some opening braces left. The also input string isn't balanced
  • Otherwise balanced

For the given String, the stack at each read will be as follows

S = empty

S= '['

S= '[' , '{'

S = '[' , '{' , '('

S = '[' , '{'

S= '['

S = empty

Therefore in this case the input string has balanced paranthesis.

Add a comment
Know the answer?
Add Answer to:
3. Given to you are some of the applications of linear data structures: Matching braces/paranthesis in...
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
  • Basic data structures such as arrays are not sufficient for some applications. In some cases, more...

    Basic data structures such as arrays are not sufficient for some applications. In some cases, more advanced data structures are more suitable. In this assignment you will examine Stacks and Queues using linked lists. Complete the following: Create a flowchart to represent the Push and Pop operations for a Stack based on a linked list data structure. Create a flowchart to represent the Enqueue and Dequeue operations for a Queue based on a linked list data structure.

  • OPS Practice quiz 2. The benefits of risk pooling depend on the behavior of demand from...

    OPS Practice quiz 2. The benefits of risk pooling depend on the behavior of demand from one market relative to demand from another. True False 3. What is Supply Chain Management? A set of approaches utilized to efficiently integrate suppliers, manufacturers, warehouses and stores so that merchandize is produced, distributed at the right quantities, to the right locations and at the right time in order to minimize system wide costs while satisfying service level requirements. The management of the flow...

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

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