@@ -270,32 +270,32 @@ function isBalanced(parentheses) {
...
@@ -270,32 +270,32 @@ function isBalanced(parentheses) {
## Quotienting a Free Monoid by Relations
## Quotienting a Free Monoid by Relations
* The sequence `…` cancels to the identity.
* The sequence `()` cancels to the identity.
* If we simplify any input by repeatedly removing occurrences of `…`, we eventually end up with a string of the form `…` where `…` is ….
* If we simplify any input by repeatedly removing occurrences of `()`, we eventually end up with a string of the form `)*(*` where `*` is **the Kleene star**.
## Parentheses Monoid
## Parentheses Monoid
* Monoid:
* Monoid:
*`P = (…, ∙, …)` where `(a, b) ∙ (c, d) = (…, …)`
*`P = (𝐍 × 𝐍, ∙, (0, 0))` where `(a, b) ∙ (c, d) = (a + c - min(b, c), b + d - min(b, c))`
## Divide-and-Conquer Design
## Divide-and-Conquer Design
```
```
In: '()(())'
In: '()(())'
Out:
Out: 0, 0
/ \
/ \
/ \
/ \
/ \
/ \
In: '()(' In: '())'
In: '()(' In: '())'
Out: Out:
Out: 0, 1 Out: 1, 0
/ \ / \
/ \ / \
/ \ / \
/ \ / \
In: '(' In: ')(' In: '(' In: '))'
In: '(' In: ')(' In: '(' In: '))'
Out: Out: Out: Out:
Out: 0, 1 Out: 1, 1 Out: 0, 1 Out: 2, 0
/ \ / \
/ \ / \
/ \ / \
/ \ / \
In: ')' In: '(' In: ')' In: ')'
In: ')' In: '(' In: ')' In: ')'
Out: Out: Out: Out:
Out: 1, 0 Out: 0, 1 Out: 1, 0 Out: 1, 0
```
```
## New Iterative Solution
## New Iterative Solution
...
@@ -303,22 +303,22 @@ function isBalanced(parentheses) {
...
@@ -303,22 +303,22 @@ function isBalanced(parentheses) {