CS 40 - Lecture 20

Cover page image

CS is Not Just Programming

CS is Not Just Programming

CS is Abstraction

CS is Abstraction

Marines Crossing a Bridge

Four injured marines come to an old, rickety bridge, at night.

Marines Crossing a Bridge: Details

Four injured marines come to an old, rickety bridge, at night.

Lets add some details:

Can they make it across in time?

Use resources wisely.

Error Detecting Codes

Consider a number:
94783341609

Add one extra digit to make the digit sum "%10 == 0"
947833416096

Why? It gives good probability to find an error
947833476096 % 10 = 6

For CS, we usually just use binary.

Error CORRECTING Codes

Pick one of the following 7 bit numbers: 0000000, 1101001, 0101010, 1000011, 1001100, 0100101, 1100110, 0001111, 1110000, 0011001, 1011010, 0110011, 0111100, 1010101, 0010110, 1111111

Write it down carefully. No transcription errors allowed.

For your code:

All (r, s, t) should be zero.

Error Correcting Codes

Flip one bit in your code. (Don't tell me which.) For your altered code, calculate:

Now, at least one of (r, s, t) should be one.

Error Correcting Codes

Flip one bit in your code. (Don't tell me which.) For your altered code, calculate:

Now, at least one of (r, s, t) should be one.

Calculate x = r * 1 + s * 2 + t * 4.

Error Correcting Codes

Flip one bit in your code. (Don't tell me which.) For your altered code, calculate:

Now, at least one of (r, s, t) should be one.

Calculate x = r * 1 + s * 2 + t * 4.

Error Correcting Codes

Here, 3 error correcting bits (positions 1, 2, 4) were added to four original code word bits. We use 7 bits to transmit 4 bits of information, but can correct if a bit is flipped, or detect if two bits have flipped.

Similarly, we can use 4 error correcting bits (postions 1, 2, 4, 8), along with 11 original bits, and still correct one bit flip. Can you guess the pattern for how we set the error correcting bits in the word of 15 bits?

This can be extended indefinitely. We only need 10 error correcting bits, with 1013 original code word bits, to correct for one bit flip in a word of 1023 bits.

Codes to correct two or more errors also exist, though the need more error correcting bits per code word bit.

Another White/Black Hat Game

You win if:

Otherwise, you lose.

How well can your team do?

Another White/Black Hat Game

Another White/Black Hat Game

Strategy:

Another White/Black Hat Game

Another White/Black Hat Game

This is the error correcting code in disguise!

NIM (time permitting)

We saw this in our AI class, but we can play a bit in class if we have time.

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18
5 3 7 2 12 15 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18
5 3 7 2 12 15 18
5 3 2 7 12 15 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18
5 3 7 2 12 15 18
5 3 2 7 12 15 18
3 2 5 7 12 15 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18
5 3 7 2 12 15 18
5 3 2 7 12 15 18
3 2 5 7 12 15 18
2 3 5 7 12 15 18

Efficiency and Sorting? (time permitting)

We saw a sorting algorithm in the homework on Lists. Lets consider the "find Max value" approach on the following data:
5 15 3 18 7 12 2
5 15 3 7 12 2 18
5 3 7 12 2 15 18
5 3 7 2 12 15 18
5 3 2 7 12 15 18
3 2 5 7 12 15 18
2 3 5 7 12 15 18
2 3 5 7 12 15 18

Wow, that was painful. For each iteration, we needed to go through almost the same length list as the previous iteration. (One shorter each time.)

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2
3 2 5 15 18 7 12

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2
3 2 5 15 18 7 12
2 3 5 15 18 7 12

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2
3 2 5 15 18 7 12
2 3 5 15 18 7 12
2 3 5 7 12 15 18

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2
3 2 5 15 18 7 12
2 3 5 15 18 7 12
2 3 5 7 12 15 18
2 3 5 7 12 15 18

Efficiency and Sorting? (time permitting)

Consider instead a "Divide and Conquer" strategy:
5 15 3 18 7 12 2
3 2 5 15 18 7 12
2 3 5 15 18 7 12
2 3 5 7 12 15 18
2 3 5 7 12 15 18
2 3 5 7 12 15 18

Much better! After the 1st iteration, all others are much quicker.

Reminders

???