Basic Recursion, Check Balanced Parenthesis
Posted
by pws5068
on Stack Overflow
See other posts from Stack Overflow
or by pws5068
Published on 2010-04-26T03:41:21Z
Indexed on
2010/04/26
3:43 UTC
Read the original article
Hit count: 380
Greetings all,
I've written software in the past that uses a stack to check for balanced equations, but now I'm asked to write a similar algorithm recursively to check for properly nested brackets and parenthesis.
Good examples: () [] () ([]()[])
Bad examples: ( (] ([)]
Suppose my function is called: isBalanced.
Should each pass evaluate a smaller substring (until reaching a base case of 2 left)? Or, should I always evaluate the full string and move indices inward?
© Stack Overflow or respective owner