Question: this is all i have from pythonds.basic import Deque deck=Deque print(deck.isEmpty() deck.addRear (44) deck.addRear('cat') print(deck.size() deck.addFront (False) print(deck.isEmpty O) print(deck.size()). deck.addFront (3.1415) print(deck, removeFront) print(deck.size()

 this is all i have from pythonds.basic import Deque deck=Deque print(deck.isEmpty()
deck.addRear (44) deck.addRear('cat') print(deck.size() deck.addFront (False) print(deck.isEmpty O) print(deck.size()). deck.addFront (3.1415) print(deck,
removeFront) print(deck.size() print (deck.removeRear) print(deck.removeFront() print(deck.size() class Deque: def init__(self): self.items =
this is all i have

from pythonds.basic import Deque deck=Deque print(deck.isEmpty() deck.addRear (44) deck.addRear('cat') print(deck.size() deck.addFront (False) print(deck.isEmpty O) print(deck.size()). deck.addFront (3.1415) print(deck, removeFront) print(deck.size() print (deck.removeRear) print(deck.removeFront() print(deck.size() class Deque: def init__(self): self.items = [] def isEmpty(self): return self.items == [] def addFront(self, item): self.items.append(item) def addRear (self, item): self.items.insert(0, item) def removeFront(self): return self.items.pop() def removeRear(self): return self.items.pop() def size (self): return len(self.items) Description Develop a Python solution to the following problems. 1. Motivating observations. a. The Big-O for the addFront() and removeFront() methods are both 0(1). b. The Big-O for the addRear() and removeRear() methods are both O(n). C. We would like to use a dictionary inside a Deque2 class to result in constant time performance 0(1) for addFront(), addRear(), removeFront(), and removeRear(). 2. Create a new Deque class, called Deque2, and modify this class as follows. (You may start by copying the Deque.py file from the pythonds folder.) a. Use a dictionary instead of a list to store the items in the double ended queue. That is, self.items should be initialized to an empty dictionary. i. You will need to determine how you will know the key value for the front and rear of the double ended queue. Hint: you will likely need a few instance variables to keep track of this information. b. Modify each method so that it will work for the self.items dictionary. C. Have the removeFront and removeRear methods return None when self.items is empty. 3. In your deque2.py source code file, add test code to test your Deque2 class. a. Be sure you are testing each method. b. Be sure you are testing use of a dictionary under the following conditions. i. Does each method work when the dictionary is empty? il. Does each method work when the dictionary contains exactly one item? iii. Does each method work when the dictionary contains many items? 4. What files should you submit? a. Submit one Python source code file-deque2.py - as described in steps 2 and 3

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!