CP164 Final: Stacks
Notes - Stacks - The Mirror Problem
We have already used stacks check if brackets are properly balanced. We can use a similar
idea to determine if a string is a mirror. A mirror can be thought of as a special form of a
palindrome, and consists of a string of the form:
LmR
where:
• m is the mirror character at the centre of the string
• L and R are strings where R is the reverse of L (They may be empty strings)
• L and R are formed from a limited set of characters that do not include m
•
Some examples of the abc mirror pattern (i.e. L and R are limited to the characters abc):
cmc
bbaamaabb
m
abacmcaba
These strings do not fit the abc mirror pattern:
abmb
gmg
abacmcabb
find more resources at oneclass.com
find more resources at oneclass.com