ดาวน์โหลดงานนำเสนอ
งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ
1
9. การออกแบบขั้นตอนวิธี
Algorithm Design Algorithm Design Techniques Practice Problems Algorithmic Process and Programming , created by Dararat Saelee
2
ลักษณะของขั้นตอนวิธีที่ดี
แก้ปัญหาได้อย่างมีประสิทธิภาพ ให้คำตอบที่ถูกต้อง ใช้เวลาในการปฏิบัติการน้อย ชัดเจนและกะทัดรัด
3
Algorithm Design definition requirement strategy techniques
4
Algorithm Design Definition
Algorithm Definition : a method to solve a problem described as a sequence of steps to be performed in a specific logical order Several algorithms for solving the same problem may exist , based on very different ideas , performance (efficiency , cost and speed) Algorithm หมายถึง กรรมวิธีที่มีขั้นตอนแบบทีละขั้นอย่างชัดเจนในการแก้ปัญหาใดปัญหาหนึ่ง เพื่อให้ได้คำตอบที่ถูกต้องสำหรับทุกรูปแบบข้อมูล ภายในเวลาและทรัพยากรณ์ที่จำกัด
5
Algorithm Design Requirement
Satisfied Requirements : unambiguousness generality correctness finiteness From Uckan p. 27
6
Satisfied Requirements
unambiguousness easier to understand and to program , so contain fewer bugs. sometimes simpler algorithm are more efficient than more complicated algorithm.
7
Satisfied Requirements
generality easier to design an algorithm in more general terms. handle a range of input that is natural for the problem.
8
Satisfied Requirements
correctness must be proved by 1) Mathematical Induction. 2) Testing with sample input data that possibly prove the algorithm failure or give wrong answer.
9
Satisfied Requirements
finiteness–must concern about 1) execution in finite steps. 2) termination in finite time.
10
Algorithm Design Strategy
Computational Device Solving Decision Data Structure Efficiency
11
Algorithm Design Strategy
Computational Device Von Neumann sequential algorithm Multiprocessor parallel algorithm network algorithm distributed algorithm
12
Algorithm Design Strategy
Solving Decision choose between solving the problem with approximation or exact algorithm approximation algorithm - square roots, integrals - shortest path
13
Algorithm Design Strategy
Solving Decision (cont.) choose to solve the problem with non-recursive or recursive algorithm recursion is easy to program, but uses a large number of function calls that affect to execution efficiency.
14
Algorithm Design Strategy
Data Structure to solve problems easier, we need to use appropriate data structure. - student id : int or string ? - matrix 10x5 : array 2D or 50 var.? - graph, tree : array or linked list ?
15
Algorithm Design Strategy
Efficiency time : how fast the algor. runs space : how much extra memory the algor. needs worst / best / average case - sequential search : n / 1 / n/2
16
Algorithm Design Strategy
Efficiency (cont.) Order of Growth for Input size - when input size is large, how is the run time ? - order of growth : O (big oh) - input size : n
17
Algorithm Design Strategy
Efficiency (cont.) - O(n2) : n = 10 running time = 100 n = 100 running time = 10,000 - O(2n) : n = 10 running time = 1,024 - O(log2n) : n = 10 running time = 3.3 n = 100 running time = 6.6
18
Algorithm Design Techniques
To provide guidance for designing algorithms for new problems To make it possible to classify algorithms according to design idea
19
Algorithm Design Techniques
No any general technique can solve all problems e.g. Unsorted data cannot use with Binary search algorithm
20
Algorithm Design Techniques
An algorithm design technique (or strategy or paradigm) is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing.
21
Algorithm Design Techniques
Greedy Method Divide and Conquer Decrease and Conquer / Prune- and-Search Transform and Conquer From Goodrich
22
Algorithm Design Techniques
Dynamic Programming Randomized Algorithms Backtracking Algorithms
23
Motto Today เพราะแสวงหา มิใช่เพราะรอคอย เพราะเชี่ยวชาญ มิใช่เพราะโอกาส
เพราะแสวงหา มิใช่เพราะรอคอย เพราะเชี่ยวชาญ มิใช่เพราะโอกาส เพราะสามารถ มิใช่เพราะโชคช่วย Algorithmic Process and Programming , created by Dararat Saelee
24
Greedy Method “take what you can get now”
make a decision that appears to be good (close to optimal solution) proceed by searching a sequence of choices iteratively to decide the (seem to be) best solution Greedy Algorithms หมายถึง เป็นอัลกอริทึมที่จะหาคาตอบโดยการเลือกทางออกที่ดีที่สุดที่พบได้ในขณะนั้นเพื่อให้ได้คาตอบที่ดีที่สุด แต่ในบางครั้ง Greedy Algorithms อาจจะไม่สามารถหาคาตอบของปัญหาที่ดีที่สุดได้เสมอไป
25
Greedy Method Coin Changing Fractional Knapsack Bin Packing
Task Scheduling
26
Greedy Method Prim’s Kruskal’s Dijkstra’s Huffman Code
graph tree
27
Greedy Method Coin Changing สมมุติว่าเรามีเหรียญขนาดดังต่อไปนี้เหรียญ 10 บาท, เหรียญ 5 บาท, และเหรียญ 1 บาทและสมมุติว่าเราต้องการแลกเงิน 89 บาท เราจะได้เงินเหรียญดังนี้ 10 บาท 8 เหรียญ, 5 บาท 1 เหรียญ, 1 บาท 4 เหรียญจะเห็นว่าอัลกอริทึมที่เราใช้ก็คือ เรา เลือกเหรียญที่มีค่ามากที่สุด แต่ไม่มากกว่า 89 บาท ออกมาก่อน (เหรียญ 10 บาท 8 เหรียญ ) จากนั้นลบค่านี้ออกจาก 89 บาท ก็ จะเหลือ 9 บาท หลังจากนั้นเราเลือกเหรียญที่มีค่ามากที่สุดแต่ไม่ เกิน 9 บาท นั่นก็คือได้(เหรียญ 5 บาท 1 เหรียญ) แล้วลบค่านี้ ออกจาก 9 บาท จะเหลืออยู่อีก 4 บาท และในที่สุดเราก็จะได้ (เหรียญ 1 บาทอีก 4 เหรียญ)
28
Greedy Method Fractional Knapsack
มีสิ่งของ n ประเภทซึ่งแต่ละประเภท(i) กำหนดให้มี จำนวน xi ชิ้น มีค่าความสำคัญ bi และมีน้ำหนัก wi ต้องการหาจำนวนสิ่งของแต่ละประเภทที่บรรจุลงใน เป้ที่รับน้ำหนักได้ไม่เกิน W กิโลกรัม ให้เลือกหยิบสิ่งของทีละชิ้นที่มีค่าดัชนี (vi=bi/wi) สูงสุดและทำให้น้ำหนักรวมไม่เกิน W ก่อน
29
Greedy Method ตัวอย่างเช่น มีของ 4 ประเภทคือ
หนังสือ 4 เล่ม มี b1=10 และ w1=0.6 (v1=16.7) ขนม 2 กล่อง มี b2=7 และ w2= (v2=17.5) น้ำ 2 ขวด มี b3=5 และ w3= (v3=10) ซีดีเพลง 8 แผ่น มี b4=3 และ w4=0.2 (v4=15) เป้รับน้ำหนักได้ไม่เกิน 4 กิโลกรัม เลือก ขนม 2 กล่อง หนังสือ 4 เล่ม และซีดีเพลง 4 แผ่น ได้ค่าความสำคัญสูงสุดและน้ำหนักไม่เกิน 4 กิโลกรัม
30
Greedy Method Bin Packing given N items of sizes s1 , s2 , …, sN;
while 0 < si < 1 find a solution to pack these items in the fewest number of bins 2 algor. versions : on-line : an item must be placed in a bin before the next item is read off-line : all item list are read in a bin
31
Optimal Bin Packing solution given an item list with sizes :
0.2 , 0.5 , 0.4 , 0.7 , 0.1 , 0.3 , 0.8 0.8 0.3 0.5 0.7 0.1 0.4 0.2 Bin Bin Bin 3 Algorithmic Process and Programming , created by Dararat Saelee
32
Bin Packing strategy Next fit : fill items in a bin until the next item can’t fit , then insert a new bin (never look back) [0.2 , 0.5 , 0.4 , 0.7 , 0.1 , 0.3 , 0.8] empty empty empty empty empty 0.1 0.8 0.5 0.7 0.4 0.3 0.2 Bin Bin Bin Bin Bin 5 Algorithmic Process and Programming , created by Dararat Saelee
33
Bin Packing strategy First fit : fill items in a bin , but if any first previous bin can fit the next item then we can fill in until no any bin can fit , then insert a new bin [0.2 , 0.5 , 0.4 , 0.7 , 0.1 , 0.3 , 0.8] empty empty empty empty 0.1 0.8 0.3 0.5 0.7 0.4 0.2 Bin Bin Bin Bin 4 Algorithmic Process and Programming , created by Dararat Saelee
34
Bin Packing strategy Best fit : fill items in a bin by trying to place the new item in the bin that left the smallest space [0.2 , 0.5 , 0.4 , 0.7 , 0.1 , 0.3 , 0.8] empty empty 0.3 empty 0.1 0.8 0.5 0.7 0.4 0.2 Bin Bin Bin Bin 4 Algorithmic Process and Programming , created by Dararat Saelee
35
Class Exercise ร้านขนมเค้กแห่งหนึ่งรับทำขนมเค้กตามคำสั่งของลูกค้า โดยการสั่งขนมเค้กอาจเป็น 1 ก้อน ½ ก้อน ¼ ก้อน และขนมเค้กที่ลูกค้าได้รับต้องเป็นขนาดก้อนที่ไม่มีรอย แบ่งภายในก้อน ทั้งนี้ในการทำขนมเค้ก ทางร้านไม่ต้องการให้เหลือขนมเค้กมากจึง ต้องคำนึงถึงจำนวนก้อนขนมเค้กที่น้อยที่สุดที่ต้องทำ ตัวอย่าง ถ้าหากลูกค้า 5 คน มีคำสั่ง ½ ¼ ½ ¼ ดังนั้นทางร้าน ต้องทำเค้ก 3 ก้อน จงเขียนโปรแกรมเพื่ออ่านข้อมูลคำสั่งของลูกค้าจากแฟ้มและหาว่าต้องทำเค้กอย่าง น้อยที่สุดกี่ก้อน Algorithmic Process and Programming , created by Dararat Saelee
36
Task Scheduling Greedy Method
ตัวอย่างงาน (1,3) , (1,4) , (2,5) , (3,7) , (4,7) , (6,9) , (7,8) จะได้ผลดังนี้ เครื่องที่ 1 : (1,3) , (3,7) , (7,8) เครื่องที่ 2 : (1,4) , (4,7) และเครื่องที่ 3 : (2,5) , (6,9) Algorithmic Process and Programming , created by Dararat Saelee
37
Job Scheduling (Uniprocessor)
Greedy Method Job Scheduling (Uniprocessor) j1 j2 j3 j4 Job Time j j j j First-come-First-serve : avg. completion time = 25 avg. waiting time = 16 j3 j2 j4 j1 Shortest Job First : avg. completion time = 17.75 avg. waiting time = 8.75 Algorithmic Process and Programming , created by Dararat Saelee
38
Job Scheduling (Multiprocessor)
Greedy Method Job Scheduling (Multiprocessor) FCFS Job Time j j j j j j j j j j1 j4 j7 j2 j5 j8 j3 j6 j9 Algorithmic Process and Programming , created by Dararat Saelee
39
Job Scheduling (Multiprocessor)
Greedy Method Job Scheduling (Multiprocessor) Optimal #1 Job Time j j j j j j j j j j1 j6 j7 j2 j5 j8 j3 j4 j9 Algorithmic Process and Programming , created by Dararat Saelee
40
Job Scheduling (Multiprocessor)
Greedy Method Job Scheduling (Multiprocessor) Job Time j j j j j j j j j j2 j5 j8 j6 j9 j1 j3 j4 j7 Optimal #2 – minimize completion time Algorithmic Process and Programming , created by Dararat Saelee
41
Divide and Conquer divide : break a given problem into subproblems
recur : try to solve each in recursive way conquer : derive the final solution from all solutions Algorithmic Process and Programming , created by Dararat Saelee
42
Divide and Conquer … Problem of size n Subproblem m of size n/m
Solution to Subproblem 1 Solution to Subproblem 2 Solution to Subproblem m Solution to the original problem Algorithmic Process and Programming , created by Dararat Saelee
43
Divide and Conquer Quick sort Binary Tree Traversal
Merge sort Quick sort Binary Tree Traversal Closest-Pair and Convex-Hall Selection problem Algorithmic Process and Programming , created by Dararat Saelee
44
Divide and Conquer Fibonacci Binary search
Factorial Fibonacci Binary search Strassen’s Matrix Multiplication Big Integer Multiplication From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
45
Factorial Divide and Conquer n! = n * (n-1)! (n-1)! = (n-1) * (n-2)! …
1! = 1 0! = 1 ตัวอย่าง 4! = ? 4! = 4 * 3! 3! = 3 * 2! 2! = 2 * 1! 1! = 1 * 0! 0! = 1 From Goodrich Describe with Tree structure Algorithmic Process and Programming , created by Dararat Saelee
46
fibo (n) = fibo (n-1) + fibo (n-2)
Divide and Conquer Fibonacci num.: 1,1,2,3,5,8,13,… fibo (n) = fibo (n-1) + fibo (n-2) fibo (n-1) = fibo (n-2) + fibo (n-3) fibo (n-2) = fibo (n-3) + fibo (n-4) … fibo (3) = fibo (2) + fibo (1) fibo (2) = 1 fibo (1) = 1 From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
47
Divide and Conquer Binary search 12 15 18 23 26 37 39 41 43 48
mid mid From Goodrich mid Algorithmic Process and Programming , created by Dararat Saelee
48
Strassen’s Matrix Multiplication
Divide and Conquer Strassen’s Matrix Multiplication Z = X * Y ; matrix n x n I = AxE + BxG , J = AxF + BxH K = CxE + DxG , L = CxF + DxH I J K L A B C D E F G H = x From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
49
Big Integer Multiplication
Divide and Conquer Big Integer Multiplication multiply 2 N-digit numbers : X , Y XY = XLYL10N + (XLYR + XRYL)10N/2 + XRYR XLYR+XRYL = (XL-XR)(YR-YL) + XLYL + XRYR require : 2 subtraction , 3 multiplication D1 = XL-XR , D2 = YR-YL XLYL , XRYR , D1D2 D3 = D1D2 + XLYL + XRYR From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
50
Big Integer Multiplication
Divide and Conquer Big Integer Multiplication X = 61,438,521 & Y = 94,736,407 XL = , XR = 8521 YL = , YR = 6407 D1 = XL-XR = -2378, D2 = YR-YL = -3066 XLYL = , XRYR = D1D2 = D3 = D1D2 + XLYL + XRYR = XY = XLYL108 + D XRYR From Goodrich XY = Algorithmic Process and Programming , created by Dararat Saelee
51
Motto Today ในการอยู่ร่วมกันกับผู้อื่น ควร
ในการอยู่ร่วมกันกับผู้อื่น ควร มองโลกในแง่ดี และ คิดในทางสร้างสรร มีน้ำใจ เอาใจเขามาใส่ใจเรา และรู้จักให้อภัย Algorithmic Process and Programming , created by Dararat Saelee
52
Decrease and Conquer based on exploiting the relationship between a solution to a given instance of a problem and a solution to a smaller instance of the same problem. it can be exploited either top down (recursively) or bottom up (without a recursion) . Algorithmic Process and Programming , created by Dararat Saelee
53
Decrease and Conquer 3 major variations :
decrease-by-a-constant decrease-by-a-constant-factor variable-size-decrease From Anany Algorithmic Process and Programming , created by Dararat Saelee
54
Decrease and Conquer decrease-by-a-constant
the size of instance is reduced by the same constant on each iteration decrease-by-a-constant-factor the size of instance is reduced by the same constant factor on each iteration
55
Decrease-by-a-constant
Insertion sort Depth-First search and Breadth-First search (graph) Topological sorting (graph) Generating Combinatorial Objects Algorithmic Process and Programming , created by Dararat Saelee
56
Decrease-by-a-constant
Insertion sort use the decrease-by-one sorted-side unsorted-side the size of unsorted data is reduced by 1 on each loop From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
57
Insertion Sort Algorithmic Process and Programming , created by Dararat Saelee
58
Decrease-by-a-constant-factor
Jasephus Problem Fake-Coin problem Multiplication à la Russe From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
59
Decrease-by-a-constant-factor
Josephus problem to determine the survivor by eliminating every second person (stand in circle) until only one survivor is left e.g. J(6) = 5 , J(7) = 7 , J(9) = 3 use the decrease-by-half (=2) Algorithmic Process and Programming , created by Dararat Saelee
60
Josephus problem use the decrease-by-half (=2) can consider J(n)
if n is even (n=2k) , J(2k) = 2 J(k) -1 if n is odd (n=2k+1) , J(2k+1) = 2 J(k) +1 J(6) = 2 J(3) -1 , J(3) = 2 J(1) + 1 , J(1) = 1 J(3) = 3 J(6) = 5 Algorithmic Process and Programming , created by Dararat Saelee
61
Josephus problem use the decrease-by-half (=2)
can be obtained by rotate left 1 bit J(6) = J(1102) 1012 = 5 J(7) = J(1112) 1112 = 7 J(9) = J(10012) = 3 Algorithmic Process and Programming , created by Dararat Saelee
62
Josephus problem use the decrease-by-3 (=3) eliminate every 3 person
Algorithmic Process and Programming , created by Dararat Saelee
63
Decrease and Conquer 3 major variations : decrease-by-a-constant
decrease-by-a-constant-factor variable-size-decrease a size reduction pattern varies from one iteration to another Algorithmic Process and Programming , created by Dararat Saelee
64
Variable-size-decrease
Euclid algor. Computing a median and the selection problem Interpolation search Binary search tree Algorithmic Process and Programming , created by Dararat Saelee
65
Decrease and Conquer Euclidean algor.: finding gcd(a,b) recursively
a ,if b=0 gcd(a,b) = b ,if a=0 gcd (b,a%b) ,otherwise e.g. gcd(124,40) = gcd(40,4) = 4 Algorithmic Process and Programming , created by Dararat Saelee
66
Transform and Conquer Problem’s instance solution Change to Another
problem instance Simpler instance Change representation solution Algorithmic Process and Programming , created by Dararat Saelee
67
Transform and Conquer Horner’s Rule Presorting Gaussian Elimination
Balanced Search tree Heap sort (tree) Problem Reduction Algorithmic Process and Programming , created by Dararat Saelee
68
Transform and Conquer Horner’s rules
p(x) = anxn + an-1xn-1 + … + a1x1 + a0 use the representation change technique p(x) = (…(anx + an-1)x +…)x + a e.g. p(x) = 2x4 – x3 + 3x2 + x – 5 = x(x(x(2x–1) +3) +1) – 5 From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
69
Transform and Conquer Problem Reduction
reduce the problem to another problem that solving algor. is known Problem1 Problem2 Solution Problem : counting paths in a graph , linear programming , the Least Common Multiple (lcm) From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
70
Transform and Conquer 24 = 2 2 2 3 60 = 2 2 3 5 lcm(11,5) = 55
the Least Common Multiple (lcm) lcm(24,60) = = 120 24 = 60 = lcm(11,5) = 55 From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
71
Transform and Conquer the Least Common Multiple (lcm) lcm (m,n) =
lcm(24,60) = 120 gcd(24,60) = 12 lcm(11,5) = 55 gcd(11,5) = 1 From Goodrich Algorithmic Process and Programming , created by Dararat Saelee
72
Dynamic Programming Characterizing subproblems using a small set of integer indices – to allow an optimal solution to a subproblem to be defined by the combination of solutions to even smaller subproblems Algorithmic Process and Programming , created by Dararat Saelee
73
Dynamic Programming Binomial Coefficient
Warshall’s & Floyd’s Directed Graph Optimal Binary Search tree Tree Ordering Matrix Multiplication or Matrix Chain- Product (ABCD A(BC)D , (AB)(CD)) All-pair Shortest Path Directed Graph ABCD, all-pair from Mark p. 386 Matrix chain from goodrich p.274, anany p.294 Algorithmic Process and Programming , created by Dararat Saelee
74
Dynamic Programming Solving each of smaller subproblems only once and recording the results in a table from which can obtain a solution to the original problem Using a table instead of recursion Factorial Fibonacci numbers Algorithmic Process and Programming , created by Dararat Saelee
75
Dynamic Programming 0-1 Knapsack problem 0-1 : reject or accept
given n items of weights w1 , w2 ,…, wn and values v1 , v2 ,…, vn and a knapsack of capacity W find the best solution that gives maximum weight and value p.278 from goodrich , p. 295 from anany Algorithmic Process and Programming , created by Dararat Saelee
76
0-1 Knapsack problem use table to fill in by applying formulas
B[k-1,w] , if wk > w B [k,w] = max{B[k-1,w],B[k-1,w-wk]+bk}, else e.g. let W = 5 and data : (item,weight,value) (1,2,12) (2,1,10) (3,3,20) (4,2,15) p.278 from goodrich , p. 295 from anany Algorithmic Process and Programming , created by Dararat Saelee
77
0-1 Knapsack problem Select 1, 2, 4
capacity j (W=5) weight, value i w1=2, v1= w2=1, v2= w3=3, v3= w4=2, v4= p.278 from goodrich , p. 295 from anany Select 1, 2, 4 Algorithmic Process and Programming , created by Dararat Saelee
78
Dynamic Programming Ordering Matrix Multiplication or Matrix Chain-Product find the best solution that gives minimum times of multiplication e.g. ABCD , A(BC)D , (AB)(CD) p.278 from goodrich , p. 295 from anany Algorithmic Process and Programming , created by Dararat Saelee
79
No ego Help each other then Everyone will succeed
80
Randomized Algorithms
a random number is used to make a decision in some situation e.g. giving a quiz by using a coin a good randomized algor. has no bad inputs and no relative to the particular input , e.g. data testing Algorithmic Process and Programming , created by Dararat Saelee
81
Randomized Algorithms
Random Number Generator a method to generate true randomness is impossible to do on computer since numbers , called pseudorandom numbers, will depend on the algorithm e.g. linear congruential generator xi+1 = Axi % M , given seed (x0) value Algorithmic Process and Programming , created by Dararat Saelee
82
Randomized Algorithms
Skip Lists (in searching & insertion) e.g. use random number generator to determine which node to be traversed within the expected time Primality Testing e.g. to determine a large N-digit number is prime or not by factoring into N/2-digit primes, then a random generator is needed p. 470 test prime Algorithmic Process and Programming , created by Dararat Saelee
83
Backtracking Algorithms
there are many possibilities to try, if not succeed then step back to try another way the elimination of a large group of possibilities in one step is known as pruning e.g. arranging furniture in a new house , never place sofa, bed & closet in the kitchen Algorithmic Process and Programming , created by Dararat Saelee
84
Backtracking Algorithms
n-Queens Hamiltonian Circuit Subset-Sum Goal Seeking Turnpike Reconstruction Goal seeking from gilberg Algorithmic Process and Programming , created by Dararat Saelee
85
Backtracking Algorithms
Games : chess n-Queens checker Tic-Tac-Toe Minimax strategy Algorithmic Process and Programming , created by Dararat Saelee
86
Practice Problems When confronted with a problem, it is worthwhile to see if any method of algor. design can apply properly together with data structure that will lead to efficient solution.
87
Practice Problems Bin packing Task scheduling
Knapsack problem Bin packing Task scheduling Strassen’s matrix multiplication Big Integer multiplication Josephus problem an Greedy Divide &conquer Decrease&conquer Algorithmic Process and Programming , created by Dararat Saelee
88
Practice Problems Non-recursive : an, fibonacci
Recursive exponentiation : an , Horner’s Rule LCM & GCD – Euclid Algor. 0-1 Knapsack Problem Dynamic programming transform Algorithmic Process and Programming , created by Dararat Saelee
89
ทำเดี๋ยวนี้ คือหนทางสู่ความสำเร็จ คิดแต่ไม่ทำ เท่ากับไม่ได้คิด
Motto Today ทำเดี๋ยวนี้ คือหนทางสู่ความสำเร็จ คิดแต่ไม่ทำ เท่ากับไม่ได้คิด Algorithmic Process and Programming , created by Dararat Saelee
90
Class Exercises Fractional Knapsack : W= 5 หนังสือ 4 เล่ม มี b1=10 และ w1=0.5 ขนม 3 กล่อง มี b2=5 และ w2=0.4 น้ำ 2 ขวด มี b3=7 และ w3=0.5 โน้ตบุ้ค 1 เครื่อง มี b4=15 และ w4=1.8 Bin Packing : 0.25 , 0.5 , 1.0 , 0.75 , , 0.25 , 0.5
91
Class Exercises Task Scheduling : act# start finish a1 1 4 , a2 2 5 , a3 1 5 , a4 5 8 a5 4 6 , a , a7 7 9 Big Integer Multiplication X = 4,123,450,732 Y = 8,159,324,570 an 1321 (decrease-by-2) Josephus Problem : J(82) decrease-by-3
92
Class Exercises Euclidean : gcd (2039,113) , gcd (1548,204) Horner’s Rule : p(x) = 7x9 + 4x6 - 3x5 - x4 + 5x2 + 9 Least Common Multiple : lcm (2039,113) , lcm (1548,204) 0-1 knapsack Problem : W = 6 , (1,2,12) (2,1,10) (3,4,20) (4,3,15) (5,2,14) (2039,113) gcd =1 , lcm = 2039*113 = (1548,204) gcd =12 , lcm = 1548*204/12 = 26316 0-1 select 2,4,5 (v=39)
งานนำเสนอที่คล้ายกัน
© 2024 SlidePlayer.in.th Inc.
All rights reserved.