Presentation is loading. Please wait.

Presentation is loading. Please wait.

PS9-Slides Comparison of Searching Methods Unsorted Sorted Hashed 6240 11203 03495 2801 21690 1 4731 31731 2 7887 41973 3 2143 52143 47416 8776 62777 51731.

Similar presentations


Presentation on theme: "PS9-Slides Comparison of Searching Methods Unsorted Sorted Hashed 6240 11203 03495 2801 21690 1 4731 31731 2 7887 41973 3 2143 52143 47416 8776 62777 51731."— Presentation transcript:

1 PS9-Slides Comparison of Searching Methods Unsorted Sorted Hashed 6240 11203 03495 2801 21690 1 4731 31731 2 7887 41973 3 2143 52143 47416 8776 62777 51731 9703 72801 61973 3522 83495 7 5116 93522 88311 5799103619 9 9027114002108610 1690124615116872 4002134731123619 6114144997137128 46151551161435229703 8311165708151203 7416175799166240 8229186021174997 17311961141827774615 120320624019 6021216872201690 8273227128212143 8610237416225708 2777247887239897 6872258229245116 1973268273258229 7128278311268273 9897288610275799 361929877628 5708309027292801 349531970330 4997329897319027 326114 33 348776 354731 367887 37 386021 39 40 41 424002

2 PS9-Slides Modulo 43 Table 043 86129172 144 87130173 245 88131174 346 89132175 447 90133176 548 91134177 649 92135178 750 93136179 851 94137180 952 95138181 1053 96139182 1154 97140183 1255 98141184 1356 99142185 1457100143186 1558101144187 1659102145188 1760103146189 1861104147190 1962105148191 2063106149192 2164107150193 2265108151194 2366109152195 2467110153196 2568111154197 2669112155198 2770113156199 2871114157200 2972115158201 3073116159202 3174117160203 3275118161204 3376119162205 3477120163206 3578121164207 3679122165208 3780123166209 3881124167210 3982125168211 4083126169212 4184127170213 4285128171214

3 PS9-Slides A hash Function for Integers. 1. break the long integer up into 3 pieces of 3 digits each - add a leading 0, if necessary, to make the 9 digits. 2. Add the three pieces; 3. Find the remainder of the division of this sum by M (= 67, in this case). Ex. 012053488-> 012 053 488 ------ 553 -> 553 % 67 = 17

4 PS9-Slides Distribution of h(x): x ------------------------------------------------------------------- 0123456789111111111122222222223333333333444444444455555555556666666 012345678901234567890123456789012345678901234567890123456

5 PS9-Slides Table ADT void Initialize Table(Table T); bool isNullEntry(TableEntry E); bool isEmpty(Table T, int probe); void InsertTable(Table T, TableEntry newitem); TableEntry RetrieveTable(Table T, KeyType *target)

6 PS9-Slides Hash Table Definition

7 PS9-Slides President Hash Table

8 PS9-Slides Appendix D: President Names File (PresName.dat) George Washington John Adams Thomas Jefferson James Madison James Monroe John Quincy Adams Andrew Jackson Martin Van_Buren William H. Harrison John Tyler James Knox Polk Zachary Taylor Millard Fillmore Franklin Pierce James Buchanan Abraham Lincoln Andrew Johnson Ulysses Simpson Grant Rutherford B. Hayes James Abram Garfield Chester Alan Arthur Grover Cleveland Benjamin Harrison William McKinley Theodore Roosevelt William Howard Taft Woodrow Wilson Warren G. Harding Calvin Coolidge Herbert Clark Hoover Franklin D. Roosevelt Harry S. Truman Dwight D. Eisenhower John F. Kennedy Lyndon Baines Johnson Richard Milhous Nixon Gerald R. Ford Jimmy Carter Ronald Reagan George Bush Bill Clinton

9 PS9-Slides

10 Experimental Values for Hash Function Distribution Problem 1. Distribution of h(x) for Integers in IntKeys.dat x ------------------------------------------------------------------- 0123456789111111111122222222223333333333444444444455555555556666666 012345678901234567890123456789012345678901234567890123456 Problem 2. Distribution of h(x) for String Keys Developed from PresName.dat x ------------------------------------------------------------------- 0123456789111111111122222222223333333333444444444455555555556666666 012345678901234567890123456789012345678901234567890123456

11 PS9-Slides Experimental Values for Hash Function Distribution Problem 3. Distribution of of Table Entries for President Hash Tables. Table Entry Locations: Linear Probing. x x ------------------------------------------------------------------- 0123456789111111111122222222223333333333444444444455555555556666666 012345678901234567890123456789012345678901234567890123456 Table Entry Locations: Double Hashing. x x ------------------------------------------------------------------- 0123456789111111111122222222223333333333444444444455555555556666666 012345678901234567890123456789012345678901234567890123456

12 PS9-Slides Using Defines to Control Program Output #define _STUDY : #ifdef _STUDY printf(" Insert %s:\n",E.key); #endif // _STUDY :

13 PS9-Slides Using Defines to Select Functions (Macros) #define EQ(a,b) (!strcmp((a),(b))) #define EQ(a,b) ((a) == (b)) : if( EQ(E.Key,EmptyKey)) return true; else return false; :


Download ppt "PS9-Slides Comparison of Searching Methods Unsorted Sorted Hashed 6240 11203 03495 2801 21690 1 4731 31731 2 7887 41973 3 2143 52143 47416 8776 62777 51731."

Similar presentations


Ads by Google