example the following table shows series of operations and their effects on an initially empty deque of integers operation add last( add first( add first( firstd delete lastlen(dd delete lastd delete lastd add first( lastd add first( is emptyd lastreturn value false deque [ [ [ [ [ [ [ [[ [ [ [ [ implementing deque with circular array we can implement the deque adt in much the same way as the arrayqueue class provided in code fragments and of section (so much so that we leave the details of an arraydeque implementation to exercise - we recommend maintaining the same three instance variablesdatasizeand front whenever we need to know the index of the back of the dequeor the first available slot beyond the back of the dequewe use modular arithmetic for the computation for exampleour implementation of the lastmethod uses the index back (self front self size len(self dataour implementation of the arraydeque add last method is essentially the same as that for arrayqueue enqueueincluding the reliance on resize utility likewisethe implementation of the arraydeque delete first method is the same as arrayqueue dequeue implementations of add first and delete last use similar techniques one subtlety is that call to add first may need to wrap around the beginning of the arrayso we rely on modular arithmetic to circularly decrement the indexas self front (self front len(self datacyclic shift the efficiency of an arraydeque is similar to that of an arrayqueuewith all operations having ( running timebut with that bound being amortized for operations that may change the size of the underlying list