## 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 the dog.

1. Flip the quarter twice.
2. If the outcome is heads on the first flip and tails on the second, then I will walk the dog.
3. If the outcome is tails on the first flip, and heads on the second, then you will walk the dog.
4. If both outcomes are tails or both outcomes are heads, then we flip twice again.
Calvin's technique is an algorithm.
a) True
b) False.

### Write Algorithms for these Problems

1. How would you add a list of numbers on the computer?
2. How would you find the largest number in a list of numbers without sorting?
3. How would you find the number of occurrences of a given number in a list of unsorted numbers? You may sort if want to.

### Number Conversions

1. Convert the following numbers in decimal to 8-bit 2's complement binary: 28, -39
2. Write the binary equivalent of all numbers from 0 to 15 in 4-bit binary.
3. These are 8-bit 2's complement binary. What decimal numbers do they represent?
• 0110 1100
• 1111 1111
• 1000 0000
• 0111 1111