As Chapter 4 pointed out, you can define ADT operations in a mathematically formal way by using axioms. For example, the following axioms formally define the ADT stack, wherestack is an arbitrary stack anditem is an arbitrary stack item.
(aStack.createStack()).isEmpty()= true
(aStack.push(item)).isEmpty() =false
(aStack.createStack()) .pop() = error
(aStack.push(item)).pop() = aStack
(aStack.createStackf)) .peek() = error
(aStack.push(item)).peek() =item
You can use these axioms, for example, to prove that the stack defined by the sequence of operations
Create an empty stack
Push a 5
Push a 7
Push a 3
Pop (the 3)
Push a 9
Push a 4
Pop (the 4)
which you can write as
(((((((aStack.createStackf)) .push(5)).push(7)).push(3)). pop()).push(9)).push(4)).pop()
is exaedy the same as the stack defined by the sequence
Create an empty stack
Push a 5
Push a7
Push a 9
which you can write as
(((aStack.createStack()).push(5)).push(7)).push(9) .
Similarly, you can use the axioms to show drat
(((((((aStack.createStack()).push(l)).push(2)).pop()).push(3)).pop())«pop())•isEmpty()
is true.
a. The following representation of a stack as a sequence ofpush operations without anypop operations is called a canonical form:
(...(aStack.createStack()).push()).push()...).push()
Prove that any stack is equal to a stack that is in canonical form.
b. Prove that the canonical form is unique. That is, a stack is equal to exactly one stack that is in canonical form.
c. Use the axioms to show formally that
((((((((((aStack.createStack()).push(6)).push(9)). pop()).pop()).push(2)).pop()).push(3)).push(l)). pop()).peek()
equals 3.
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.