HW6 ans - 1 Say you want to have a string of n as followed...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1. Say you want to have a string of n a’s followed by n b’s. Pretend like your computer can only read character-by-character and cannot traverse backwards in the string. Show how you can use a stack to make sure you have n b’s after n a’s. As you read the string, push any a you encounter onto the stack. Once you start reading b’s, pop a’s for every b you encounter. If the stack is emptied by reading the last b, you pass. If the stack has something when the string has been read or if the stack becomes empty before reading the last b, then the string is not of the correct form. aaabbb - > pass aaabb - > fail aabbb - > fail 2. Similar problem to one, only we have n a’s followed by n b’s followed by n c’s. Again, assume the computer can only read character-by-character and can’t traverse backwards. Can you use one stack to make sure the string is of this type? If not, how many do you need? Run the same algorithm but with two stacks. When reading a’s push
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 3

HW6 ans - 1 Say you want to have a string of n as followed...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online