greedy algorithms ms jeevani goone llake university of
play

Greedy Algorithms ms Jeevani Goone*llake University of - PowerPoint PPT Presentation

Greedy Algorithms ms Jeevani Goone*llake University of Colombo School of Compu*ng Sri Lanka Jeevani Goone*llake (University of Colombo - Sri


  1. ¡ ¡ ¡ ¡ ¡ ¡ Greedy ¡ ¡Algorithms ms Jeevani ¡Goone*llake ¡ University ¡of ¡Colombo ¡School ¡of ¡Compu*ng ¡ Sri ¡Lanka ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  2. Hufffma man ¡ ¡Coding Jeevani ¡Goone*llake ¡ UCSC ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  3. Examp mple • Suppose ¡there ¡is ¡a ¡file ¡with ¡100K ¡characters. ¡ ¡ • Assume ¡that ¡there ¡are ¡only ¡6 ¡dis*nct ¡characters ¡in ¡the ¡file ¡ from ¡a ¡through ¡f, ¡with ¡frequencies ¡as ¡indicated ¡below. ¡ a b c d e f Frequency 45 13 12 16 9 5 (in 1000s) A ¡binary ¡code ¡encodes ¡each ¡character ¡as ¡a ¡binary ¡string ¡or ¡ codeword. ¡ ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  4. Cod Codewor ord • In ¡a ¡fixed-­‑length ¡code ¡each ¡codeword ¡has ¡the ¡same ¡length. ¡In ¡ a ¡variable-­‑length ¡code ¡codewords ¡may ¡have ¡different ¡lengths. ¡ a b c d e f Frequency 45 13 12 16 9 5 (in 1000s) Fixed-length 000 001 010 011 100 101 codeword Variable-length 0 101 100 111 1101 1100 codeword • Fixed-­‑length ¡= ¡(45*3 ¡+ ¡13*3 ¡+ ¡12*3 ¡+ ¡16*3 ¡+ ¡9*3 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡+ ¡5*3) ¡* ¡1000 ¡= ¡300K ¡bits ¡ • Variable-­‑length ¡= ¡(45*1 ¡+ ¡13*3 ¡+ ¡12*3 ¡+ ¡16*3 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡+ ¡9*4 ¡+ ¡5*4) ¡* ¡1000 ¡= ¡224K ¡bits ¡(Savings ¡= ¡25%) ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  5. Enc Encoding ding • Given ¡ a ¡ code ¡ (corresponding ¡ to ¡ some ¡ alphabet ¡ ∑ ¡ ) ¡ and ¡ a ¡ message ¡the ¡message ¡is ¡encoded ¡by ¡replacing ¡the ¡characters ¡ with ¡the ¡codewords. ¡ • Example ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡∑ ¡= ¡{a,b,c,d} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡C1 ¡ ¡{a ¡= ¡00 ¡ ¡b ¡= ¡01 ¡ ¡c= ¡10 ¡ ¡d= ¡11} ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡bad ¡is ¡encoded ¡into ¡010011 ¡ ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  6. Dec Decoding ding • Given ¡ an ¡ encoded ¡ message, ¡ decoding ¡ is ¡ the ¡ process ¡ of ¡ turning ¡it ¡back ¡into ¡the ¡original ¡message. ¡ ¡ • A ¡message ¡is ¡uniquely ¡decodable ¡if ¡it ¡can ¡only ¡be ¡decoded ¡in ¡ one ¡way. ¡ ¡ • The ¡unique ¡decipherability ¡property ¡is ¡needed ¡in ¡order ¡for ¡a ¡ code ¡to ¡be ¡useful. ¡ ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  7. Decoding ¡ ¡: ¡ ¡Examp mple • Consider ¡the ¡codes ¡C1 ¡and ¡C2 ¡ ¡ ¡ ¡ ¡ ¡ ¡C1 ¡ ¡{a ¡= ¡00 ¡ ¡b ¡= ¡01 ¡ ¡c= ¡10 ¡ ¡d= ¡11} ¡ ¡ ¡ ¡ ¡ ¡ ¡C2 ¡ ¡{a ¡= ¡1 ¡b ¡= ¡110 ¡c= ¡10 ¡d= ¡111} ¡ ¡ • Rela*ve ¡to ¡C1, ¡010011 ¡is ¡uniquely ¡decodable ¡to ¡bad. ¡ • Rela*ve ¡ to ¡ C2, ¡ 1101111 ¡ is ¡ not ¡ uniquely ¡ decodable ¡ since ¡ it ¡ could ¡be ¡decodable ¡to ¡bad, ¡acad, ¡bda ¡or ¡baaaa. ¡ Fixed-­‑length ¡codes ¡are ¡always ¡uniquely ¡decipherable ¡(e.g. ¡ASCII) ¡ Since ¡these ¡do ¡not ¡always ¡give ¡the ¡best ¡compression ¡variable ¡length ¡codes ¡are ¡preferred. ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  8. Pr Prefix efix ¡Co ¡Code de • A ¡ code ¡ is ¡ called ¡ a ¡ prefix ¡ (free) ¡ code ¡ if ¡ no ¡ codeword ¡ is ¡ a ¡ prefix ¡ of ¡ another ¡one. ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡C1 ¡{a ¡= ¡0 ¡b ¡= ¡110 ¡c ¡= ¡10 ¡d ¡= ¡111} ¡ ¡is ¡a ¡prefix ¡code. ¡ • Every ¡message ¡encoded ¡by ¡a ¡prefix ¡free ¡code ¡is ¡uniquely ¡decodable. ¡ ¡ • Unlike ¡ASCII, ¡prefix ¡codes ¡can ¡be ¡variable ¡length ¡codes. ¡ • Please ¡also ¡refer ¡to ¡Frank ¡Drew’s ¡slide ¡no.10 ¡on ¡Huffman’s ¡algorithm. ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

  9. Cod Coding ¡t ¡trees ees ¡f ¡for or ¡p ¡prefix ¡c efix ¡cod odes es • A ¡ prefix ¡ code ¡ can ¡ be ¡ represented ¡ as ¡ a ¡ binary ¡ coding ¡ tree ¡ whose ¡leaves ¡are ¡the ¡symbols ¡in ¡this ¡tree. ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Example: ¡ ¡ 000 ¡ 01 ¡ 10 ¡ 11 ¡ 0011 ¡ ¡ a ¡ b ¡ c ¡ d ¡ e ¡ ¡ • A ¡ Human ¡ code ¡ is ¡ a ¡ prefix ¡ code ¡ whose ¡ coding ¡ tree ¡ is ¡ a ¡ full ¡ binary ¡tree. ¡ Jeevani ¡Goone*llake ¡(University ¡of ¡Colombo ¡-­‑ ¡Sri ¡Lanka) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Lecture ¡5 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend