Comp Sci 101 Introduction to Computer Science March

  • Slides: 20
Download presentation
Comp. Sci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci 101

Comp. Sci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci 101 spring 15 1

Announcements • Reading and RQ 12 for next time • Assignment 5 due Thursday

Announcements • Reading and RQ 12 for next time • Assignment 5 due Thursday • APT 5 due today, APT 6 due March 17 compsci 101 spring 15 2

Set Operations from pictures bit. ly/101 S 15 -0303 -01 Question: Which operation does

Set Operations from pictures bit. ly/101 S 15 -0303 -01 Question: Which operation does the red represent? A) C) D) B) E) compsci 101 spring 15 3

Problems – snarf set. Example. py • Given a list of strings that have

Problems – snarf set. Example. 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 ["econ 101 Abroms Curtson Williams Smith”, "history 230 Black Wrigley Smith”, … ] compsci 101 spring 15 4

Data for example [“compsci 101 Smith Ye Li Lin Abroms Black“, “math 101 Green

Data for example [“compsci 101 Smith Ye Li Lin Abroms Black“, “math 101 Green Wei Lin Williams De. Long Noell, Ye, Smith”, “econ 101 Abroms Curtson Williams Smith”, “french 1 Wills Wrigley Olson Lee”, "history 230 Black Wrigley Smith” ] compsci 101 spring 15 5

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green Noell Wei Delong Yavatkar Black Wrigley HISTORY 230 Set Picture of Data FRENCH 1 Wills Lee Olson compsci 101 spring 15 6

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green Noell Wei Delong Yavatkar Black Wrigley HISTORY 230 People in Comp. Sci 101 FRENCH 1 Wills Lee Olson compsci 101 spring 15 7

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Intersection People Taking both Math And

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Intersection People Taking both Math And Comp. Sci Ye Lin Smith Green Noell Wei Delong Yavatkar Black Wrigley HISTORY 230 MATH 101 FRENCH 1 Wills Lee Olson compsci 101 spring 15 8

Part 1 – process. List bit. ly/101 S 15 -0303 -02 • Given a

Part 1 – process. List bit. ly/101 S 15 -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 ["econ 101 Abroms Curtson Williams Smith", "history 230 Black Wrigley Smith", … ] [[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’, …]] compsci 101 spring 15 9

Part 2 – people. Taking. Courses bit. ly/S 15 -0303 -03 • Given a

Part 2 – people. Taking. Courses bit. ly/S 15 -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 compsci 101 spring 15 10

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith Wrigley HISTORY 230

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith Wrigley HISTORY 230 MATH 101 Green Noell Wei Delong Yavatkar Black Total Number Is 17 unique names People taking Courses - Union FRENCH 1 Wills Lee Olson compsci 101 spring 15 11

Next, find the number of people taking just one course compsci 101 spring 15

Next, find the number of people taking just one course compsci 101 spring 15 12

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green Noell Wei Delong Yavatkar Black Wrigley HISTORY 230 Union all sets But French 1 FRENCH 1 Wills Lee Olson compsci 101 spring 15 13

To solve this problem • First let’s write a helper function compsci 101 spring

To solve this problem • First let’s write a helper function compsci 101 spring 15 14

Part 3 – union. All. Sets. But. Me bit. ly/101 S 15 -0303 -04

Part 3 – union. All. Sets. But. Me bit. ly/101 S 15 -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"])] union. All. Sets. But. Me(example, 1) is set(["a", "b", "c", "e", "d" ]) 15

Part 4 – people. Taking. Only. One. Course bit. ly/101 S 15 -0303 -05

Part 4 – people. Taking. Only. One. Course bit. ly/101 S 15 -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 compsci 101 spring 15 16

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green

COMPSCI 101 ECON 101 Li Abroms Curtson Williams Ye Lin Smith MATH 101 Green Noell Wei Delong Yavatkar Black Wrigley HISTORY 230 People taking Only one course FRENCH 1 Wills Lee Olson compsci 101 spring 15 17

APT - Unique. Zoo • How do you solve this problem? • How is

APT - Unique. Zoo • How do you solve this problem? • How is it similar to the problem we just solved compsci 101 spring 15 18

Example Data for Unique. Zoo ["zebra bear fox elephant", "bear crocodile fox", "rhino elephant

Example Data for Unique. Zoo ["zebra bear fox elephant", "bear crocodile fox", "rhino elephant crocodile kangaroo", "elephant bear"] fox zebra bear crocodile elephant rhino kangaroo compsci 101 spring 15 19

Unique. Zoo – two zoos have unique animals fox zebra bear crocodile elephant rhino

Unique. Zoo – two zoos have unique animals fox zebra bear crocodile elephant rhino kangaroo compsci 101 spring 15 20