Introduction To Cs 2

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 1

Santa's Dirty Socks

Overview:
This activity introduces the idea of "divide and conquer" using a fictitious but serious problem - a
pair of dirty socks have accidently been wrapped in one of the presents that Santa is about to
deliver, and he needs to figure out which one to avoid a child getting a nasty surprise. You can
either play the video (below), or download the PDF of the book (see the PDF files below) to read
aloud or give to students. The solution in the story points out that when there are 1024 boxes to test,
instead of having to open all of them until the socks are found, one half can be eliminated at a time,
and repeatedly halving the problem very quickly narrows it down to one box (the size of the
problem starts at 1024, then with one weighing there are 512 boxes, then 256, 128, 64, 32, 16, 8, 4, 2
and 1.) This idea comes up frequently in the design of fast computer algorithms.

Essence of Divide and Conquer


1. Divide problem into several smaller subproblems
• Normally, the subproblems are similar to the original

2. Conquer the subproblems by solving them recursively
• Base case: solve small enough problems by brute force

3. Combine the solutions to get a solution to the subproblems
• And finally a solution to the orginal problem

4. Divide and Conquer algorithms are normally recursive

You might also like