Before jumping into the code, learn one approach to solving the balanced symbols problem, which makes use of the "fail fast" paradigm.
(light music)…- [Instructor] Let's talk through one possible solution…to the stacks challenge.…The approach I took was to fail fast.…I chose to return False as soon as I hit a mismatch.…If I got through the whole input string…and the stack was empty, then I returned True…because that would mean that all the symbols were balanced.…If I didn't encounter that situation, I would return False.…I decided to loop through the symbols of the input string.…If one of those symbols was an opening symbol,…I would push it onto my stack.…
If the symbol that I got to was a closing symbol,…then I would check to see if the top item on the stack…was its matching opening symbol.…If they were a matched pair, the symbols would be balanced…and so, I could move on to the next symbol in the string.…If they weren't a pair, I could return False immediately.…By the end of all that iterating,…if I had made it through the whole input string…and the stack was empty, I could return True…because I would know that all of the symbols were balanced.…
- Abstract types and data structures
- Stacks as a linear abstract data type
- Creating the Stack class and its methods
- Adding items to the top and bottom of a stack
- Creating the Queue class and its methods
- Manipulating items in a queue
- Creating the Dequeue class and its methods
- Adding and removing items from a dequeue
Skill Level Advanced
Learning the Python 3 Standard Librarywith Kathryn Hodge2h 10m Intermediate
What you should know1m 26s
1. Abstract Data Types and Data Structures
2. The Stack
3. The Queue
4. The Deque
Next steps1m 43s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.