Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 18, Problem 1P

(a)

Program Plan Intro

Describe thenumber of disk accesses and CPU time for n stack operations in worse-case by using the simple implementation.

(a)

Expert Solution
Check Mark

Explanation of Solution

In worse case for every stack operation it requires disk access for implementation sothe number of disk accesses for n stack operations using this simple implementation is asymptotically equals to θ(m) .

The CPU time in worse case for n -stack operations is θ(mn) .

(b)

Program Plan Intro

Describethe number of diskaccesses and the CPU time required for n -PUSH operations in worse-case.

(b)

Expert Solution
Check Mark

Explanation of Solution

The new page starts only when everymthpushes therefore the number of disk operations is n/m. The diskaccess requires time of asymptotically θ(n) .

Hence,the number of disk accesses and CPU time for n - PUSH operations in worse-case is θ(n) .

(c)

Program Plan Intro

Describe the disk accesses and the CPU time required for n -stack operations in worse-case.

(c)

Expert Solution
Check Mark

Explanation of Solution

Stack operations include PUSH and POP. The PUSH and POP operations requires alternate disk accesses that means mdisk accesses for performing stack operation so the number of disk accesses asymptotically is θ(m) .

The CPU time for performing stack operations is equal to θ(mn) ,where m is number of words andn is number of stack operations.

(d)

Program Plan Intro

Describe that the amortized number of disk accesses is O (1 /m ) and the amortized CPU time is O (1) for any stack operation .

(d)

Expert Solution
Check Mark

Explanation of Solution

At the initial function called as Potential Function of stack defined by difference of size of stack and recent pass which is multiple of m. The value of potential function is 0 at initial state.

When any stack operation is performed the value is decreased and increased according to the operation by one.Loading new pages requires the position which is at leastm position away from recent position to cross the page boundary therefore loading and storing of new stack page requires CPU time of O ( m ).

By dropping appropriate Potential function of order O ( m ) and selecting the suitable value for potential value results to managed the stack pages so that the amortized number of disk accesses for any stack operation is O (1 /m ) and the amortized CPU time for any stack operation is O (1).

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Suppose you have a stack with a maximum size of 1000 elements and you want to perform the following operations: Push 500 elements onto the stack. Pop 200 elements from the stack. Push 800 elements onto the stack. Pop all remaining elements from the stack. What is the final size of the stack after performing all these operations?
Complete the following ():a. A stack is used by the system when a function call is madeb. A stack can become full during program execution
Examine the stack's performance when it is allowed to operate in its natural state.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning