4deaf52e1ef169e2673d67b04d4d9ed4.ppt
- Количество слайдов: 92
. การออกแบบขนตอนว ธ 9 Algorithm Design Techniques Practice Problems 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 1/93
ลกษณะของขนตอนวธ ทด oแกปญหาไดอยางม ประสทธภาพ oใหคำตอบทถกตอง oใชเวลาในการปฏบตก ารนอย oชดเจนและกะทดรด 2/93
Design o definition o requirement o strategy o techniques 3/93
Algorithm Design Definition o Algorithm Definition : a method to solve a problem described as a sequence of steps to be performed in a specific logical order o Algorithm หมายถงalgorithms for solving the Several กรรมวธทมขนตอนแบบทละขนอยางชดเจนในการแกปญ same problem may exist , based หาใดปญหาหนง เพอใหไดคำตอบทถกตองสำหรบทกรปแบบขอมล on very ทจำกด different ideas , ภายในเวลาและ ทรพยากรณ 4/93
Requirement Satisfied Requirements : o o unambiguousness generality correctness finiteness 5/93
Requirements unambiguousness o easier to understand to program , so contain fewer bugs. o sometimes simpler algorithm are more efficient than more complicated algorithm. 6/93
Satisfied Requirements generality o easier to design an algorithm in more general terms. o handle a range of input that is natural for the problem. 7/93
Requirements correctness proved by must be 1) Mathematical Induction. 2) Testing with sample input data that possibly prove the algorithm failure or give wrong answer. 8/93
Requirements finiteness–must concern about 1) execution in finite steps. 2) termination in finite time. 9/93
Algorithm Design Strategy o. Computational Device o. Solving Decision o. Data Structure o. Efficiency 10/93
Strategy Computational Device o Von Neumann osequential algorithm o Multiprocessor o parallel algorithm o network algorithm o distributed algorithm 11/93
Strategy Solving Decision ochoose between solving the problem with approximation or exact algorithm oapproximation algorithm - square roots, integrals - shortest path 12/93
Strategy Solving Decision (cont. ) ochoose to solve the problem with non-recursive algorithm or orecursion is easy to program, but uses a large number of function calls that affect to execution efficiency. 13/93
Strategy Data Structure o to solve problems easier, we need to use appropriate data structure. - student id : int or string ? - matrix 10 x 5 : array 2 D or 50 var. ? - graph, tree : array or linked list ? 14/93
Strategy Efficiency otime : how fast the algor. runs ospace : how much extra memory the algor. needs oworst / best / average case - sequential search : n / 1 / n/2 15/93
Strategy Efficiency (cont. ) o. 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 16/93
Strategy Efficiency (cont. ) - O(n 2) : n = 10 running time = 100 n = 100 running time = 10, 000 - O(2 n) : n = 10 running time = 1, 024 - O(log 2 n) : n = 10 running time = 3. 3 n = 100 running time = 6. 6 17/93
Algorithm Design Techniques o To provide guidance for designing algorithms for new problems o To make it possible to classify algorithms according to design idea 18/91
Algorithm Design Techniques o. No any general technique can solve all problems oe. g. Unsorted data cannot use with Binary search algorithm 19/91
Techniques An algorithm design technique (or strategy paradigm) is a or general approach to solving problems algorithmically that is applicable to a variety of problems from 20/93
Algorithm Design Techniques o Greedy Method o Divide and Conquer o Decrease and Conquer / Prune-and. Search o Transform and Conquer 21/93
Algorithm Design Techniques Dynamic Programming o Randomized Algorithms o Backtracking Algorithms o 22/93
Motto Today เพราะแสวงหา มใชเพราะรอคอย เพราะเชยวชาญ มใชเพราะโอก เพราะสามารถ มใชเพราะโชคชว 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 23/93
Greedy Method o “take what you can get now” o make a decision that appears to be good (close to optimal solution) o proceed by searching a Greedy Algorithms หมายถง เปนอลกอรทมทจะหาคาตอบโดยการเลอกทางออกทดทสดทพบไดใน sequence of แตในบางครงchoices ขณะนนเพอใหไดคาตอบทดทสด Greedy Algorithms อาจจะไมสามารถหาคาตอบของปญหาทดทสดไดเสมอไป iteratively to decide the 24/93
Greedy Method ตวอยางวธคดแบบ Greedy o Coin Changing o Fractional Knapsack o Bin Packing o Task Scheduling 25/93
Greedy Method ตวอยางวธคดแบบ Greedy o Prim’s graph o Kruskal’s o Dijkstra’s tree o Huffman Code 26/93
Greedy Method Coin Changing สมมตวาเรามเหรยญขนาดดงตอไปน เหรยญ 10 บาท, เหรยญ 5 บาท, และเหรยญ 1 บาทและสมมตวาเราตองการแลกเงน 89 บาท เราจะไดเงนเหรยญดงน 10 บาท 8 เหรยญ , 5 บาท 1เหรยญ , 1 บาท 4 เหรยญจะเหนวาอลกอรทมทเราใช กคอ เราเลอกเหรยญทมคามากทสด แตไมมากกวา 89 บาท ออกมากอน (เหรยญ 10 บาท 8 เหรยญ ) 27/93
Greedy Method Fractional Knapsack มสงของ n ประเภทซงแตละประเภท (i) กำหนดใหมจำนวน xi ชน มคาความสำคญ bi และมนำหนก wi o ตองการหาจำนวนสงของแตละ ประเภททบรรจลงในเปทรบน ำหนกไดไมเกน W o 28/93
Greedy Method o ตวอยางเชน มของ 4 ประเภทคอ oหนงสอ 4 เลม ม b 1=10 และ w 1=0. 6 (v 1=16. 7) oขนม 2 กลอง ม b 2=7 และ w 2=0. 4 (v 2=17. 5) oนำ 2 ขวด ม b 3=5 และ w 3=0. 5 (v 3=10) oซดเพลง 8 แผน ม b 4=3 และ w 4=0. 2 (v 4=15) o เปรบนำหนกไดไมเกน 29/93 4
Greedy Method o Bin Packing o given N items of sizes s 1 , s 2 , …, s N; o while 0 < si < 1 o find a solution to pack these items in the fewest number of bins o 2 algor. versions : o on-line : an item must be placed in a bin before the next item is read o off-line : all item list are read in a bin 30/93
Optimal Bin Packing solution given an item list with sizes : 0. 2 , 0. 5 , 0. 4 , 0. 7 , 0. 1 , 0. 3 0. 5 0. 8 0. 7 0. 4 0. 2 Bin 1 0. 1 Bin 2 Bin 3 31/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
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 0. 1 empty 0. 5 0. 8 0. 7 0. 2 Bin 1 0. 4 Bin 2 0. 3 Bin 4 Bin 5 32/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
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 , empty 0. 8] 0. 1 empty 0. 7 empty 0. 8 Bin 3 Bin 4 0. 3 0. 5 0. 4 0. 2 Bin 1 Bin 2 33/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
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 0. 7 0. 1 0. 3 0. 8 empty 0. 5 0. 4 0. 2 Bin 1 Bin 2 Bin 3 Bin 4 34/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Class Exercise o รานขนมเคกแหงหนงรบทำขนมเคกตามคำสง ของลกคา โดยการสงขนมเคกอาจเปน 1 กอน ½ กอน ¼ กอน และขนมเคกทลกคาไดรบตองเปน ขนาดกอนท ไมมรอยแบงภายในกอน ทงนในการทำขนมเคก ทางรานไมตองการใหเหลอขนมเคกมากจงตองค ำนงถงจำนวนกอนขนมเคกทนอยทสดท ตองทำ o ตวอยาง ถาหากลกคา 5 คน มคำสง 1 ½ ¼ ดงนนทางรานตองทำเคก 3 กอน 35/93 o จงเขยนโปรแกรมเพออานขอมลคำสงของลกค 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Greedy Method Task Scheduling oกำหนดงาน n งานดวย (เวลาเรม , เวลาเสรจ ) โดยใหทำงานทละงานบนเครอง และจะเอางานใดมาทำบนเครองเด ยวกนไดถาเวลางานไมทบซอน กน ทงนตองใชจำนวนเครองใ นการทำงานทงหมดนอยทสด 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 36/93
Greedy Method Job Scheduling (Uniprocessor) Job Time j 1 15 j 2 8 j 3 3 j 4 j 1 10 j 2 0 15 j 3 23 j 4 26 36 First-come-First-serve : avg. completion time = 25 avg. waiting time = 16 j 3 0 j 2 3 j 4 11 j 1 21 36 Shortest Job First : avg. completion time = 17. 75 avg. waiting time = 8. 75 37/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Greedy Method FCFS Job Scheduling (Multiprocessor) Job Time j 1 3 j 2 6 j 4 10 j 5 11 j 6 15 j 8 18 j 9 j 7 14 j 7 j 4 5 j 3 j 1 20 0 3 13 j 2 0 j 5 j 8 5 16 j 3 0 28 34 j 6 6 j 9 20 40 38/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Greedy Method Optimal #1 Job Scheduling (Multiprocessor) Job Time j 1 3 j 2 5 j 3 6 j 4 10 j 5 11 j 6 14 j 7 15 j 8 18 j 9 j 1 j 6 j 7 20 0 3 17 j 2 0 j 5 5 j 8 16 j 3 0 32 j 4 6 34 j 9 16 36 39/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Greedy Method Job Scheduling (Multiprocessor) Job Time j 1 3 j 2 5 j 3 6 j 4 10 j 5 11 j 6 14 j 7 15 j 8 20 j 5 j 8 18 j 9 j 2 0 5 16 34 j 6 j 9 0 14 j 1 0 j 3 3 34 j 4 9 j 7 19 34 Optimal #2 – minimize completion time 40/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer divide : break a given problem into subproblems o recur : try to solve each in recursive way o conquer : derive the final solution from all solutions o 41/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Problem of size n Subproblem 1 of size n/m Solution to Subproblem 1 Subproblem 2 of size n/m Solution to Subproblem 2 … Subproblem m of size n/m Solution to Subproblem m Solution to the original problem 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 42/93
Divide and Conquer Merge sort o Quick sort o Binary Tree Traversal o Closest-Pair and Convex -Hall o Selection problem o 43/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Factorial o Fibonacci o Binary search o Strassen’s Matrix Multiplication o Big Integer Multiplication o 44/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Factorial o o o ตวอยาง n! = n * (n-1)! 4! = ? (n-1)! = (n-1) * (n-2)!4! = 4 * 3! … 3! = 3 * 2! 1! = 1 2! = 2 * 1! 0! = 1 1! = 1 * 0! 0! = 1 Describe with Tree structure 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 45/93
Divide and Conquer Fibonacci num. : 1, 1, 2, 3, 5, 8, 13, … o fibo (n) = fibo (n-1) + fibo (n-2) o fibo (n-1) = fibo (n-2) + fibo (n 3) o fibo (n-2) = fibo (n-3) + fibo (n 4) o… o fibo (3) = fibo (2) + fibo (1) 46/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Binary search Search = 37 12 15 18 23 26 37 39 41 43 48 mid 12 15 18 23 26 37 39 41 mid 47/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Strassen’s Matrix Multiplication x o Z = X J Y ; matrix. E n F n * I A B = x o K L C D G H o I = A x. E + B x. G , J = A x. F + B x. H o K = C x. E + D x. G , L = C x. F + D x. H 48/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Big Integer Multiplication o multiply 2 N-digit numbers : X , Y o XY = XLYL 10 N + (XLYR + XRYL)10 N/2 + XRYR o XLYR+XRYL = (XL-XR)(YR-YL) + XLYL + XRYR o require : 2 subtraction , 3 multiplication o D 1 = XL-XR , D 2 = YR-YL o X LY L , X RY R , D 1 D 2 o D 3 = D 1 D 2 + X LY L + X RY R 49/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Divide and Conquer Big Integer Multiplication o X = 61, 438, 521 & Y = 94, 736, 407 o XL = 6143 , XR = 8521 o YL = 9473 , YR = 6407 o D 1 = XL-XR = -2378, D 2 = YR-YL = -3066 o XLYL = 58192639 , XRYR = 54594047 o D 1 D 2 = 7290948 o D 3 = D 1 D 2 + XLYL + XRYR = 120077634 o XY = XLYL 108 + D 3104 + XRYR 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 50/93
Motto Today ในการอยรวมกนกบผ อน ควร มองโลกในแงด และ คดในทาง สรางสรร มนำใจ เอาใจเขามาใสใจเรา 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 5
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. o it can be exploited either top down (recursively) or bottom up (without a recursion). o 52/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease and Conquer 3 major variations : o decrease-by-a-constant- factor o variable-size-decrease From Anany 53/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease and Conquer o decrease-by-a-constant o the size of instance is reduced by the same constant on each iteration o decrease-by-a-constant-factor o the size of instance is reduced by the same constant factor on each iteration 54/93
Decrease-by-a-constant o Insertion sort o Depth-First search and Breadth- First search (graph) o Topological sorting (graph) o Generating Combinatorial Objects 55/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease-by-a-constant Insertion sort o use the decrease-by-one o sorted-side unsorted-side o the size of unsorted data is reduced by 1 on each loop 56/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Insertion Sort 43 22 22 17 17 16 16 22 43 43 22 22 17 17 80 80 80 43 36 22 22 17 17 17 80 43 36 29 36 36 80 43 36 16 16 16 80 43 29 29 29 80 57/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease-by-a-constant-factor o Jasephus Problem o Fake-Coin problem o Multiplication à la Russe 58/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease-by-a-constant-factor Josephus problem o to determine the survivor by eliminating every second person (stand in circle) until only one survivor is left o e. g. J(6) = 5 , J(7) = 7 , J(9) = 3 o use the decrease-by-half (=2) 59/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Josephus problem use the decrease-by-half (=2) o can consider J(n) o if n is even (n=2 k) , J(2 k) = 2 J(k) -1 o if n is odd (n=2 k+1) , o J(2 k+1) = 2 J(k) +1 o o J(6) = 2 J(3) -1 , J(3) = 2 J(1) + 1 , o J(1) = 1 J(3) = 3 J(6) = 5 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 60/93
Josephus problem use the decrease-by-half (=2) can be obtained by rotate left 1 bit o o J(6) = J(1102) 1012 = 5 o J(7) = J(1112) 1112 = 7 J(9) = J(10012) 00112 = 3 o 61/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Josephus problem use the decrease-by-3 (=3) o eliminate every 3 person o J(6) = 1 o J(7) = 4 o J(9) = 1 62/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease and Conquer 3 major variations : o decrease-by-a-constant-factor o variable-size-decrease o a size reduction pattern varies from one iteration to another 63/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Variable-size-decrease o Euclid algor. o Computing a median and the selection problem o Interpolation search o Binary search tree 64/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Decrease and Conquer Euclidean algor. : o finding gcd(a, b) recursively gcd(a, b) = , otherwise e. g. gcd(124, 40) a , if b=0 b , if a=0 gcd (b, a%b) = gcd(40, 4) =4 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 65/91
Transform and Conquer Problem’s instance Simpler instance Change representation Change to Another problem instance solution 66/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Transform and Conquer o Horner’s Rule o Presorting o Gaussian Elimination o Balanced Search tree o Heap sort (tree) 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 67/93
Transform and Conquer Horner’s rules o p(x) = anxn + an-1 xn-1 + … + a 1 x 1 + a 0 ouse the representation change technique p(x) ax )x + (…(an n-1 +…)x = + a 4 – x 3 + 3 x 2 + x o e. g. p(x) = 2 x 68/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Transform and Conquer Problem Reduction reduce the problem to another problem that solving algor. is known o Problem 1 Problem 2 Solution o Problem : counting paths in a graph , linear o 69/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Transform and Conquer o the Least Common Multiple (lcm) lcm(24, 60) = 2 2 3 2 5 = 120 o 24 = 2 2 2 3 o 60 = 2 2 3 5 o lcm(11, 5) = 55 o 70/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Transform and Conquer o the Least Common Multiple (lcm) o lcm (m, n) = lcm(24, 60) = gcd(24, 60) = 12 o 120 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 71/93
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 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 72/93
Dynamic Programming o Binomial Coefficient o Warshall’s & Floyd’s Directed Graph o Optimal Binary Search tree Tree o Ordering Matrix Multiplication or Matrix Chain-Product (ABCD 73/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Dynamic Programming o. Solving each of smaller subproblems only once and recording the results in a table from which can obtain a solution to the original problem o Using a table instead of recursion 74/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Dynamic Programming 0 -1 Knapsack problem o 0 -1 : reject or accept o given n items of weights w 1 , w 2 , …, wn and values v 1 , v 2 , …, vn and a knapsack of capacity W o find the best solution that gives maximum weight and 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 75/93
0 -1 Knapsack problem o use table to fill in by applying formulas >w B [k, w] = B[k-1, w] , if wk max{B[k-1, w], B[k 1, w-wk]+bk}, else o e. g. let W = 5 and data : (item, weight, value) 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 76/93
0 -1 Knapsack problem capacity j (W=5) weight, value w 1=2, v 1=12 w 2=1, v 2=10 w 3=3, v 3=20 w 4=2, v 4=15 i 1 1 0 2 10 3 10 4 10 2 12 15 3 4 12 12 22 22 22 30 25 30 5 12 22 32 37 Select 1, 2, 4 77/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Dynamic Programming Ordering Matrix Multiplication or Chain-Product Matrix o find the best solution that gives minimum times of multiplication o e. g. ABCD , A(BC)D , 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 78/93
No ego Help each other then Everyone will succeed 79/91
Randomized Algorithms o a random number is used to make a decision in some situation o e. g. giving a quiz by using a coin o a good randomized algor. has no bad inputs and no relative to 80/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Randomized Algorithms Random Number Generator randomness is impossible to do on computer since numbers , called pseudorandom numbers, will depend on the algorithm e. g. linear congruential 81/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Randomized Algorithms Skip Lists (in searching & insertion) o e. g. use random number generator to determine which node to be traversed within the expected time Primality Testing o e. g. to determine a large N-digit number is prime or not by 82/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Backtracking Algorithms othere are many possibilities to try, if not succeed then step back to try another way othe elimination of a large group of possibilities in one step is known as pruning oe. g. arranging furniture in a new 83/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Backtracking Algorithms o n-Queens o Hamiltonian Circuit o Subset-Sum o Goal Seeking Turnpike o Reconstruction 84/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Backtracking Algorithms o Games : chess n-Queens checker Tic-Tac-Toe o Minimax strategy 85/93 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
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. 86/91
Practice Problems Knapsack problem Greedy o Bin packing o Task scheduling o Strassen’s matrix Divide &conquer multiplication o Big Integer multiplication Decrease&conquer o Josephus problem o an o 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 87/91
Practice Problems o o o Non-recursive : programming Dynamic an, fibonacci Recursive exponentiation : n , Horner’s Rule transform a LCM & GCD – Euclid Algor. 0 -1 Knapsack Problem 88/91 344 -211 Algorithmic Process and Programming , created by Dararat Saelee
Motto Today ทำเดยวน คอหนทางสความสำ คดแตไมทำ เทากบไมไดคด 344 -211 Algorithmic Process and Programming , created by Dararat Saelee 89
Class Exercises Fractional Knapsack : W= 5 หนงสอ 4 เลม ม b 1=10 และ w 1=0. 5 ขนม 3 กลอง ม b 2=5 และ w 2=0. 4 นำ 2 ขวด ม b 3=7 และ w 3=0. 5 โนตบค 1 เครอง ม b 4=15 และ w 4=1. 8 Bin Packing : 0. 25 , 0. 5 , 1. 0 , 0. 75 , 0. 125 , 90/93
Class Exercises Task Scheduling : act# start finish a 1 1 4 , a 2 2 5 , a 3 1 5 , a 4 5 8 a 5 4 6 , a 6 6 10 , a 7 7 9 Big Integer Multiplication X = 4, 123, 450, 732 Y = 8, 159, 324, 570 an 1321 (decrease-by-2) Josephus Problem : J(82) decreaseby-3 91/93
Class Exercises Euclidean : gcd (2039, 113) , gcd (1548, 204) Horner’s Rule : p(x) = 7 x 9 + 4 x 6 - 3 x 5 - x 4 + 5 x 2 + 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) 92/93
4deaf52e1ef169e2673d67b04d4d9ed4.ppt