Download presentation
Presentation is loading. Please wait.
Published byWilliam Patrick Modified over 8 years ago
1
Data Structures & Algorithms Lecturer : Kritawan Siriboon, Room no. 913 Text : Data Structures & Algorithm Analysis in C, C++,… Mark Allen Weiss, Addison Wesley
2
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.
3
Algo.1 :Two coins at a time Best Case Worst Case Average Case 1 n/2 How many times you weight?
4
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/2 3... = n/2 d 2 n/4 3 n/8...... d 1 n/2 1 How many times you weight?
5
2. Data Structure Structures of all data : how to keep related data in memory. Ex. The Eight Queen Problem.
6
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
7
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.
8
The Eight Queen Problem Data Structures 31625741 col 0 1 2 3 4 5 6 7 Row Coloumn 0 3 1 1 2 6 3 2 4 5 5 7 6 4 7 1 row 0123456701234567 Q Q Q Q Q Q Q Q 0 1 2 3 4 5 6 7 2-D array1-D array
9
2-D array & 1-D array x A 0 1 2 3 4 5 6 7 0123456701234567 B x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 … A[1][5] B[13] B[13] : BaseAdd + 13 * sizeof(int) A[1][5] : BaseAdd + ( (1*8 ) + (5) )*sizeof(int) Column size
10
Data Structures & Algorithms Data Structures abstract data type: stack, queue, linked list, trees, heap, graph. Algorithms : recursion, complexity (algorithm analysis), hashing, searching, sorting.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.