Using Figure 10.1 as a model, illustrate the result of each operation in the sequence PUSH(S, 4), PUS(S, 1), PUSH(S, 3), POP(S), PUSH(S, 8), and POP(S) on an initially empty stack S stored in array S [1… 6].
ok we have a stack of size 6 which is initially empty.
1. operation push(s,4)
stack will look like
4
2)
push(s,1)
stack will look like
1
4
3)
push(s,3)
stack will look like
3
1
4
4)
pop(s)
stack will look like
1
4
5) push (s,8)
stack will look like
8
1
4
6)
pop(s)
stack will look like
1
4
Finally stack will have two values
1
4
Using Figure 10.1 as a model, illustrate the result of each operation in the sequence PUSH(S,...
Data Structures and Algorithm Analysis illustrate the result of each operation in the sequence PUSH(S, 4), PUSH(S, 2), POP(), PUSH(S, 3), PUSH(S, 9), POP(), and PUSH(S, 0) on an initially empty stack S stored in array S[1..6]. 1 2 3 4 5 6 7 1 2 3 4 5 6 7 15 6 2 9 17 3 S15 6 29 173 top[S] = 4 top[S] = 6 top[S] = 5
3. (15 points) Using Figure 6.3 as a model, illustrate the operation of BUILD-MAX-HEAP on the array A = (3,2,15,9, 70, 18,5, 33, 8).
Problem solving manually 2. Using Figure 2.4 as a model, illustrate the operation of merge sort on the array A = 〈11, 9, 13, 2, 7, 8, 3, 11, 5〉.
Use Figure 6.4 as a model, illustrate the operation of HEAPSORT on the array A = <4, 10, 7, 25, 8, 3>. Show all intermediate steps how the heap is transformed. 6.4/ 91|11|016 | 8|4|||7|V (9) 09
Define a class DoubleStack which implements two stacks of objects of type Object using a single shared array, so that the push and pop operations specify which of the two stacks is involved in the operation (as described below). (a) Specify necessary instance variables and write a constructor “DoubleStack(int n)” that takes integer n and creates an empty DoubleStack object with the shared array with room for n elements (2 pt); b) Write methods "boolean push(int i, Object o)" and...
(ii) [6 marks] Assume that we have an empty stack S and an empty queue Q. Given a series of stack operations on S as below: Push(S,10), Push(S, 7), Push(S, 23), Pop(S), Push(S, 9), Pop(S), Pop(S) Output the element returned by each Pop operation. Given a series of queue operations on Q as below: Enqueue(0,10),Enqueue(Q,20), Enqueue(0,33), Dequeue(Q), Enqueue(Q,55), Dequeue(Q), Dequeue(Q) Output the element returned by each Dequeue operation. (iii) [8 marks] Given an empty binary search tree T, draw the...
Backtracking is a computing algorithm using stack to “remember” user-generated events when using a program. A user event may be “pressing the Enter key on keyboard” or “clicking a mouse button”. Stack is a data structure with the Last-In-First-Out property (LIFO). If we push the aforesaid user events into a stack, a computer program using that data structure can “rewind” user events by popping them out of stack one at a time. This backtracking feature is available as Edit ->...
Please help with program this. Thank you so much in advance! Create a Java program which implements a simple stack machine. The machine has 6 instructions Push operand Puts a value on the stack. The operand is either a floating point literal or one of 10 memory locations designated MO M9 Pop operand Pops the value on the top of the stack and moves it to the memory location MO-M9 Add Pops the top two values off the stack, performs...
//stack_exception.h #ifndef STACK_EXCEPTION #define STACK_EXCEPTION #include <string> using namespace std; class Stack_Exception { public: Stack_Exception(string what) : what(what) {} string getWhat() {return what;} private: string what; }; #endif //stack_test_app.cpp #include <iostream> #include <sstream> #include <string> #include "stack.h" using namespace std; /********************************************* * The 'contains' function template goes here * *********************************************/ int main() { cout << boolalpha; cout << "--- stack of int" << endl; Stack<int> si; cout << "si intially " << si << endl; ...
Suppose the following operations are performed on a queue containing integers. Create an empty queue Push 1 Push 2 Push 3 Pop Push 4 Push 5 Pop Now do the following: a. Draw a sketch of a doubly linked-list based queue after steps 1-4. b. Draw a sketch of a doubly linked-list based queue after all steps 1-8. c. Draw a sketch of a circular array-based queue with capacity 6 after steps 1-4. Specify f, t, and size after each...