DOC PREVIEW
Duke CPS 100E - chapter 12

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CPS 10012.1What is Computer Science?What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex.C.A.R (Tony) HoareCPS 10012.2What can be programmed?● What class of problems can be solved?➤ G4, 1000Mhz Pentium III, Cray, pencil?➤ Alan Turing proved some things, hypothesized others• Halting problem, Church-Turing thesis● What class of problems can be solved efficiently?➤ Problems with no practical solution• What does practical mean?➤ Problems for which we can’t find a practical solution• Solving one solves them all• Would you rather be rich or famous?CPS 10012.3Schedule students, minimize conflicts● Given student requests, available teachers➤ write a program that schedules classes➤ Minimize conflicts● Add a GUI too➤ Web interface➤ …➤ …I can’t write this program because I’m too dumbCPS 10012.4One better scenarioI can’t write this program because it’s provably impossibleCPS 10012.5Another possible scenarioI can’t write this program but neither can all these famous peopleCPS 10012.6Graph coloring (see colorable.cpp)● Can vertices of a graph be colored so that no two adjacent vertices share the same color?➤ What is minimum # colors➤ Can graph be k-colored?● Two problems, second is called a decision problem, first is an optimization problem● Can a graph be 2-colored?➤ Depth first search, mark vertex with a color and …● Can a graph be k-colored?➤ Backtrack searchCPS 10012.7Graph coloring continued● Two-color problem solving using depth-first search, see code in colorable.cpp that uses stack➤ Every reachable vertex put on stack,➤ Every edge processed once➤ Complexity is O(…..)● K-colorable problem tries each of k-colors➤ For each color, use it on a vertex and then visit all adjacent vertices that aren’t colored yet➤ Backtrack to undo colorings if they don’t work out before trying next color➤ Recurrence is at best: T(n) = k T(n-1) + O(1)➤ What was solution to Towers of Hanoi problem?CPS 10012.8The halting problem: writing DoesHaltbool DoesHalt(const string& progname,const string& s)// post: returns true if progname halts given s// as input, false otherwiseint main(){string f = PrompString("enter filename ");string s = PromptString("input for "+filename);if (DoesHalt(f,s)) cout << "does halt" << endl;else cout << "does not halt" << endl;}● A compiler is a program that reads other programs as input➤ Can a word counting program count its own words?● The DoesHalt function might simulate, analyze, …➤ One program/function that works for any program/inputCPS 10012.9Consider the program confuse.cpp#include "halt.h"int main(){string f = PrompString("enter filename ");if (DoesHalt(f,f)) {while (true){ // do nothing forever}} return 0;}● We want to show writing DoesHalt is impossible➤ Proof by contradiction:➤ Assume possible, show impossible situation resultsCPS 10012.10Not impossible, but impractical● Towers of Hanoi➤ How long to move n disks?● What combination of switches turns the light on?➤ Try all combinations, how many are there?➤ Is there a better way?CPS 10012.11Travelling Salesperson● Visit every city exactly once● Minimize cost of travel or distance● Is there a tour for under $2,000 ? less than 6,000 miles?● Is close good enough?➤ Consider spanning treeTry all paths, fromevery starting point --how long does this take?a, b, c, d, e, f, gb, a, c, d, e, f, g ...CPS 10012.12Complexity Classifications● This route hits all cities for less than $2,000 --- verifyproperties of route efficiently.● Hard to find optimal solutionPack trucks with barrels,use minimal # trucksIdeas?Problems are the “same hardness”: solve one efficiently, solve them allCPS 10012.13Are hard problems easy?● P = easy problems, NP = “hard” problems➤ P means solvable in polynomial time• Difference between N, N2, N10?➤ NP means non-deterministic, polynomial time• guess a solution and verify it efficiently● Question: P = NP ?➤ if yes, a whole class of difficult problems can be solved efficiently---one problem is reducible to another➤ if no, none of the hard problems can be solved efficiently➤ showing the first problem was NP complete was an exercise in intellectual bootstrapping, satisfiability/Cook/(1971)➤An NP complete problem is in NP (guessable/verify) and is the same “difficulty” as every other problem in NPCPS 10012.14Theory and Practice● Number theory: pure mathematics➤ How many prime numbers are there?➤ How do we factor?➤ How do we determine primeness?● Computer Science➤ Primality is “easy”➤ Factoring is “hard”➤ Encryption is possibletop secretpublic-key cryptographyrandomized primalitytestingCPS 10012.15Shafi Goldwasser● RCS professor of computer science at MIT➤ Co-inventor of zero-knowledge proof protocolsHow do you convince someone that you know something without revealing “something”● Consider card readers for dorms➤ Access without trackingWork on what you like, what feels right, I now of no other way to end up doing creative workCPS 10012.16Why is programming fun?What delights may its practitioner expect as a reward?First is the sheer joy of making thingsSecond is the pleasure of making things that are useful Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts Fourth is the joy of always learningFinally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from pure thought-stuff.Fred BrooksCPS 10012.17What is computer science?● What is a computation? ➤ Can formulate this precisely using mathematics➤ Can say “anything a computer can compute”➤ Study both theoretical and empirical formulations, build machines as well as theoretical models● How do we build machines and the software that runs them?➤ Hardware: gates, circuits, chips, cache, memory, disk, …➤ Software: operating systems, applications, programs● Art, Science, Engineering➤ How do we get better at programming and dealing with abstractions➤ What is hard


View Full Document

Duke CPS 100E - chapter 12

Documents in this Course
Topics

Topics

9 pages

Lecture

Lecture

3 pages

Notes

Notes

2 pages

Hashing

Hashing

19 pages

Lecture

Lecture

59 pages

Lecture

Lecture

6 pages

Lecture

Lecture

4 pages

Lecture

Lecture

20 pages

Lecture

Lecture

12 pages

Lecture

Lecture

12 pages

Lecture

Lecture

7 pages

Lecture

Lecture

8 pages

Lecture

Lecture

10 pages

Lecture

Lecture

4 pages

Notes

Notes

16 pages

Lecture

Lecture

5 pages

Lecture

Lecture

9 pages

Lecture

Lecture

4 pages

Lecture

Lecture

13 pages

Lecture

Lecture

6 pages

Lecture

Lecture

16 pages

Lecture

Lecture

5 pages

Lecture

Lecture

5 pages

Lecture

Lecture

12 pages

Lecture

Lecture

12 pages

Lecture

Lecture

10 pages

Sets

Sets

14 pages

Lecture

Lecture

9 pages

Lecture

Lecture

4 pages

Test 1

Test 1

7 pages

Load more
Download chapter 12
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view chapter 12 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view chapter 12 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?