Introduction to Computer Science / Procedural – 67130 Exam Information Units 20-21.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
21/3/00SEM107- Kamin & ReddyClass 15 - Recursive Sorting - 1 Class 15 - Recursive sorting methods r Processing arrays by recursion r Divide-and-conquer.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 24 Sorting.
Recursive sorting: Quicksort and its Complexity
Analysis of Algorithms. Time and space To analyze an algorithm means: –developing a formula for predicting how fast an algorithm is, based on the size.
Quicksort. Quicksort I To sort a[left...right] : 1. if left < right: 1.1. Partition a[left...right] such that: all a[left...p-1] are less than a[p], and.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Quicksort.
CHAPTER 4 Decidability Contents Decidable Languages
Introduction to Computer Science Exam Information Unit 20.
CS 106 Introduction to Computer Science I 02 / 28 / 2007 Instructor: Michael Eckmann.
Data Structures Review Session 1
Slide 1 of No. Insert Unit Name Here Lecture L: Computability Unit L1: What is Computation?
Chapter 11: Limitations of Algorithmic Power
29-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
1 Chapter 7 Recursion. 2 What Is Recursion? l Recursive call A method call in which the method being called is the same as the one making the call l Direct.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Introduction to Computer Science Recursive Array Programming Recursive Sorting Algorithms Unit 16.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Week 11 Sorting Algorithms. Sorting Sorting Algorithms A sorting algorithm is an algorithm that puts elements of a list in a certain order. We need sorting.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
CS 1704 Introduction to Data Structures and Software Engineering.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
Analysis of Algorithms
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Week 6 - Wednesday.  What did we talk about last time?  Exam 1 post-mortem  Recursive running time.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
CSC 211 Data Structures Lecture 13
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 26 Sorting.
Data Structure Introduction.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Quicksort CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
(c) , University of Washington18a-1 CSC 143 Java Searching and Recursion N&H Chapters 13, 17.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Searching and Sorting Searching: Sequential, Binary Sorting: Selection, Insertion, Shell.
27-Jan-16 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
CompSci On the Limits of Computing  Reasons for Failure 1. Runs too long o Real time requirements o Predicting yesterday's weather 2. Non-computable.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Overview of the theory of computation Episode 3 0 Turing machines The traditional concepts of computability, decidability and recursive enumerability.
Computer Sciences Department1. Sorting algorithm 4 Computer Sciences Department3.
329 3/30/98 CSE 143 Searching and Sorting [Sections 12.4, ]
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 26 Sorting.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 23 Sorting.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesTuring.
Introduction to Computer Science / Procedural – 67130
Universality of Computation
Introduction to Computer Science / Procedural – 67130
Theory of Computation Turing Machines.
Presentation transcript:

Introduction to Computer Science / Procedural – Exam Information Units 20-21

21- 2 Internal Representation A computer word of 32 bits is “just” a string of 1’s and 0’s: It might represent any one of a number of things:  4 characters  An integer  Half of a double (floating point number)  A computer command in machine language

21- 3 Internal Representation 4 characters An integer Half of a double A computer command in machine language The computer system itself must keep track of what the bits represent --- or allow a program to decide at runtime.

21- 4 Binary (half) Addition 0 plus 0 is 0 0 plus 1 is 1 1 plus 0 is 1 1 plus 1 is 0, carry a 1 to next column Only good for first column.

21- 5 Binary (full) Addition, Handles Other Columns 0 plus 0 plus 0 is 0 0 plus 0 plus 1 is 1 0 plus 1 plus 0 is 1 0 plus 1 plus 1 is 0, carry a 1 to next column 1 plus 0 plus 0 is 1 1 plus 0 plus 1 is 0, carry a 1 to next column 1 plus 1 plus 0 is 0, carry a 1 to next column 1 plus 1 plus 1 is 1, carry a 1 to next column These actions are carried out by circuits in the computer.

’s and 1’s What represents the 0’s and 1’s? It can be (and has been) many things… Voltages, magnetic fields of various kinds, physical relays that are open or closed, vacuum tubes, transistors in different states… Anything that can be in two well- differentiated states, and that can be easily/quickly switched between the states.

21- 7 What is Computation? E.g., Physical Computation

21- 8 Mathematically defined computation public class PrintPrimes { public static void main(String[ ] args) { for (j = 2; j < 1000; j++) if (isPrime(j)) System.out.println(j); } private static boolean isPrime(int n) { for (int j=2; j < n; j++) if (n%j == 0) return false; return true; }

21- 9 Turing Machines a a b b z z 0, R, b 1, L, b 0, L, a 1, L, g 0, L, a 1, R, x a a b b z z e e

Turing Machine for adding 1 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt

Seeing How It Works, Example 1 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt 0011 …… … head Starts in state a, sees a 0…

Seeing How It Works, Example 1 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt 0111 …… … head Starts in state a, sees a 0, so writes a 1, stays in the same location, and goes to state b -- halt

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Starts in state a, sees a 1…

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Starts in state a, sees a 1, so writes a 0, moves left, and stays in state a…

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Still in state a, and still sees a 1, so…

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Still in state a, and still sees a 1, so write a 0, moves left, and stays in state a…

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Still in state a, now sees a 0, so…

Seeing How It Works, Example 2 a a b b , _, b 0, L, a 1, _, b 0, _, b start halt …… … head Still in state a, now sees a 0, so writes a 1, stays in same place, and moves to state b -- halt

Universal Computers Theoretical version: there exists a single Universal Turing Machine that can simulate all other Turing machines  The input will be a coding of another machine + an input to the other machine Hardware version: stored program computer Software version: interpreter /** * Runs the first method in the Java class that is given in * “program” on the parameter given in “input”. Returns * the value returned by the method. The method must be * static, accept a single String parameter, and return a * String value. */ static String simulate(String program, String input){ … }

Church-Turing Hypothesis “Every effective computation can be carried out by a Turing machine” “A method, or procedure, M, for achieving some desired result is called ‘effective’ or ‘mechanical’ just in case  M is set out in terms of a finite number of exact instructions (each instruction being expressed by means of a finite number of symbols);  M will, if carried out without error, produce the desired result in a finite number of steps;  M can (in practice or in principle) be carried out by a human being unaided by any machinery save paper and pencil;  M demands no insight or ingenuity on the part of the human being carrying it out.”

Church-Turing Hypothesis This notion of an “effective method” is informal – the key requirement that the method “demands no insight or ingenuity” is left undefined Turing published a paper in 1936 that presented a formally exact predicate to replace the informal statement ‘can be calculated by means of an effective method’ Church did the same (in 1936!) “The replacement predicates that Turing and Church proposed were, on the face of it, very different from one another, but they turned out to be equivalent, in the sense that each picks out the same set of mathematical functions” “Whenever there is an effective method for obtaining the values of a mathematical function, the function can be computed by a Turing machine”

The Church-Turing Hypothesis Everything computable is computable by a Turing machine  Everything computable is computable by a Java program  All “good enough” computers are equivalent ANY "COMPUTABLE" FUNCTION IS A PARTIAL RECURSIVE FUNCTION. ══ ANY "COMPUTABLE" FUNCTION HAS A TM TO COMPUTE IT Partial recursive functions are the only computable functions, and these are the functions computable by TMs.

“Intrinsic Power” vs. “Effective Power” Anything you can do with a minimally capable computer language, you can theoretically do with any other minimally capable computer language (ignoring storage constraints) But that is like saying a shovel is theoretically as capable as a tractor. In practice, using a shovel might make things very hard…

What to Concentrate On The exam will not ask any questions about the robot world material The exam assumes knowledge of everything else that you’ve seen in this course, including simple understanding of complexity Concentrate more on algorithms and data structures than on “system building”

Good/Bad Questions Good question:  “Write an algorithm using recursion to solve the following problem”  “Write a method that solves the following problem, using a linked list” Bad question (not the kind we’ll ask):  “Develop a class hierarchy for representing employment information for Israel’s Mas Hachnasa office”

Other Things to Use as Study Resources Besides the old exams, you can look at the book “Introduction to Computer Science using Java” in the library There are questions in every chapter, with some answers at the back of the book Practice answering these questions (obviously, ignore applet sections)

Translating from Previous Tests Some previous tests had file operations (reading and writing) Assume that if we asked those kinds of questions, we’ll restrict ourselves to the input/output operations you’ve seen in the class SimpleInput, or provide you with others

Test-Taking Hints Read through the instructions at the beginning of the exam – we mean them! Look at all the questions quickly at the beginning. You will choose 3 out of 4 to answer. Do not necessarily work on Question 1 first – choose an order that makes sense for you. Do not spend too much time on any question – time constraints are real (no extensions). But you do have an hour for each question; don’t expect the answer to be obvious right away.

Sample Question 1 You have seen the QuickSort algorithm, which made use of the partition method: int partition(double[] a, int lo, int hi) { // Choose middle element among a[lo]…a[hi], // and move other elements so that a[lo]…a[m-1] // are all less than a[m] and a[m+1]…a[hi] are // all greater than a[m] // // m is returned to the caller swap(a, lo, medianLocation(a, lo+1, hi, (lo+hi)/2)); int m = shuffle(a, lo+1, hi, a[lo]); swap(a, lo, m); return m; }

Sample Question 1 Write a method called “selection” that takes two arguments: an array of ints, a[ ], and an int, k, and returns what would be the k-th element of the sorted array a[ ] – but do it without completely sorting a[ ]! You may mutate a[ ] You should use the partition method, and solve the problem using recursion What are the big O worst-case and best- case complexities of your method?

Solution public static int selection(int a[], int k) { return selection(a, k, 0, a.length-1); } private static int selection(int a[], int k, int lo, int hi) { int p = partition(a, lo, hi); // index of pivot if ( p == k ) return a[p]; else if ( p > k ) return selection(a, k, lo, p-1); else // p < k return selection(a, k, p+1, hi ); }

Worst Case Complexity The recurrence relation will be: T(n) = T(n – 1) + O(n) This is when partition, unluckily, keeps returning the worst possible division of the array We know that recurrence relation results in the following complexity (it’s one of the big-5 recurrence relations): O(n 2 ) Best Case Complexity: one partition and you get lucky, so it’s O(n)

Average Case Complexity This recurrence relation is kind of like QuickSort’s best case, but is missing the “2” that results from having to do both halves of a problem: T(n) = T(n/2) + O(n) = [T(n/4) + n/2] + n = T(n/4) + 3n/2 = [T(n/8) + n/4] + 3n/2 = T(n/8) + 7n/4 = T(n/2 k ) + (2 k – 1)n/2 k-1 [eureka!] = T(1) + 2(n – 1)n/n[log 2 n = k] = O(n)[T(1) is 1, etc.] This isn’t a proof, we’re just noticing a pattern…

Sample Question 2 You are given an unsorted array of “Flat” objects, which have a method getNum( ) that returns a value between 1 and 4 Sort the array of objects in time O(n), calling getNum( ) no more than once on each object Do not create new heap objects 3 [0][1][2][3][4][5][6][7][8][9]

Question 2 This was a moed bet question; many students did a “countsort”, which they had learned in the second semester “Run through the array, count how many times each object appears, shift objects around” This did not satisfy the requirement to call getNum( ) no more than once on each object A correct answer is a simple extension of the Dutch Flag problem solution

public static void sortFlats (Flat[] flats) { int border1 = -1; int border2 = 0; int border3 = flats.length-1; int border4 = flats.length; do { switch ( flats[border2].getNum( ) ) { case 1: border1++; swap(flats, border1, border2); border2++; break; case 2: border2++; break; case 3: swap(flats, border2, border3); border3--; break; case 4: border4--; swap(flats, border2, border4); if (border3 < border 4) swap(flats, border2, border3); border3--; break; } } while border2 <= border3; } and write swap( )...

Sample Question 3 Assume that you have an array, u, of n integers, where no integer appears more than once. u is said to be unimodal if there is some index i (where 0 ≤ i ≤ n-1) such that u[0],…,u[i] is a strictly increasing sequence and u[i],…,u[n-1] is a strictly decreasing sequence. For example, u = 2, 4, 8, 7, 6, 5, 4, 1, 0, -1 is unimodal, and u = 5, 3, 2, 1 is unimodal, but u = 2, 3, 1, 4 is not.

Sample Question 3a Write a non-recursive method that receives an array of integers, returns the value of i if the array is unimodal, and returns -1 if the array is not unimodal. Make this method as efficient as you can. What are the big-O best-case and worst-case complexities of your method? Explain.

/************************************************************** * Once a unimodal array starts decreasing, it doesn’t increase data * Possibly unimodal array data[ ] * The location of the array’s single peak, or -1 if the array is not unimodal * Best case: O(1) --- it can discover the first two values are equal * Worst case: O(n) --- it has to run through whole array to check if it's unimodal **************************************************************/ public static int unimodalCheck (int[ ] data) { int last = data.length - 1, maxLoc = 0; // location of peak boolean falling = false; for (int i = 0; i < last; i++) { if (data[i+1] == data[i]) return -1; if (data[i+1] > data[i]) { if (falling == true) return -1; else maxLoc = i+1; } else falling = true; // data[i] > data[i+1] } return maxLoc; // we get here, it's a unimodal array }

Sample Question 3b Now write a non-recursive method that is guaranteed to receive a unimodal array of integers, and returns the value of i. Make this method as efficient as you can. What are the big-O best-case and worst-case complexities of your method? Explain.

/************************************************************* * A unimodal binary search, checking for a complete peak at each jump. * There are no duplicated contiguous entries in the array, by the definition of * unimodal arrays --- and the array is guaranteed unimodal, we're just * looking for the peak data * Guaranteed unimodal array data[ ] * The location of the array’s single peak * Best case: O(1) --- might find peak after first calculation of middle * Worst case: O(log n) --- it might have to collapse the unknown region to a * single array location, before it finds the peak; but the collapsing is done * like binary search, so it cuts the unknown region in half each time *************************************************************/

public static int unimodal (int[ ] data) { int middle, lower = 0, upper = (data.length - 1); do { middle = ((lower + upper) / 2); if (middle == 0) { if (upper == 0) return 0; // array of one element else if (data[middle] > data[middle+1]) return middle; else return (middle+1); } else { if (data[middle] > data[middle+1]) { if (data[middle] > data[middle-1]) return middle; else upper = middle-1; } else lower = middle+1; } } while (lower < upper); // we stop if lower and upper meet // if we get here, data[lower] is the array’s peak return lower; } // unimodal

Sample Question 4 Assume that you have an array, u, of n integers, n>0, where the same integer may appear more than once in u Write 3 non-recursive methods that receive the array u as an argument and return the value of the integer that appears most often in it – each method designed to work under one of the 3 conditions below In all cases, if multiple integers appear with the same maximal frequency, your method can return any one of them

Sample Question 4a The array u is not necessarily sorted. In your solution, do not create any additional objects in the heap, and do not sort the array! What are the big-O best-case and worst-case complexities of your method? Explain.

Answer to Question 4a public static int common1 (int[ ] data) { intcurFreq = 0, maxFreq = 0, maxInt = 0, size = data.length; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (data[j] == data[i]) curFreq++; } if (curFreq > maxFreq) { maxFreq = curFreq; maxInt = data[i]; } curFreq = 0; // reset the current // frequency for next int } return maxInt; } // Best and worst case running time are O(n 2 )

Sample Question 4b Now assume that the you have access to a method public void qsort(int[ ] data) that sorts an array in ascending order using the QuickSort algorithm. You may use qsort( ) in your solution. What are the big-O best-case and worst-case complexities of your method? Explain.

Answer to Question 4b public static int common2 (int[ ] data) { int curFreq = 1, maxFreq = 1, maxInt = data[0], size = data.length; qsort(data); for (int i = 1; i < size; i++) { if (data[i] == data[i-1]) curFreq++; else { // we have a new integer if (curFreq > maxFreq) { maxFreq = curFreq; maxInt = data[i-1]; } curFreq = 1; } // need to check if last integer in array is most frequent if (curFreq > maxFreq) maxInt = data[size-1]; return maxInt; } // Best case is O(n log n) + O(n), i.e., O(n log n) // Also because of qsort( ), the worst case is O(n 2 )

Sample Question 4c Now assume the array, u, is unsorted, but the only integers appearing in it are in the range 0 to 99. What are the big-O best-case and worst-case complexities of your method? Explain.

Answer to Question 4c public static int common3 (int[ ] data) { final int RANGE = 100; intmaxLoc = 0, maxNum = 0, size = data.length; int[] counts = new int[RANGE]; for (int i = 0; i < size; i++) counts[data[i]]++; for (int i = 0; i < RANGE; i++) { if (counts[i] > maxNum) { maxNum = counts[i]; maxLoc = i; } return maxLoc; } // Best and worst case are O(n)

Question 5 x and y are two linked lists, with a standard Node definition (e.g., a field called ‘next’) They are “joint” if they meet at some point, such as the following example: How would you find the node at which the two lists meet?

Answer to Question 5 Let n1 be the size of l1 (list1) and n2 be the size of l2 (list2) Assume that n1 >= n2 Let d = n1 - n2 (i.e., d >= 0) Let l1b be a sublist of l1 which begins in the d-th element of l1 (e.g., if d=0 then l1=l1b ; if d=1 than the head of l1b is the 2 nd element in l1, etc.) Now, l1b and l2 are lists of the same size.

while ( l1b != l2 ) { // since l1b and l2 are of the same size then // either the two will become null at the same // time (which means they are disjoint), or will // become equal before both turn into null // (which means they are joint) l1b = l1b.next; l2 = l2.next; } if ( l1 == null ) { // lists are disjoint assert l2 == null; } else { // l1 is the merge-point assert l1 == l2; } Verify whether two lists of the same size are joint using a simple O(n) loop:

The Brain vs. a Pentium There are 10^ ^10 neurons in the brain Each neuron receives input from 10^ ^4 synapses Each neuron can fire about ^2 times/sec Total computing power is 10^ ^16 ops/sec Pentium IV computing power ≈ 10^9 ops/sec

Artificial Intelligence Why can’t we program computers to do what humans easily do?  Recognize faces  Understand human language (Ironically, we can program computers to do what humans cannot easily do  Play chess at world champion levels  Carry out massive optimization problems) Processing power? --- doesn’t seem to be the real issue Software?  Scruffy vs. Neat debate

Artificial Intelligence: Scruffy vs. Neat The Scruffy approach says, “Build systems that work, and principles will emerge.”  E.g., the Wright Brothers building a heavier-than-air flying machine The Neat approach says, “Explore principles first, and having understood them, embody them in systems.”  E.g., radar

The Turing Test

Self-Reference Leads to Paradoxes Example: Things in the world can be classified according to what sets they belong to  “The set of all tables” “the set of all chairs” … … … …

Self-Reference Leads to Paradoxes Sets themselves can be grouped into sets “The set of all sets having more than three members”  That set would have “the set of all chairs” inside of it The set of all sets having more than three members … …

Self-Reference Leads to Paradoxes Some sets are even contained in themselves! “The set of all sets having more than three members” contains itself (since there are more than three such sets…) Some sets do not contain themselves, e.g., “the set of all chairs” does not contain itself: … … The set of all sets having more than three members

Self-Reference Leads to Paradoxes We could even define “The set of all sets that do not contain themselves”  That set would contain “the set of all chairs”, for example The set of all sets that do not contain themselves

Self-Reference Leads to Paradoxes Does “The set of all sets that do not contain themselves” contain itself?  If it contains itself, then it can’t contain itself (by definition)  If it doesn’t contain itself, then it contains itself (by definition) Paradox! The set of all sets that do not contain themselves

The Halting problem program must be a Java class. The method that is run is the first one in the class and must be of the form static boolean XXXX(String input) /** * Return true if the program finishes * running when given the input as its * parameter. Return false if it gets into * an infinite loop. */ static boolean halt(String program, String input){ // fill in – can you do it? }

Diagonalization static boolean autoHalt(String program){ return halt(program, program); } static boolean paradox(String program){ if autoHalt(program) while(true) ; // do nothing else return true; }

The Halting problem cannot be solved Will paradox halt when running on its own code?  Yes ==> autoHalt(paradoxString) returns false ==> No  No ==> autoHalt(paradoxString) returns true ==> Yes Contradiction. Hence the assumption that halt(program, input) exists is wrong Theorem: the halt method cannot be written String paradoxString = “class Test {\n” + “ static boolean paradox(String program){\n” + … “ static boolean halt(String program, String input){\n” + … boolean answer = Test.paradox(paradoxString);

There are Limits to Computation There are theoretical limits to what can be computed In practice, we are nowhere near the limits of what we can do with computers The most interesting question remains “What new things can we do with computer power?” In this course, you have started the journey of understanding in Computer Science, so that you can help answer that question

Areas in Computer Science Algorithms and Data Structures Programming Languages Computer Architecture Operating Systems Software Engineering Symbolic and numerical computation and modeling, graphics Databases Artificial Intelligence Robotics Computer Vision

How they fit together ArchitectureLanguages Software Engineering Algorithms Operating Systems Robotics Databases Artificial Intelligence Symbolic/Numerical Computation

This is Not the End We have covered a lot of subjects in Computer Science (e.g., sorting, searching, recursion, simple data structures like arrays and linked lists) We have covered a lot in Java (e.g., variables, types, conditionals, loops, objects, inheritance, polymorphism) But it’s only the beginning You’ll be carrying this forward in the next semester in Data Structures

The End, for Now Good Luck on the Exam!