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.

  • Java - Data structures and algorithms VI. Matching Game Consider a matching game in which you...

    Java - Data structures and algorithms VI. Matching Game Consider a matching game in which you have a list of random integer values between 10 and 99. You remove from the list any pair of consecutive integers that match. If first integer has digits xly1 and the second integer has digits x2y2 the match is found if any ofthe following is true xi is the same as x2 x1 is the same as y2 yl is the same as x2...

  • The language we are using in Data Structures is C++ right now. Assignment9-Apr 3 References A...

    The language we are using in Data Structures is C++ right now. Assignment9-Apr 3 References A A A X? A. Mailings Review A E E. A. View . :. 2+ . 1 . Albebote albebete Nere AutoCeDdte AaBbCcDc AabCeDdE Heading 1 Heading 2 Student Name: Student ID (Last 4 digits): Due Date: 4/3/2020 Note: For any program questions of the assignment, Make sure you complete programs. You may copy & paste the code to this word file, and submit them...

  • In this stage you should read all of the data into internal structures suitable for use in the later stages and create...

    In this stage you should read all of the data into internal structures suitable for use in the later stages and create an output representation that provides an overview of the data that was read. Photo 1&2 - Question Photo 3 - Input data Photo 4 - Introduction please write a code that will execute such function & generate a required output (as stated on the question). Input data is not required to write a code but if you need...

  • CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As...

    CARD GAME (LINKING AND SORTING) DATA STRUCTURES TOPIC(S) Topic Primary Linked lists Sorting Searching Iterators As needed Recursion OBJECTIVES Understand linked lists and sorting concepts and the syntax specific to implementing those concepts in Java. PROJECT The final objective of this project is to create a multi-player card game, but you will create your classes in the order given, as specified. (Analogy: you must have a solid foundation before you can build a house). In order to allow creative freedom,...

  • 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
ADVERTISEMENT