9:00 AM โ 9:45 AM | Session 204
Computational Thinking is a set of problem-solving skills that allow you to create algorithms. At the heart of Computer Science is the building of algorithms โ the step-by-step solutions to problems with or without computers. Here are four key components of Computational Thinking:
We will work through some puzzles to sharpen our Computational Thinking. Try each one on your own first โ a hidden answer/hint is provided below for the first 20 puzzles if you get stuck.
A farmer is on a riverbank with a wolf, a goat, and a head of cabbage. He wants to transport all three to the other side of the river in a boat. However, the boat has room for the farmer and just one other item (the wolf, goat, or cabbage). How can he safely carry all three across without the wolf eating the goat, or the goat eating the cabbage?
Four people have to cross a footbridge at night. It is dark and they have one flashlight. A maximum of two people can cross the bridge at a time. Any party that crosses must have the flashlight with them, and it cannot be thrown. Person 1 takes 1 minute, Person 2 takes 2 minutes, Person 3 takes 5 minutes, and Person 4 takes 10 minutes to cross. What is the minimum total time for all four to cross?
A student is counting from 1 to 1000 using the fingers of her left hand. She starts by calling her thumb 1, first finger 2, middle finger 3, ring finger 4, and little finger 5. Then she reverses direction, calling the ring finger 6, middle finger 7, first finger 8, thumb 9, then first finger 10, and so on back and forth. On which finger will she stop at 1000?
There are eight identical-looking coins; one is fake and lighter than the others. What is the minimum number of weighings needed to identify the fake coin using a two-pan balance scale (no weights)? Now suppose there are nine coins and one is fake, but you don't know whether it's lighter or heavier โ what is the minimum number of weighings needed then?
Pages of a book are numbered sequentially starting with 1. If the total number of decimal digits used is 1578, how many pages are in the book? Without a calculator, find the total sum of the digits in all integers from 1 to one million inclusive.
A magic square of order 3 is a 3ร3 table filled with nine distinct integers from 1 to 9 so that the sum of the numbers in each row, column, and both corner-to-corner diagonals is the same. Find magic squares of order 3, 5, and 7.
A stick 100 units long needs to be cut into 100 unit pieces. What is the minimum number of cuts required if you are allowed to cut several stick pieces at the same time (stacking them)? Now generalize an algorithm that performs this task with the minimum number of cuts for a stick that is n units long.
You have 20 black balls and 10 white balls in a bag. You repeat the following operation until a single ball is left: remove two balls at a time. If they are the same color, add a black ball back to the bag; if they are different colors, add a white ball back. What color is the last ball left in the bag? What if you start with 20 black balls and 15 white balls instead?
There are n lockers in a hallway, numbered 1 to n. All doors start closed. You make n passes by the lockers, starting at locker #1 each time. On the ith pass, you toggle every ith locker's door (open it if closed, close it if open). After the last pass, which locker doors are open, and how many are open?
You are given a sorted array of n distinct integers, some of which may be negative. Describe an algorithm to determine whether there exists an index i such that array[i] = i, using far fewer than n comparisons. What is the time complexity of your algorithm?
A group of 10 people at a party each shake hands with some subset of the others (no one shakes their own hand, and no pair shakes hands twice). Prove that at least two people at the party shook hands with the same number of people.
Conway's Game of Life is played on an infinite grid of cells, each either "alive" or "dead." Each generation, a cell's next state depends only on its 8 neighbors: a live cell with 2 or 3 live neighbors survives (otherwise it dies), and a dead cell with exactly 3 live neighbors becomes alive. Starting from a single row of 3 live cells in a row (a "blinker"), what does the grid look like after 1 generation? After 2 generations?
You have three numbers stored in variables A, B, and C, and you may only swap the contents of two variables at a time using a temporary variable. What is the minimum number of swaps needed, in the worst case, to sort A, B, and C into ascending order? Describe your algorithm.
The Tower of Hanoi puzzle has 3 pegs and n disks of different sizes stacked in decreasing size on one peg. You must move the entire stack to another peg, moving one disk at a time and never placing a larger disk on a smaller one. What is the minimum number of moves required as a function of n? Describe the recursive algorithm.
Design a system so that a blindfolded person can determine, using only touch, whether a coin placed in front of them is heads-up or tails-up, without being allowed to flip or feel the coin's face design. You may arrange any number of coins on a table beforehand in any configuration you like, and the blindfolded person must separate them into two groups โ "heads" and "tails" โ using only the rule you devise, even though they cannot tell heads from tails by touch or sight.
A robot starts at the top-left corner of an mรn grid and can only move right or down one cell at a time. How many distinct paths are there to reach the bottom-right corner? Describe both a direct formula and a decomposition (recursive) approach.
Three boxes are labeled "Apples," "Oranges," and "Apples and Oranges." All three labels are wrong. Each box is filled with either only apples, only oranges, or a mix of both. You may draw exactly one piece of fruit from exactly one box (without looking inside) to correctly relabel all three boxes. Which box do you draw from, and how do you deduce the rest?
You are given a list of n integers and want to find the two numbers that sum to a given target value, T. Describe a brute-force algorithm and its time complexity, then describe a faster algorithm using a hash set. What is the time complexity of the improved approach?
A vending machine accepts nickels (5ยข) and dimes (10ยข) only, and an item costs 25ยข. Design a state diagram (or table) that tracks the total amount inserted so far as states, with transitions on "insert nickel" and "insert dime," until reaching or exceeding 25ยข. How many distinct states (amounts) are reachable before the machine dispenses the item?
A classmate writes an algorithm to find the maximum value in a list: they
initialize a variable max to 0, then loop through the list
comparing each element to max and updating it when a larger
value is found. Identify the flaw in this algorithm, construct a specific
test case (list of numbers) that exposes the bug, and describe the fix.
max is never updated.
Fix: initialize max to the first element of the list instead
of 0.Place eight queens on a standard chess board (8 x 8) so that no queen can capture another queen.
A software engineer lived in a neigborhood where all the houses were on one side of the street. The houses were numbered sequentially starting from 1.
Every morning she would walk her dog in one direction and in the evening she would walk her dog in the other direction. On one of these walks she noticed something special about her house - the sum of addresses on one side of her house was equal to the sum of the addresses on the other side of her house. [Her house address was not in either sum.]Now her house address was 6 and the last house on the street had an address of 8. The sum of addresses on one side was 15 [= 1 + 2 + 3 + 4 + 5] and on the other side was also 15 [= 7 + 8]. She was convinced that hers was a lucky house since it had that property.
When she relocated to another town she went to the real estate agent and asked for a house that had exactly the same property - the sum of addresses on one side had to be equal to the sum of addresses on the other side. Now the lucky house number is dependent on the last house on the street. We know that the first set of numbers (the lucky house and the last house on the street) that satisfies that property is 6 and 8. What is the next set of numbers that have the same property. Assume that the last house on the street could be at most 10,000.
Samuel Pepys once wrote to Issac Newton to determine which was more probable: at least one six in six throws of a fair die or at least two sixes in twelve throws of a fair die? Give a convincing argument which scenario has the higher probability.
You have 20 coin machines, each of which produce the same kind of coin. You know how much a coin is supposed to weigh. One of the machines is defective, in that every coin it produces weighs 1 gram less than it is supposed to. You also have an electronic weighing machine. How can you determine which of the 20 machines is defective with only one weighing?
By one weighing, we mean you put a certain number of coins on the weighing machine and make a note of the reading and that is all. You are not allowed to add a few coins at a time on the weighing machine and watch the reading increase. That is multiple weighings.
You are allowed to crank out as many coins from each machine as you like.
What is the four-digit number in which the first digit is one-third the second, the third is the sum of the first and second, and the last is three times the second?
On Citrus Island there are three tribes - the Tangerines, the Oranges, and the Lemons. They have different standards of veracity but otherwise are indistinguishable. Tangerines always tell the truth; Oranges always lie; Lemons, when asked a series of questions, tell the truth and lie alternately. A Lemon's first answer in a series may be either true or otherwise.
A visitor was somewhat confused recently when he was introduced to three natives named Tangerine, Orange, and Lemon, who are - not necessarily respectively - a Tangerine, an Orange, and a Lemon. There was also a fourth native, a lady named Pomelo. The visitor asked each of the first three natives (a) what his own tribe was, and (b) what was Ms. Pomelo's tribe.
To these questions, Mr. Tangerine replied: "I'm not a Tangerine and Ms. Pomelo is an Orange."
Mr. Orange replied: "I'm not an Orange and Ms. Pomelo is a Lemon."
Mr. Lemon replied: "I'm not a Lemon and Ms. Pomelo is a Tangerine."
To which tribe does Ms. Pomelo actually belong?
Here is an exercise in inference that appealed to Lewis Carroll. You are given a series of statements that may seem absurd but are all factually correct. What conclusion can you draw from these statements?