Neat Ideas in Computer Science Ooi Wei Tsang School of Computing - - PowerPoint PPT Presentation

neat ideas in computer science
SMART_READER_LITE
LIVE PREVIEW

Neat Ideas in Computer Science Ooi Wei Tsang School of Computing - - PowerPoint PPT Presentation

Neat Ideas in Computer Science Ooi Wei Tsang School of Computing 1 DISCLAIMER a personal view of whats neat not comprehensive not rigorous 2 some problems cant be solved by a computer some problems can be solved easily in one way


slide-1
SLIDE 1

Neat Ideas in Computer Science

Ooi Wei Tsang School of Computing

1

slide-2
SLIDE 2

a personal view of what’s neat not rigorous not comprehensive DISCLAIMER

2

slide-3
SLIDE 3

some problems can’t be solved by a computer some problems can be solved easily in one way but difficult in the reverse direction some problems can be solved randomly (but still gives right solution most of the time)

3

slide-4
SLIDE 4

Is it possible to pose an Algo*Mania contest problem that is impossible to solve?

4

slide-5
SLIDE 5

Given a program P with input I, will the program halt?

HALT?

P I

YES: P(I) eventually halt NO: P(I) loops forever

5

slide-6
SLIDE 6

Write another program X(P) { while (HALT(P, P)) { // loop forever if P halts } } What is the output of HALT(X,X)?

6

slide-7
SLIDE 7

X(P) { while (HALT(P, P)) { // loop forever if P(P) halts } }

Suppose HALT(X,X) is YES (that is HALT tells us X(X) will halt) Then the while loop will loop forever, meaning X(X) will not halt!

7

slide-8
SLIDE 8

X(P) { while (HALT(P, P)) { // loop forever if P(P) halts } }

HALT(X,X) must be false! (that is, HALT says X(X) will loop forever) But if HALT(X,X) is false, the while loop won’t execute and X(X) will exit.

8

slide-9
SLIDE 9

Halting Problem First problem shown to be non-computable

9

slide-10
SLIDE 10

Why is this neat?

10

slide-11
SLIDE 11

Computer can’t program better than human!

11

slide-12
SLIDE 12

Given two programs P1 and P2, are they equivalent?

12

slide-13
SLIDE 13

Is a given program buggy?

13

slide-14
SLIDE 14

Given a program P ,

  • utput optimized version of P

14

slide-15
SLIDE 15

Computer can’t replace mathematician

15

slide-16
SLIDE 16

Fermat’s Last Theorem

xn + yn = zn has no non-zero integer solution for n > 2

16

slide-17
SLIDE 17

Fermat() { for all possible non-zero integer values

  • f x, y, z, and n > 2 do

if xn + yn = zn // found a solution return true } HALT(Fermat, nil) would proved Fermat’s Last Theorem by returning NO

17

slide-18
SLIDE 18

Other Non-computable Problems Given a set of substitution rules, and two strings s and t, can we transform s to t by applying the set of rules?

18

slide-19
SLIDE 19

P and NP Not all problems has known efficient solutions

19

slide-20
SLIDE 20

some problems are known to have efficient solutions e.g. shortest path on a graph

20

slide-21
SLIDE 21

some problems have no known efficient solutions e.g. longest path on a graph

21

slide-22
SLIDE 22

No one knows if integer factoring can be done efficiently

22

slide-23
SLIDE 23

2799783391122132787082946763872260162107 0446786955428537560009929326128400107609 3456710529553608560618223519109513657886 3710595448200657677509858055761357909873 4950144178863178946295187237869221823983

Factor the following 200-digit integer:

23

slide-24
SLIDE 24

27997833911221327870829467638722601621070446786955 42853756000992932612840010760934567105295536085606 18223519109513657886371059544820065767750985805576 13579098734950144178863178946295187237869221823983

=

35324619344027701212726049781984643686711974001976 25023649303468776121253679423200058547956528088349

x

79258699544783330333470858414800596877379758573642 19960734330341455767872818152135381409304740185467

Christmas 2003 - May 2005 Equivalent of 55 years of CPU time on a 2.2 GHz CPU

24

slide-25
SLIDE 25

Some problems are easy to compute one way, but computing the reverse is difficult (unless you know a secret)

A x B = C given A and B, find C is easy given C, find A and B is hard

25

slide-26
SLIDE 26

Why is this neat?

26

slide-27
SLIDE 27

Easy: encrypt a message Hard: decrypt the message (unless know the secret) Public Key Cryptography

27

slide-28
SLIDE 28

publish C (product of two large primes A and B) encrypt message using C can only decrypt the message if we know A and B Public Key Cryptography

28

slide-29
SLIDE 29

Sender and receiver no longer have to agree on a common key before communication!

29

slide-30
SLIDE 30

A hash function transforms input into a fixed length string. hash(input) = k e.g., MD5(“Algo*Mania”) =

2e8f46a660fb57201b93ed9c1cf86d08

30

slide-31
SLIDE 31

hash(input) = k good hash function: slight change in input gives totally different k e.g., MD5(“Algo*Mania”) =

2e8f46a660fb57201b93ed9c1cf86d08 MD5(“algo*mania”) = 92ae377f2f5cccf585eb84ccd7c8156c

31

slide-32
SLIDE 32

hash(input) = k good hash function: given k, hard to guess input e.g., MD5( ? ) =

2e8f46a660fb572012343ed9c1cf86d08

32

slide-33
SLIDE 33

build data structures (hash tables) store passwords verify file integrity use as fingerprint to identify files

33

slide-34
SLIDE 34

Authenticated Messages with common secret Sender: h = hash(msg + secret) send msg and h Receiver: compute h’ = hash(msg’ + secret) if h’ = h then very likely msg = msg’

34

slide-35
SLIDE 35

Mitigate Spam Sender must spend some effort to show it’s sincerity before receiver accepts the email.

35

slide-36
SLIDE 36

Sender must find a number X such that first k bits of hash(X + time + receipient email) are zeros. include X in the email

X-Hashcash: 1:20:060408:adam@cypherspace.org::1QTjaYd7niiQA/sc:ePa

36

slide-37
SLIDE 37

Receiver verifies that the first k bits of the hash are all zeros

37

slide-38
SLIDE 38

Other one way function can be used. Recipient can also issue a challenge (e.g. factor this!) to sender

38

slide-39
SLIDE 39

Integer factoring is especially hard if the number is a product of two very large primes.

39

slide-40
SLIDE 40

How to test if a number is prime?

40

slide-41
SLIDE 41

IsPrime? (n) { for (k = 2 to n-1) { if n is divisible by k then return not a prime } return it’s a prime }

41

slide-42
SLIDE 42

Sieve of Eratosthenes (Animation from Wikipedia)

42

slide-43
SLIDE 43

35324619344027701212726049781984643686711974001976 25023649303468776121253679423200058547956528088349

is prime?

43

slide-44
SLIDE 44

I can be 99.9999% sure this number is a prime by looping only 20 times.

44

slide-45
SLIDE 45

Fermat showed that if n is prime then

an-1 = 1 mod n

for all values of a in [1 .. n-1]

45

slide-46
SLIDE 46

but if n is not prime then

an-1 = 1 mod n

for at most half the values of a in [1 .. n-1]

46

slide-47
SLIDE 47

IsPrime? (n) { repeat k times randomly pick a from between 1 and n-1 if an-1 != 1 mod n then return not a prime return it’s a prime // with prob >= 1 - 1/2k }

A Probabilistic Algorithm

47

slide-48
SLIDE 48

3532461934402770121272604 9781984643686711974001976 2502364930346877612125367 9423200058547956528088349

I can tell if is a prime with a probability 0.999999 by looping 20 times instead of 10100 times

48

slide-49
SLIDE 49

NOTE: The above discussion ignores the existance

  • f Carmichael numbers, which are odd composites

that satisfies Fermat’s little theorem.

49

slide-50
SLIDE 50

some problems can’t be solved by a computer some problems can be solved easily in one way but difficult in the reverse direction some problems can be solved randomly (but still gives right solution most of the time)

50

slide-51
SLIDE 51

The End

51