Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graph Theory in Computer Science Greg Stoll November 22, 2008.

Similar presentations


Presentation on theme: "Graph Theory in Computer Science Greg Stoll November 22, 2008."— Presentation transcript:

1 Graph Theory in Computer Science Greg Stoll November 22, 2008

2 Today's Topics Graph colorings Huffman encoding

3 Graph colorings

4

5 What's the fewest number of colors that are needed to color a given graph?

6 Graph colorings A clique of size n is a graph with n vertices where all vertices have edges between them.

7 Register allocation Modern computers do operations (+, -, *, etc.) on registers. Fixed number of these (x86 architecture has 8, x64 has 16). When compiling code, need to assign variables to registers to use them.

8 Register allocation

9

10 In fact, this is always true for interval graphs – the number of registers needed (i.e. the number of colors to color the graph) is equal to the size of the largest clique!

11 Register allocation Unfortunately, even finding the largest clique in a graph is NP-hard, but a greedy algorithm does pretty well.

12 Register allocation Another problem: what if there aren't enough registers?

13 Worksheet, part 1 Work on questions 1-6 on the worksheet!

14 Cookies! Mmmm....

15 Sending a message On a computer, all you have are bits (0's and 1's). How can you send a text message to another computer?

16 ASCII encoding ASCII is a standard way to turn characters into bits. A = 65 = 01000001 B = 66 = 01000010... Z = 90 = 01011010

17 Modified ASCII What if we just want to send letter and a little punctuation? We can use a smaller code: a = 0 = 00000 b = 1 = 00001... = 26 = 11010 5 bits means 2^5 = 32 characters

18 Modified ASCII Our modified ASCII uses 5 bits per character. Sample message: “hello mom, how are you?” is 22 characters * 5 bits/character = 110 bits. How could we reduce the average number of bits per character?

19 Shrinking the message Not all letters are created equal. “e” is much more common than “x” in most English text. We could take advantage of this if we made the code for “e” smaller than the code for “x”.

20 Shrinking the message “o” and “ ” are the most commonly used letters in our sample message. Let “o” = 0 “ “ = 1 “m” = 00.... Will this work?

21 Prefix-free code A prefix-free code is one in which no code word is a prefix of another. “o” = 0 “ “ = 1 “m” = 00 is not prefix free, since “o”=0 is a prefix of “m”=00.

22 Binary tree A binary tree is a common data structure where each node has up to two children.

23 Binary tree What if we assign a character to each leaf?

24 Huffman encoding We want a way to build up a binary tree where the least common characters are lower. (i.e. their code words are longer) We can do this by starting at the bottom and always combining the least common two characters, and continuing until we've formed a binary tree.

25 Huffman encoding Example: “hello mom, how are you?”

26 Huffman encoding Using Huffman encoding lets us send the message in 78 bits, as opposed to 110. With longer message, you can get even greater savings.

27 Worksheet, part 2 Work on questions 7-12 on the worksheet!


Download ppt "Graph Theory in Computer Science Greg Stoll November 22, 2008."

Similar presentations


Ads by Google