Class Work (CS 312) 23 Jan 2013
Is this an Algorithm?
Lynne and Calvin are trying to decide who will take the dog for a walk.
Lynne suggests that they flip a coin and pulls a quarter out of her
pocket. Calvin does not trust Lynne and suspects that the quarter maybe
weighted (meaning that it might favor a particular outcome when tossed)
and suggests the following procedure to fairly determine who will walk
Calvin's technique is an algorithm.
- Flip the quarter twice.
- If the outcome is heads on the first flip and tails on the second,
then I will walk the dog.
- If the outcome is tails on the first flip, and heads on the second,
then you will walk the dog.
- If both outcomes are tails or both outcomes are heads, then we flip
Write Algorithms for these Problems
- How would you add a list of numbers on the computer?
- How would you find the largest number in a list of numbers without
- How would you find the number of occurrences of a given number in
a list of unsorted numbers? You may sort if want to.
- Convert the following numbers in decimal to 8-bit 2's complement
binary: 28, -39
- Write the binary equivalent of all numbers from 0 to 15 in 4-bit
- These are 8-bit 2's complement binary. What decimal numbers do
- 0110 1100
- 1111 1111
- 1000 0000
- 0111 1111