Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 3. (15 marks) Once a Push() call is invoked on a full stack (stack.size- stack.capacity), we increase the capacity of a stack (or a

image text in transcribed

Problem 3. (15 marks) Once a Push() call is invoked on a full stack (stack.size- stack.capacity), we increase the capacity of a stack (or a queue, or a hash-table) using IncreaseCapacity) 1. Allocate a new array with 2 x stack.capacity cells; 2. Copy all items from the original array to the new array, delete the old array Analogously to this, once stack.size is small in comparison to stack.capacity, we can decrease the capacity and clear some memory using DecreaseCapacity() 1. Allocate a new array with stack.capacity/2 cells; 2. Copy all items from the original array to the new array, delete the old array Note that both increas eCapacity() and DecreaseCapacity() run in ?(n)-time a. (5 marks) Prove that invoking DecreaseCapacity) whenever stack.size- stack.capacity/2 is unwise. That is, show that starting with stack.size -0, there exists a sequence of n Push/Pop ) instructions whose amortized cost is S2(n) b. (10 marks) Prove that invoking DecreaseCapacity() whenever stack, size = stackcapacity/3 main- tains constant amortized cost. That is, show that any sequence of n PushO/Pop) instructions has amortized cost of O(1). You may assume stack.capacity1 initially Hint: Call an instruction heavy if it invokes either IncreaseCapacity) or DecreaseCapacity); and call it light otherwise. Light instructions always take O(1). Your argument should probably begin by showing that between any two heavy instructions there have to be at least p m light instructions (by considering all 4 possible cases), where m denotes the capacity of the stack between the two heavy instructions and 0

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

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions