Assignment: 7. Due: Language level: Allowed recursion:

Size: px
Start display at page:

Download "Assignment: 7. Due: Language level: Allowed recursion:"

Transcription

1 Assignment: 7 Due: Language level: Allowed recursion: CS 135 Winter 2018 Graham, Nijjar Tuesday, March 13th, :00pm Beginning Student with List Abbreviations Pure Structural and Structural Recursion with an Accumulator, unless otherwise specified filedir.rkt, binencoding.rkt, encodingbonus.rkt Files to submit: Warmup exercises: HtDP , , , , , , , , Practice exercises: HtDP , , , , , Make sure you read the OFFICIAL A07 post on Piazza for the answers to frequently asked questions. Unless stated otherwise, all policies from Assignment 06 carry forward. You may use the following list functions and constants: cons, cons?, empty, empty?, first, second, third, rest, list, append, length, string->list, list->string. You may not use reverse unless specified in the question. Some correctness marks will be allocated for avoiding exponential blowups, as demonstrated by the max-list example in slide (But note that not every repeated function invocation leads to an exponential blowup.) You may not use local in this assignment. Sorry. 1. Note: For this question, you must use the provided a07lib.rkt file, which includes the structure definitions, data definitions, some sample data, and some functions to display data. To make use of these definitions and functions, you must place the a07lib.rkt file in the same directory (folder) as your assignment file for Question 1. At the beginning of your filedir.rkt, include the following: (require "a07lib.rkt") As a test, in your assignment file, try using the function (fs-print sample-fs) in a file that you have saved, which uses the provided print function to display the information in the Dir that has been consumed. You may reuse the examples provided in the question specifications below or our sample data from a07lib.rkt, but you should ensure you have an appropriate number of examples and tests. The structure definitions for a dir and a filedata are defined in the a07lib.rkt file so you must not include them in your file. It will cause an error if you try to include a structure CS 135 Winter 2018 Assignment 7 1

2 definition using define-struct in your own file, as they are already defined in a07lib.rkt. If you want to include the structure definitions in your file for easy reference, be sure to have them commented out in your code. For this question you will we working with files and directories similar to those you saw in A05. However, in this case the directory structure will be represented by a general tree. We call this tree a file system. The file data structure no longer requires a path as one of its fields, since the path of the file will be determined by its location within the tree. We will use the following data definitions for representing a file system (file tree) on a computer. Note that file names and directory names may be repeated in multiple places within the tree, but pathnames must be unique. A name of a directory may be the same as the name of a file. Do not include the define-struct in your file as code (comment it out, see above note): (define-struct dir (name contents)) ;; A Dir is a (make-dir Str FDList) ;; An FDList is one of: ;; * empty ;; * (cons File/Dir FDList) ;; requires: full names of files (name and format) within a ;; given directory must be unique ;; names of directories within a given directory must be unique ;; A File/Dir is one of: ;; * FileData ;; * Dir (define-struct filedata (name format size)) ;; A FileData is a (make-filedata Str Sym Num) ;; requires: ;; name is a non-empty string ;; that contains only alphanumeric characters ;; format is one of 'doc, 'txt, 'rtf, 'zip, ;; 'raw, 'jpg, 'wav, 'mp3 ;; size > 0, and represents the size of the file in kilobytes The following constant definitions are used in the question specifications below. (define file1 (make-filedata "oldfile" txt 1)) (define file2 (make-filedata "newfile" doc 10)) (define dir0 (make-dir "emptydir" empty)) (define dir1 (make-dir "onefile" (list file1))) (define dir1a (make-dir "onefilea" (list file1))) (define dir1b (make-dir "onefileb" (list file1))) (define dir2 (make-dir "twofiles" (list file1 file2))) (define dir2b (make-dir "twofiles" (list file1))) (define dir3 (make-dir "onesies" (list dir1 dir1a dir1b))) (define fs1 (make-dir "rootdir" (list file1 dir0 dir1 dir2 dir3 file2))) (define fs2 (make-dir "u" (list file2 dir0 dir1))) Place your solutions in filedir.rkt. CS 135 Winter 2018 Assignment 7 2

3 (a) Provide templates for FileData, Dir, File/Dir and FDList. (b) Write a function count-files that consumes a Dir and produces the total number of files in the entire file system tree. For example, (count-files dir0) produces 0, (count-files dir3) produces 3, and (count-files fs1) produces 8. (c) A directory is empty if it does not contain any sub-directory or file. Write a function empty-dir-exist? that consumes a Dir and produces true if an empty directory exists anywhere in the tree and produces false otherwise. (d) Write a function largest-filesize that consumes a Dir and produces the size of the largest FileData in the in the entire tree, or zero if there are no files. (e) Every file and directory in a file system has a hierarchical name. For a target file or directory fd, the hierarchical name consists of the names of all the ancestor directories one must traverse to reach fd, with the names separated by slashes (/). There is also a slash at the beginning of every file s hierarchical name. Write a function list-file-paths that consumes a Dir and produces a (listof Str) that contains the hierarchical names for all of the files in the entire file system. The function should produce the files hierarchical names in the same order as generated by the provided fs-print function. You may use string-append in this question. For example, (list-file-paths fs2) produces (list "/u/newfile" "/u/onefile/oldfile"). (f) Write a function backup-fs that consumes a Dir and a Sym representing a file s format and produces a Dir containing only the files whose format matches the consumed symbol. Note that some of the directories of the file system will be empty if they only contained files that did not match the format being being backed up. The backup Dir should have the same directory structure as the consumed Dir except any directory that contains no files and no subdirectories should be removed. If there are no files to be backed up, the backup Dir should have an empty FDList. For example, (backup-fs fs1 txt) will produce (make-dir "rootdir"(list file1 dir1 dir2b dir3)). 2. All information stored in a computer, characters, pixels, sound, etc., is represented by a sequence of zeros and ones, known as a binary code. Each zero or one is known as a bit. There are many different encoding schemes used by computer applications to represent data. In some applications, the binary codes for different data values are all the same length. ASCII is an example of this type of encoding, where each character on a standard English keyboard is represented by an 8-bit code. For example an A is represented by the ASCII code Other applications may use encoding schemes where the codes for the data are different lengths. For example, you might represent an A with the code 1011 and represent a B with the code This question will have you working with binary encodings of characters where the codes have variable lengths. CS 135 Winter 2018 Assignment 7 3

4 One way to assign variable length, binary codes to characters is to use a binary, leaf-labelled tree. The leaves of the tree contain characters you want to represent. A binary encoding of a character is determined by following a path from the root of the tree to the leaf that contains that character. As you follow the path, when you take a left branch that represents a 0 in the code, and when you take a right branch that represents a 1 in the code. For example, consider the binary tree that has the leaves with values #\A, #\B, #\C, and #\space. #\space #\C #\A #\B Given this tree, the character encodings are as follows: Character Encoding #\A 100 #\B 101 #\C 11 #\space 0 For this question you will work with the following data definitions: ;; An EncodingTree is a tree with at least two leaf nodes, and is one of: ;; * a Char ;; * (list EncodingTree EncodingTree) ;; In addition, an EncodingTree has the following properties: ;; * the internal nodes of an EncodingTree always have exactly ;; two children ;; * the leaf node values are unique, ;; i.e. there will be no duplicate values in the tree. ;; A BinaryCode is a non-empty string that contains ;; only the characters #\0 and #\1. A starter file (binencoding.rkt) has been provided for you that includes the data definitions described above, as well as some constants that may be used for some of your tests and examples. It is a good idea to draw the trees that are represented by the constants, on paper, so it is easier to predict the expected values produced by your functions as you test them. CS 135 Winter 2018 Assignment 7 4

5 Place your solutions in binencoding.rkt. (a) Write a function called max-code-length that consumes a EncodingTree and produces a Nat which is the length of the longest code for any of the characters in the EncodingTree. For example (max-code-length big-nlt) produces 5, and (max-code-length (list #\q #\z)) produces 1. (b) Write a function called bincode->char that consumes a BinaryCode and an EncodingTree in that order. The function should produce the Char that is determined by the BinaryCode value and the EncodingTree. If the path represented by the BinaryCode does not exist in the EncodingTree, or following the path indicated by the code ends at an internal node of the tree, the function should produce the symbol Error. For example, if you were using the tree in the diagram above, bincode->char for the code "100" would produce #\A, but bincode->char for the code "10" would produce Error, and bincode->char for the code "01" would produce Error. (c) Write a function called decode-msg that consumes a BinaryCode and an EncodingTree in that order. The function should produce either a string that is formed by the characters represented in the BinaryCode, or should produce the symbol Error if it is not possible to decode the message with the given EncodingTree. For example (decode-msg big-binary-code big-nlt) would produce "The cat in the hat.", and (decode-msg "101101" 7-char-nlt) would produce Error. Notes: This solution may be done using generative recursion. It can be completed with a single, relatively small (< 20 lines) helper function with a carefully selected set of parameters. If you are finding yourself writing many and/or large functions to solve this problem, then you should rethink your approach. The function bincode->char may not be directly useful as a helper function here. However, a modified version could be very useful. (d) Write a function called encode-msg that consumes a Str and an EncodingTree in that order. The function should produce a BinaryCode that is formed by concatenating the BinaryCode values of the individual characters of the consumed Str. You may assume that all of the characters in the Str appear in the EncodingTree. If the string consumed is empty, the function should produce the empty string. For example, (encode-msg "The cat in the hat." big-nlt) produces big-binary-code. This concludes the list of questions for which you need to submit solutions. As always, do not forget to check your for the basic test results after making a submission. 2% Bonus: For this question place your solution in the file encodingbonus.rkt. This question is an extension of question 2 on the assignment. You may use any of the code you have written for that question in your solution for the bonus question. CS 135 Winter 2018 Assignment 7 5

6 The encoding scheme described in question 2, can be used to compress files. For example, suppose we had a file that contained 10 different characters, and we were using a fixed-length binary code to represent those characters. The code length would have to be at least four bits (a 0 or 1) to generate enough unique codes to represent the different values in the file. Note that there are 16 different 4-bit codes. Now suppose that in that file, one of the characters appears 60 times, another character appears 32 times, and the other eight characters each appear once. Using the 4-bit encoding, this would mean we need 100*4, or 400 bits in total to represent all of the characters in the file. However, if we assigned a 1-bit code to the most frequent character in the file, a 2-bit code to the second most frequent character, and a 5-bit code to each of the other characters, we would have a total of (1*60) + (2*32) + (5*8), or 164 bits to represent all of the characters in the file. A compression ratio is the ratio of the total number of bits required to encode the entire file using the variable-length coding scheme, divided by the total number of bits required using the fixed-length encoding scheme. In the example above the compression ratio would be 164/400, or A smaller number means better compression. Note that you can compress files that contain data other than characters. For example JPEG is a way of compressing digital image files, and MP3 is a way of compressing sound files. You could use an EncodingTree to generate binary codes for any type of data, not just characters. To create these codes, the different data values in the file (for example the colour of a pixel) would appear as the values in the leaf nodes of the tree. Write a function called compression-ratio that consumes an EncodingTree and a non-empty association list in that order. The keys in the association list are the same type as the data found in the leaves of the EncodingTree, and each associated value in the list is a Nat greater than 0. In the association list, the key represents a unique data value that occurs in a file, and the Nat is the frequency (i.e. number of occurrences) of that data value in the file. The function compression-ratio will produce the compression ratio that is achieved by taking the total number of bits required by the variable length codes generated by the EncodingTree to represent all of the data in the file, divided by the total number of bits required by a fixed-length encoding scheme on the same data. The minimum number of bits required for a single, fixed-length code will depend on the number of different data values that appear in the file. You will need to figure out how to compute this number based on the values consumed by the function. You may assume that all keys in the association list appear in the EncodingTree. Enhancements: Reminder enhancements are for your interest and are not to be handed in. The material below first explores the implications of the fact that Racket programs can be viewed as Racket data, before reaching back seventy years to work which is at the root of both the Scheme language and of computer science itself. The text introduces structures as a gentle way to talk about aggregated data, but anything that can be done with structures can also be done with lists. Section 14.4 of HtDP introduces a representation CS 135 Winter 2018 Assignment 7 6

7 of Scheme expressions using structures, so that the expression (+ ( 3 3) ( 4 4)) is represented as (make-add (make-mul 3 3) (make-mul 4 4)) But, as discussed in lecture, we can just represent it as the hierarchical list (+ ( 3 3) ( 4 4)). Scheme even provides a built-in function eval which will interpret such a list as a Scheme expression and evaluate it. Thus a Scheme program can construct another Scheme program on the fly, and run it. This is a very powerful (and consequently somewhat dangerous) technique. Sections 14.4 and 17.7 of HtDP give a bit of a hint as to how eval might work, but the development is more awkward because nested structures are not as flexible as hierarchical lists. Here we will use the list representation of Scheme expressions instead. In lecture, we saw how to implement eval for expression trees, which only contain operators such as +,,,/, and do not use constants. Continuing along this line of development, we consider the process of substituting a value for a constant in an expression. For instance, we might substitute the value 3 for x in the expression (+ ( x x) ( y y)) and get the expression (+ ( 3 3) ( y y)). Write the function subst which consumes a symbol (representing a constant), a number (representing its value), and the list representation of a Scheme expression. It should produce the resulting expression. Our next step is to handle function definitions. A function definition can also be represented as a hierarchical list, since it is just a Scheme expression. Write the function interpret-withone-def which consumes the list representation of an argument (a Scheme expression) and the list representation of a function definition. It evaluates the argument, substitutes the value for the function parameter in the function s body, and then evaluates the resulting expression using recursion. This last step is necessary because the function being interpreted may itself be recursive. The next step would be to extend what you have done to the case of multiple function definitions and functions with multiple parameters. You can take this as far as you want; if you follow this path beyond what we ve suggested, you ll end up writing a complete interpreter for Scheme (what you ve learned of it so far, that is) in Scheme. This is treated at length in Section 4 of the classic textbook Structure and Interpretation of Computer Programs, which you can read on the Web in its entirety at So we ll stop making suggestions in this direction and turn to something completely different, namely one of the greatest ideas of computer science. Consider the following function definition, which doesn t correspond to any of our design recipes, but is nonetheless syntactically valid: (define (eternity x) (eternity x)) CS 135 Winter 2018 Assignment 7 7

8 Think about what happens when we try to evaluate (eternity 1) according to the semantics we learned for Scheme. The evaluation never terminates. If an evaluation does eventually stop (as is the case for every other evaluation you will see in this course), we say that it halts. The non-halting evaluation above can easily be detected, as there is no base case in the body of the function eternity. Sometimes non-halting evaluations are more subtle. We d like to be able to write a function halting?, which consumes the list representation of the definition of a function with one parameter, and something meant to be an argument for that function. It produces true if and only if the evaluation of that function with that argument halts. Of course, we want an application of halting? itself to always halt, for any arguments it is provided. This doesn t look easy, but in fact it is provably impossible. Suppose someone provided us with code for halting?. Consider the following function of one argument: (define (diagonal x) (cond [(halting? x x) (eternity 1)] [else true])) What happens when we evaluate an application of diagonal to a list representation of its own definition? Show that if this evaluation halts, then we can show that halting? does not work correctly for all arguments. Show that if this evaluation does not halt, we can draw the same conclusion. As a result, there is no way to write correct code for halting?. This is the celebrated halting problem, which is often cited as the first function proved (by Alan Turing in 1936) to be mathematically definable but uncomputable. However, while this is the simplest and most influential proof of this type, and a major result in computer science, Turing learned after discovering it that a few months earlier someone else had shown another function to be uncomputable. That someone was Alonzo Church, about whom we ll hear more shortly. For a real challenge, definitively answer the question posed at the end of Exercise of the text, with the interpretation that function=? consumes two lists representing the code for the two functions. This is the situation Church considered in his proof. CS 135 Winter 2018 Assignment 7 8

CS115 - Module 10 - General Trees

CS115 - Module 10 - General Trees Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Sections 15 and 16. Arithmetic Expressions Recall with binary trees we could represent an expression containing binary

More information

Working with recursion

Working with recursion Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

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

Trees. Readings: HtDP, sections 14, 15, 16. Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

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

Trees. Binary arithmetic expressions. Visualizing binary arithmetic expressions. ((2 6) + (5 2))/(5 3) can be defined in terms of two smaller Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2).

Working with recursion. From definition to template. Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). Working with recursion Readings: HtDP, sections 11, 12, 13 (Intermezzo 2). We can extend the idea of a self-referential definition to defining the natural numbers, which leads to the use of recursion in

More information

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1

CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees. CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees CS 135 Winter 2018 Tutorial 7: Accumulative Recursion and Binary Trees 1 Goals of this tutorial You should be able to... understand

More information

Module 10: General trees

Module 10: General trees Module 10: General trees Readings: HtDP, Sections 15 and 16 CS 115 Winter 2019 10: General trees 1 General trees Binary trees can be used for a large variety of application areas. One limitation is the

More information

Trees. Example: Binary expression trees. Example: Evolution trees. Readings: HtDP, sections 14, 15, 16.

Trees. Example: Binary expression trees. Example: Evolution trees. Readings: HtDP, sections 14, 15, 16. Trees Readings: HtDP, sections 14, 15, 16. We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

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

Lists. Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter : Lists 1 Lists Readings: HtDP, sections 9 and 10. Avoid 10.3 (uses draw.ss). CS 135 Winter 2018 05: Lists 1 Introducing lists Structures are useful for representing a fixed amount of data. But there are many circumstances

More information

Assignment: 2. CS 135 Winter 2018 Graham, Nijjar

Assignment: 2. CS 135 Winter 2018 Graham, Nijjar Assignment: 2 CS 135 Winter 2018 Graham, Nijjar Due: Tuesday, January 23, 9:00 pm Language level: Beginning Student Files to submit: resistance.rkt, immigration.rkt, fridge-foods.rkt, bonus.rkt Warmup

More information

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1

Types of recursion. Readings: none. In this module: a glimpse of non-structural recursion. CS 135 Winter : Types of recursion 1 Types of recursion Readings: none. In this module: a glimpse of non-structural recursion CS 135 Winter 2018 07: Types of recursion 1 Structural vs. general recursion All of the recursion we have done to

More information

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

Module 9: Trees. If you have not already, make sure you. Read How to Design Programs Sections 14, 15, CS 115 Module 9: Trees Module 9: Trees If you have not already, make sure you Read How to Design Programs Sections 14, 15, 16. 1 CS 115 Module 9: Trees Mathematical Expressions We are going to discuss how to represent mathematical

More information

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

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

Functional abstraction

Functional abstraction Functional abstraction Readings: HtDP, sections 19-24. Language level: Intermediate Student With Lambda different order used in lecture section 24 material introduced much earlier sections 22, 23 not covered

More information

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion

Types of recursion. Structural vs. general recursion. Pure structural recursion. Readings: none. In this module: learn to use accumulative recursion Types of recursion Readings: none. In this module: learn to use accumulative recursion learn to recognize generative recursion CS 135 Fall 2018 07: Types of recursion 1 Structural vs. general recursion

More information

Module 9: Binary trees

Module 9: Binary trees Module 9: Binary trees Readings: HtDP, Section 14 We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

CS 135 Fall 2018 Final Exam Review. CS 135 Fall 2018 Final Exam Review 1

CS 135 Fall 2018 Final Exam Review. CS 135 Fall 2018 Final Exam Review 1 CS 135 Fall 2018 Final Exam Review CS 135 Fall 2018 Final Exam Review 1 Final Exam Information The final exam will be held on Saturday, December 15 th 9:00AM - 11:30AM in the PAC Check your exam seating

More information

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

Module 5: Lists. Readings: HtDP, Sections 9, 10. Module 5: Lists Readings: HtDP, Sections 9, 10. Lists are the main tool used in Racket to work with unbounded data. As with conditional expressions and structures, the data definition for lists leads naturally

More information

CS115 - Module 8 - Binary trees

CS115 - Module 8 - Binary trees Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Section 14. Binary arithmetic expressions Operators such as +,,, and take two arguments, so we call them binary operators.

More information

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31

Generative and accumulative recursion. What is generative recursion? Example revisited: GCD. Readings: Sections 25, 26, 27, 30, 31 Generative and accumulative recursion Readings: Sections 25, 26, 27, 30, 31 Some subsections not explicitly covered in lecture Section 27.2 technique applied to strings CS 135 Fall 2017 11: Generative

More information

Local definitions and lexical scope

Local definitions and lexical scope Local definitions and lexical scope Readings: HtDP, Intermezzo 3 (Section 18). Language level: Intermediate Student CS 135 Winter 2018 09: Local definitions and lexical scope 1 Local definitions The functions

More information

Local definitions and lexical scope. Local definitions. Motivating local definitions. s(s a)(s b)(s c), where s = (a + b + c)/2.

Local definitions and lexical scope. Local definitions. Motivating local definitions. s(s a)(s b)(s c), where s = (a + b + c)/2. Local definitions and lexical scope Readings: HtDP, Intermezzo 3 (Section 18). Language level: Intermediate Student CS 135 Winter 2018 09: Local definitions and lexical scope 1 Local definitions The functions

More information

Module 8: Binary trees

Module 8: Binary trees Module 8: Binary trees Readings: HtDP, Section 14 We will cover the ideas in the text using different examples and different terminology. The readings are still important as an additional source of examples.

More information

Module 8: Local and functional abstraction

Module 8: Local and functional abstraction Module 8: Local and functional abstraction Readings: HtDP, Intermezzo 3 (Section 18); Sections 19-23. We will cover material on functional abstraction in a somewhat different order than the text. We will

More information

Welcome to CS 135 (Winter 2018)

Welcome to CS 135 (Winter 2018) Welcome to CS 135 (Winter 2018) Instructors: Sandy Graham, Paul Nijjar Other course personnel: see website for details ISAs (Instructional Support Assistants) IAs (Instructional Apprentices) ISC (Instructional

More information

Module 10: Imperative Programming, Modularization, and The Future

Module 10: Imperative Programming, Modularization, and The Future Module 10: Imperative Programming, Modularization, and The Future If you have not already, make sure you Read How to Design Programs Sections 18. 1 CS 115 Module 10: Imperative Programming, Modularization,

More information

Graphs. Directed graphs. Readings: Section 28

Graphs. Directed graphs. Readings: Section 28 Graphs Readings: Section 28 CS 135 Winter 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an

More information

CS115 - Module 9 - filter, map, and friends

CS115 - Module 9 - filter, map, and friends Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Intermezzo 3 (Section 18); Sections 19-23. Abstraction abstraction, n. 3a.... The process of isolating properties or

More information

CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local. CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1

CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local. CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1 CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local CS 135 Winter 2018 Tutorial 8: Mutual recursion, nested lists, and local 1 Goals of this tutorial You should be able to... write

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant

More information

ITI Introduction to Computing II

ITI Introduction to Computing II ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Binary search tree (part I) Version of March 24, 2013 Abstract These lecture notes are meant

More information

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

The design recipe. Readings: HtDP, sections 1-5. (ordering of topics is different in lectures, different examples will be used) The design recipe Readings: HtDP, sections 1-5 (ordering of topics is different in lectures, different examples will be used) Survival and Style Guides CS 135 Winter 2018 02: The design recipe 1 Programs

More information

Functions that return lists

Functions that return lists 342 Chapter 23 Functions that return lists If you did exercises 22.5.15 or 22.5.16, you ve already written some functions that return lists, but only in a very simple way: adding one new element to the

More information

Module 3: New types of data

Module 3: New types of data Module 3: New types of data Readings: Sections 4 and 5 of HtDP. A Racket program applies functions to values to compute new values. These new values may in turn be supplied as arguments to other functions.

More information

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g))

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g)) CS61A Notes 02b Fake Plastic Trees Box and Pointer Diagrams QUESTIONS: Evaluate the following, and draw a box-and-pointer diagram for each. (Hint: It may be easier to draw the box-and-pointer diagram first.)

More information

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices. Trees Trees form the most widely used subclasses of graphs. In CS, we make extensive use of trees. Trees are useful in organizing and relating data in databases, file systems and other applications. Formal

More information

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

Graphs. Readings: Section 28. CS 135 Fall : Graphs 1 Graphs Readings: Section 28 CS 135 Fall 2018 12: Graphs 1 Directed graphs A directed graph consists of a collection of vertices (also called nodes) together with a collection of edges. An edge is an ordered

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017 SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

CS115 - Module 4 - Compound data: structures

CS115 - Module 4 - Compound data: structures Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, sections 6-7, omitting 6.2, 6.6, 6.7, and 7.4. Compound data It often comes up that we wish to join several pieces

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING. 1 Introduction. 2 Huffman Coding. Due Thursday, March 8, 11:59pm

COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING. 1 Introduction. 2 Huffman Coding. Due Thursday, March 8, 11:59pm COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING Due Thursday, March 8, 11:59pm Reminder regarding intellectual responsibility: This is an individual assignment, and the work you submit should be your own.

More information

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015 SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,

More information

Welcome to CS 135 (Fall 2018) Themes of the course. Lectures. cs135/

Welcome to CS 135 (Fall 2018) Themes of the course. Lectures.   cs135/ Welcome to CS 135 (Fall 2018) Instructors: Byron Weber Becker, Charles Clarke, Gord Cormack, Robert Hackman, Kevin Lanctot, Paul Nijjar, Adrian Reetz Other course personnel: see website for details ISAs

More information

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

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Algorithms Dr. Haim Levkowitz

Algorithms Dr. Haim Levkowitz 91.503 Algorithms Dr. Haim Levkowitz Fall 2007 Lecture 4 Tuesday, 25 Sep 2007 Design Patterns for Optimization Problems Greedy Algorithms 1 Greedy Algorithms 2 What is Greedy Algorithm? Similar to dynamic

More information

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018

Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Integrated Introduction to Computer Science Klein Homework 6: Higher-Order Procedures Due: 11:59 PM, Oct 16, 2018 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

More information

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017

Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Integrated Introduction to Computer Science Hughes Homework 6: Higher-Order Procedures Due: 10:00 PM, Oct 17, 2017 Contents 1 Fun with map (Practice) 2 2 Unfold (Practice) 3 3 Map2 3 4 Fold 4 5 All You

More information

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim:

We will show that the height of a RB tree on n vertices is approximately 2*log n. In class I presented a simple structural proof of this claim: We have seen that the insert operation on a RB takes an amount of time proportional to the number of the levels of the tree (since the additional operations required to do any rebalancing require constant

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

From the λ-calculus to Functional Programming Drew McDermott Posted

From the λ-calculus to Functional Programming Drew McDermott Posted From the λ-calculus to Functional Programming Drew McDermott drew.mcdermott@yale.edu 2015-09-28 Posted 2015-10-24 The λ-calculus was intended from its inception as a model of computation. It was used by

More information

CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel

CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel CSCI 270: Introduction to Algorithms and Theory of Computing Fall 2017 Prof: Leonard Adleman Scribe: Joseph Bebel We will now discuss computer programs, a concrete manifestation of what we ve been calling

More information

CSE341 Spring 2017, Final Examination June 8, 2017

CSE341 Spring 2017, Final Examination June 8, 2017 CSE341 Spring 2017, Final Examination June 8, 2017 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, etc. except for both sides of one 8.5x11in piece of paper. Please

More information

Repetition Through Recursion

Repetition Through Recursion Fundamentals of Computer Science I (CS151.02 2007S) Repetition Through Recursion Summary: In many algorithms, you want to do things again and again and again. For example, you might want to do something

More information

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Programming Standards: You must conform to good programming/documentation standards. Some specifics: CS3114 (Spring 2011) PROGRAMMING ASSIGNMENT #3 Due Thursday, April 7 @ 11:00 PM for 100 points Early bonus date: Wednesday, April 6 @ 11:00 PM for a 10 point bonus Initial Schedule due Thursday, March

More information

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Integrated Introduction to Computer Science Hughes (Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017 Contents 1 Announcements 1 2 Evaluation Correction 1 3 Lists 2

More information

How to Design Programs

How to Design Programs How to Design Programs How to (in Racket): represent data variants trees and lists write functions that process the data See also http://www.htdp.org/ 1 Running Example: GUIs Pick a fruit: Apple Banana

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

COMP 250 Fall recurrences 2 Oct. 13, 2017

COMP 250 Fall recurrences 2 Oct. 13, 2017 COMP 250 Fall 2017 15 - recurrences 2 Oct. 13, 2017 Here we examine the recurrences for mergesort and quicksort. Mergesort Recall the mergesort algorithm: we divide the list of things to be sorted into

More information

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018

Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 CS17 Integrated Introduction to Computer Science Klein Homework 8: Matrices Due: 11:59 PM, Oct 30, 2018 Contents 1 Reverse (Practice) 4 2 Main Diagonal (Practice) 5 3 Horizontal Flip 6 4 Vertical Flip

More information

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1

RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 RACKET BASICS, ORDER OF EVALUATION, RECURSION 1 COMPUTER SCIENCE 61AS 1. What is functional programming? Give an example of a function below: Functional Programming In functional programming, you do not

More information

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday)

Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) CS 215 Fundamentals of Programming II Spring 2017 Programming Project 7 30 points Out: April 19, 2017 Due: April 26, 2017 (Wednesday, Reading/Study Day, no late work accepted after Friday) This project

More information

p x i 1 i n x, y, z = 2 x 3 y 5 z

p x i 1 i n x, y, z = 2 x 3 y 5 z 3 Pairing and encoding functions Our aim in this part of the course is to show that register machines can compute everything that can be computed, and to show that there are things that can t be computed.

More information

Lecture 5: The Halting Problem. Michael Beeson

Lecture 5: The Halting Problem. Michael Beeson Lecture 5: The Halting Problem Michael Beeson Historical situation in 1930 The diagonal method appears to offer a way to extend just about any definition of computable. It appeared in the 1920s that it

More information

Outline: Search and Recursion (Ch13)

Outline: Search and Recursion (Ch13) Search and Recursion Michael Mandel Lecture 12 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture12final.ipynb

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

Draw a diagram of an empty circular queue and describe it to the reader.

Draw a diagram of an empty circular queue and describe it to the reader. 1020_1030_testquestions.text Wed Sep 10 10:40:46 2014 1 1983/84 COSC1020/30 Tests >>> The following was given to students. >>> Students can have a good idea of test questions by examining and trying the

More information

CS61A Lecture 38. Robert Huang UC Berkeley April 17, 2013

CS61A Lecture 38. Robert Huang UC Berkeley April 17, 2013 CS61A Lecture 38 Robert Huang UC Berkeley April 17, 2013 Announcements HW12 due Wednesday Scheme project, contest out Review: Program Generator A computer program is just a sequence of bits It is possible

More information

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 15 @ 11:00 PM for 100 points Due Monday, October 14 @ 11:00 PM for 10 point bonus Updated: 10/10/2013 Assignment: This project continues

More information

CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

More information

CS116 - Module 5 - Accumulative Recursion

CS116 - Module 5 - Accumulative Recursion CS116 - Module 5 - Accumulative Recursion Cameron Morland Winter 2018 1 Cameron Morland CS116 - Module 5 - Accumulative Recursion Types of Recursion Structural Recursion Generative Recursion Accumulative

More information

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017 Homework 1 Due 14 February Handout 3 CSCI 334: Spring, 2017 Notes This homework has three types of problems: Self Check: You are strongly encouraged to think about and work through these questions, but

More information

Functional Languages. Hwansoo Han

Functional Languages. Hwansoo Han Functional Languages Hwansoo Han Historical Origins Imperative and functional models Alan Turing, Alonzo Church, Stephen Kleene, Emil Post, etc. ~1930s Different formalizations of the notion of an algorithm

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

15-122: Principles of Imperative Computation, Fall 2015

15-122: Principles of Imperative Computation, Fall 2015 15-122 Programming 5 Page 1 of 10 15-122: Principles of Imperative Computation, Fall 2015 Homework 5 Programming: Clac Due: Thursday, October 15, 2015 by 22:00 In this assignment, you will implement a

More information

6.001 Notes: Section 31.1

6.001 Notes: Section 31.1 6.001 Notes: Section 31.1 Slide 31.1.1 In previous lectures we have seen a number of important themes, which relate to designing code for complex systems. One was the idea of proof by induction, meaning

More information

Binary Trees

Binary Trees Binary Trees 4-7-2005 Opening Discussion What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment? What is a Tree? You are all familiar with what

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

Lecture 1: Overview

Lecture 1: Overview 15-150 Lecture 1: Overview Lecture by Stefan Muller May 21, 2018 Welcome to 15-150! Today s lecture was an overview that showed the highlights of everything you re learning this semester, which also meant

More information

15-122: Principles of Imperative Computation, Spring 2013

15-122: Principles of Imperative Computation, Spring 2013 15-122 Homework 6 Page 1 of 13 15-122: Principles of Imperative Computation, Spring 2013 Homework 6 Programming: Huffmanlab Due: Thursday, April 4, 2013 by 23:59 For the programming portion of this week

More information

CSCC24 Functional Programming Scheme Part 2

CSCC24 Functional Programming Scheme Part 2 CSCC24 Functional Programming Scheme Part 2 Carolyn MacLeod 1 winter 2012 1 Based on slides from Anya Tafliovich, and with many thanks to Gerald Penn and Prabhakar Ragde. 1 The Spirit of Lisp-like Languages

More information

CSE341 Spring 2017, Final Examination June 8, 2017

CSE341 Spring 2017, Final Examination June 8, 2017 CSE341 Spring 2017, Final Examination June 8, 2017 Please do not turn the page until 8:30. Rules: The exam is closed-book, closed-note, etc. except for both sides of one 8.5x11in piece of paper. Please

More information

Lambda Calculus and Computation

Lambda Calculus and Computation 6.037 Structure and Interpretation of Computer Programs Chelsea Voss csvoss@mit.edu Massachusetts Institute of Technology With material from Mike Phillips and Nelson Elhage February 1, 2018 Limits to Computation

More information

HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other?

HIERARCHICAL DATA What is a Tree? How is it different from a Deep List? When would you use one over the other? HIERARCHICAL DATA 5 COMPUTER SCIENCE 61AS Concepts and Definitions 1. What is a Tree? How is it different from a Deep List? When would you use one over the other? A Tree is an Abstract Data Type composed

More information

Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018

Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Homework 7: Subsets Due: 11:59 PM, Oct 23, 2018 1 Bookends (Practice) 2 2 Subsets 3 3 Subset Sum 4 4 k-subsets 5 5 k-subset Sum 5 Objectives

More information

CS 125 Section #4 RAMs and TMs 9/27/16

CS 125 Section #4 RAMs and TMs 9/27/16 CS 125 Section #4 RAMs and TMs 9/27/16 1 RAM A word-ram consists of: A fixed set of instructions P 1,..., P q. Allowed instructions are: Modular arithmetic and integer division on registers; the standard

More information

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0))

SCHEME 10 COMPUTER SCIENCE 61A. July 26, Warm Up: Conditional Expressions. 1. What does Scheme print? scm> (if (or #t (/ 1 0)) 1 (/ 1 0)) SCHEME 0 COMPUTER SCIENCE 6A July 26, 206 0. Warm Up: Conditional Expressions. What does Scheme print? scm> (if (or #t (/ 0 (/ 0 scm> (if (> 4 3 (+ 2 3 4 (+ 3 4 (* 3 2 scm> ((if (< 4 3 + - 4 00 scm> (if

More information

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 CS 3512, Spring 2011 Instructor: Doug Dunham Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010 Prerequisites: Calc I, CS2511 Rough course outline:

More information

Assignment 1. Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do

Assignment 1. Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do University of Toronto Mississauga CSC 324 - Principles of Programming Languages, Fall 2016 Assignment 1 Due Tuesday October 11 at 11pm. No late assignments will be accepted. What to do The questions below

More information

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) CSE 11 Winter 2017 Program Assignment #2 (100 points) START EARLY! Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time) PROGRAM #2: DoubleArray11 READ THE ENTIRE ASSIGNMENT BEFORE STARTING In lecture,

More information

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4

Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions. 1 Calculator. calc> (+ 2 2) 4 CS 61A Interpreters and Tail Calls Fall 2017 Discussion 8: November 1, 2017 Solutions 1 Calculator We are beginning to dive into the realm of interpreting computer programs that is, writing programs that

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

Style and Submission Guide

Style and Submission Guide Style and Submission Guide 1 Assignment Style Guidelines The code you submit for assignments, as with all code you write, can be made more readable and useful by paying attention to style. This includes

More information

CMPSCI 250: Introduction to Computation. Lecture #22: Graphs, Paths, and Trees David Mix Barrington 12 March 2014

CMPSCI 250: Introduction to Computation. Lecture #22: Graphs, Paths, and Trees David Mix Barrington 12 March 2014 CMPSCI 250: Introduction to Computation Lecture #22: Graphs, Paths, and Trees David Mix Barrington 12 March 2014 Graphs, Paths, and Trees Graph Definitions Paths and the Path Predicate Cycles, Directed

More information

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am.

Announcements. The current topic: Scheme. Review: BST functions. Review: Representing trees in Scheme. Reminder: Lab 2 is due on Monday at 10:30 am. The current topic: Scheme! Introduction! Object-oriented programming: Python Functional programming: Scheme! Introduction! Numeric operators, REPL, quotes, functions, conditionals! Function examples, helper

More information

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017

Scribe: Virginia Williams, Sam Kim (2016), Mary Wootters (2017) Date: May 22, 2017 CS6 Lecture 4 Greedy Algorithms Scribe: Virginia Williams, Sam Kim (26), Mary Wootters (27) Date: May 22, 27 Greedy Algorithms Suppose we want to solve a problem, and we re able to come up with some recursive

More information

Use recursion to write a function that duplicates the following function: (def (f L) (map (lambda (x) (+ (sqr x) x)) L))

Use recursion to write a function that duplicates the following function: (def (f L) (map (lambda (x) (+ (sqr x) x)) L)) Write a function (multiply-each L n). It consumes a (listof Num) and a Num, and returns the list containing all the values in L, each multiplied by n. (multiply-each (list 2 3 5) 4) => (list 8 12 20) Write

More information

Welcome to CS 115 (Winter 2019)

Welcome to CS 115 (Winter 2019) Welcome to CS 115 (Winter 2019) Web page (the main information source): http://www.student.cs.uwaterloo.ca/ cs115/ Course Personnel: Contact information and office hours for all staff: instructors, ISAs

More information

Problem 1. Remove consecutive duplicates (6 points, 11 mintues)

Problem 1. Remove consecutive duplicates (6 points, 11 mintues) Problem 1. Remove consecutive duplicates (6 points, 11 mintues) CS3 Fall 04 Midterm 2 Consider a function remove-conseq-dups that takes a sentence and returns a sentence in which any occurrences of a word

More information

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003 CS 314, LS, LTM: Functional Programming 1 Scheme A program is an expression to be evaluated (in

More information