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
A data structure known as a drop-out stack functions exactly like a stack, with the exception that if the stack size is n, the first element is lost when the n + 1 element is pushed. Use an array to implement a drop-out stack. (Hint: It would make sense to implement a circular array.)
Consider the Stack ADT: Stack: push(x) adds x to top of stack pop() removes top element of stack and returns it size() returns number of elements in stack Select all options that allow for an efficient implementation based on the discussions from class. For any array implementation, you can assume the array is large enough so that making a larger one is not needed when pushing an item to the stack. Using an array with the top at the front of the array. Using an array with the top at the back of the array. Using a singly linked list with the top at the head of the list. Using a singly linked list with the top at the tail of the list. ENG
A data structure known as a drop-out stack functions exactly like a stack, with the exception that if the stack size is n, the first element is lost when the n + 1 element is pushed. Apply an array to a drop-out stack. (Hint: It would make sense to implement a circular array.)
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