Infix expression has balanced parenthesis or not, Data Structure & Algorithms

Assignment Help:

Q. By making use of stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not.                                                                                                               

Ans.

Algorithm parentheses is written below

This specific algorithm reads a source program and parses it to make sure all opening -closing parenthesis are systematically paired

1. loop (more data)

read (character)

if (character is not a closing parenthesis)

pushstack ( stack, character)

else

if (character is closing parenthesis)

popstack (stack, token)

while ( token is not an opening paranthesis)

popstack (stack, token)

endwhile end if

end if end loop

if (not emptystack (stack))

print (Error: opening parenthesis not matched)

end parseparens.


Related Discussions:- Infix expression has balanced parenthesis or not

Chaining Method as Method of Collision Resolution , Q. The given values are...

Q. The given values are to be stored in a hash table 25, 42, 96, 101, 102, 162, 197 Explain how the values are hashed by using division technique of hashing with a table

Determine the algorithm for z-buffer method, Algorithm for Z-Buffer Method ...

Algorithm for Z-Buffer Method (a)  Initialize every pixel in the viewport to the smallest value of z, namely z0 the z-value of the rear clipping plane or "back-ground". Store a

Circular linked list, In a circular linked list There is no beginning a...

In a circular linked list There is no beginning and no end.

Rules for abstract data type-tree, null(nil) = true                     // ...

null(nil) = true                     // nil refer for empty tree null(fork(e, T, T'))= false   //  e : element , T and T are two sub tree leaf(fork(e, nil, nil)) = true leaf(

Array, extra key inserted at end of array is called

extra key inserted at end of array is called

State an algorithm which inputs 3 - digit code for 280 items, A small shop ...

A small shop sells 280 different items. Every item is identified by a 3 - digit code. All items which start with a zero (0) are cards, all items which start with a one (1) are swee

Hashing and hash functions, Q. Describe the term hashing. Explain any two u...

Q. Describe the term hashing. Explain any two usually used hash functions. Explain one method of collision resolution.

Linked List Variations, Part1: Deque and Bag Implementation First, complet...

Part1: Deque and Bag Implementation First, complete the Linked List Implementation of the Deque (as in Worksheet 19) and Bag ADTs (Worksheet 22). Files Needed: linkedList.c Linke

Logical database design, 1. For the ER diagram you created in assignment, t...

1. For the ER diagram you created in assignment, the artefact of the conceptual database design, map the ER model into the relational model according to how it was designed in the

Threads in main method, Create main method or a test class that creates 2 E...

Create main method or a test class that creates 2 Element objects that are neighbours of each other, the first element temperature set at 100, the 2nd at 0 and use an appropriate h

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd