Tracking Rumors. Suppose that we want to track gossip in a rumor mill

Similar documents
Tracking Rumors. Tracking Rumors. Representing Rumor Mills. Representing Rumor Mills. Suppose that we want to track gossip in a rumor mill

How to Design Programs

Wednesday, November 5

Outline. Helper Functions and Reuse. Conditionals. Evaluation Rules for cond. Design Recipe with cond. Compound Data

From Scheme to Java. So far, we ve translated data definitions: ; A snake is ; (make-snake sym num sym) (define-struct snake (name weight food))

ormap, andmap, and filter

CS115 - Module 3 - Booleans, Conditionals, and Symbols

Outline. Data Definitions and Templates Syntax and Semantics Defensive Programming

Text Input and Conditionals

Module 5: Lists. Readings: HtDP, Sections 9, 10.

Control Structures: The IF statement!

CS115 - Module 4 - Compound data: structures

Graphs. Directed graphs. Readings: Section 28

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1

CS131 Typed Lambda Calculus Worksheet Due Thursday, April 19th

Functions in Scheme. From Scheme to Java. Functions in Java. Functions in Java. method that is in the class // Determines whether it s < n lbs

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS115 - Module 8 - Binary trees

Lecture 31: Graph Search & Game 10:00 AM, Nov 16, 2018

Module 3: New types of data

Conditionals and Recursion. Python Part 4

Lists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

The story so far. Elements of Programming Languages. Pairs in various languages. Pairs

MetacircularScheme! (a variant of lisp)

CIS 120 Midterm I February 16, 2015 SOLUTIONS

CSE341 Spring 2016, Midterm Examination April 29, 2016

COMP1730/COMP6730 Programming for Scientists. Testing and Debugging.

Module 9: Trees. If you have not already, make sure you. Read How to Design Programs Sections 14, 15, CS 115 Module 9: Trees

Racket Style Guide Fall 2017

CS 1101 Exam 3 A-Term 2013

From FP to OOP. Start with data: class Posn { int x; int y; Posn(int x, int y) { this.x = x; this.y = y; } }

Documentation for LISP in BASIC

What is Iteration? CMPT-101. Recursion. Understanding Recursion. The Function Header and Documentation. Recursively Adding Numbers

5. Control Statements

CSE341 Spring 2016, Midterm Examination April 29, 2016

CS115 - Module 10 - General Trees

ENGI 1020 Introduction to Computer Programming J U L Y 5, R E Z A S H A H I D I

Module 8: Local and functional abstraction

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Module 8: Binary trees

Intro. Scheme Basics. scm> 5 5. scm>

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

X X C 1. Recap. CSE 486/586 Distributed Systems Gossiping. Eager vs. Lazy Replication. Recall: Passive Replication. Fault-Tolerance and Scalability

Comp 151. Control structures.

A linked list grows as data is added to it. In a linked list each item is packaged into a node.

Chapter 20: Binary Trees

Case Study: Undefined Variables

Data Structures And Algorithms

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

Introduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017

Exam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011

Lesson 7: Graphics (cont) Ricardo Salazar, Pic 10A

CS 2316 Exam 1 Spring 2014

Module 9: Binary trees

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College September 13, 2018

A Third Look At ML. Chapter Nine Modern Programming Languages, 2nd ed. 1

Trees. Readings: HtDP, sections 14, 15, 16.

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller

Local defini1ons. Func1on mul1ples- of

CS 5010 Program Design Paradigms Lesson 6.1

More About Recursive Data Types

Unit 7. 'while' Loops

The design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used)

CS 432 Fall Mike Lam, Professor. Code Generation

COMP-520 GoLite Tutorial

P Is Not Equal to NP. ScholarlyCommons. University of Pennsylvania. Jon Freeman University of Pennsylvania. October 1989

Computer Programming. Basic Control Flow - Decisions. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

CS 320: Concepts of Programming Languages

CMPSCI 521/621 Homework 2 Solutions

CS1102: Macros and Recursion

Software Testing. Lecturer: Sebastian Coope Ashton Building, Room G.18

Module 08: Searching and Sorting Algorithms

Introduction to Programming in C Department of Computer Science and Engineering

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

The Stack ADT. Stacks. The Stack ADT. The Stack ADT. Set of objects in which the location an item is inserted and deleted is prespecified.

Backtracking and Branch-and-Bound

Control Flow. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 21

Conditional Expressions and Decision Statements

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Distributed System Engineering: Spring Exam I

CMSC 336: Type Systems for Programming Languages Lecture 5: Simply Typed Lambda Calculus Acar & Ahmed January 24, 2008

Types, Expressions, and States

Announcements. HW 0 due tonight (check that it compiles on CSE labs) (make sure you submit the code part)

Lab 4: N-Element FIFOs 6.175: Constructive Computer Architecture Fall 2014

CSE 486/586 Distributed Systems

CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018

Programming Languages Fall 2014

Synchronization. Before We Begin. Synchronization. Example of a Race Condition. CSE 120: Principles of Operating Systems. Lecture 4.

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

Typing Data. Chapter Recursive Types Declaring Recursive Types

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

Suggested Solutions (Midterm Exam October 27, 2005)

6.001 Notes: Section 8.1

Algorithm Design And Analysis Asst. Prof. Ali Kadhum Idrees The Sum-of-Subsets Problem Department of Computer Science College of Science for Women

Lecture Notes CPSC 122 (Fall 2014) Today Quiz 7 Doubly Linked Lists (Unsorted) List ADT Assignments Program 8 and Reading 6 out S.

CS1102: What is a Programming Language?

Transcription:

Tracking Rumors Suppose that we want to track gossip in a rumor mill 1

Tracking Rumors Suppose that we want to track gossip in a rumor mill Seiichi 2

Tracking Rumors Suppose that we want to track gossip in a rumor mill Seiichi 3

Tracking Rumors Suppose that we want to track gossip in a rumor mill Mike Seiichi Lindsey 4

Tracking Rumors Suppose that we want to track gossip in a rumor mill Mike Seiichi Amir Lindsey Derrick 5

Tracking Rumors Suppose that we want to track gossip in a rumor mill Mike Seiichi Amir Joseph Lindsey Derrick 6

Tracking Rumors Simplifying assumption: each person tells at most two others Mike Seiichi Amir Joseph Lindsey Derrick 7

Tracking Rumors Simplifying assumption: each person tells at most two others Mike Seiichi Amir Joseph Lindsey Derrick 8

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick Is a rumor mill simply a list of people? 9

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick Is a rumor mill simply a list of people? No, because there are relationships among people 10

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick How about this?: ; A person is ; (make-person image person person)) 11

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick How about this?: ; A person is ; (make-person image person person)) No, because some people don t gossip to anyone else or they gossip to an empty rumor mill... 12

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick How about this?: ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (define-struct gossip (who next1 next2)) 13

Representing Rumor Mills Mike Seiichi Amir Joseph Lindsey Derrick How about this?: ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (define-struct gossip (who next1 next2)) This looks promising... 14

Example Rumor Mills ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) empty 15

Example Rumor Mills ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (make-gossip empty empty) Joseph 16

Example Rumor Mills ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (make-gossip empty (make-gossip empty empty)) Amir Joseph 17

Example Rumor Mills ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (make-gossip (make-gossip empty empty) (make-gossip (make-gossip empty (make-gossip empty empty)) (make-gossip empty empty))) Mike Seiichi Amir Joseph Lindsey Derrick 18

Example Using Abbreviations (define joseph-mill (make-gossip empty empty)) (define amir-mill (make-gossip empty joseph-mill)) (define derrick-mill (make-gossip empty empty)) (define lindsey-mill (make-gossip amir-mill derrick-mill)) (define mike-mill (make-gossip empty empty)) (define seiichi-mill (make-gossip mike-mill lindsey-mill)) 19

Programming with Rumors ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) 20

Programming with Rumors ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) 21

Programming with Rumors ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (define (func-for-rumor-mill rm) (cond [(empty? rm)...] [(gossip? rm)... (gossip-who rm)... (func-for-rumor-mill (gossip-next1 rm))... (func-for-rumor-mill (gossip-next2 rm))...])) 22

Programming with Rumors ; A rumor-mill is either ; - empty ; - (make-gossip image rumor-mill rumor-mill)) (define (func-for-rumor-mill rm) (cond [(empty? rm)...] [(gossip? rm)... (gossip-who rm)... (func-for-rumor-mill (gossip-next1 rm))... (func-for-rumor-mill (gossip-next2 rm))...])) 23

Rumor Program Examples Implement the function informed? which takes a person image and a rumor mill and determines whether the person is part of the rumor mill Implement rumor-delay which takes a rumor mill and determines the maximum number of days required for a rumor to reach everyone, assuming that each person waits a day before passing on a rumor Implement add-gossip which takes a rumor mill and two person images one new and one old and adds the new person to the rumor mill, receiving rumors from the old person; the old person must not already have two next persons Implement rumor-chain which takes a person image and a rumor mill and returns a list of person images representing everyone who must pass on the rumor for it to reach the given person; return false if the given person is never informed 24

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch 25

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch 26

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch 27

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch 28

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch 29

More Pipes In the Mid-Term I example, we had all straight pipes in a pipeline Real pipes end in faucets (open or closed) and sometimes branch ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (define-struct straight (kind next)) (define-struct branch (next1 next2)) 30

Example Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) false 31

Example Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) true 32

Example Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-straight copper false) 33

Example Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-straight copper (make-straight lead false)) 34

Example Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (make-branch (make-branch (make-straight copper true) false) (make-branch false false)) 35

Programming with Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) 36

Programming with Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) 37

Programming with Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (define (func-for-pipeline pl) (cond [(boolean? pl)...] [(straight? pl)... (straight-kind pl)... (func-for-pipeline (straight-next pl))...] [(branch? pl)... (func-for-pipeline (branch-next1 pl))... (func-for-pipeline (branch-next2 pl))...])) 38

Programming with Pipelines ; A pipeline is either ; - bool ; - (make-straight sym pipeline) ; - (make-branch pipeline pipeline) (define (func-for-pipeline pl) (cond [(boolean? pl)...] [(straight? pl)... (straight-kind pl)... (func-for-pipeline (straight-next pl))...] [(branch? pl)... (func-for-pipeline (branch-next1 pl))... (func-for-pipeline (branch-next2 pl))...])) 39

Pipeline Examples Implement the function water-running? which takes a pipeline and determines whether any faucets are open Implement the function modernize which takes a pipeline and converts all lead straight pipes to copper Implement the function off which takes a pipeline and turns off all the faucets Implement the function lead-off which takes a pipeline and turns off all the faucets that receive water through a lead pipe Implement the function twice-as-long which takes a pipeline and inserts a copper straight pipe before every existing piece of the pipeline 40