Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 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

Step: 1

To derive the expected number of steps taken to perform all n operations we need to consider the exp... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete Mathematics and Its Applications

Authors: Kenneth H. Rosen

7th edition

0073383090, 978-0073383095

More Books

Students also viewed these Programming questions