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
Modular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
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
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr