งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

Asst.Prof. Dr.Surasak Mungsing

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "Asst.Prof. Dr.Surasak Mungsing"— ใบสำเนางานนำเสนอ:

1 Asst.Prof. Dr.Surasak Mungsing E-mail: Surasak.mu@spu.ac.th
CSC201 การวิเคราะห์และออกแบบขั้นตอนวิธี Analysis and Design of Algorithms Asst.Prof. Dr.Surasak Mungsing Apr-17

2 Analysis and Design of Algorithms
CSC201 Analysis and Design of Algorithms Lecturer: Aaat.Prof. Dr.Surasak Mungsing Contact: 12th Floor, Building 11 Office Hour: TBA 4-Apr-17

3 Course Description การวิเคราะห์ทางทฤษฎีของขั้นตอนวิธี การเลือกโครงสร้างข้อมูลที่เหมาะสม ขั้นตอนวิธีเรียกซ้ำ การวิเคราะห์ชั้นความซับซ้อน การเรียงลำดับและการค้นหา การวิเคราะห์ความต้องการของเนื้อที่และเวลาที่ต้องการของขั้นตอนวิธี การคำนวณได้และการตัดสินใจได้ของปัญหาที่ยากต่อการแก้ไข เช่นที่พบในปัญญาประดิษฐ์ แนะนำขั้นตอนวิธีแบบขนาน 4-Apr-17

4 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 วัตถุประสงค์ เพื่อให้นักศึกษาเข้าใจทฤษฎีและการประยุกต์ใช้ขั้นตอนวิธีทางคอมพิวเตอร์ เพื่อพัฒนาความคิดด้านการวิเคราะห์กับปัญหาทางคอมพิวเตอร์ เพื่อเสริมสร้างพื้นฐานด้านทักษะการออกแบบวิธีการแก้ปัญหาทางคอมพิวเตอร์ 4-Apr-17

5 ตำราและเอกสารประกอบการสอน
Books Mark Allen Weiss. Data Structures and Algorithm Analysis in Java, International Edition. Addison-Wesley ( ) 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 4-Apr-17

6 Evaluation Final Exam 40 % Mid-Term Exam 20 % Quiz 20 %
H/W & Exercise 10% Participation 10 % Total % 4-Apr-17

7 Grading Score Grade 80-100 A 75-79 B+ 70-74 B 65-69 C+ 60-64 C 55-59
50-54 D 0-49 F 4-Apr-17

8 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) 1. แนะนำจุดมุ่งหมายวิชาและทบทวนความรู้ด้าน โครงสร้างข้อมูล 2. ทฤษฎีความซับซ้อน และคณิตศาสตร์ที่จำเป็นสำหรับการวิเคราะห์ 3. ขั้นตอนวิธีและการวิเคราะห์ขั้นตอนวิธี 4. การวิเคราะห์หาความซับซ้อนด้านเวลาในรูป แบบของ Big-Oh 5. การวิเคราะห์ความซับซ้อนของขั้นตอนวิธีการเรียงลำดับข้อมูล 6. การวิเคราะห์ขั้นตอนวิธีที่ใช้ในโครงสร้างข้อมูลแบบ List และ Stack และ Queues 7. การวิเคราะห์ขั้นตอนวิธีที่ใช้ในโครงสร้างข้อมูลแบบ Trees Time complexity Analysis of Algorithms using List, tack, and Queue data structures Apr-17

9 Time complexity analysis for searching in graph
Outline(Cont.) Analysis of Algorithms using Trees data structure Applications of Decision Tree Shortest Path and Minimum Spanning Tree Week 8 -11 Time complexity analysis for searching in graph Algorithm design using Greedy and Divide and Conquer techniques (e-Learning) 8. ประยุกต์ใช้ Tree กับปัญหาต้องตัดสินใจ 9. กราฟกับปัญหา Shortest Path และ Minimum Spanning Tree 10. การวิเคราะห์ค่าความซับซ้อนของการค้นหา 11. เทคนิคการออกแบบขั้นตอนวิธี Greedy และ Divide and Conquer 12. เทคนิคการออกแบบขั้นตอนวิธี Dynamic Programming, Backtracking 13. การคำนวณได้และการตัดสินใจของปัญหาที่ยากต่อการแก้ไข 14. ทบทวนเนื้อหาและประเด็นสำคัญของที่เรียนมาทั้งหมด Algorithm design using Dynamic Progra mming, and Backtracking techniques (e-Learning) P and NP Problem (e-Learning) Apr-17

10 Mutual Agreement Attendant checking for each lecture
Postpone lectures will informed at least 1 week 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 มีการเช็คขื่อเข้าเรียนทุกครั้ง การแจ้งงดการเรียนการสอน จะแจ้งล่วงหน้าอย่างน้อย 1 สัปดาห์ แต่ถ้าเป็นกรณีกะทันหันและไม่สามารถติดต่อตัวแทนกลุ่มนักศึกษาได้ทัน ให้นักศึกษารออยู่ภายในห้องเรียนอย่างน้อย 20 นาทีแต่ไม่เกิน 40 นาทีและถ้ายังไม่มีการเรียนการสอนเกิดขึ้น ให้ถือว่าครั้งนั้นงดการเรียนการสอนโดยปริยาย และจะแจ้งวันเรียนชดเชยในครั้งถัดไป นักศึกษาต้องมีเวลาเข้าเรียนอย่างน้อย 80 % ของเวลาเรียนทั้งหมด จึงจะมีสิทธิ์เข้าสอบไล่ นักศึกษาสามารถ download สไลด์ประกอบการสอนได้จาก website ของอาจารย์ผู้สอน 4-Apr-17

11 CSE221/NMT221/ICT221 การวิเคราะห์และออกแบบขั้นตอนวิธี
4-Apr-17

12 Review: Data Structures
Apr-17

13 next (datatype ChainNode)
The Class Chain a b c d e null firstNode size = number of elements Use ChainNode next (datatype ChainNode) element (datatype Object)

14 public Object get(int index)
The Method get a b c d e null firstNode 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; }

15 remove(0) firstNode = firstNode.next;
Removing An Element a b c d e null firstNode remove(0) firstNode = firstNode.next;

16 determine beforeNode and change pointer.
remove(2) beforeNode a b c d e null firstNode determine beforeNode and change pointer. beforeNode.next = beforeNode.next.next;

17 firstNode = new ChainNode(‘f’, firstNode);
One-Step add(0,’f’) a b c d e null firstNode f newNode firstNode = new ChainNode(‘f’, firstNode);

18 Two-Step add(3,’f’) a b c d e firstNode f newNode beforeNode
null firstNode f newNode beforeNode beforeNode = firstNode.next.next; beforeNode.next = new ChainNode(‘f’, beforeNode.next);

19 Circular List firstNode a b c d e
Useful, for example, when each node represents a supplier and you want each supplier to be called on in round-robin order. Other applications seen later. A variant of this has a header node—circular list with header node. When you don’t have a header node, it is often useful to have a last node pointer rather than a first node pointer. By doing this, additions to the front and end become O(1).

20 Doubly Linked List a b c d e firstNode lastNode null
Can be used to reduce worst-case run time of a linear list add/remove/get by half. Start at left end if index <= size/2; otherwise, start at right end.

21 Doubly Linked Circular List With Header Node

22 Doubly Linked Circular List
firstNode

23 Stacks Linear list. One end is called top. Other end is called bottom.
Additions to and removals from the top end only. 4-Apr-17

24 Stack Of Cups top bottom F E D C B A
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. 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. 4-Apr-17

25 Checking Matching Parentheses
(((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 u is 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 Matching parenthesis is nearest unmatched parenthesis on left. ผลลัพธ์เป็นคู่ของตำแหน่ง (u,v) ซึ่งวงเล็บเปิดที่ตำแหน่ง u เข้าคู่อย่างถูกต้องกับวงเล็บปิดที่ตำแหน่ง v วงเล็บปิดที่ตำแหน่ง 5 ไม่มีวงเล็บเปิดที่เป็นคู่ของมัน วงเล็บเปิดที่ตำแหน่ง7 ไม่มีคู่วงเล็บปิด 4-Apr-17

26 Tower of Hanoi A B C 4 3 2 1 Could use animation of towers of hanoi from animations page on Web site. Also known as Towers of Brahma. According to legend, on the day of creation Buddhist monks began the task of moving disks from tower A to tower C. When they get done, the world will come to an end. 64 discs 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 4-Apr-17

27 Towers Of Hanoi/Brahma
C 3 2 1 A towers of Hanoi with 3 discs 4-Apr-17

28 B C 2 1 3 A towers of Hanoi with 3 discs 4-Apr-17

29 B C 1 2 3 A towers of Hanoi with 3 discs 4-Apr-17

30 B C 3 1 2 A towers of Hanoi with 3 discs 4-Apr-17

31 B C 3 2 1 A towers of Hanoi with 3 discs 4-Apr-17

32 B C 3 2 1 A towers of Hanoi with 3 discs 4-Apr-17

33 Towers Of Hanoi/Brahma
C 2 3 1 A towers of Hanoi with 3 discs 4-Apr-17

34 B C 3 2 1 A towers of Hanoi with 3 discs พำๆรพำห 7 moves 4-Apr-17

35 Recursive Solution A B C 1
Towerof Hanoi with n > 0 discs to be moved from tower A 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 4-Apr-17

36 B C 1 A ย้ายแผ่นทองคำด้านบนจาก A ไปยัง C 4-Apr-17

37 B C A 1 ย้ายแผ่นที่อยู่ด้ายบนจำนวน n-1 จาก B ไปยัง C โดยใช้ A ช่วย
4-Apr-17

38 B C 1 A moves(n) = 0 เมื่อ n = 0 moves(n) = 2*moves(n-1) + 1 = 2n-1 เมื่อ n > 0 4-Apr-17

39 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 At the rate of a billion moves/second it would take 570 years to complete the task of moving 64 disks. Of course, the Buddhist monks engaged in this activity are moving far fewer disks/second. At the rate of (say) 1 disk a minute (the disks are, after all, rather heavy), the monks will take about 3.4 * 1013 years. So there is quite a while to go before the world comes to an end. moves(64) = 1.8 * 1019 (โดยประมาณ) ประสิทธิภาพในการเคลื่อนย้าย 109 ครั้ง/วินาที คอมพิวเตอร์ต้องใช้เวลาประมาณ 570 ปี จึงจะทำสำเร็จ ทำการเคลื่อนย้ายที่อัตราความเร็ว 1 แผ่น/นาที พระจะต้องใช้เวลาทั้งหมดประมาณ 3.4 * 1013 ปี หรือ 34,000,000,000,000 ปี (สามสิบสี่ล้านล้านปี) 4-Apr-17

40 4-Apr-17

41 Queue at the bus station
Bus Stop front rear rear

42 Queue at the bus station
Bus Stop front rear

43 Queue at the bus station
Bus Stop front rear rear

44 Queue at the bus station
Bus Stop front rear rear This is FIFO queue. Some real life queues are not FIFO. Removal from a queue may be done by priority rather than by arrival time order. For example, loading into a plane– first class, frequent fliers, by rows from back of plane rather than by order in which you arrive at the departure gate.

45 Queue implemented with array
Use 1-dimentional array to represent a queue queue[] Can be viewed as a circular queue [0] [1] [2] [3] [4] [5]

46 Add an element into queue
Requires two pointers, front and rear [0] [1] [2] [3] [4] [5] A B C front rear

47 Add an element into queue
move rear pointer clockwise 1 position then assign a value to the array pointed by the rear pointer [0] [1] [2] [3] [4] [5] A B C front rear D queue[rear]

48 Current queue status [0] [1] [2] [3] [4] [5] A B C front rear

49 Remove an element from queue
Move front pointer clockwise 1 position then move the value out from queue [0] [1] [2] [3] [4] [5] A B C front rear queue[front]

50 Empty the queue [0] [1] [2] [3] [4] [5] A B C front rear

51 Empty the queue [0] [1] [2] [3] [4] [5] B C rear front

52 Empty the queue [0] [1] [2] [3] [4] [5] C rear front

53 Empty the queue [0] [1] [2] [3] [4] [5] rear front
Continuously remove elements from queue causes the queue to be empty  front = rear. The queue is also empty when created  Starts with front = rear = 0.

54 Make the queue full [0] [1] [2] [3] [4] [5] A B C front rear
By keep adding an element to the queue [0] [1] [2] [3] [4] [5] A B C front rear

55 Make the queue full [0] [1] [2] [3] [4] [5] rear D front C B A
By keep adding an element to the queue [0] [1] [2] [3] [4] [5] rear D front C B A

56 Make the queue full [0] [1] [2] [3] [4] [5] rear D E front C B A
By keep adding an element to the queue [0] [1] [2] [3] [4] [5] rear D E front C B A

57 Make the queue full [0] [1] [2] [3] [4] [5] D E front C F B A rear
By keep adding an element to the queue [0] [1] [2] [3] [4] [5] D E front C F B A rear When continuously adding elements to queue, it is finally full so front = rear. How do you know whether the queue is empty or full when front = rear ?

58 How do we know whether the queue is empty or full when front = rear ?
Assign a variable, size, to keep number of element in queue Increase queue size by 1 each time when when adding an element to queue (size++) Reduce queue size by 1 each time when remove an element from queue (size--) Queue is empty when queue size = 0 (size=0) solution กำหนดตัวแปรสำหรับเก็บค่าขนาดของคิว (size) ทุกครั้งที่เพิ่มสมาชิกในคิว ต้องเพิ่มขนาดของคิวด้วย (size++) ทุกครั้งที่ลบสมาชิกในคิว ต้องลดขนาดของคิวด้วย (size--) คิวว่างเมื่อ size เท่ากับ 0 (size == 0) คิวเต็มเมื่อ sizeเท่ากับขนาดของคิว (size == queue.length)

59 Tree in computer science
leaves root nodes branches Tree is a set with at least 1 member t one of the tree member is called “root” other members(if any) are subtree(s) ต้นไม้ (Tree) คือเซ็ตที่มีสมาชิกอย่างน้อย1สมาชิก t หนึ่งในสมาชิกเรียกว่าราก หรือ root สมาชิกที่เหลือ (ถ้ามี) แบ่งกลุ่มเป็นต้นไม้ย่อยๆ 4-Apr-17

60 Binary Tree is a tree that may be an empty tree (a tree with no member) A non-empty binary tree has “root “ Remaining member (if any) สมาชิกที่เหลือ(ถ้ามี) จะแบ่งเป็นเป็น may be the root 0f at most 2 binary subtrees, called Left sub-tree and Right sub-tree เป็นต้นไม้ที่อาจไม่มีสมาชิกก็ได้ Binary tree ที่ไม่ว่างจะมี root สมาชิกที่เหลือ(ถ้ามี) จะแบ่งเป็นเป็น Binary tree ย่อย 2 ต้น เรียกว่า Left sub-tree และ Right sub-tree 4-Apr-17

61 An expression implemented by a binary tree
(a + b) * (c – d) / (e + f) / + a b - c d e f * 4-Apr-17

62 4-Apr-17


ดาวน์โหลด ppt Asst.Prof. Dr.Surasak Mungsing

งานนำเสนอที่คล้ายกัน


Ads by Google