Data Structures & Algorithms Lecturers : Boontee Kruatrachue Room no. 913 Kritawan Siriboon Room no. 913 Lecturers : Boontee Kruatrachue Room no. 913 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 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.
Algo.1 :Two coins at a time Best Case Worst Case Average Case 1 n/2 How many times you weight?
Algo 2 : Half Cutting Best Case Worst Case ½ ½ Time Remaining 1 2 d = n d = log 2 n = n/2 1 = n/2 2 = n/ = n/2 d 2 n/4 3 n/ d 1 n/2 1 How many times you weight?
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 using the standard chess queen’s move. Q Q Q Q Q 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 col Row Coloumn row Q Q Q Q Q Q Q Q D array1-D array
2-D array & 1-D array x A B x … A[1][5] B[13] B[13] : BaseAdd + 13 * sizeof(int) A[1][5] : BaseAdd + ( (1*8 ) + (5) )*sizeof(int) Column size
Data Structures & Algorithms Data Structures abstract data type: linked list, stack, queue, trees, heap, graph. Algorithms : recursion, complexity (algorithm analysis), hashing, searching, sorting.