Data Structures and Algorithm (Stacks and Queues)
Imagine you have a Queue of integers, Q1 and Q2. Draw a picture of Q1 and Q2 after the following operations:
**Note: make sure that ALL variables are simulated.**

The processing of the Queue Q1 and Q2 is given below :
Step 1 :
| Q1 | 5 | ||||||
| Q2 | 5 |
| Q1 | |||||||
| Q2 | 5 | 5 |
Step 2 :
| Q1 | 7 | ||||||
| Q2 | 7 | 5 | 5 |
| Q1 | |||||||
| Q2 | 7 | 7 | 5 | 5 |
Step 3 :
| Q1 | 12 | ||||||
| Q2 | 12 | 7 | 5 | 5 |
| Q1 | |||||||
| Q2 | 12 | 12 | 7 | 7 | 5 | 5 |
Step 4 :
| Q1 | 4 | ||||||
| Q2 | 4 | 12 | 7 | 7 | 5 | 5 |
| Q1 | ||||||||
| Q2 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
Step 5 :
| Q1 | 0 | ||||||||
| Q2 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
| Q1 | ||||||||||
| Q2 | 0 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
Step 6 :
| Q1 | 4 | |||||||||||
| Q2 | 4 | 0 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
| Q1 | ||||||||||||
| Q2 | 4 | 4 | 0 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
Step 7 :
| Q1 | 6 | ||||||||||||||
| Q2 | 6 | 4 | 4 | 0 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
| Q1 | ||||||||||||||
| Q2 | 6 | 6 | 4 | 4 | 0 | 0 | 4 | 4 | 12 | 12 | 7 | 7 | 5 | 5 |
Data Structures and Algorithm (Stacks and Queues) Imagine you have a Queue of integers, Q1 and...
Queues and Stacks Purpose: To review queues and stacks in Java, and to use the built-in Stack class and Queue interface. The Stack class is a generic class containing these methods: public void push(E value) - pushes a new value onto the Stack public E pop() - pops the next value off of the stack and returns it; throws EmptyStackExceptionl if stack is empty public E peek() - returns the next value on the Stack but does not pop it...
Imagine that the contents of queue Q1 and queue Q2 are as shown. What would be the contents of Q3 after the following code is executed? The queue contents are shown front (left) to rear (right). Q1: 42 30 41 31 19 20 25 14 10 11 12 15 Q2: 4 5 4 10 13 1 Q3 = createQueue 2 count = 0 3 loop (not empty Q1 and not empty Q2) 1 count = count + 1 ...
3) Stacks vs Queues: a) A Circular Array is a common data structure for a buffer (a type of queue). Why is this advantageous over a regular array? (Hint: think about common queue operations and what they do to an array). b) Show a traversal of the following tree using a stack: 26 1 25 2 17 3 2. (19 7 1 (The numbers under the bubbles are a node number, not the data. ) c) Why would using a...
What would be the contents of queue Q1 and Q2 after the following code is executed and the following data are entered?1 Q1 = createQueue2 Q2 = createQueue3 loop (not end of file)1 read number2 enqueue (Q1,number)3 enqueue (Q2,number)4 loop (not empty Q1)1 dequeue (Q1,x)2 enqueue (Q2,x)5 end loop4 end loopThe data are 5, 7, 12, 4, 0, 4, 6
Module 4 follow the materials available at Topic - Stacks and Queues. You should have a good understanding of Lists at Topic - Basic Data structures as a Queue and a Stack are simply implementation of a List with specific properties. Assignment - Implement a Stack computer in Javascript (you will turn in a link to your program in JSFiddle). This is a simple computer that keeps a stack, when a number is entered it goes onto the top of the...
You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List – that will technically make it a queue). You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1). When creating your Queue object use the correct function names for enqueue and dequeue functions. Again – sorry, cannot use an Javascript array...
Let’s say we have two empty stacks of integers, S1 and S2. Draw a picture of each stack after the following operations: pushStack(S1, 2); //push 2 into S1 pushStack(S1, 4); pushStack(S1, 6); pushStack(S1, 8); pushStack(S1, 10); pushStack(S1, 12); while ( !emptyStack(S1) ) { popStack(S1, x); //pop the top item of S1 and save it to variable x popStack(S1, x); pushStack(S2, x) }
IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...
Multiple choice data structures questions about stacks. Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a sequence of parentheses is balanced: declare a character stack while ( more input is available) { read a character if ( the character is a '(' ) push it on the stack else if ( the character is a ')' and the stack is not empty ) pop a character off the stack else print "unbalanced" and exit...
Create a CircularArrayQueue<E> implementation of the Queue<E> interface defined in class. Hints: You will need two index variables to keep track of the start and the end of the queue. Consider the queue to be empty when the front/back index pointers are equal (which means that the 'back' pointer will always be pointing at the next place to add an item). Be careful of index increments and decrements; make sure you perform the operations necessary to make the pointers loop...