1 / 58

Algorithmic Puzzles

Algorithmic Puzzles. Anany Levitin Villanova University anany.levitin@villanova.edu. Plan of the Talk. What is an algorithmic puzzle? Two taxonomies of algorithmic puzzles Algorithmic puzzles in research Algorithmic problem solving and puzzles in education Puzzles in job interviews (?)

tillie
Download Presentation

Algorithmic Puzzles

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithmic Puzzles Anany Levitin Villanova University anany.levitin@villanova.edu

  2. Plan of the Talk • What is an algorithmic puzzle? • Two taxonomies of algorithmic puzzles • Algorithmic puzzles in research • Algorithmic problem solving and puzzles in education • Puzzles in job interviews (?) • Q&A

  3. What is an algorithmic puzzle? An algorithm is a sequence of unambiguous instructions for solving a problem. A puzzle is a problem that challenges ingenuity. An algorithmic puzzleis a puzzle that involves the design or analysis of an algorithm.

  4. Birth of the term “algorithmic puzzle” oldest algorithmic puzzles are more than 1,200 years old(Alcuin of York’s river crossing puzzles c. 800 CE) just recently recognized as a special category of puzzles algopuzzlesA. K. Dewdney, Scientific American, June 1987 cyberpuzzlesD.Shasha, Doctor Ecco's Cyberpuzzles,2002 algorithmic puzzlesP. Winkler, Mathematical Puzzles: a Connoisseur’s Collection, 2004

  5. first large collection of algorithmic puzzles A. Levitin and M. LevitinAlgorithmic Puzzles, Oxford, 2011 30-page tutorial with 22 puzzles as examples and 150 other algorithmic puzzles divided into three difficulty levels

  6. Two Taxonomies of Algorithmic Puzzles Algorithmic puzzles can be classified by • puzzle types • algorithmic questions posed

  7. Some Types of Algorithmic Puzzles • river crossing and similar problems • weighing, measuring, and cutting puzzles • moving counter problems • state changing puzzles (coin turning, pancake frying) • chessboard problems (8 queens, knight’s tours)

  8. Some Types of Algorithmic Puzzles (cont.) • route and tracing puzzles • tiling problems • magic squares and related problems • sliding piece puzzles • 1-person games (Chinese Rings, Tower of Hanoi)

  9. 5 Types of Algorithmic Questions • find, for a given input, the output of a given algorithm • find an input yielding a required output by a given algorithm • find the number of steps needed to solve a puzzle by a given algorithm • design an algorithm for solving a given puzzle (often, in a minimum number of moves) • show that a puzzle has no solution with operations allowed by the puzzle

  10. Find an algorithm’s output • Fibonacci’s rabbit problem (1202) A man put a pair of rabbits in a place surrounded on all sides by a wall. How many pairs of rabbits can be produced from that pair in a year if it is supposed that every month each pair begets a new pair which from the second month on becomes productive?

  11. Find an algorithm’s input • Josephus ProblemThere are n people numbered 1 to n standing in a circle. Starting the count with person number 1, every second person is eliminated until only one person is left. Where in the circle should a person stand to remain the last person standing? • Infected Chessboard A virus spreads through squares of an nn chessboard infecting squares that have two infected neighbors (horizontally, vertically, but not diagonally). What is a smallest subset of unit squares that need to be infected initially for the virus to spread to the entire board?

  12. Find an algorithm’s number of steps • Single-elimination tournamentHow many matches, in total, does it take to determine a winner among n players? How many rounds need to be played? A more interesting question is about the number of byes if n ≠ 2k

  13. Design an algorithm for a puzzle given • Most algorithmic puzzles can be theoretically solved by exhaustive search (generate and check all potential solutions) or its more intelligent version called backtracking but a more efficient solution is usually expected. • Algorithm design puzzles can be classified by the solution’s design strategy (divide-and-conquer, greedy, dynamic programming, etc.)

  14. General Algorithm Design Strategies • brute force (w/exhaustive search as special case) • backtracking and branch-and-bound • decrease-and-conquer • divide-and-conquer • transform-and-conquer • greedy approach • iterative improvement • dynamic programming

  15. Divide-and-Conquer Strategy Divide a given problem into two or more smaller subproblems Solve the smaller subproblems Combine the solutions to the subproblems to get a solution to the problem given

  16. Divide-and-Conquer Example Invented by Solomon Golomb, then a math graduate student at Harvard, in the early 1950s Tromino Puzzle Cover any 2n  2n chessboard with one missing square with right trominoes (L-shaped tiles of 3 adjacent squares)

  17. Solution to the Tromino Puzzle Place one tromino at the center of the board to cover three central unit squares that are not in the 2n-1 2n-1subboard with the missing square. This reduces the problem to tiling the four 2n-1 2n-1subboards each with one missing square, which can be done by the same method (i.e. recursively).

  18. Real-Life “Application”

  19. Puzzles with no solution • 7 Bridges of Königsberg(Leonhard Euler, 1736) Find a walk through the city that would cross each bridge once and only once.

  20. Puzzles with no solution • The Fifteen Puzzle (a precursor was invented by Noyes Chapman, a postmaster in Canastota, NY; the instance below was popularized by Sam Loyd, 1870s) Slide the numbered tiles from the configuration on the left to the configuration on the right.

  21. Puzzles with no solution • Tiling a mutulated chessboard with dominoes (Martin Gardner’s 1957 column in “Scientific American”) Tile (i.e., cover exactly with no overlaps) an 88 board without two diagonally opposite corners with dominoes (21 rectangles).

  22. Puzzles in Research • Two historically important algorithmic puzzles: • Fibonacci’s Rabbits Problem Fibonacci numbers • 7 Bridges of Königsberg  topology, graph theory • Traveling Salesman Problem/Puzzle • Can TSP be solved in polynomial time, i.e. significantly faster than exhaustive search?(P  NP conjecture, with a $1 million prize from the Clay Mathematics Institute for an answer) Find a shortest tour through n citiesthat visits every city once before returning to the tour’s starting city

  23. Puzzles in Research (cont.) • Optimal solutions to some puzzles • Most research is in puzzle complexity(e.g., E. Demaine of MIT)  20-move solution for any Rubik’s Cube configuration (2010)

  24. Puzzles in Education – Why? • Help developing problem-solving skills and creativity • Attract more interest on the part of students, making them work harder on the problems assigned to them • May seem less intimidating to less prepared students • Force students to think about algorithms on a more abstract level, divorced from programming and computer language minutiae • Are excellent subjects for project assignments and independent research

  25. Puzzles in Education (cont.) • very old idea Propositiones ad acuendos juvenes (Problems to sharpen the young) attributed to Alcuin of York, c.800 CE, contained three river-crossing puzzles • the wolf-goat-cabbage puzzle • “three jealous husbands” • the two adults and the two children, where the children weigh half as much as the adults

  26. Puzzles in Education – a modern quote • “There is no better way to relieve the tedium than by injecting recreational topics into a course, topics strongly tinged with elements of play, humor, beauty, and surprise.” Martin Gardner (1914--2010)an American writer, best knownfor his "Mathematical Games" column in Scientific Americanand books on recreational mathematics(voted one of the ten most influential mathematicians of XX century, although he had no formal math training beyond ahigh school)

  27. Puzzle-Based Learning (PBL) Z. Michalewicz and M. MichalewiczPuzzle-Based LearningHybrid Publishers, 2008general problem solving oriented http://www.youtube.com/watch?v=GaKuB1lrqtw

  28. PBL

  29. Puzzles in Modern Higher Education • A few schools run puzzle-based courses Carnegie Mellon Univ. of Vermont UNC-Charlotte Univ. of Colorado-Colorado Springs UCSB Virginia Tech a few foreign schools (Australia, Israel, Japan, Poland)Villanova – fall 2012 • Two types of the courses • 3-credit course • 1-credit (in introductory engineering or problem solving courses)

  30. Algorithmic Puzzles and Main CS Ideas • Notion of an algorithm (e.g., river crossing puzzles, detecting a lighter fake coin with a balance, or the following more sophisticated example)Catching a Spy In a computer game, a spy is located on a one-dimensional line. At time 0, the spy is at location a. With each time interval, the spy moves b units to the right if b ≥ 0 and |b| units to the left if b < 0; a and b are fixed integers, but they are unknown to you. Your goal is to identify the spy's location by asking at each time interval (starting at time 0) whether the spy is currently at some location of your choosing. For example, you can ask whether the spy is currently at location 19, to which you will receive a truthful yes/no answer. If the answer is "yes," you reach your goal; if the answer is "no," you can ask the next time whether the spy is at the same or another location of your choice. Devise an algorithm that will find the spy after a finite number of questions.

  31. Catching a Spy (Algorithmic Puzzles, #136) How to catch the spy? -4 -3 -2 -1 0 1 2 3 4

  32. Algorithmic Puzzles and Main CS Ideas • Tower of Hanoi (Édouard Lucas, 1883) • There are n disks of different sizes and three pegs. Initially, all the disks are on the first peg in order of size, the largest on the bottom and the smallest on top. The objective is to transfer all the disks to another peg by a sequence of moves. Only one disk can be moved at a time, and it is forbidden to place a larger disk on top of a smaller one.

  33. Algorithmic Puzzles and Main CS Ideas All 9 general algorithm design strategies can be nicely illustrated by algorithmic puzzles, showing applicability of the strategies to problems outside traditional computing domainSee:A. Levitin, Introduction to the Design and Analysis of Algorithms, 3rd ed., 2011A. Levitin and M. Levitin, Algorithmic Puzzles, 2011A. Levitin and M.-A. Papalaskari, Proc. of SIGCSE’02

  34. Algorithmic Puzzles and Main CS Ideas • Insolvability of some problems and the idea of an invariant: a property that doesn’t change by any of the operations allowed in the problem • Parity (e.g. 7 Bridges of Königsberg, the Fifteen Puzzle) • Coloring (e.g. many tiling and chessboard tour problems)

  35. Algorithmic Puzzles and Main CS Ideas • Algorithm efficiency False CoinDetection Find a lighter fake among n coins with a balance scale without any weights. • Brute force: weigh coin pairs (1 vs. 1) • Divide-by-half: divide into two halves (with 1 aside if n is odd) and compare their weights • Divide into 3 about equal subsets is better than dividing into two

  36. Schweik’s Puzzle (Algorithmic Puzzles, #50) Note: The puzzle alludes to the hero of the novel The Good Soldier Schweik by the Czech writer Yaroslav Hašek (1883--1923). In this satirical novel, Schweik is depicted as a simple minded man who appears to be eager to execute orders but does it in a manner that, in fact, contradicts their intended goal. The good soldier Schweik had been ordered to line up a band of new recruits. The desired line was required to minimize the average difference in height of adjacent men. Schweik put the tallest recruit first, the shortest one last, and let the remaining men stand between them in random order. Did Schweik execute his order as stated?

  37. Instance of Schweik’s Puzzle Is the average difference in height of adjacent men minimized in this line? What mathematical fact, which is occasionally useful for algorithm analysis, does the puzzle demonstrate?

  38. Algorithmic Thinking For Other Majors • Increasing importance of algorithmic thinking for all • Computational thinking is a problem solving approach named for its extensive use of computer science techniques. The term was first used by Seymour Papert (of the Logo fame) in 1996. • Basic skills: 3R’s (Reading, wRiting, aRithmetic) + computational thinkingJeannette Wing, Head of CS Dept. at CMU, CACM, March 2006 • Algorithmic thinking is the main component of computational thinking

  39. Importance of Algorithmic Thinking (cont.) • Increasing importance of algorithmic methods in sciences from biology to sociology“The Algorithm's coming-of-age as the new language of science promises to be the most disruptive scientific development since quantum mechanics.” Bernard Chazellehttp://www.cs.princeton.edu/~chazelle/pubs/algorithm.html XVII-XX centuries math equations XXI century CS algorithms

  40. General Problem Solving Strategies • by a famous physicist • by a prominent mathematician • by CS (algorithmics)

  41. General Problem Solving Strategies (cont.) • Richard Feynman (1918-1988),Nobel Prize winner (1965)A fellow physicist joked that Feynmansolved problems by what has becomeknown as The Feynman Problem-Solving Algorithm:  1. write down the problem  2. think very hard  3. write down the answer

  42. General Problem Solving Strategies (cont.) • George Pólya (1887-1985),prominent Hungarian mathematician, lived in the U.S. since 1940 Author of the most well-known book on problem solvingHow to Solve It, published first in 1945 and still in print! The four-step plan: 1. Understand the problem 2. Devise a plan 3. Carry out the plan 4. Look backThe plan is further elaborated by 67 (!) heuristics

  43. General Problem Solving Strategies (cont.) • Computer Science can offer several general problem solving strategies: • brute force (w/exhaustive search as special case) • backtracking and branch-and-bound • decrease-and-conquer • divide-and-conquer • transform-and-conquer • greedy approach • iterative improvement • dynamic programming This is what CS should be “selling” to the world!

  44. Algorithmic Puzzle-Based Course for Other Majors • Algorithmic puzzles can help teaching algorithmic thinking without traditional CS background and computer programming • CS ≠ programming • Major objectives • appreciation of the concept of algorithm including that of recursive algorithm • familiarity with major algorithm design strategies • some familiarity with importance of algorithm efficiency • recognition of problems that have no algorithmic solution

  45. Algorithmic Puzzles in K–12 Education • "Most (U.S.) students are not exposed to computer science in the same way they are to biology and physics. We have to incorporate computer science at the K-12 level. It's not easy to do, but this is what is needed." Jeannette Wing, quoted in The Pittsburgh Tribune-Review, 2/27/2012 • Algorithmic puzzles are particularly attractive for the pre-college exposure to algorithmic problem solving

  46. Algorithmic Puzzles in K–12 Education • Some chapters for a 2007 supplement to the Russian course on informatics (grades 5–6) • Patterns • Sorting • 1-to-1 correspondence • Problems about liars • River crossing problems • Decanting problems • Weighing problems • Combinatorial problems • Numeral systems • Game strategies

  47. Summary • Algorithmic puzzles is an interesting puzzle genre • still underappreciated • exceptionally promising for growth in importance • Problem solving is increasingly understood as algorithmicproblem solving • Algorithmic puzzles can illustrate main ideas of CS • In particular, they show that algorithm design strategies are general problem solving tools with applications outside traditional CS domain

  48. In addition to all the utilitarian benefits of algorithmic puzzles, the best of them are remarkable and inspiring products of human ingenuity and wit.

  49. Puzzles in Technical Interviews • Until recently, puzzles were a standard component of job interviews at leading software companies and Wall Street • Influenced (but not originated) by MicrosoftW. Poundstone, How Would You Move Mount Fuji? Microsoft’s Cult of the Puzzle: How the World’s Smartest Companies Select the Most Creative Thinkers, 2004Are You Smart Enough to Work at Google? 2012 • The practice remains controversial

  50. Arguments against interview puzzles • Solving puzzles is irrelevant to specific skills required for the job in question • Typical interview puzzles are too difficult for the short time allotted to an interview • Puzzles can be vague or based on tricks, with some of them not even having a clear-cut correct answer • There is no convincing documented evidence that persons hired after successful puzzle-solving prove to be better employees than candidates turned down after such interviews • After many interview puzzles and their solutions have been published in books and on the Internet, their value has all but disappeared because there is no way to verify whether the interviewee knew the puzzle’s solution before the interview

More Related