1 / 13

Abstract

Abstract. Informatics is concerned with such topics as the theory and properties of algorithms ,methods for the design and analysis of algorithms, programming and other languages for describing algorithms and so on .

pearlm
Download Presentation

Abstract

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Abstract Informatics is concerned with such topics as the theory and properties of algorithms ,methods for the design and analysis of algorithms, programming and other languages for describing algorithms and so on. We now study these description schemes in more detail and also introduce several important analysis issues.

  2. Euclid live in the city of Euclid is the most famous ancient Greek mathematician. With regard to the life we knows very little. About early schooling in Athens, and well aware of Plato's theory. Euclid’s algorithm ( Greatest Common Divisor) Euclid

  3. Theorem 1.1 Given positive integers m and n ,there exist unique integers q and r such that q ≥0,0≤r<n, and m = q ×n+r Theorem 1.2 Given positive integers m and n and the unique integers q and r such that q ≥0,0≤r<n ,and m = q × n + r ,then (1) if r = 0,then gcd ( m ,n) = n ,and (2) if r≠0,then gcd (m ,n)=gcd (n ,r). ‘Greatest common divisor’ is based on the following two theorems.

  4. Describe Euclid’s algorithm in mathematics. • For example ,let m = 20 and n = 8,then m = 2 × 8+4.therefore gcd(20,8) = gcd(8,4). • r0=m – q0 × n (0 ≤q0,0 <r0 <n) • r1 = n – q1 × r0 (0 ≤q1,0 <r1 <r0) • r2 = r0 – q2 × r1 (0 ≤q2,0 <r2 <r1) • ………… • ri = ri-2 – qi × ri-1 (0 ≤qi,0 <ri <ri-1)

  5. Not an entirely evident translation of the mathematics • 1. Divide m by n ,and obtain the remainder r. • 2.if r = 0,then halt. The answer is n. • 3. Replace m by n (m ←n) and n by r (n ← r). • 4.Go to step 1.

  6. Flowchart –Euclid’s Algorithm shows instructions in flow chart form Mod : take the remainder on dividing m by n

  7. Another flow chart which is Correctness of Euclid’s Algorithm For example M=20 and N=8,yields the command execution sequence : {A0} C0 {A1} C1 {A2} C2 {A3} C3 {A5} C4 {A6} C1 {A2} C2 {A3} C3 {A4}

  8. One Algolic program that directly follows the preceding descriptions for Euclid’s algorithm • 0 algorithm GCD0; • 1 m , n , r : integer • 2 begin • 3 read ( m , n); • 4 write(‘ m =‘, m ,’n =‘,n); • 5 l: r: = m mod n; • 6 if r≠0 thenbegin • 7 m: = n ; n : = r; • 8 go to l • 9 end; • 10 write(‘ The gcd is ’,n) • 11 end.

  9. Another way to express the same algorithm as a program in a given language • 0 algorithm GCD1; • 1 m , n , r : integer; • 2 begin • 3 read ( m , n ) ; write (‘ m ’ , m , ’ n= ’,n); • 4 while n≠0 dobegin { Perform loop as long as n ≠0.} • 5 r: = m mod n; • 6 m: = n ; n: = r • 7 end ; { gcd is in m.} • 8 write ( ‘The gcd is ’,m) • 9 end.

  10. A description that closely resembles the original mathematical basis of the algorithm • 0 functiongcd ( m , n : integer ) : integer; • 1 gcd:=if n = 0 then m • 2 elsegcd ( n , m mod n); • Recursive : invoke themselves.

  11. Another way to solve the same problem • 1. Set g equal to n ( g ←n). • 2. If g divides m and n , then halt. G is the gcd. • 3. Decrement g by 1 (g ←g-1). • 4. Go to step 2.

  12. Euclid’s algorithm is better than SimpleGCD • 0 algorithm SimpleGCD; • 1 …… • 2 g:=n; • 3 l: ifnot (m mod g = 0) and (n mod g=0) then begin • 4 {g is not a divisor of both m and n.} • 5 g:=g-1; • 6 goto l • 7 end; • 8 {g is the gcd.} • 9 …. • 10 end • Efficient ( in time ) : SimpleGCD tests every integer between n and the gcd ( m , n ),but Euclid’s algorithm use the remainder. • Complicated : SimpleGCD requiring two divisions ( m mod g and n mod g )for each candidate. And For example , gcd(20,8) is obtained in two passes through the loop with Euclid’s algorithm ,and five passes using SimpleGCD .

  13. Thank you.

More Related