10- question Consider the following pseudocode that uses a queue. Declare a queue Q1 and a stack S1 Get the input string from the user While (there are more characters in the input string) { read a character from the input string // the characters will be read starting from the beginning of string enqueue the character to the queue Q1 } While (queue Q1 is not empty) { dequeue a character off the queue Q1 push the dequeued character to stack S1 } While (stack S1 is not empty) { Pop a character off the stack S1 Write the popped character to the screen } What is output for input "hello"? a) hello b) olleh c) hheelllloo d) oolllleehh a) correct answer: a b) correct answer: b c) correct answer: c d) correct answer: d Bo? b?rak
Added by Salvador G.
Close
Step 1
The input string is "hello". Show more…
Show all steps
Your feedback will help us improve your experience
K S and 81 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write pseudo-code for problems requiring code. Do not write Java, Python or C++. You are responsible for the appropriate level of detail. 1. a) Use the operations push, pop, peek and empty to construct an operation which sets i to the bottom element of the stack, leaving the stack unchanged. (hint: use an auxiliary stack.) b) Use the operations push, pop, peek and empty to construct an operation which sets i to the third element from the bottom of the stack. The stack may be left changed. 2. Simulate the action of the algorithm for checking delimiters for each of these strings by using a stack and showing the contents of the stack at each point. Do not write an algorithm. a) {[A+B]-[(C-D)] b) ((H) * {([J+K])})
Supreeta N.
Q 8. Consider the context-free grammar G with terminal symbols T = {x, y, e, -1, (, )}, non-terminal symbols N = {σ, F, B}, starting symbol σ, and production rules σ → Fσ | F F → B | B-1 B → x | y | e | (Fσ) Note that we are regarding -1 as a single symbol. The string B-1, for example, has length 2; it is the symbol B followed by the symbol -1. (a) Give leftmost derivations in G for each of the following strings. (i) e-1 (ii) y-1x-1 (iii) xyx-1y-1 (b) Use the method of Lecture 8B to draw the transition diagram of a PDA accepting the language generated by G. State the input alphabet and the stack alphabet of your PDA. (c) Show how your PDA in (b) accepts the string y-1x-1. Your answer to (a)(ii) will be useful.
Adi S.
(Vowel or consonant?) Write a program that prompts the user to enter a letter and checks whether the letter is a vowel or consonant. For a non-letter input, display invalid input. Sample Run 1: Enter a letter: B B is a consonant Sample Run 2: Enter a letter: a a is a vowel Sample Run 3: Enter a letter: # # is an invalid input Class Name: Exercise 04 13 If you get a logical or runtime error, please refer to https://liveexample.pearsoncmg.com/fag.html.
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD