103
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Embed Size (px)

Citation preview

Page 1: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Page 2: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Announcements

Next Week: OpenData Showcase: 28 March,4:30-6pm (rescheduled due to snow).

Each lecture includes a survey of computingresearch and tech in NYC.

Today: Mitsue IwataNYC OpenData InitiativeMayor’s Office

CSci 127 (Hunter) Lecture 7 21 March 2018 2 / 26

Page 3: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 4: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!

No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 5: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 6: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?

The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 7: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 8: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!

We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 9: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 10: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.

I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 11: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.

I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 12: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.

I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 13: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 14: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 15: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.

I Tech Meetups: focused on just about everything tech(both via CUNY and city-wide).

I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 16: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).

I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 17: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Frequently Asked QuestionsFrom lecture slips & recitation sections.

I didn’t get the tree-based networks from last time!No worries– we’ll talk about it first.

Why do we have design questions (like the tree-based one)?The design questions cover two of the course’s learning objectives: exposure toadvanced computer science topics & problem solving.

Please, more time on circuits/logical expressions/truth tables/decisions!We will do a bit today, but much more in the following weeks.

Why is the schedule of classes and quizzes so crazy?

I Lots of holidays has “our week” now starting on Wednesday.I Spring Break is Friday, 30 March to Sunday, 8 April.I Since we’ll miss 2 Fridays, 11 April will follow Friday schedule.I After spring break, “our week” will start on Thursdays.

I’d like to do more. Any suggestions?

I Hunter has an ACM Chapter & Women in CS clubs.I Tech Meetups: focused on just about everything tech

(both via CUNY and city-wide).I Internships: https://jobs.lever.co/cunyinternships

CSci 127 (Hunter) Lecture 7 21 March 2018 3 / 26

Page 18: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Today’s Topics

Recap: Tree-based Networks

Introduction to Functions

NYC Open Data

CSci 127 (Hunter) Lecture 7 21 March 2018 4 / 26

Page 19: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Tree-Based Networks

Haekel List et al., 2013 Network Highlighted Tree

Evolutionary history can be represented by a tree.

Events like hybridization can cause non-tree-like networks.

Is there a tree on which the network is based?That is, can you start with a tree and only add lines between theoriginal tree edges.

CSci 127 (Hunter) Lecture 7 21 March 2018 5 / 26

Page 20: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Tree-Based Networks

Haekel List et al., 2013 Network Highlighted Tree

Evolutionary history can be represented by a tree.

Events like hybridization can cause non-tree-like networks.

Is there a tree on which the network is based?That is, can you start with a tree and only add lines between theoriginal tree edges.

CSci 127 (Hunter) Lecture 7 21 March 2018 5 / 26

Page 21: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Tree-Based Networks

Haekel List et al., 2013 Network Highlighted Tree

Evolutionary history can be represented by a tree.

Events like hybridization can cause non-tree-like networks.

Is there a tree on which the network is based?That is, can you start with a tree and only add lines between theoriginal tree edges.

CSci 127 (Hunter) Lecture 7 21 March 2018 5 / 26

Page 22: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Tree-Based Networks

Haekel List et al., 2013 Network Highlighted Tree

Evolutionary history can be represented by a tree.

Events like hybridization can cause non-tree-like networks.

Is there a tree on which the network is based?That is, can you start with a tree and only add lines between theoriginal tree edges.

CSci 127 (Hunter) Lecture 7 21 March 2018 5 / 26

Page 23: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 24: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 25: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 26: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 27: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).

I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 28: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.

I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 29: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.

I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 30: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the tree

I Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 31: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Tree-based Networks: Lecture Slip

List et al., 2013

When is the network just a tree with edges joining its branches?

Input: A network.

Output: True if the network is tree-based, and false otherwise.

Design:

I Need paths that connect the “root” to the leaves (with no cycles).I Start by highlighting all edges that must be part of the tree.I Then figure out which edges can’t be there and mark those.I What’s left: a bunch of choices on which edge to include in the treeI Becomes a logic puzzle: a logical expression that can be solved.

CSci 127 (Hunter) Lecture 7 21 March 2018 6 / 26

Page 32: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 33: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 34: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 35: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 36: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 37: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 38: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 39: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 40: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 41: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 42: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Tree-Based Networks

First, highlight what must/mustnot be there.

Then, what’s left: can have edgex if edge y isn’t there (and viceversa):

(x and not y) or (not x and y)

Solve the resulting logical puzzle.

CSci 127 (Hunter) Lecture 7 21 March 2018 7 / 26

Page 43: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 44: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 45: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 46: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 47: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 48: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 49: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 8 / 26

Page 50: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

“Hello, World!” with Functions

CSci 127 (Hunter) Lecture 7 21 March 2018 9 / 26

Page 51: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 21 March 2018 10 / 26

Page 52: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

In Pairs or Triples:

1. Predict what the code will do: 2. Fill in the missing code:

CSci 127 (Hunter) Lecture 7 21 March 2018 11 / 26

Page 53: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 21 March 2018 12 / 26

Page 54: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

IDLE

(Demo with IDLE)

CSci 127 (Hunter) Lecture 7 21 March 2018 13 / 26

Page 55: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

In Pairs or Triples:

Predict what the code will do:

CSci 127 (Hunter) Lecture 7 21 March 2018 14 / 26

Page 56: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

IDLE

(Demo with IDLE)

CSci 127 (Hunter) Lecture 7 21 March 2018 15 / 26

Page 57: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 16 / 26

Page 58: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 16 / 26

Page 59: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 16 / 26

Page 60: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 16 / 26

Page 61: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap: Functions

Functions are a way to break code into pieces,that can be easily reused.

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 7 21 March 2018 16 / 26

Page 62: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

In Pairs or Triples:

Predict what the code will do:

CSci 127 (Hunter) Lecture 7 21 March 2018 17 / 26

Page 63: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 7 21 March 2018 18 / 26

Page 64: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 21 March 2018 19 / 26

Page 65: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 21 March 2018 19 / 26

Page 66: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 21 March 2018 19 / 26

Page 67: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 21 March 2018 19 / 26

Page 68: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Accessing Structured Data: NYC Open Data

Freely available source of data.

Maintained by the NYC data analytics team.

We will use several different ones for this class.

Will use pandas, pyplot & folium libraries to analyze, visualize andmap the data.

Lab 7 covers accessing and downloading NYC OpenData datasets.

CSci 127 (Hunter) Lecture 7 21 March 2018 19 / 26

Page 69: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 70: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 71: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 72: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 73: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 74: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Structured Data

Common to have data structured in a spread sheet.

The text file version is called CSV for comma separated values.

Each row is a line; columns are separated by commas.

We will use the popular Python Data Analysis Library (Pandas).

To use, add to the top of your file:

import pandas as pd

To read in a CSV file:myVar = pd.read csv("myFile.csv")

CSci 127 (Hunter) Lecture 7 21 March 2018 20 / 26

Page 75: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Reading in CSV Files

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 7 21 March 2018 21 / 26

Page 76: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Reading in CSV Files

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 7 21 March 2018 21 / 26

Page 77: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Reading in CSV Files

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 7 21 March 2018 21 / 26

Page 78: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Reading in CSV Files

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 7 21 March 2018 21 / 26

Page 79: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Example: Reading in CSV Files

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 7 21 March 2018 21 / 26

Page 80: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Series in Pandas

Series can store a column or row of aDataFrame.

Example: pop["Manhattan"] is the Seriescorresponding to the column of Manhattandata.

Example:print("The largest number living in

the Bronx is", pop["Bronx"].max())

CSci 127 (Hunter) Lecture 7 21 March 2018 22 / 26

Page 81: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Series in Pandas

Series can store a column or row of aDataFrame.

Example: pop["Manhattan"] is the Seriescorresponding to the column of Manhattandata.

Example:print("The largest number living in

the Bronx is", pop["Bronx"].max())

CSci 127 (Hunter) Lecture 7 21 March 2018 22 / 26

Page 82: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Series in Pandas

Series can store a column or row of aDataFrame.

Example: pop["Manhattan"] is the Seriescorresponding to the column of Manhattandata.

Example:print("The largest number living in

the Bronx is", pop["Bronx"].max())

CSci 127 (Hunter) Lecture 7 21 March 2018 22 / 26

Page 83: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

CS Survey: Mitsue Iwata, Data Analytics

Project Manager, NYC Mayor’s Office of Data Analytics

Hunter College, Class of 2014.

MS, Computational Analysis & Public Policy,University of Chicago, 2016.

CSci 127 (Hunter) Lecture 7 21 March 2018 23 / 26

Page 84: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

CS Survey: Mitsue Iwata, Data Analytics

Project Manager, NYC Mayor’s Office of Data Analytics

Hunter College, Class of 2014.

MS, Computational Analysis & Public Policy,University of Chicago, 2016.

CSci 127 (Hunter) Lecture 7 21 March 2018 23 / 26

Page 85: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

CS Survey: Mitsue Iwata, Data Analytics

Project Manager, NYC Mayor’s Office of Data Analytics

Hunter College, Class of 2014.

MS, Computational Analysis & Public Policy,University of Chicago, 2016.

CSci 127 (Hunter) Lecture 7 21 March 2018 23 / 26

Page 86: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.(Design only the pseudocode.)

CSci 127 (Hunter) Lecture 7 21 March 2018 24 / 26

Page 87: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.(Design only the pseudocode.)

CSci 127 (Hunter) Lecture 7 21 March 2018 24 / 26

Page 88: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 89: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 90: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 91: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 92: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 93: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).

2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 94: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.

3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 95: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.

4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 96: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.

5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 97: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Design Question

Design an algorithm that uses NYC OpenData collision data and computesthe closest collision to the location the user provides.

How to approach this:

Create a “To Do” list of what your program has to accomplish.

Read through the problem, and break it into “To Do” items.

Don’t worry if you don’t know how to do all the items you write down.

Example:

1 Find data set (great place to look: NYC OpenData).2 Ask user for current location.3 Open up the CSV file.4 Check distance to each to user’s location.5 Save the location with the smallest distance.

CSci 127 (Hunter) Lecture 7 21 March 2018 25 / 26

Page 98: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26

Page 99: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26

Page 100: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26

Page 101: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26

Page 102: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26

Page 103: CSci 127: Introduction to Computer Science · 2018-05-26 · CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 7 21 March 2018 1 / 26

Recap

On lecture slip, write down a topic youwish we had spent more time (and why).

Functions are a way to break code intopieces, that can be easily reused.

You call or invoke a function by typingits name, followed by any inputs,surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

Accessing Formatted Data: NYCOpenData

CSci 127 (Hunter) Lecture 7 21 March 2018 26 / 26