CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Advertisements

How does Google search for everything? Searching For and Organizing Data Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014.
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
Complexity (Running Time)
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
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
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known.
CompSci 101 Introduction to Computer Science March 31, 2016 Prof. Rodger.
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.
Algorithms.
Creativity of Algorithms & Simple JavaScript Commands
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Week 9 - Monday CS 113.
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
CompSci 101 Introduction to Computer Science
Last Class We Covered Sorting algorithms Searching algorithms
Last Class We Covered Sorting algorithms “Run” time Selection Sort
Intro to Computer Science CS1510 Dr. Sarah Diesburg
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Search Lesson Outline Searching Lesson Outline
CompSci 101 Introduction to Computer Science
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
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Last Class We Covered Data representation Binary numbers ASCII values
Creativity in Algorithms
CSc 110, Spring 2017 Lecture 39: searching.
CompSci 101 Introduction to Computer Science
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014
THE SCIENTIFIC METHOD A Detective Story.
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Last Class We Covered Sorting algorithms Searching algorithms
UMBC CMSC 104 – Section 01, Fall 2016
4. Computational Problem Solving
Searching, Sorting, and Asymptotic Complexity
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
Discrete Mathematics CS 2610
Last Class We Covered Sorting algorithms Searching algorithms
Presentation transcript:

CompSci 101 Introduction to Computer Science Oct 6, 2016 Prof. Rodger This lecture was 5 to 10 minutes short compsci 101, fall16

Announcements Reading and RQ due next time APT 4 out today, due Oct 18 Do not discuss exam1 with anyone until it is handed back, likely after fall break No Lab this week or next week Today: Loops – While, While True Problem Solving compsci 101, fall16

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 spring 2016

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/101f16-1006-1 Ask for a volunteer What is the best first guess? Second guess compsci 101 spring 2016

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 spring 2016

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 spring 2016

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 spring 2016

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!

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,620 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!

Is number a Prime number? Bit.ly/101f16-1006-2 def isPrime(number): if number<4: return True for n in range(4,number): if number/n * n == number: return False Run this one compsci 101, fall16

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, fall16

Examples for while Playing chess while (game not over) play game (game must get closer to ending) Finding the 100th prime compsci 101, fall16

Mystery While example bit.ly/101f16-1006-3 compsci 101, fall16 Where is the update? What does this do? compsci 101, fall16

Problem: Given a number, want the largest list of unique digits from 1 to x whose sum is less than or equal to the number Given 5 Answer is 1 + 2 , list [1,2] Given 6 Answer is 1+2+3, list [1,2,3] compsci 101, fall16

bit.ly/101f16-1006-4 compsci 101, fall16

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

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, fall16

While True initialize while True: if something: break if something2: update Continue or return compsci 101, fall16

Revisit addDigitsTilSum bit.ly/101f16-1006-5 compsci 101, fall16

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

condition body TRUE FALSE compsci 101, fall16