Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 10 - Friday CS 113.

Similar presentations


Presentation on theme: "Week 10 - Friday CS 113."— Presentation transcript:

1 Week 10 - Friday CS 113

2 Last time What did we talk about last time? Turing machines
Halting problem Started review

3 Questions?

4 Project 3

5 Review

6 Lists in Python

7 Strings Strings hold text
They are lists of characters (letters, digits, punctuation, etc.) A string literal in Python is text with either single or double quotes around it It doesn't matter which you use, but you can't mix them in one string line = "Stop, collaborate, and listen!" countdown = 'Launching in 5, 4, 3, 2, 1... Blast off!'

8 String operations You can use + to concatenate two strings together (to get a third string that is both of them stuck together) You can use * to get repetitions of a string place = "boon" + "docks" print(place) #prints boondocks comment = "yeah " * 3 print(comment) #prints yeah yeah yeah

9 String operations continued
You can use the len() function to get the length of a string You can use square brackets to get a particular character in the string Indexes start at 0 The first character in a string is at 0, the last is at its length - 1 author = "Thomas Pynchon" print( len(author) ) #prints 14 movie = "Dr. Strangelove" print(movie[4]) #prints S

10 Slices If you want to get more than one character from a string, you can use the slice notation Two numbers with a colon (:) in between The first number is the starting point, the second number is the location after the ending point If you subtract the first from the last, you'll get the length of the result adjective = "dysfunctional" noun = adjective[3:6] #noun contains "fun"

11 Lists You can think of a string as a list of characters
Python provides a way to make lists of other things too To make a list, you can put a collection of objects inside square brackets They can even be different types days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] stuff = ["Danger!", 3, True, 1.7]

12 Accessing an element As with strings, use square brackets and a number to access an element in the list Like strings, elements are numbered from 0 to the length – 1 You can use the len() function to get the length of a list days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] bleh = days[0] #contains "Monday" count = len(days) #contains 7

13 Changing elements in a list
You can also change the elements in a list using the square bracket notation This is one of the bigger differences between strings and general lists You cannot change the characters in a string You have to make a new string birds = ["Duck", "Duck", "Duck"] birds[2] = "Goose" print(birds) #prints ['Duck', 'Duck', 'Goose']

14 Slices on lists Just like strings, you can use the slice notation to get a copy of part of a list There are shortcuts too Python assumes 0 if you leave off the first number It assumes the length if you leave off the last number days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] weekend = days[5:7] print(weekend) #prints ['Saturday', 'Sunday'] weekdays = days[:5] #Monday through Friday

15 For loops and lists A for loop can be used to iterate over all the elements in a list Since a string is a special kind of list, you can iterate over the characters in them too days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] for day in days: print( day ) #prints each day on a line word = "HEY" for letter in word: print( letter ) #H E Y on separate lines

16 split() method Sometimes you get a string that contains a lot of words
You'd like to split the string up into a list of those individual words so that you can deal with each Calling the split(" ") method returns just such a list, breaking apart the string wherever there is a space character (" ") sentence = "I seem to be having tremendous difficulty with my lifestyle." words = sentence.split(" ") print(words[5]) #prints tremendous print( len(words) ) #prints 10

17 Simulation For many reasons, we want to simulate the real world inside of a computer Reason Example Predict the future Weather forecasting Too dangerous to do Observe how a disease spreads Too expensive to test Traffic engineering Too hard to measure Processes inside of cells Education A basketball bouncing in Scratch

18 Types of simulation Simulations are generally either stochastic or deterministic Stochastic means that it models a process with random elements Deterministic means that everything should behave the same every time Another way to categorize simulations is discrete or continuous Discrete event simulations view a process as a series of events that happen at points in time Like people getting in line at McDonald's Continuous simulations look at time as continuous Like the moon being pulled by the earth

19 Bioinformatics Bioinformatics is using computer science to analyze biological data A number of important areas within bioinformatics are: Computational genetics and evolutionary biology Literature analysis Network and systems biology Image analysis Molecular interaction and protein structure

20 Artificial intelligence
Artificial intelligence (AI) is hard to define Trying to make machines think? Goals Problem solving Representing knowledge Creating machines that can learn Natural language processing Interpreting and interacting with the physical world and humans Creativity General intelligence is perhaps the combination of all these things Achieving general intelligence is sometimes called strong AI

21 Approaches There are many approaches for generating various aspects of artificial intelligence Simulating the human brain Like with Blue Gene Symbolic approaches Views all intelligence as manipulating symbols Sub-symbolic approaches Became popular in the 1980s Tries to process data without directly manipulating symbols Statistical approaches Combinations

22 i Neural networks Neural networks are a popular sub-symbolic tool
They are composed of simple nodes that take numerical inputs and add them together with different weights By adjusting the weights, you can train a group of nodes to solve a problem There are handwriting recognizers and speech recognizers that use neural networks i

23 Statistical approaches
In the 1990s, statistical approaches became popular For example, you can analyze language statistically and Find rarely used words, are some of them misspelled? Find buzzwords Link different search terms together Know that this phrase in Farsi is almost always translated into that phrase in English Most of Google's success in AI has been statistical Like neural networks, statistical models of how speech (or other intelligent behavior) is formed tend to give us little insight into how intelligence works But they work!

24 Turing test Alice: Are you a human? Bob: What else would I be?
Alan Turing, a great early computer scientist, argued that acting like a human being was proof of intelligence In the Turing test, person A (call her Alice) texts with entity B (call him Bob) Bob could be a computer or a human If a computer can reliably fool Alice into thinking is a human, it is displaying human intelligence Alice: Are you a human? Bob: What else would I be? Alice: Do you like pie? Bob: The value of pi is approximately

25 Chinese Room John Searle proposed an argument against symbolic AI and the Turing test: Imagine a room filled with rules to manipulate symbols A man in the room receives symbols written on paper slipped through a slot in the door He follows the rules, creates new symbols, writes them on paper, and slips them back out the slot The symbols are actually Chinese characters Because the rules are complex enough, the Chinese speaker on the outside believes that she is interacting with someone who understands Chinese Does the man in the room understand Chinese? Do our brains understand English or are they just manipulating symbols?

26 What is a graph? Vertices (Nodes) Edges

27 What can graphs represent?
Friendships on Facebook Steps in a task Nodes: Subtasks Nodes: People Edges: Decisions Edges: Friendship Routes between cities 6 degrees of Kevin Bacon Nodes: Cities Edges: Streets Nodes: Actors Edges: Whether or not they've been in a movie together

28 Lots of flavors of graphs
Labeled Weighted Colored Multigraphs E A D B F C A 5 6 4 3 2 3 E 5 B D F C 7 1

29 No Triangle Inequality
When a weighted graph obeys the triangle inequality, the direct route to a node is always fastest 1 4 2 3 5 No Triangle Inequality 1 2 4 3 5 Triangle Inequality

30 Directed graphs Some graphs have edges with direction
Example: One way streets Reachability? ONE WAY E A D B F C

31 Connected graphs Often we talk about connected graphs
But, not all graphs have to be connected

32 Paths A path is a sequence of connected nodes
The cost or weight of the path is usually the sum of the edge weights This path from A to C costs 5 A 5 6 4 3 2 3 E B D 3 F 7 C

33 Cycles A cycle is a path that starts at a node and comes back to the same node How many cycles of length 3 does this graph have? What about 4? 5? 6? A D B A E B D F C

34 Tours A tour is a path that visits every node and (usually) returns to its starting node In other words, it's a cycle that visits every node This tour costs 24 A 5 6 4 3 2 3 E B D 3 F 7 C

35 Bipartite graphs A bipartite graph is one whose nodes can be divided into two disjoint sets X and Y There can be edges between set X and set Y There are no edges inside set X or set Y A graph is bipartite if and only if it contains no odd cycles

36 Bipartite graph X A B C D E F Y A B C D E F

37 Maximum matching A perfect matching is when every node in set X and every node in set Y is matched It is not always possible to have a perfect matching We can still try to find a maximum matching in which as many nodes are matched up as possible

38 Matching algorithm Come up with a legal, maximal matching
Take an augmenting path that starts at an unmatched node in X and ends at an unmatched node in Y If there is such a path, switch all the edges along the path from being in the matching to being out and vice versa If there is another augmenting path, go back to Step 2

39 X Y Match the graph Anna Becky Caitlin Daisy Erin Fiona A B C D E F A
Adam Ben Carlos Dan Evan Fred

40 Stability Consider two marriages:
Anna and Bob Caitlin and Dan This pair of marriages is unstable if Anna likes Dan more than Bob and Dan likes Anna more than Caitlin or Caitlin likes Bob more than Dan and Bob likes Caitlin more than Anna We want to arrange all n marriages such that none are unstable

41 Gale-Shapley algorithm
n rounds Each round, every unengaged man proposes to the woman he likes best (who he hasn’t proposed to already) An unengaged woman must accept the proposal from the one of her suitors she likes best If a woman is already engaged, she accepts the best suitor only if she likes him better than her fiance

42 Euler path Can you find a path that starts anywhere and crosses each bridge exactly once

43 Graph theoretical view
By simplifying the problem into a graph, the important features are clear To arrive as many times as you leave, the degrees of each node must be even (except for the starting and ending points) Center Island North Shore East South Shore

44 Eulerian Path Algorithm
There is actually an way to find such a path on a graph where one exists: Start with a node of odd degree if there is one Every time we move across an edge, delete it If you have a choice, always pick an edge whose deletion will not disconnect the graph At the end of the algorithm, you will either have an Eulerian path or an Eulerian cycle, depending on the graph

45 Minimum Spanning Tree An airline has to stop running direct flights between some cities But, it still wants to be able to reach all the cities that it can now What’s the set of flights with the lowest total cost that will keep all cities connected? Essentially, what’s the lowest cost tree that keeps the graph connected? This is called the minimum spanning tree (MST) for a graph

46 Prim’s Algorithm Start with two sets, S and V:
S has the starting node in it V has everything else Find the node u in V that is closest to any node in S Put the edge to u into the MST Move u from V to S If V is not empty, go back to Step 2

47 Shortest Paths Let’s think more about weight on edges
Weight can represent time, distance, cost: anything, really The shortest path (lowest total weight) is not always obvious 6 B 5 2 D 8 3 4 C A 16 E

48 What’s the shortest path?
Take a moment and try to find the shortest path from A to E The shortest path has length 14 6 B B A 5 2 D E D C 8 3 4 C A 16 E

49 Dijkstra’s Algorithm Start with two sets, S and V:
S has the starting node in it V has everything else Set the distance to all nodes in V to ∞ Find the node u in V that is closest to a node in S For every neighbor v of u in V If d(v) > d(u) + d(u,v) Set d(v) = d(u) + d(u,v) Move u from V to S If V is not empty, go back to Step 2

50 Finding the shortest distance from A to all other nodes
Example for Dijkstra Node d(u) A B 5 C 7 D 10 E 14 Node d(u) A B 5 C 8 D E 16 Node d(u) A B 5 C 7 D 10 E 16 Node d(u) A B 5 C 7 D 11 E 16 Node d(u) A B 5 C 7 D 10 E 16 Sets S V A, B, C D, E Sets S V A, B C, D, E Sets S V A, B, C, D E Sets S V A B, C, D, E Sets S V A, B, C, D, E Finding the shortest distance from A to all other nodes 6 B 5 2 D 8 3 4 C A 16 E

51 Software development Often goes through phases similar to the following: Understand the problem Plan a solution to the problem Implement the solution in a programming language Test the solution Maintain the solution and do bug fixes Factor of 10 rule!

52 Therac-25 Radiation treatment machine for cancer patients Caused:
Used June Jan 1987 Caused: At least six serious overdoses Several deaths Many permanently maimed Radiation treatment is normally around 200 rads 500 rads can be lethal Therac-25 delivered dosages of over 20,000 rads because of a software error 11 units in US and Canada had treated hundreds of patients over the course of several years Earlier Therac-20 and Therac-6 models had been in service, without incident, for many years

53 Test case selection Positive test cases Boundary condition test cases
Cases that should work, and we can easily check the answer Boundary condition test cases Special cases, like deleting the first or last item in a list Sometimes called "corner cases" Negative test cases Cases that we know should fail

54 Black box testing One philosophy of testing is making black box tests
A black box test takes some input A and knows that the output is supposed to be B It assumes nothing about the internals of the program To write black box tests, you come up with a set of input you think covers lots of cases and you run it and see if it works In the real world, black box testing can easily be done by a team that did not work on the original development

55 White box testing White box testing is the opposite of black box testing Sometimes white box testing is called "clear box testing" In white box testing, you can use your knowledge of how the code works to generate tests Are there lots of if statements? Write tests that go through all possible branches There are white box testing tools that can help you generate tests to exercise all branches Which is better, white box or black box testing?

56 Popular programming languages
Description Typing C/C++ Fast and powerful systems language, prone to nasty bugs Static Java Platform independent OO language, uses virtual machine Objective-C Apple language for writing Mac, iPhone, and iPad apps C# Microsoft language for applications and the web, like Java Python Interpreted language with unusual syntax, easy to read Dynamic Perl Scripting language, good at processing text Ruby Interpreted language, popular for making websites PHP Interpreted, C-like language that runs on web servers JavaScript Interpreted language that runs on web browsers Visual Basic Microsoft language, good at making GUIs SQL Language for talking to databases

57 Compilers We use a program called a compiler to turn a high level language into a low level language Usually, the low level language is machine code Python uses an interpreter instead of a compiler An interpreter runs the program line by line instead of turning it into a machine code file that the OS can run

58 General compilation model
Solve a problem; Computer! Source Code Machine Code Hardware

59 Moore’s Law Observation made by Gordon Moore, co-founder of Intel in a 1965 paper The density of transistors on a CPU doubles every 18 months The period of time has been debated Historically, this has meant that CPU speeds have also doubled every two years We can’t make things much faster because of heat and power We can still put more “stuff” into a CPU

60 Logarithmic scale The growth of computer power has been so fast that we have to describe it using a logarithmic scale In a logarithmic scale, the y units are multiplied by a power (often of ten) instead of linearly increasing Linear Scale Logarithmic Scale

61 Silicon feature size Even though Moore's Law has affected speed, it's really talking about the size of transistors Transistors are the fundamental building blocks of computer chips The smaller they get, the more you can pack into a small space

62 Pipelining Clock rate is misleading because some processors take fewer clock cycles to perform the same instructions One trick for getting more speed is pipelining Same as the trick of washing your second load while drying your first load Different architectures are different, but the steps to perform an instruction are similar to: Fetch instruction Decode instruction Execute instruction Read from memory Write back to memory

63 Example of pipelining Instruction Pipeline Stage 1 Fetch Decode
Execute Read Write 2 3 4 5 Clock Cycle 6 7

64 Parallel processing Even though computers are fast, they are never as fast as we want Parallel processing is the field within CS focused on solving hard problems with multiple computers Often it follows this pattern: One computer breaks a problem into pieces It sends the pieces to the other computers Each computer completes its work independently The computers send back their results to the master computer It assembles the partial answers into a final answer Regular (non-parallel) computing is sequential processing

65 𝑠𝑝𝑒𝑒𝑑𝑢𝑝= 𝑡𝑖𝑚𝑒 𝑠𝑒𝑞𝑢𝑒𝑛𝑡𝑖𝑎𝑙 𝑡𝑖𝑚𝑒 𝑝𝑎𝑟𝑎𝑙𝑙𝑒𝑙
Speedup The goal of parallel processing is speedup Speedup is defined as 𝑠𝑝𝑒𝑒𝑑𝑢𝑝= 𝑡𝑖𝑚𝑒 𝑠𝑒𝑞𝑢𝑒𝑛𝑡𝑖𝑎𝑙 𝑡𝑖𝑚𝑒 𝑝𝑎𝑟𝑎𝑙𝑙𝑒𝑙 In other words, how many times faster is doing the job in parallel? If you have n computers, what's the best speedup you can hope for? Is it ever possible to have a speedup less than 1?

66 Amdahl's law Communication time is usually what stops speedup from being very good Another problem is that only part of a problem is parallelizable Amdahl's law states that if p is the fraction (between 0 and 1) of the program that can be parallelized, then 𝑠𝑝𝑒𝑒𝑑𝑢𝑝< 1 1 −𝑝 Let's say that 75% of your program can be parallelized Your speedup will never be greater than 4, even if you used 1,000,000 computers to solve your problem

67 Multicore processors Parallel processing used to be something that only research scientists talked about Owning multiple computers was expensive Now, computers are cheap and virtually all desktops and laptops have multicore processors A multicore processor has several independent processors inside Multicore processors bring the possibility of parallel processing to the common person

68 What is an algorithm? An algorithm is a finite sequence of steps you can follow to solve a problem Long division is a good example You can follow the steps and divide even very large numbers Algorithms are independent of programming languages One algorithm could be implemented in many different languages

69 Search algorithm The algorithm to find a number in a list is straightforward We just look through every element in the list until we find it or run out If we find it, we return True, otherwise we return False def find( haystack, needle ): for i in haystack: if i == needle: return True return False

70 How long does it take? Measuring in seconds isn't really helpful
It depends on the length of the list Let's say that the length of the list is n How many numbers do we have to check in the worst possible case? We have to check n different numbers

71 Binary search Check the middle Check the middle Check the middle
A binary search is faster, but only works if the values are in sorted order Play a high-low game by repeatedly dividing the search space in half We’re looking for 37, let’s say 23 54 31 37 Check the middle Check the middle Check the middle Check the middle (Too low) (Too low) (Found it!) (Too high)

72 Running time for binary search
We cut the search space in half every time At worst, we keep cutting n in half until we get 1 Let’s say x is the number of times we look: 1 2 x n = n = 2 x log n = x It takes at most log n steps

73 What is log? The log operator is short for logarithm
Taking the logarithm means de-exponentiating something log =7 log 10 𝑥 =𝑥 What's the log 1,000,000 ?

74 Log base 2 In the normal world, when you see a log without a subscript, it means the logarithm base 10 "What power do you have to raise 10 to to get this number?" In computer science, a log without a subscript usually means the logarithm base 2 "What power do you have to raise 2 to to get this number?" log 2 8 =8 log 2 𝑦 =𝑦 What's the log 2048? (Assuming log base 2)

75 Sorting The importance of sorting should be evident to you by now
Applications: Sorting a column in Excel Organizing your iTunes playlists by artist name Ranking a high school graduating class Finding a median score to report on an exam Countless others…

76 Bubble sort is a classic sorting algorithm
It is simple to understand It is simple to code It is not very fast The idea is simply to go through your list, swapping out of order elements until nothing is out of order

77 Single pass example Run through the whole list, swapping any entries that are out of order No swap 45 Swap No swap 7 45 54 37 108 51 54 37 Swap No swap 108 51 Swap

78 How many passes do we need?
How bad could it be? What if the list was in reverse-sorted order? One pass would only move the largest number to the bottom We would need n – 1 passes to sort the whole list 6 5 4 3 2 7 1 6 5 4 3 2 1 7 6 5 4 3 7 2 1 6 5 7 4 3 2 1 7 6 5 4 3 2 1 6 7 5 4 3 2 1 6 5 4 7 3 2 1

79 Full bubble sort code The full Python function for bubble sort would require us to have at least n – 1 passes We'll do n, since it's simpler def bubbleSort( list ): for i in list: #n passes for j in range( len(list) - 1): if list[j] > list[j + 1]: list[j], list[j + 1] = list[j + 1], list[j]

80 Mathematical description
We want to compare the running time of one program to another We want a mathematical description with the following characteristics: Worst case We care mostly about how bad things could be Asymptotic We focus on the behavior as the input size gets larger and larger

81 Everything's about n We want our description to take into account the number of things we are taking as input Sometimes that's the number of things in a list Sometimes that's the number of lines in a file However many things we're processing, we'll call it n

82 Our approach Any code that isn't inside of a loop takes constant time
If a loop runs n times, then it takes n time But that means that a loop that runs n times which is inside another loop that runs n times will take n2 time And loops inside of loops inside of loops take n3 time, and so on There are more complex situations (like binary search), but we'll focus on simple ones

83 Big Oh notation The notation we use for representing running time is called Big Oh notation It's goal is to simplify the expression so we can focus on whatever grows the fastest All constant coefficients are ignored All low order terms are ignored 7n3 + 10n2 + 3n + 3 is O(n3) Big Oh states that, ignoring constants, the running time is no worse than some simple function of n

84 Big Oh simplification examples
147n3 + 2n2 + 5n is O(n3) n n is O(2n) 15n2 + 6n + 7log n is O(n2) 659n + nlog n is O(n log n) Note: In CS, we use log2 unless stated otherwise

85 Finding the largest element in an list
How do we find the largest element in a list? Running time: O(n) if n is the length of the listt What if the list is sorted in ascending order? Running time: O(1) largest = numbers[0] for i in numbers: if i > largest: largest = i print("Largest:", largest) print("Largest:", numbers[len(numbers)-1]);

86 Bubble sort What is the running time for bubble sort?
Running time: O(n2) def bubbleSort( list ): for i in list: #n passes for j in range( len(list) - 1): if list[j] > list[j + 1]: list[j], list[j + 1] = list[j + 1], list[j]

87 Hierarchy of complexities
Here is a table of several different complexity measures, in ascending order, with their functions evaluated at n = 100 Description Big Oh f(100) Constant O(1) 1 Logarithmic O(log n) 6.64 Linear O(n) 100 Linearithmic O(n log n) 664.39 Quadratic O(n2) 10000 Cubic O(n3) Exponential O(2n) 1.27 x 1030 Factorial O(n!) 9.33 x 10157

88 Hamiltonian Cycle (NP-complete)
The Eulerian Cycle problem asked if you could start at some node, cross every edge once, and return to the start The Hamiltonian Cycle problem asks if you can start at some node, visit every node only once, and return to the start In other words, find a tour Sounds easy, right?

89 Find the Hamiltonian Cycle
Finding a Hamiltonian cycle on this graph might even be hard for a computer

90 Traveling Salesman Problem: Hamiltonian Cycle Meets Shortest Path
Given a graph, find the shortest tour that visits every node and comes back to the starting point Like a lazy traveling salesman who wants to visit all possible clients and then return to his home TSP is an NP-complete problem

91 What’s the shortest tour?
Find the shortest TSP tour: Starts anywhere Visits all nodes Has the shortest length of such a tour A 5 6 4 3 2 3 E B D 3 F 7 C

92 What’s the best time for TSP?
No one knows how to find the best solution to TSP in an efficient amount of time The best solutions known take O(2n) For a general graph, no good approximation even exists For a graph with the triangle inequality, there is an approximation that yields a tour no more than 3/2 the optimal Some variations on the problem are easier than others

93 NP-completeness TSP is one of many problems which are called NP-complete All of these problems share the characteristic that the only way we know to find best solution uses brute force All NP-complete problems are reducible to all other NP-complete problems An efficient solution to one would guarantee an efficient solution to all

94 Graph Coloring (NP-complete)
Find the smallest number of colors for coloring nodes such that no two adjacent nodes have the same color Like TSP and Hamiltonian Cycle, large graphs get really hard to find the smallest coloring for Graph coloring has many practical applications E A D B F C A E B D F C

95 Maximum Clique (NP-complete)
Find the largest complete subgraph in a given graph This graph has a clique of size 3

96 Knapsack problem (NP-complete)
Not all NP-complete problems are graph problems The knapsack problem is the following: Imagine that you are Indiana Jones You are the first to open the tomb of some long-lost pharaoh You have a knapsack that can hold m pounds of loot, but there's way more than that in the tomb Because you're Indiana Jones, you can instantly tell how much everything weighs and how valuable it is You want to find the most valuable loot that weighs less than or equal to m pounds

97 Subset sum (NP-complete)
This one is a little bit mathematical Say you have a set of numbers Somebody gives you a number k Is there any subset of the numbers in your set that add up to exactly k? Example: Set: { 3, 9, 15, 22, 35, 52, 78, 141} Is there a subset that adds up to exactly 100? What about 101?

98 NP NP is actually a class of problem
Problems in NP can be solved in polynomial time on a non-deterministic computer A deterministic computer is the kind you know: First it has to consider possibility A, then, it can consider possibility B

99 Deterministic vs. non-deterministic
A non-deterministic computer (which, as far as we know, only exists in our imagination) can consider both possibility A and possibility B at the same time Deterministic A B C D E F A B C D E F Non-Deterministic

100 P P is the class of decision problems that can be solved in polynomial time by a deterministic computer Lots of great problems are in P: Is this list sorted? Is this number prime? Is the shortest path from node A to node B of length 37? It's unknown whether some problems are in P: Does this number have exactly two factors? Is this graph equivalent to this other graph?

101 NP-complete Everything in P is also in NP
Some problems are the “hardest” problems in NP This means that any problem in NP can be converted into one of these problem in polynomial time These problems make up the class NP-complete NP-complete NP-complete

102 Easy to check vs. easy to answer
Computer scientists view problems in P as "easy to answer" They can be computed in polynomial time Problems in NP are "easy to check" An answer can be checked in polynomial time For example, if someone gives you a Traveling Salesman tour, you can verify that it is a legal tour of the required length But is easy to check the same as easy to answer?

103 Lab 10

104 Upcoming

105 Next time… Exam 2!

106 Reminders Keep working on Project 4
Turn in your Final Project Design Document Due tonight before midnight! Study for Exam 2


Download ppt "Week 10 - Friday CS 113."

Similar presentations


Ads by Google