270 likes | 323 Views
Greg Stoll November 22, 2008. Graph Theory in Computer Science. Graph colorings Huffman encoding. Today's Topics . Graph colorings. Graph colorings. What's the fewest number of colors that are needed to color a given graph?. Graph colorings.
E N D
Greg Stoll November 22, 2008 Graph Theory in Computer Science
Graph colorings Huffman encoding Today's Topics
What's the fewest number of colors that are needed to color a given graph? Graph colorings
A clique of size n is a graph with n vertices where all vertices have edges between them. Graph colorings
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. Register allocation
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! Register allocation
Unfortunately, even finding the largest clique in a graph is NP-hard, but a greedy algorithm does pretty well. Register allocation
Another problem: what if there aren't enough registers? Register allocation
Work on questions 1-6 on the worksheet! Worksheet, part 1
Mmmm.... Cookies!
On a computer, all you have are bits (0's and 1's). How can you send a text message to another computer? Sending a message
ASCII is a standard way to turn characters into bits. A = 65 = 01000001 B = 66 = 01000010 ... Z = 90 = 01011010 ASCII encoding
What if we just want to send letter and a little punctuation? We can use a smaller code: a = 0 = 00000 b = 1 = 00001 ... <space> = 26 = 11010 5 bits means 2^5 = 32 characters 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? Modified ASCII
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”. Shrinking the message
“o” and “ ” are the most commonly used letters in our sample message. Let “o” = 0 “ “ = 1 “m” = 00 .... Will this work? Shrinking the message
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. Prefix-free code
A binary tree is a common data structure where each node has up to two children. Binary tree
What if we assign a character to each leaf? Binary tree
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. Huffman encoding
Example: “hello mom, how are you?” 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. Huffman encoding
Work on questions 7-12 on the worksheet! Worksheet, part 2