In this example, we prove that when we set index 1 of list [0, [1, [2,[]]]] to 4, the result is [0, [4, [2, []]]].

There are two parts to this process. In part 1, we pop an element from the front of the list, store this element in a "visited" list, and decrease the index by 1. We repeat this until index is 0. At this point, we have reached the element that we want to replace.

In part 2, we pop the element to be replaced. Then we prepend the new value (4) to the "visited" list, reverse it, and then prepend the reversed list to the remaining list.

For instance, the following:

set index 1 of remaining stack [ 0, [ 1, [ 2, [ ] ] ] ] to 4 with visited : [ ]

is equal to:

set index 0 of remaining stack [ 1, [ 2, [ ] ] ] to 4 with visited : [ 0, [ ] ]

which is equal to:

result of dumping [ 4, [ 0, [ ] ] ] to [ 2, [ ] ]

which is equal to:

[ 0, [ 4, [ 2, [ ] ] ] ]

Quiz (1 point)

Prove that:
result of storing 4 at index 1 of stack [ 0, [ 1, [ 2, [ ] ] ] ] = [ 0, [ 4, [ 2, [ ] ] ] ]

The following properties may be helpful:

Please write your proof in the table below. Each row should contain one claim. The last claim is the statement that you are trying to prove.

Step Claim Reason (optional) Error Message (if any)
1
2
3
4
5
6
7
8
9
10

Become a subscriber to save your progress, see the correct answer, and more!