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

CompSci 101 Introduction to Computer Science January 13, 2015 Prof. Rodger compsci 101 spring
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
Introduction. 2COMPSCI Computer Science Fundamentals.
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 100e Program Design and Analysis II March 29, 2011 Prof. Rodger CompSci 100e, Spring20111.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
CompSci 6 Introduction to Computer Science November 1, 2011 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
Compsci 101.2, Fall Plan for FWON l Review current assignments and APTs  Review Dictionaries and how to use them  Code and APT walk-through.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
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
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 6/101: I Python Techniques for looping
CompSci 6 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
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Last Class We Covered File I/O How to open a file
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CSC 131: 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
Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Searching CLRS, Sections 9.1 – 9.3.
Elements of a Python Program
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
15-110: Principles of Computing
Last Class We Covered File I/O How to open a file
CS150 Introduction to Computer Science 1
Homework Reading Machine Projects Labs
Course A201: Introduction to Programming
Presentation transcript:

CompSci 101 Introduction to Computer Science Nov 1, 2016 Prof. Rodger compsci 101, fall 2016

Announcements Reading and RQ due next time APT 6 due today, APT 7 out Do more APTs to catch up…. APT QUIZ 2 – Nov. 6-8 Next Assignment out Thursday Lab this week! Today: Processing data – how to organize it? enumerate compsci 101, fall 2016

Lab this week! - Odds with poker! Deck of playing cards I made of 54 notable women in computing! Full House – three jacks and 2 fours – what are the odds? Flush compsci 101, fall 2016

ACM Programming Contest Need volunteers to help on Saturday Nov 5 from 11:20am to 6pm. (includes food) Contest Team of three, one computer, 6-8 problems, 5 hours Problems “APT-like” See Piazza post for how to sign up compsci 101, fall 2016

Registration time… What CS courses can you take next? CompSci 201 CompSci 230 is prereq for CompSci 330 CompSci 201 is prereq for many electives compsci 101, fall 2016

When Halloween and Computer Science COLLIDE! compsci 101, fall 2016

CS Concepts Coming Alive What data structure is this? This is me in my Halloween costume back in 1989, teaching the algorithms course. Anyone know what I am? I am a 2D-range tree data structure

YARN, in the shape of a binary tree Subtrees made with molecule kit What is it?

2D-range tree Search in x-y plane Main tree organized by x-values Subtree organized by y values y-range x-range

Binary Search tree of points in the plane – sorted by X-value Each subtree organized by y-value Search each subtree by y-value In the x-range

Problem: Longest Name Given a list of names (one word only) and a letter (assume names start with capital letter, and letter is capital) names = [‘Helen’, ‘Bob’, ‘Bart’, ‘Hugh’] Find the longest name that starts with that letter Mention Examples compsci 101, fall 2016

Code for longest name def longestName(alist, letter): longest = '' for name in alist: if letter == name[0] and len(name) > len(longest): longest = name return longest How do you modify to find the location (position) of the longest name? compsci 101, fall 2016

Problem: Find the position of the longest name that starts with that letter bitly/101f16-1101-1 Go over code solutions compsci 101, fall 2016

Enumerate An iterator, generates a sequence Generates tuples of (index, item) Used with for loop to get both index and item for (index,item) in enumerate(somelist): You get both at the same time! compsci 101, fall 2016

Solve previous problem with enumerate compsci 101, fall 2016

Problem: Popular Name Given a list of names, determine the most popular first name and print that name with all of its last names. Input: Names are always two words, names are in a file. If multiple names are on the same line they are separated by a “:” Output: Most popular first name, followed by a “:”, followed by corresponding last names separated by a blank compsci 101, fall 2016

Example Input File with 5 lines Susan Smith:Jackie Long:Mary White Susan Brandt Jackie Johnson:Susan Rodger:Mary Rodger Eric Long:Susan Crackers:Mary Velios Jack Frost:Eric Lund Corresponding Output Susan: Smith Brandt Rodger Crackers compsci 101, fall 2016

What do you need to solve this problem? bit.ly/101f16-1101-2 compsci 101, fall 2016

How might one organize the data to solve this problem? How many different ways to solve this problem? compsci 101, fall 2016

One way to solve Create a list of unique first names Create a list of lists of last names that are associated with each first name compsci 101, fall 2016

Example – two lists Unique First names Corresponding Last names ’Susan’’ [ ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’]’ ‘Jackie’ [ ‘Long’, ‘Johnson’]’ 1 1 ‘Mary’ [ ‘White’,’Rodger’,’Velios’]’ 2 2 ‘Eric’ [ ‘Long’, ‘Lund’]’ 3 3 ‘Jack’ [ ‘Frost’]’ 4 4

Example – two lists Unique First names Corresponding Last names ’Susan’’ [ ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’]’ ‘Jackie’ [ ‘Long’, ‘Johnson’]’ 1 1 ‘Mary’ [ ‘White’,’Rodger’,’Velios’]’ 2 2 ‘Eric’ [ ‘Long’, ‘Lund’]’ 3 3 ‘Jack’ [ ‘Frost’]’ 4 4 Jackie in position 1 Jackie’s last names in position 1

Now can we solve the problem? Compute those two lists that are associated with each other List of unique first names List of corresponding last names Compute the max list of last names Now easy to print the answer. See popular.py compsci 101, fall 2016

Look at the code for popular.py www.bit.ly/101f16-1101-3 Which datafile is read in? What format is namelist in? Write the code for uniqueFirstNames compsci 101, fall 2016

Write the code: www.bit.ly/101f16-1101-4 allLastNames correspondingLastNames printFirstWithLasts compsci 101, fall 2016

Finish maxnum = max([len(item) for item in lastNames]) print maxnum lastIndex = [index for (index, v) in enumerate(lastNames) if len(v) == maxnum] print "first name with most last names is:" What is the last line of code? compsci 101, fall 2016

Another way – list of lists First word in each list is a first name The rest are last names. [ ‘Susan’, ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’]’ [‘Jackie’, ‘Long’, ‘Johnson’]’ 1 [‘Mary’, ‘White’,’Rodger’,’Velios’]’ 2 [ ‘Eric’, ‘Long’, ‘Lund’]’ 3 Another way to do it. What would change? How you process the data? Can you find the max size list still? yes [ ‘Jack’, ‘Frost’]’ 4 compsci 101, fall 2016

Expanding the Problem Suppose we want to read from multiple data files names1.txt, names2.txt, names3.txt See processFiles in popular.py compsci 101, fall 2016