620 likes | 632 Views
CSE 221/ICT221 การวิเคราะห์และออกแบบขั้นตอนวิธี Analysis and Design of Algorithms. Asst.Prof . Dr.Surasak Mungsing E-mail: Surasak.mu@spu.ac.th. CSE 221/ICT221 Analysis and Design of Algorithms. Lecturer : Asst.Prof . Dr.Surasak Mungsing surasak.mu@spu.ac.th
E N D
CSE 221/ICT221 การวิเคราะห์และออกแบบขั้นตอนวิธี Analysis and Design of Algorithms Asst.Prof. Dr.SurasakMungsing E-mail: Surasak.mu@spu.ac.th
CSE 221/ICT221 Analysis and Design of Algorithms Lecturer: Asst.Prof. Dr.SurasakMungsing surasak.mu@spu.ac.th http://www.spu.ac.th/teacher/surasak.mu Contact:12th Floor, Building 11 Office Hour: TBA
Course Description การวิเคราะห์ทางทฤษฎีของขั้นตอนวิธี การเลือกโครงสร้างข้อมูลที่เหมาะสม ขั้นตอนวิธีเรียกซ้ำ การวิเคราะห์ชั้นความซับซ้อน การเรียงลำดับและการค้นหา การวิเคราะห์ความต้องการของเนื้อที่และเวลาที่ต้องการของขั้นตอนวิธี การคำนวณได้และการตัดสินใจได้ของปัญหาที่ยากต่อการแก้ไข เช่นที่พบในปัญญาประดิษฐ์ แนะนำขั้นตอนวิธีแบบขนาน (Prerequisite: CSE102andMAT231 or together with MAT231 for Vocational Students)
Objective • Understanding of theory and applications of algorithms for computer-based problem solving • Concept development for computer-based problem solving • Skill improvement for design of computer-based problem solving
ตำราและเอกสารประกอบการสอนตำราและเอกสารประกอบการสอน Books Mark Allen Weiss. Data Structures and Algorithm Analysis in Java, International Edition. Addison-Wesley. 2007. (www.cs.fiu.edu/~weiss ) R.T.C. Lee, S.S. Tseng, R.C. Chang, Y.T. Tsai. Introduction to the Design and Analysis of Algorithms, A Strategic Approach. McGraw-Hill Education (Asia). 2005
Evaluation Theory Final Exam 30 % Mid-Term Exam 20 % Quiz 10 % Exercise 10 % Participation 5 % Lab Reports 15 % Quiz 10 % Total100 % 75% 25%
Outline • Course Introduction and review of Data Structures • Complexity theory and necessary mathematical background • Algorithms and algorithm analysis Week 1-7 • Time complexity of algorithms in form of Big-Oh • Time complexity analysis of sorting algorithms (Part I) • Time complexity analysis of sorting algorithms (Part II) • Time complexity Analysis of Algorithms using • List, tack, andQueue data structures
Outline(Cont.) • Analysis of Algorithms using Trees data structure • Applications of Decision Tree Shortest Pathand Minimum Spanning Tree Week 8 -11 Time complexity analysis for searching in graph Algorithm design using Greedy and Divide and Conquer techniques (e-Learning) Algorithm design using Dynamic Programming, and Backtracking techniques (e-Learning) P and NP Problem (e-Learning)
Mutual Agreement • Attendant checking for each lecture • Postpone lectures will informed at least 1week in advance • Makeup class will be announced in next class • Late class is not more than 20 minutes, otherwise there will be no class and requires a makeup class • Class attendance must be at least 80% to be eligible for final examination • All documents can be downloaded at http://www.spu.ac.th/teacher/surasak.mu/
CSE221/NMT221/ICT221 การวิเคราะห์และออกแบบขั้นตอนวิธี
firstNode null a b c d e • size = number of elements The Class Chain UseChainNode next (datatype ChainNode) element (datatype Object)
firstNode null a b c d e The Method get public Object get(int index) { checkIndex(index); // move to desired node ChainNode currentNode = firstNode; for (int i = 0; i < index; i++) currentNode = currentNode.next; return currentNode.element; }
firstNode Removing An Element null a b c d e remove(0) firstNode = firstNode.next;
firstNode remove(2) null a b c d e beforeNode determine beforeNode and change pointer. beforeNode.next = beforeNode.next.next;
f firstNode One-Step add(0,’f’) null a b c d e newNode firstNode = new ChainNode(‘f’, firstNode);
c firstNode newNode f Two-Step add(3,’f’) null a b c d e beforeNode beforeNode = firstNode.next.next; beforeNode.next = new ChainNode(‘f’, beforeNode.next);
firstNode Circular List a b c d e
firstNode lastNode Doubly Linked List null null a b c d e
headerNode Doubly Linked Circular List With Header Node a b c d e
firstNode Doubly Linked Circular List a b c d e
Stacks • Linear list. • One end is called top. • Other end is called bottom. • Additions to and removals from the top end only.
F E E D D C C B B A A Stack Of Cups top top bottom bottom Picture is really a stack of cups and saucers LIFO = last in first out. The first cup that is removed from a stack of cups is the Last one that was added to the stack. Other examples of LIFO lists in real life: stack of trays in a cafeteria; paper stack in a printer or copy machine; newspaper stack at a news stand.
Checking MatchingParentheses • (((a+b)*c+d-e)/(f+g)-(h+j)*(k-l))/(m-n) • The result is pairs of position(u,v) where the open parenthesis at uis correctly matched with the close parenthesis at v • (2,6) (1,13) (15,19) (21,25) (27,31) (0,32) (34,38) • (a+b))*((c+d) • (0,4) • The close parenthesis at position 5 does not have an open parenthesis as its pairs • (8,12) • the open parenthesis at position 7 does not have a close parenthesis as its pairs
4 3 1 A B C Tower of Hanoi 64discs are to be moved from tower A to tower C on the condition that larger disc cannot be placed on top of the smaller one 2
3 2 1 B C Towers Of Hanoi/Brahma • towers of Hanoi with 3 discs A
2 1 3 B C • towers of Hanoi with 3 discs A
1 2 3 B C • towers of Hanoi with 3 discs A
3 1 2 B C • towers of Hanoi with 3 discs A
3 2 1 B C • towers of Hanoi with 3 discs A
3 2 1 B C • towers of Hanoi with 3 discs A
2 3 1 B C Towers Of Hanoi/Brahma • towers of Hanoi with 3 discs A
3 2 1 B C • towers of Hanoi with 3 discs A • พำๆรพำห 7 moves
1 A B C Recursive Solution • Towerof Hanoi with n > 0 discs to be moved from towerA to tower C with the help of tower B • Move n-1 discs from tower A to tower B with the help of tower C
1 B C • ย้ายแผ่นทองคำด้านบนจาก A ไปยัง C A
1 B C • ย้ายแผ่นที่อยู่ด้ายบนจำนวน n-1 จาก B ไปยัง C โดยใช้ A ช่วย A
1 B C • moves(n) = 0 เมื่อ n = 0 • moves(n) = 2*moves(n-1) + 1 = 2n-1 เมื่อ n > 0 A
Moves required • moves(64) = 1.8 * 1019 (approximately) required • At the rate of a billion moves/second it would take 570 years to complete the task of moving 64 disks. • At the rate of 1 disk a minute (the disks are, after all, rather heavy), will take about 3.4 * 1013 years or 34,000,000,000,000 years
Bus Stop Queue at the bus station front rear rear
Bus Stop Queue at the bus station front rear
Bus Stop Queue at the bus station front rear rear
Bus Stop Queue at the bus station front rear rear
queue[] [2] [3] [1] [4] [0] [5] Queue implemented with array • Use 1-dimentional array to represent a queue • Can be viewed as a circular queue
[2] [3] A B rear front C [1] [4] [0] [5] Add an element into queue • Requires two pointers, front and rear
[2] [3] A B front C [1] [4] [0] [5] rear Add an element into queue • move rear pointer clockwise 1 position • then assign a value to the array pointed by the rear pointer D queue[rear]
[2] [3] A B rear front C [1] [4] [0] [5] Current queue status
[2] [3] front A B rear C [1] [4] [0] [5] Remove an element from queue • Move front pointer clockwise 1 position • then move the value out from queue queue[front]
[2] [3] rear front C [1] [4] B A [0] [5] Empty the queue