Menu

[solved]-Code Questions Python Submitting Answer Please Show Screenshots Code Instead Typing Commen Q39040071

How to code all these questions in Python? When submitting theanswer, please show screenshots of code instead of typing it out ina comment so it is easier to see and understanding. Please nakesure the code is shown for all questions. just answering the firstquestion would be an incomplete answer!
Stacks with Queues 3 In this problem, try to implement a stack using a queue. Write a class called class QStack that has implor raise an Exception if the stack is empty def top(self) Returns (without removing) the element at the top of the stack

Stacks with Queues 3 In this problem, try to implement a stack using a queue. Write a class called class QStack that has implements the stack ADT. It should have an instance of the class ArrayQueue as a data member (use the ArrayQueue class we wrote in lecture – you can get the code from NYU Classes). You can only access and modify this ArrayQueue instance by using the methods that are defined as part of the ArrayQueue class (that is, the methods that make up the interface of the Queue ADT). Your QStack class may also use O(1) additional space for other data members as necessary (this is a constant amount of extra spaceso you may not include extra data structures or collections of non-constant size) Recall that as the QStack will implement the Stack ADT, you must define all the operations of the Stack ADT. A skeleton of the class along with the methods you must implement is below: class QStack: def_init__ (self, max_num_of_elems) Initialize an empty leaky stack” self.data queue = Array Queue ( # You may need to add to this cons tructor, such as adding more data memb ers # But you should at minimum have the ArrayQueue data member as above def len__(self) Return the number of elements in the stack’ ‘ ‘ def is_empty (self) ‘Returns True if the stack is empty’ def push(self, elem) Adds elem to the top of the stack” def pop(self) Remove and return the element at the t op of the stack or raise an Exception if the stack is empty’ ” def top(self) ‘Returns (without removing) the element at the top of the stack or raise an Exception if the stack is empty”’ Hint: You will not be able to achieve O(1) worst-case running times for all operations. In fact, some operations may be very inefficient. That is okay: There is no running time requirement for this problem (however, see below). Analyze the running time of the operations in your implementation, particularly push and pop. In the code you submit, include the running time of each of your operations in a comment at the top of each method’s implementation. While there is no requirement for efficiency, you must analyze the running times and include them in your submission for full credit Also think about, but don’t submit: Which of the operations, push or pop, is more efficient in your implementation? If your pop is more efficient, can you think of an alternate implementation where push would be more efficient (possibly at the expense of making pop less efficient)? If your push is more efficient, can you think of an alternate implementation where pop would be more efficient (at the expense of making push more expensive)? Show transcribed image text Stacks with Queues 3 In this problem, try to implement a stack using a queue. Write a class called class QStack that has implements the stack ADT. It should have an instance of the class ArrayQueue as a data member (use the ArrayQueue class we wrote in lecture – you can get the code from NYU Classes). You can only access and modify this ArrayQueue instance by using the methods that are defined as part of the ArrayQueue class (that is, the methods that make up the interface of the Queue ADT). Your QStack class may also use O(1) additional space for other data members as necessary (this is a constant amount of extra spaceso you may not include extra data structures or collections of non-constant size) Recall that as the QStack will implement the Stack ADT, you must define all the operations of the Stack ADT. A skeleton of the class along with the methods you must implement is below: class QStack: def_init__ (self, max_num_of_elems) Initialize an empty leaky stack” self.data queue = Array Queue ( # You may need to add to this cons tructor, such as adding more data memb ers # But you should at minimum have the ArrayQueue data member as above def len__(self) Return the number of elements in the stack’ ‘ ‘ def is_empty (self) ‘Returns True if the stack is empty’ def push(self, elem) Adds elem to the top of the stack” def pop(self) Remove and return the element at the t op of the stack
or raise an Exception if the stack is empty’ ” def top(self) ‘Returns (without removing) the element at the top of the stack or raise an Exception if the stack is empty”’ Hint: You will not be able to achieve O(1) worst-case running times for all operations. In fact, some operations may be very inefficient. That is okay: There is no running time requirement for this problem (however, see below). Analyze the running time of the operations in your implementation, particularly push and pop. In the code you submit, include the running time of each of your operations in a comment at the top of each method’s implementation. While there is no requirement for efficiency, you must analyze the running times and include them in your submission for full credit Also think about, but don’t submit: Which of the operations, push or pop, is more efficient in your implementation? If your pop is more efficient, can you think of an alternate implementation where push would be more efficient (possibly at the expense of making pop less efficient)? If your push is more efficient, can you think of an alternate implementation where pop would be more efficient (at the expense of making push more expensive)?

Expert Answer


Answer to How to code all these questions in Python? When submitting the answer, please show screenshots of code instead of typing… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *