CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Final Project Web Design. Final Project Your robot will be placed in a room with the red cone. Your robot will need to find the cone in the room and run.
Advertisements

How does Google search for everything? Searching For and Organizing Data Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Basics of Recursion l Programming with Recursion Recursion.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
Compsci 101.2, Fall Plan For the Day l Discuss Algorithms and Programming at a high level, examples with cooperative/group work  Connect to reading.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
How to Read Code Benfeard Williams 6/11/2015 Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Compsci 101.2, Fall Plan for eleven-four l Thinking about APTs and test problems  How do you choose: list, string, set, dictionary  Experience?
CompSci 101 Introduction to Computer Science January 19, 2016 Prof. Rodger compsci 101 spring
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science March 31, 2016 Prof. Rodger.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
CMSC201 Computer Science I for Majors Lecture 23 – Algorithms and Analysis Prof. Katherine Gibson Based on slides from previous iterations.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
CompSci 4 Java 1 Apr 2, 2009 Prof. Susan Rodger. Announcements Assignment 7 questions? –Beware having two events that kick in at the same time! –Beware.
Algorithms.
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
Introduction to C++ Programming Language
UMBC CMSC 104 – Section 01, Fall 2016
More on Functions (Part 2)
Week 9 - Monday CS 113.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Week 13: Searching and Sorting
CMSC201 Computer Science I for Majors Lecture 23 – Sorting
Algorithmic complexity: Speed of algorithms
CompSci 101 Introduction to Computer Science
Last Class We Covered Sorting algorithms Searching algorithms
What to do when a test fails
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Search Lesson Outline Searching Lesson Outline
Creativity in Algorithms
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CSc 110, Spring 2017 Lecture 39: searching.
CompSci 101 Introduction to Computer Science
Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014
CSE 8A Lecture 6 Reading for next class:
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Last Class We Covered Sorting algorithms Searching algorithms
UMBC CMSC 104 – Section 01, Fall 2016
Searching and Sorting Topics Sequential Search on an Unordered File
4. Computational Problem Solving
Algorithmic complexity: Speed of algorithms
More on Functions (Part 2)
More on Functions (Part 2)
Searching, Sorting, and Asymptotic Complexity
Basics of Recursion Programming with Recursion
DW Daniel High, SC; Jan 25, 2010 Murali Sitaraman
Algorithmic complexity: Speed of algorithms
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Last Class We Covered Recursion Stacks Parts of a recursive function:
Presentation transcript:

CompSci 101 Introduction to Computer Science Sept 28, 2017 Prof. Rodger compsci 101, fall 2017

Announcements Exam 1 is Thursday, Oct 5 RQ Reviews available today – not for credit Practice exams on today’s date Work them on paper before Tuesday Assignment 4 due Tuesday, try for Monday! No Lab next 2 weeks Today: Loops – While, While True Problem Solving compsci 101, fall 2017

Lab 5 – First part Practicing the first four steps of the 7 steps for problem solving Find the pattern, what is next, then generalize compsci 101, fall 2017

Pattern 1

Notice things about the pattern You want to place N legos If N is odd – Start with a green First blue is third lego If N is even – start with a blue Every third lego is blue compsci 101, fall 2017

Bottom Left is (0,0) (2,3) (0,0) compsci 101, fall 2017

Try it N=8 Num Location Lego color 1 (0,0) blue 2 (1,2) green 3 (2,4) green 4 (3,5) blue 5 (4, 6) green 6 (5, 8) green 7 (6, 10) blue 8 (7, 12) green compsci 101, fall 2017

Algorithm for placing N legos Legos placed long way with bottom left at location, explain the grid For num from 1 to N Location is ( (num-1), (num-1)*2 ) If N is even If num is divisible by 3 Place blue lego at location Else Place green lego at location If N is odd … compsci 101, fall 2017

Developing an Algorithm http://www.youtube.com/watch?v=AEBbsZK39es $193, $540, $820, $700, $749. Are these reasonable? Why? This is the price is right game where you bid to try to guess the price of an item and you get several tries. Play the video Are these numbers reasonable? Poll the class compsci 101, fall 2017

I'm thinking of a number … You guess. I'll tell you high, low, or correct Goal: guess quickly, minimal number of guesses Number between 1 and 100… Number between 1 and 1000… Can you describe an algorithm, instructions, that would allow someone to use your instructions to play this game correctly. Start with 1 and 100, but ideally your instructions work with 1 and N bit.ly/101f17-0928-1 Ask for a volunteer What is the best first guess? Second guess compsci 101, fall 2017

Analyzing the binary search algorithm Is the algorithm correct? Try it, again, and again and … Reason about it: logically, informally, … How efficient is the algorithm? How many guesses will it take (roughly, exactly) Should we care about efficiency? When do we really care about efficiency? Examples? Algorithm correct? Can you try all possible data? Too much! Why does google care about efficiency, and what does "efficient" mean? Searching billions of webpages in no time, making the user think it's no time, even when it is, e.g., auto-complete search query and scrolling google maps. Sometimes about algorithm and sometimes about user experience and making the web more efficient Also efficiency of the user experience compsci 101, fall 2017

Find Narten Anderson Applegate Bethune Brooks Carter Douglas Edwards Franklin Griffin Holhouser Jefferson Klatchy Morgan Munson Narten Oliver Parker Rivers Roberts Stevenson Thomas Wilson Woodrow Yarbrow Find Narten The magenta/purple shows where Narten could be. After each guess, roughly in the middle, we eliminate half of the names from being the range Of names in which Narten could be. So how many times can we cut the range in half? compsci 101, fall 2017

Find Narten FOUND! Anderson Applegate Bethune Brooks Carter Douglas Edwards Franklin Griffin Holhouser Jefferson Klatchy Morgan Munson Narten Oliver Parker Rivers Roberts Stevenson Thomas Wilson Woodrow Yarbrow Find Narten FOUND! The magenta/purple shows where Narten could be. After each guess, roughly in the middle, we eliminate half of the names from being the range Of names in which Narten could be. So how many times can we cut the range in half? compsci 101, fall 2017

Looking for a Needle in a Haystack If a computer can examine 10 million names/numbers a second, suppose the list isn't sorted, or I say "yes/no", not "high/low" How long to search a list of 10 million? How long to search a list of a billion? 14 billion pixels in a 2 hour blu-ray movie What about using binary search? How many guesses for 1000, 106, 109, 1012 One of the things to remember: 210 = 1024 1 sec – 10 million 100 sec – billion – 2 min 14 billion pixels in 2 hour blu-ray movie – days to render a movie Faster 1000 – 10 10^6 – 20 10^9 – 30 10^12 - 40

Review - Searching for words If we had a million words in alphabetical order, how many would we need to look at worst case to find a word? If you are clever, cut the number of numbers to look at in half, over and over again If you are clever, you only have to look at a few word! compsci 101, fall 2017

Review - Searching for words If we had a million words in alphabetical order, how many would we need to look at worst case to find a word? 20 words! 1,000,000 500,000 250,000 125,000 62,500 31,250 15,625 7812.5 3906 1953 976.56 488 244 122 61 30 15 7.5 3.75 1.875 If you are clever, cut the number of numbers to look at in half, over and over again If you are clever, you only have to look at a few word! compsci 101, fall 2017

Prime Numbers An integer > 1 is prime if it has no positive divisors other than 1 and itself. 12 is not prime! 12 is divisible by 2, 3, 4, 6 3*4 = 12, 2*6 = 12 Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23 Is 8315411 prime? What if we write a program to determine if a number is prime compsci 101, fall 2017

Is number a Prime number? Bit.ly/101f17-0928-2 def isPrime(number): if number < 2: # must be greater than 1 return False if number < 4: # 2 and 3 are prime return True for n in range(4,number): if number/n * n == number: Run this one compsci 101, fall 2017

Write Helper functions to help solve problems!!!! Find all the primes between 10 and 100 Use isPrime as a helper function Assignment 4 helper functions isVowel(letter) – return true if letter is a vowel NoVowels(word) – return True if no vowels in word Automatic Decrypt, what helper function? countWords(wordlist, shift, phrase) Decrypt with shift, then count how many words in phrase are in wordlist Helper functions make your code shorter, compsci 101, fall 2017

Write Helper functions to help solve problems!!!! Find all the primes between 10 and 100 Use isPrime as a helper function Assignment 4 helper functions isVowel(letter) – return true if letter is a vowel NoVowels(word) – return True if no vowels in word Automatic Decrypt, what helper function? countWords(wordlist, shift, phrase) Decrypt with shift, then count how many words in phrase are in wordlist Helper functions make your code shorter, compsci 101, fall 2017

Undetermined Repetition Game of chess, when does it end? What is the 100th prime number? Guessing a number from 1 to 100? How many numbers are you going to check? compsci 101, fall 2017

While loops Repetition when you stop a loop based on a condition while CONDITION: BODY As long as condition is true, keep executing loop. Must have an update in the body to get closer to condition being false compsci 101, fall 2017

Example for while Playing chess while (game not over) make a move in the game (game must get closer to ending) With the indefinite loop you have to be getting closer and closer to stopping the loop. compsci 101, fall 2017

Example2 for while What is the 100th prime number? number = 2 while (not 100th prime) is number prime? update count generate next number to check (program must get closer to ending) compsci 101, fall 2017

Example3 - Factorial 5! = 5 * 4 * 3 * 2 * 1 = 120 3! = 3 * 2 * 1 = 6 compsci 101, fall 2017

Example with while loop compsci 101, fall 2017

Mystery While example bit.ly/101f17-0928-3 Where is the update? What does this do?

Computer Science Duke Alum Noam Shazeer (works at google, sat in the front row in B101 in CompSci 101!) compsci 101, fall 2017

Looping with while – not sure when to stop Playing chess Determining the 100th prime number Another way – while True – EASIER! Must have ways to break out of infinite loop Must have update – gets closer to ending compsci 101, fall 2017

while condition vs while True while condition: while True: body body continue if condition: break continue While condition is true - must update - must get closer to making condition false - use break to exit compsci 101, fall 2017

Format of While True initialize while True: if something: break if something2: update Continue or return compsci 101, fall 2017

Revisit Factorial with while True compsci 101, fall 2017

Revisit Mystery with while True bit.ly/101f17-0928-4 compsci 101, fall 2017

Problem: Find the location of first adjacent duplicate word bit Problem: Find the location of first adjacent duplicate word bit.ly/101f17-0928-5 “This is a story about a a girl with a red hood…” Return six as the location of the second word “a” compsci 101, fall 2017

Extra Slides compsci 101, fall 2017

APT PrimeTime compsci 101, fall 2017