20
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring15 1

CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Embed Size (px)

Citation preview

Page 1: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

CompSci 101Introduction to Computer Science

March 3, 2015

Prof. Rodger

compsci101 spring15 1

Page 2: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Announcements• Reading and RQ 12 for next time• Assignment 5 due Thursday• APT 5 due today, APT 6 due March 17

compsci101 spring15 2

Page 3: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Set Operations from picturesbit.ly/101S15-0303-01

Question: Which operation does the red represent?

E)

A)

B)

C) D)

compsci101 spring15 3

Page 4: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Problems – snarf setExample.py

• Given a list of strings that have the name of a course (one word), followed by last names of people in the course:– Convert list into lists of strings of names for

each course– Find total number of people taking any course– Find number of people taking just one course

["econ101 Abroms Curtson Williams Smith”,

"history230 Black Wrigley Smith”, … ]compsci101 spring15 4

Page 5: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Data for example

[“compsci101 Smith Ye Li Lin Abroms Black“,

“math101 Green Wei Lin Williams DeLong

Noell, Ye, Smith”,

“econ101 Abroms Curtson Williams Smith”,

“french1 Wills Wrigley Olson Lee”,

"history230 Black Wrigley Smith” ]

compsci101 spring15 5

Page 6: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

Set Picture of Data

compsci101 spring15 6

Page 7: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

People in CompSci 101

compsci101 spring15 7

Page 8: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

People Taking both MathAnd CompSci

Intersection

compsci101 spring15 8

Page 9: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Part 1 – processListbit.ly/101S15-0303-02

• Given a list of strings that have the name of a course (one word), followed by last names of people in the course:– Convert list into lists of strings of names for

each course

["econ101 Abroms Curtson Williams Smith",

"history230 Black Wrigley Smith", … ]

[[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’, …]]

compsci101 spring15 9

Page 10: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Part 2 – peopleTakingCoursesbit.ly/S15-0303-03

• Given a list of lists of names, each list represents the people in one course:– Find total number of people taking any course

• Small Example

[[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’]]

Answer is 6 unique names

compsci101 spring15 10

Page 11: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

People taking Courses - Union

TotalNumberIs17unique names

compsci101 spring15 11

Page 12: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Next, find the number of people taking just one course

compsci101 spring15 12

Page 13: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

Union all sets But French1

compsci101 spring15 13

Page 14: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

To solve this problem

• First let’s write a helper function

compsci101 spring15 14

Page 15: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Part 3 – unionAllSetsButMebit.ly/101S15-0303-04

• Given example, a list of sets of strings, and the index of one of the sets, return the union of all the sets but that one

example = [set(["a", "b", "c"]), set(["b", "c", "d", "g"]), set(["e", "d", "a"])]

unionAllSetsButMe(example,1) is

set(["a", "b", "c", "e", "d" ])

15

Page 16: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Part 4 – peopleTakingOnlyOneCoursebit.ly/101S15-0303-05

• Given a list of lists of strings of names representing people from courses– Find number of people taking just one course

[[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’, ‘Abroms’]]

4

compsci101 spring15 16

Page 17: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Smith

COMPSCI101

MATH101

ECON101

HISTORY230

FRENCH1

Green

Ye

Li

Black

Lee Olson

Wills

Wrigley

Abroms

Williams

Curtson

Lin

WeiYavatkar

Delong

Noell

People taking Only one course

compsci101 spring15 17

Page 18: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

APT - UniqueZoo

• How do you solve this problem?• How is it similar to the problem we just

solved

compsci101 spring15 18

Page 19: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

Example Data for UniqueZoo

["zebra bear fox elephant","bear crocodile fox",

"rhino elephant crocodile kangaroo", "elephant bear"]

zebra

elephant

fox

bear

kangaroorhino

crocodile

compsci101 spring15 19

Page 20: CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151

UniqueZoo – two zoos have unique animals

zebra

elephant

fox

bear

kangaroorhino

crocodile

compsci101 spring15 20