Before jumping into the code, learn one approach for using a deque to determine whether or not a string is a palindrome.
(tinkly music)…- [Instructor] While there are of course…many approaches you could've taken to solving this problem,…I'll share with you what I decided to do.…I knew that I would have to loop through the input string…and add all of the characters to the rear of the deck…to get them into the deck.…I chose to add each item to the rear of the deck…because adding an item to the rear of the deck…is a constant time operation.…As long as the deck's size is greater than two,…I would remove the front-most item…and the rear-most item from the deck,…and store each of those in their own variables.…
If those two variables aren't equivalent,…I would return false right away.…If the two variables are equivalent though,…then I could proceed to the next pair of items.…If the size of the deck eventually gets to be smaller…than two, meaning there's only one…or zero characters left in the deck,…then I know the string is a palindrome,…and I can return true.…Now let's talk through how I implemented this in code.…
- 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 9m 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.