As Chapter pointed out, you can define ADT operations in a mathematically formal way by using axioms. Consider the following axioms for the ADT queue, where queue is an arbitrary queue and item is an arbitrary queue item.
(queue.createQueue()).isEmpty() = true
(queue.enqueue(item)).isEmpty() =false
(queue.createQueue()).dequeue() =error
((queue.createQueue()).enqueue(item)).dequeue() =
queue.createQueue()
queue. isEmpty () = false =>
(queue.enqueue(item)).dequeue() =
(queue.dequeue()).enqueue(item)
(queue.createQueue()) .peek() = error
((queue.createQueue()).enqueue(item)).peek() = item
queue.isEmpty() = false =>
(queue.enqueue(item)).peek() = queue.peek()
a. Note the recursive nature of the definition of peek. What is the base case? What is the recursive step? What is the significance of the isEmpty test? Why is peek recursive in nature while the operation peek for the ADT stack is not?
b. The representation of a stack as a sequence of push operations without any pop operations was called a canonical form. (See 16a in Chapter.) Is there a canonical form for the ADT queue diat uses only enqueue operations? That is, is every queue equal to a queue that can be written with only enqueues? Prove your answer.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.