Halting Problem and TSP - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Halting Problem and TSP

Description:

Definition. Design a program, H, that will do the following: ... A salesperson has a group of cities that he/she needs to visit. ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 28
Provided by: pcut
Category:

less

Transcript and Presenter's Notes

Title: Halting Problem and TSP


1
Halting Problem and TSP
  • Wednesday, Week 8

2
Background - Halting Problem
  • Common error Program goes into an infinite
    loop.
  • Wouldnt it be nice to have a tool that would
    warn us that our program has this bug?
  • (We could make a lot of money if we could develop
    such a tool!)

3
Example
  • Infinite loop - we get into a loop but for some
    reason we never get out of it.
  • for (i 0 i lt 10 i--)
  • document.writeln(Help, Im in an infinite
    loop!ltBRgt)

4
Example Output
  • Help, Im in an infinite loop!
  • Help, Im in an infinite loop!
  • Help, Im in an infinite loop!
  • Help, Im in an infinite loop!
  • Help, Im in an infinite loop!
  • Help, Im in an infinite loop!

5
Definition
  • Design a program, H, that will do the following
  • Take as its input a description of a program P
    (in binary, say).
  • Halt eventually and answer "yes" if P will
    eventually halt, or halt and answer "no" if P
    will run forever.

6
Halting Problem
  • In other words,
  • Program H will always halt and give the correct
    answer no matter what program has been given as
    input.

H
program
Halts? Yes or No
7
Proving the Halting Problem
  • We want to prove that the halting problem is
    non-computable.
  • In other words, there is no algorithm that we can
    use to tell whether or not a program will halt.
  • We will use proof by contradiction.

8
Proof by Contradiction
  • Prove if xy gt 2, then xgt1 or ygt1.
  • Assume that xygt2 and that xlt1 and ylt1.
  • Then, xy lt 11 2.
  • This is a contradiction since xy gt2!
  • Thus our assumption that xlt1 and ylt1 is false.
  • Note NOT(xgt1 or ygt1) (xlt1 and ylt1) by
    DeMorgans Laws.

9
Proof by Contradiction
  • Well assume that the Halting Problem CAN be
    computed.
  • Well develop another program that uses the
    Halting Problem function.
  • Well find ourselves caught in a paradox (the
    contradiction).
  • Well have proven that our original assumption is
    false.

10
Assume Halting Problem OK
  • Let H be a program (or sub-program) that
    determines whether a program will halt.

H
program
Halts? Yes or No
11
Lets Build Another Program
  • Let P be a program that uses H.
  • For any given program, P will call H and pass it
    the given program.


P
H
program
program
12
What does P do?
  • Now, P acts as follows
  • P takes a program as input and feeds the program
    to H as input.
  • If H answer yes, then P will enter an infinite
    loop and run forever.
  • If H answer no, then P will stop.

13
What does P do?
P

P loops
H
Yes
program
program
No
P halts
14
The program P
  • function P (program)
  • var halts H(program)
  • if (halts True)
  • infinite loop
  • else
  • stop

15
What Can We Do With P?
  • Lets give P a copy of itself as its input.

P
P loops
H
Yes
P
P
program
No
P halts
16
What If P Halts?

P
P loops
H
Yes
P
P
program
No
P halts
17
What If P Loops Indefinitely?

P
P loops
H
Yes
P
P
program
No
P halts
18
The Paradox
  • If P is a program that halts when given itself as
    its input,
  • then, when given itself as input,
  • P will go into an infinite loop.
  • If P is a program that loops indefinitely when
    given itself as its input,
  • then , when given itself as input,
  • P will halt immediately.

19
What Went Wrong?
  • Theres nothing wrong with P, itself.
  • The problem must be with the assumption that we
    could write H.

20
So, Proof by Contradiction
  • We assumed that the Halting Problem COULD be
    computed.
  • We developed another program that used the
    Halting Problem function.
  • We found ourselves caught in a paradox (the
    contradiction).
  • We proved that the Halting Problem is not
    computable.

21
Conclusions
  • Self-referentiality is a real problem with
    programs
  • Rices theorem says that Any nontrivial property
    of programs is undecidable.
  • Thus, we cant write programs to answer questions
    about programs.

22
Intractability
  • The Traveling Salesperson Problem is intractable.
  • Proving it is beyond the scope of this class.
  • We will just understand the problem and how hard
    it is.

23
Traveling Sales Problem
  • A salesperson has a group of cities that he/she
    needs to visit.
  • There are a bunch of distances between the
    cities.
  • Our salesperson has to visit all the cities by
    following a path with the least distance (or
    cost).

24
TSP Example 1

25
TSP Answer 1

26
TSP Example 2

27
TSP Answer 2

28
Traveling Sales Problem
  • Conclusions
  • The only correct algorithm we could come up with
    had to examine all possible paths.
  • The only correct algorithm that anyone has come
    up with has to examine all possible paths.
  • Thus this algorithm is O(n!) and intractable.
Write a Comment
User Comments (0)
About PowerShow.com