11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 17.3 Impossible Problems 555algorithm m<strong>at</strong>ch the lower bound for the problem with certainty, it is nearly asgood. Once we realize th<strong>at</strong> a problem is N P-complete, then we know th<strong>at</strong> our nextstep must either be to redefine the problem to make it easier, or else use one of the“coping” str<strong>at</strong>egies discussed in this section.17.3 Impossible ProblemsEven the best programmer sometimes writes a program th<strong>at</strong> goes into an infiniteloop. Of course, when you run a program th<strong>at</strong> has not stopped, you do not knowfor sure if it is just a slow program or a program in an infinite loop. After “enoughtime,” you shut it down. Wouldn’t it be gre<strong>at</strong> if your compiler could look <strong>at</strong> yourprogram <strong>and</strong> tell you before you run it th<strong>at</strong> it will get into an infinite loop? To bemore specific, given a program <strong>and</strong> a particular input, it would be useful to know ifexecuting the program on th<strong>at</strong> input will result in an infinite loop without actuallyrunning the program.Unfortun<strong>at</strong>ely, the Halting Problem, as this is called, cannot be solved. Therewill never be a computer program th<strong>at</strong> can positively determine, for an arbitraryprogram P, if P will halt for all input. Nor will there even be a computer programth<strong>at</strong> can positively determine if arbitrary program P will halt for a specified input I.How can this be? Programmers look <strong>at</strong> programs regularly to determine if they willhalt. Surely this can be autom<strong>at</strong>ed. As a warning to those who believe any programcan be analyzed in this way, carefully examine the following code fragment beforereading on.while (n > 1)if (ODD(n))n = 3 * n + 1;elsen = n / 2;This is a famous piece of code. The sequence of values th<strong>at</strong> is assigned to nby this code is sometimes called the Coll<strong>at</strong>z sequence for input value n. Doesthis code fragment halt for all values of n? Nobody knows the answer. Everyinput th<strong>at</strong> has been tried halts. But does it always halt? Note th<strong>at</strong> for this codefragment, because we do not know if it halts, we also do not know an upper boundfor its running time. As for the lower bound, we can easily show Ω(log n) (seeExercise 3.14).Personally, I have faith th<strong>at</strong> someday some smart person will completely analyzethe Coll<strong>at</strong>z function, proving once <strong>and</strong> for all th<strong>at</strong> the code fragment halts forall values of n. Doing so may well give us techniques th<strong>at</strong> advance our ability todo algorithm analysis in general. Unfortun<strong>at</strong>ely, proofs from computability — thebranch of computer science th<strong>at</strong> studies wh<strong>at</strong> is impossible to do with a computer— compel us to believe th<strong>at</strong> there will always be another bit of program code th<strong>at</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!