74 views2 pages
School
Course
Professor
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
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

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: 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. Write and test the following function: def is_mirror(string): Determines if a string is a mirror string or not. (uses a stack) Parameters: string - the string to test (str)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents