D c examples
This presentation is the property of its rightful owner.
Sponsored Links
1 / 7

D&C Examples PowerPoint PPT Presentation


  • 72 Views
  • Uploaded on
  • Presentation posted in: General

D&C Examples. Notes:. There may be several ways to solve the same problem. Try to find a better one. To stick with the topic, try to think in the way of D&C. In case you have a straight forward approach, try to compare the expected runtime with the D&C result. D&C: Tower of Hanoi.

Download Presentation

D&C Examples

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


D c examples

D&C Examples


Notes

Notes:

  • There may be several ways to solve the same problem. Try to find a better one.

  • To stick with the topic, try to think in the way of D&C.

  • In case you have a straight forward approach, try to compare the expected runtime with the D&C result.


D c tower of hanoi

D&C: Tower of Hanoi

You are given three pads (A,B,C). On pad A, you have n disks, arranged from the smallest on top and the largest at the bottom.

At any moment, a larger disk cannot be stacked on top of a smaller disk.

You can move the top disk of one pad to the other pad, provided that the constraint holds.


D c tower of hanoi1

C

C

A

A

B

B

D&C: Tower of Hanoi

Find a way to move n disks from the pad A to pad C.


D c tower of hanoi2

C

A

B

D&C: Tower of Hanoi

Restricted Tower of Hanoi

Modification:

You can move to and from adjacent pads (A<->B,B<->C)

Derive a way to move n disk from pad A to pad C.


D c power

D&C: Power

Derive a way to compute bp quickly.

You may ignore the possible overflow problem.

Modification:

Modulo power

Derive a way to compute bp mod n quickly.


D c josephus problem

D&C: Josephus Problem

Refer to task 1030 for the problem description.

Suppose you are to find the remainder only.

(The dying sequence is not important here)

Find a quick way to locate the survival position.

Modification:

General Josephus Problem

Suppose the killing sequence is skipping k people instead of 2. Is there any good method?


  • Login