Data Structures Algorithms Lecturers Boontee Kruatrachue Kritawan Siriboon
Data Structures & Algorithms Lecturers : Boontee Kruatrachue Kritawan Siriboon Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++, … Mark Allen Weiss, Addison Wesley
Text • Text : Data Structures & Algorithm Analysis in C • Mark Allen Weiss, Addison Wesley • http: //fife. swufe. edu. cn/BILab/lectu res/ds/Data_Structures_and_Algori thm_Analysis_in_C. pdf
1. Algorithm • State how to solve problem step by step. • Ex: Finding a fake coin out of n real gold coins. Given * a two arm scale. * the fake coin is lighter.
How many times you weight? Algo. 1 : Two coins at a time • Best Case 1 • Worst Case n/2 • Average Case
How many times you weight? Algo 2 : Half Cutting • Best Case ½ 1 • Worst Case Time Remaining 1 n/2 2 n/4 3 n/8. . . d 1 =n/22 =n/23. . . =n/2 d 2 d = n d = log 2 n ½
2. Data Structure • Structures of all data : how to keep related data in memory. • Ex. The Eight Queen Problem.
The Eight Queen Problem • Puting eight Queens on 8 x 8 chessboard such that none of them is able to capture any other Q Q Q • using the standard chess queen’s move. Q Q Q
The Eight Queen Solutions • It has 92 distinct solutions. • If solutions that only differ by symmetry operatons (rotations & reflections) of the board are counted as one, the puzzle has 12 unique solutions.
The Eight Queen Problem Data Structures 0 1 2 -D array 2 0 3 4 Q 5 Q 1 Q 2 Q 4 Q 5 Q 6 Q col row 3 1 6 2 5 7 4 0 0 1 2 Row Coloumn Q 3 7 6 7 1 -D array 0 3 1 1 2 6 3 2 4 5 5 7 6 4 7 0 3 4 5 6 7
A 0 1 2 2 -D array & 1 -D array 3 4 5 6 7 A[1][5] 0 x 1 B[13] : 2 <==> B[13] Base. Add + 13 * sizeof(int) A[1][5] : Base. Add + ( (1*8 ) + (5) )*sizeof(int) 3 4 Column size 5 6 7 B 0 1 2 3 4 5 6 7 8 x 9 10 11 12 13 14 15 16 …
Data Structures & Algorithms • Data Structures abstract data type: linked list, stack, queue, trees, heap, graph. • Algorithms : recursion, complexity (algorithm analysis) , hashing, searching, sorting.
- Slides: 11