Question: 2. (15 marks) Consider the abstract datatype SEQ whose objects are sequences of elements and which supports two operations: PREPEND(x, S), which inserts element

2. (15 marks) Consider the abstract datatype SEQ whose objects are sequences

  

2. (15 marks) Consider the abstract datatype SEQ whose objects are sequences of elements and which supports two operations: PREPEND(x, S), which inserts element r at the beginning of the sequence S and ACCESS(S, i), which returns the i'th element in the sequence. Suppose that we represent S by a singly linked list. Then PREPEND(x, S) takes 1 step and ACCESS(S, i) takes i steps, provided S has at least i elements. Suppose that S initially has exactly one element. A sequence of n operations are performed. Each operation in the sequence is (independently) chosen to be a PREPEND with probability p and an ACCESS with probability 1-p. For each ACCESS operation, the value of the parameter i is chosen uniformly from [1..|S|]. (d) (4 marks) Derive the expected number of steps taken to perform all n operations.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To derive the expected number of steps taken to perform all n operations we need to consider the exp... View full answer

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 Programming Questions!