Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The operations pop, init are in an obvious way in O ( 1 ) in any scenario, so the average runtime will be also in

The operations pop, init are in an obvious way in O(1) in any scenario, so the average runtime will be
also in O(1).[Marking: 5 marks for each of pop, init, correctly indeitified as O(1)]
Now push analysis. Assume we have n different elements (comparable, so they can be sorted in increasing
order).
In order to push an element in k steps, we need to remove from top of the stack k elements greater than
the element being inserted. Since we assume uniform distribution, each of the k elements already in the
stack, are picked with following probabilities:
First element 1/n Second 1/(n-1)... k-th element 1/(n-k).
For them to occur together, probability is 1n(n-1)dots(n-k)2n2 for any n2 and precisely 1n for n=1.
Hence E(t=k)1n+22n2+cdots+2kn21n+2k2n23, showing averahe runtime is in O(1).
[marking: 5 marks for a correct argument, 3 marks for an approximately correct argument, 0 otherwise]
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

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

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago