TREES. Week 8 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist

Size: px
Start display at page:

Download "TREES. Week 8 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist"

Transcription

1 TREES Week 8 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker Pre-Laboratory Checklist vvskills: You can understand and write conditional, recursive and polymorphic programs. vvknowledge: You know what exhaustive and non-overlapping guards are and can apply this to your programming tasks. vvknowledge: You experienced that types are sometimes an alternative of multiple possibilities, like e.g. with the Maybe type or enumerations. vvknowledge: You know how conditions can be based upon pattern matching, boolean guards, or a mixture of both. vvknowledge: You understand the difference between polymorphism and overloading. vvyou have read the laboratory text below. Introduction For the last few weeks, you have been working regularly with Haskell s built-in list data structure. In this lab, you will gain experience with another kind of recursive data structure: trees. You will learn how to define different kinds of trees, and how to perform useful operations over them. You will build a module encapsulating your binary search tree code for future use. Important Note If you do not finish this lab in time, you should ensure that you complete it before next week. This is for two reasons. The first is that following labs will build on the code you have written this week. The second is that tree data structures will come in super-handy for assignment 2, and completing this lab promptly will put you in a better position to excel in the assignment. Interlude: Motivating Trees You should already be deeply familiar with the list data structure. You might recall several labs ago that I introduced a definition of lists of integers that is equivalent to the standard Haskell version []: data My_String = Empty_String Attach My_String 1 ANU College of Engineering and Computer Science April 2015

2 We have since covered polymorphism, so you should now fully understand the generalisation: data a = Empty_ Attach a ( a) (If you don t understand this, you should talk to your tutor immediately.) This is a recursive definition: a of type a is either empty, or an element of type a followed by a of type a of [5, 3, 4, 3, 0, 1] = 5 : 3 : 4 : 3 : 0 : 1 : [ ] :: [] Moreover, this definition is exactly equivalent to the standard Haskell definition. The diagram above should remind you of the recursive structure of lists. Although lists are easy to understand and work with, they are not necessarily the best choice of data structure for any given problem. In this lab, you will be introduced to another type of recursive data structure: the tree. There are several different types of trees. We will start with the simplest kind: the binary tree. A binary tree can be defined recursively by analogy to lists: a binary tree is either An empty, or null, tree. (This is similar to the empty list, i.e. the base case.) A node, which contains an element and links to two subtrees, either or both of which can be null. (This is similar to the case of a non-empty list, i.e. the step case.) Here is an algebraic type definition for binary trees: data Binary_Tree a = Null Node a (Binary_Tree a) (Binary_Tree a) Even better you can also use this amended definition which gives your individual Node components labels otherwise it is completely identical with the above (purely positional, i.e. the components are identified only by their position in a sequence of expressions) definition: data Binary_Tree a = Null Node {element :: a, left_tree, right_tree :: Binary_Tree a} Binary_Tree of 2 ANU College of Engineering and Computer Science April 2015

3 Those labels not only make the product type more readable, but also serve automatically as functions to extract those components out of a Node. Note the strong similarity between this definition and that for lists above. The only real structural difference is that the step case of the definition includes two recursive elements rather than one. We will call these links the left subtree and right subtree respectively. Above is a diagram of a sample binary tree of s. If you re still struggling to see what s going on, return to the list diagram above. Rotate the page 90 degrees clockwise so that the list moves down the page towards you. You should be able to see that a list is, in a sense, a unary tree each subtree is either null (empty), or a node with one subtree. When you understand this, the generalisation to binary trees is actually quite sensible. (This interpretation isn t very useful, but I provide it to help you develop your intuition for what a tree actually is.) Exercise 1: Exercise 1 (Basic Binary Tree Manipulation) Open a new script file, called Binary_Tree.hs. Copy the following definition into it: data Binary_Tree a = Null Node {element :: a, left_tree, right_tree :: Binary_Tree a} Save the file and load it in GHCi. Verify that the following is a legitimate value of type Binary_ Tree Double: > Node 13.2 (Node 7.9 (Node 2.0 Null Null) (Node (-18.0) Null Null)) (Node 3.2 Null Null) (The best way to do this is to simply type it into GHCi, and ensure that it is parroted back to you without errors. Once you ve done this, you can execute :type it to be sure. The it is a handly little feature of GHCi that always takes the value of the last legitimate, i.e. error-free, expression that you entered.) As you can tell, this syntax is clumsy and difficult to read. There s very little that can be done about this: because of their bifurcating nature, binary trees simply aren t as easy to express in writing as lists. Nevertheless, you will quickly develop the intuition to parse expressions like this. Grab a pen and a piece of paper, and draw a similar diagram to the one above that shows the structure of this tree. Check this diagram with your tutor. You will now gain some practice writing functions that operate on binary trees. To begin, write a function size_of_tree :: (Integral b) => Binary_Tree a -> b that calculates the number of nodes in a tree. Realise that this is very similar in concept to calculating the length of a list. Return to or quickly re-write the general list_length :: Integral b => [a] -> b function, and try to generalise the logic. (Hint: you may find it helpful to first copy my alternative list definition above into a script file, and write an equivalent function list_length :: Integral b => a -> b.) If you calculate the size of the tree I gave you, it should return 5. Then write a function depth_of_tree :: Integral b => Binary_Tree a -> b. The depth of a tree is the number of levels it contains; for example, the example tree I gave above has a depth of 3. (You might like to consider how the size of a tree and its depth are related.) Now, write a function flatten_tree :: Binary_Tree a -> [a]. This function should take a binary tree and return a list containing all the elements contained in that tree. You can also perform a simple sanity check on your function and test that the lengths of the returned list should be the size of the tree (as your calculated it above). Similarly, write a function 3 ANU College of Engineering and Computer Science April 2015

4 leaves_of_tree :: Binary_Tree a -> [a]. This function should take a binary tree and return a list containing the leaves of that tree that is, all the nodes with no subtrees beneath them. You can test your functions over the following sample values: test_case_1, test_case_2 :: Binary_Tree Float test_case_1 = Node 0.0 Null Null test_case_2 = Node 10.9 Null (Node (-1.0) Null Null) test_case_3 :: Binary_Tree String test_case_3 = Node Galvanic (Node metal (Node beats Null Null) (Node stomp Null Null)) (Node out Null (Node louder Null Null)) Submit your code now to the SubmissionApp ( under Lab 8 Binary Tree. The code you have just implemented (hopefully correctly!) is likely to be useful in future. Therefore, it makes sense to export it as a module so that you can use it again. The following code will do this: add it to the top of your script file, save, and exit. module Binary_Tree ( Binary_Tree (Null, Node, element, left_tree, right_tree), size_of_tree, -- :: Integral b => Binary_Tree a -> b depth_of_tree, -- :: Integral b => Binary_Tree a -> b flatten_tree, -- :: Binary_Tree a -> [a] leaves_of_tree, -- :: Binary_Tree a -> [a] ) where Exercise 2: Higher tree functions While we did not yet introduce higher order functions in full, here comes a simple exercise which demonstrates this concept for trees. The only extension here is that you pass on a function as a parameter. This handed-over-as-a-parameter function can then be used inside your higher-order function just like any other function which is visible. Thus write a higher-order function called map_function_over_binary_tree :: (a -> b) -> Binary_Tree a -> Binary_Tree b. This function should behave similarly to the standard map higher-order function: it should take a function and a tree, and return the tree obtained by applying that function to all elements contained in the nodes of the tree (and keep the tree structure). Hence the return type is Binary_Tree b, e.g. a tree where the elements are of type b, which is the return type of the function we just handed over. Submit your code now to the SubmissionApp ( under Lab 8 Binary Tree higher. Your code will now offer one additional function, so add it to your module definition: module Binary_Tree ( Binary_Tree (Null, Node, element, left_tree, right_tree), size_of_tree, -- :: Integral b => Binary_Tree a -> b depth_of_tree, -- :: Integral b => Binary_Tree a -> b flatten_tree, -- :: Binary_Tree a -> [a] leaves_of_tree, -- :: Binary_Tree a -> [a] map_function_over_binary_tree -- :: (a -> b) -> Binary_Tree a -> Binary_Tree b ) where 4 ANU College of Engineering and Computer Science April 2015

5 Interlude: Binary Search Trees By now you should be beginning to get a feel for how trees operate, and how you can manipulate them. However, like all new syntax, it s not much good without an example, so let s construct one. The canonical example of binary trees in use is to provide a dictionary data type; that is, a data type that stores some number of elements and admits queries on that storage. You could certainly implement a dictionary type with lists you might like to imagine how. However, using lists for this purpose is potentially inefficient. Suppose you want to query whether or not an element exists in a dictionary, which is implemented as a list of N elements. On the assumption that the list is randomly ordered, looking up an entry will take, on average, N 2 operations. (Convince yourself that this is a reasonable statement before you continue.) This is fine for small dictionaries, but consider a phonebook containing several hundred thousand phone numbers. What happens if you want to look up a hundred numbers? Or a thousand? Clearly, this will be slow. So, how can we use binary trees to provide a more efficient experience? We can introduce a special kind of binary tree: the binary search tree. This is no different structurally to a standard binary tree, but it must satisfy an additional property: given any binary search tree with element x, it must be the case that every element e l in the left subtree is strictly less than x. Similarly, every element e r in the right subtree must be strictly greater than x. This is referred to as the binary search tree ordering constraint. (You should see that this immediately puts a restriction on the types of elements we can store in our tree, namely that they must be in a particular typeclass. Which?) What does this property do? At first glance, it might seem quite arbitrary. However, when this property is satisfied, searching the tree for an element becomes very easy and efficient. Start at the root node. If the element you re looking for is less than the element contained at the root, then you can completely forget about the other half of the tree and search only the left-hand subtree, and similarly if the element you are searching for is greater than the root element. You can then recursively search the interesting half of the tree. On the assumption that the tree is balanced (i.e. that one side is not much larger than the other), you can find an element of the tree in log2 ] Ng operations, rather than N 2. This is significantly faster! (We will return to the notion of efficiency and tree balance next week. For the moment, you should keep it in mind but not worry too much about it.) A phonebook is, again, a good analogy. If I m looking for, say, Cedric s Cakes, I can open a phonebook more-or-less at random. If I find myself at the page containing Monica s Muffins, then because the phonebook is in alphabetical order, I can ignore every page after 'g' the one I opened. I can then repeat the process, splitting the left-hand half of the phone book about halfway, perhaps finding the entry for Bob s Bakery. I now only have 'c' 'i' to worry about the pages between the two entries I ve just found. If I repeat this, I will find the entry for Cedric s Cakes much 'a' 'e' 'h' 'j' quicker than if I laboriously read through the book from the start. Here is a simple binary search tree containing the letters a through j, using standard alphabetical ordering. Convince yourself that this tree satisfies the binary search tree ordering property. If you aren t sure how this works, check with your tutor or discuss with a fellow student. 'b' 'd' 'f' Binary Search Tree of 5 ANU College of Engineering and Computer Science April 2015

6 Exercise 3: Binary Search Trees Create a new script file, called Binary_Search_Tree.hs. Do not write these functions in your earlier binary tree module. You can define a binary search tree very easily: simply note that a binary search tree is, structurally, a binary tree: type BS_Tree a = Binary_Tree a (You will need to import your previously-written Binary_Tree module.) Of course, this definition does not capture the ordering constraint. There is no easy way in Haskell to define the type in a way that ensures satisfaction of the ordering constraint. (I m not even sure that there s a hard way.) However, we do need a way to check. Therefore, define a function is_valid_binary_search_tree :: Ord a => BS_Tree a -> Bool that returns True if and only if the input tree satisfies the ordering constraint. Hint: a BS_Tree is valid if the maximum element in the left subtree is less than the element at the root, similarly for the right subtree, and both subtrees are valid binary trees. A BS_Tree is also valid if the flattened tree (if cleverly flattened) results in a sorted list. Your implementation could end anywhere between a one liner and a code massacre. If getting out of hand: step back, let it rest and do something else first. Now write some simple functions to query a BS_Tree. You should write the functions minimum_element :: Ord a => BS_Tree a -> a maximum_element :: Ord a => BS_Tree a -> a contains_element :: Ord a => a -> BS_Tree a -> Bool Of course, you should use the ordering constraint when working out how to write these functions. You should also reimplement the function flatten_in_order :: Ord a => BS_Tree a -> [a] (if you didn t already do so as part of your is_valid_binary_search_tree function). Given the ordering constraint, you should be able to write this function in such a way that the resulting list is produced in such a way that it is already sorted into ascending order. Up to this point, we have been using pre-existing trees for test values. This is not particularly useful: in the phonebook example, it would be difficult in the extreme to manually construct a properly-ordered binary search tree. (In fact, it would be difficult to construct any non-trivial tree manually, full stop.) So we need to write a function to add an element to a binary search tree. (Of course, this function must maintain the ordering constraint.) We will call this function insert_element_to_tree :: Ord a => a -> BS_Tree a -> BS_Tree a. How can we do this? It s not actually that hard, and uses very similar logic to that which we used to search a BS_Tree. The basic idea is to move down through the tree until we find an fitting spot to place the new element. Here is a simple English description of the (recursive, of course) algorithm you will use: a. Investigate the root node of the tree. b. if this node is Null, then return a new Node containing the new element. c. if the element at this node is identical to the element to be inserted, then return the tree (effectively not actually inserting anything, but omitting the new element as a duplicate). d. If the element at this node is greater than the element to be inserted, then insert the element into the left-hand subtree. e. If the element at this node is less than the element to be inserted, then insert the element into the right-hand subtree. Take some time to read this algorithm and make sure you understand it. How can you be sure that the resulting tree still maintains the ordering constraint? You might like to experiment on 6 ANU College of Engineering and Computer Science April 2015

7 paper to try and see what s going on. Don t be afraid to ask your tutor this is a tricky idea and it may take some explanation before it makes sense to you. As always, you should test your code. Load up your script into GHCi and try to build a binary search tree by repeatedly calling the insert_element_to_tree function. Use the is_valid_binary_tree function to make sure that the ordering constraint remains satisfied after each insertion. Play around with your minimum_element, maximum_element and contains_element functions. Basically, persuade yourself that everything works like you expect. After you have completed your insert_element_to_tree function, compare your solution with the version used in the lectures. How is yours different? Here are some sample value to test your functions with: test_case_4 :: BS_Tree test_case_4 = Node g (Node c (Node a Null (Node b Null Null)) (Node e (Node f Null Null) (Node g Null Null))) (Node i (Node h Null Null) (Node j Null Null)) test_case_5 :: BS_Tree test_case_5 = Node 92 (Node 11 Null Null) (Node 101 Null (Node 102 Null Null)) (You might wonder how to delete elements from a binary tree. It can of course be done, but it is quite a bit more fiddly. We will return to this next week.) Finally submit your code to the SubmissionApp ( under Lab 8 Binary Search Tree. Check out the code which you receive for peer review. Take especially note of the function is_valid_binary_search_tree. Is this function way shorter or longer than yours? More efficient? Slower? Exercise 4: Arithmetic Tree Expressions You remember the evaluation of arithmetic token lists you did in lab five? (Take a quick walk down memory lane and look it up if you don t.) Wouldn t it have been great to know about trees back then? Well, now you do, so let s do it again only this time this will be an affair of a few lines of code. Given these definitions (start in a new file): data Expression a = Number a Node (Expression a) Operand (Expression a) data Operand = Plus Minus Times Divided_By Power write a function with the profile: eval :: Floating a => Expression a -> Expression a which evaluates any given expression to an expression which only contains a single number. Such that > eval (Node (Node (Number (3 :: Double)) Times (Node (Number 1) Plus (Number 1))) Power (Node (Number 4) Divided_By (Number 2))) will result in: Number 36.0 You will notice that you will not need the function binding_power any more (as we needed it for the list expressions). Why is that? 7 ANU College of Engineering and Computer Science April 2015

8 Trees are commonly used not only for storing and searching data, but also to express structured data like the above arithmetic expressions in a natural and unambiguous way. Submit your code now to the SubmissionApp ( under Lab 8 Arithmetic Tree Expressions. After submission add a module header to your new expression code: module Tree_Expressions ( Expression (Number, Node), Operand (Plus, Minus, Times, Divided_By, Power), eval -- :: Expression -> Expression ) where so that you can refer to it later again. Exercise 5: Rose Trees "The" String "quick" "jumps" "undergrad" String String String of Rose_Tree Rose_Tree "brown" "fox" "over" "the" "lazy" "student" String String String String String String of Rose_Tree of Rose_Tree of Rose_Tree Rose_Tree In this lab, we are only scratching the surface of the possibilities of trees. To finish off, we will introduce a new tree structure. The new tree structure is called a rose tree (I don t know why, it just is I m not much of a gardener), and unlike the binary trees you ve worked with so far, each node can have any number of children. (None, one, two, three, or as many as you like.) Note that there is no requirement for two nodes in the same tree to have the same number of elements. How can we implement this? You ve already seen a data type that allows you to store an arbitrary number of elements: the list. So consider the following definition: data Rose_Tree a = Rose_Node a [Rose_Tree a] 8 ANU College of Engineering and Computer Science April 2015

9 Again, this might appear cryptic, but it s not that bad compare it with the binary tree definition above. All it says is that a rose tree is a node, with an element of type a, and a list containing the potentially-many subtrees of that node. The diagram above should help you understand what s going on. (Note that the above definition does not explicitly allow for a null node. How can you express a rose tree node with no children?) Create a new script file, Rose_Tree.hs, and copy the above definition into it. Implement the following functions appropriately: size_of_tree :: Integral b => Rose_Tree a -> b depth_of_tree :: Integral b => Rose_Tree a -> b leaves_of_tree :: Rose_Tree a -> [a] (hint: consider the concatmap higher-order function from the Prelude.) map_function_over_rose_tree :: (a -> b) -> Rose_Tree a -> Rose_Tree b Test your functions using the following sample values: test_case :: Rose_Tree test_case = Rose_Node 1 [Rose_Node 2 [], Rose_Node 3 [Rose_Node 4 []], Rose_Node 5 [Rose_Node 6 [], Rose_Node 7 []]] If you fully understood this lab as well as the last one, then your functions above should all be between one and three lines long. Submit your code to the SubmissionApp ( under Lab 8 Rose Tree. Check out the code which you receive for review. How does this code compare to yours in terms of efficiency/maintainability? Add the following header to your code: module Rose_Tree ( Rose_Tree (Rose_Node), size_of_tree, -- :: Integral b => Rose_Tree a -> b depth_of_tree, -- :: Integral b => Rose_Tree a -> b leaves_of_tree, -- :: Rose_Tree a -> [a] map_function_over_rose_tree -- :: (a -> b) -> Rose_Tree a -> Rose_Tree b ) where for future usage. If you are even more curious check out how rose trees are defined in Data.Tree (a default Haskell library). Make Sure You Logout to Terminate Your Session! Outlook In a few weeks you will put your trees to work and use them to implement another important data-structure: the set. Next week we will turn to higher order functions thought. 9 ANU College of Engineering and Computer Science April 2015

RECURSION. Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist

RECURSION. Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker. Pre-Laboratory Checklist RECURSION Week 6 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on material by James Barker Pre-Laboratory Checklist vvskills: You can write any conditional expression. vvknowledge:

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

SYNCHRONIZED DATA. Week 9 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer. Pre-Laboratory Checklist

SYNCHRONIZED DATA. Week 9 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer. Pre-Laboratory Checklist SYNCHRONIZED DATA Week 9 Laboratory for Concurrent and Distributed Systems Uwe R. Zimmer Pre-Laboratory Checklist vvyou have read this text before you come to your lab session. vvyou understand and can

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

CIS 121 Data Structures and Algorithms with Java Spring 2018

CIS 121 Data Structures and Algorithms with Java Spring 2018 CIS 121 Data Structures and Algorithms with Java Spring 2018 Homework 2 Thursday, January 18 Due Monday, January 29 by 11:59 PM 7 Required Problems (85 points), and Style and Tests (15 points) DO NOT modify

More information

FRACTALS. Week 13 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on a lab by James Barker. Pre-Laboratory Checklist

FRACTALS. Week 13 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on a lab by James Barker. Pre-Laboratory Checklist FRACTALS Week 13 Laboratory for Introduction to Programming and Algorithms Uwe R. Zimmer based on a lab by James Barker Pre-Laboratory Checklist vvskills: You can handle any recursive, or higher order

More information

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi. Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 18 Tries Today we are going to be talking about another data

More information

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without

These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without These notes are intended exclusively for the personal usage of the students of CS352 at Cal Poly Pomona. Any other usage is prohibited without previous written authorization. 1 2 The simplest way to create

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

(Refer Slide Time: 01.26)

(Refer Slide Time: 01.26) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.

More information

Excel Basics: Working with Spreadsheets

Excel Basics: Working with Spreadsheets Excel Basics: Working with Spreadsheets E 890 / 1 Unravel the Mysteries of Cells, Rows, Ranges, Formulas and More Spreadsheets are all about numbers: they help us keep track of figures and make calculations.

More information

CIS 194: Homework 6. Due Friday, October 17, Preface. Setup. Generics. No template file is provided for this homework.

CIS 194: Homework 6. Due Friday, October 17, Preface. Setup. Generics. No template file is provided for this homework. CIS 194: Homework 6 Due Friday, October 17, 2014 No template file is provided for this homework. Download the markets.json file from the website, and make your HW06.hs Haskell file with your name, any

More information

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore Lecture 04 Software Test Automation: JUnit as an example

More information

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26

COSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26 COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.

More information

Introduction. chapter Functions

Introduction. chapter Functions chapter 1 Introduction In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main

More information

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage: Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

More information

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial

CS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial Week 7 General remarks Arrays, lists, pointers and 1 2 3 We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for

More information

EC121 Mathematical Techniques A Revision Notes

EC121 Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes EC Mathematical Techniques A Revision Notes Mathematical Techniques A begins with two weeks of intensive revision of basic arithmetic and algebra, to the level

More information

n! = 1 * 2 * 3 * 4 * * (n-1) * n

n! = 1 * 2 * 3 * 4 * * (n-1) * n The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are

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

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator CMPSCI 187 / Spring 2015 Postfix Expression Evaluator Due on Thursday, 05 March, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 CMPSCI 187 / Spring 2015

More information

Project 5 - The Meta-Circular Evaluator

Project 5 - The Meta-Circular Evaluator MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Fall Semester, 2005 Project 5 - The Meta-Circular

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

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley

PAIRS AND LISTS 6. GEORGE WANG Department of Electrical Engineering and Computer Sciences University of California, Berkeley PAIRS AND LISTS 6 GEORGE WANG gswang.cs61a@gmail.com Department of Electrical Engineering and Computer Sciences University of California, Berkeley June 29, 2010 1 Pairs 1.1 Overview To represent data types

More information

6.001 Notes: Section 8.1

6.001 Notes: Section 8.1 6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything

More information

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs Lecture 16 Treaps; Augmented BSTs Parallel and Sequential Data Structures and Algorithms, 15-210 (Spring 2012) Lectured by Margaret Reid-Miller 8 March 2012 Today: - More on Treaps - Ordered Sets and Tables

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

(Refer Slide Time: 02.06)

(Refer Slide Time: 02.06) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 27 Depth First Search (DFS) Today we are going to be talking

More information

Chapter 1 Introduction

Chapter 1 Introduction Chapter 1 Introduction Why I Am Writing This: Why I am I writing a set of tutorials on compilers and how to build them? Well, the idea goes back several years ago when Rapid-Q, one of the best free BASIC

More information

COMP26120 Academic Session: Lab Exercise 6: Recursive Sorting and Searching

COMP26120 Academic Session: Lab Exercise 6: Recursive Sorting and Searching COMP26120 Academic Session: 2018-19 Lab Exercise 6: Recursive Sorting and Searching Duration: 1 lab session For this lab exercise you should do all your work in your COMP26120/ex6 directory. Learning Objectives

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

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20

CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20 CS3L Summer 2011 Final Exam, Part 2 You may leave when finished; or, you must stop promptly at 12:20 Name: Login: cs3- First names of the people to your left and right, if any: Left: Right: 1. If you have

More information

14.1 Encoding for different models of computation

14.1 Encoding for different models of computation Lecture 14 Decidable languages In the previous lecture we discussed some examples of encoding schemes, through which various objects can be represented by strings over a given alphabet. We will begin this

More information

Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras

Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Programming and Data Structures Prof. N. S. Narayanaswamy Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 02 Structures, Pointers and Functions Welcome to

More information

Word: Print Address Labels Using Mail Merge

Word: Print Address Labels Using Mail Merge Word: Print Address Labels Using Mail Merge No Typing! The Quick and Easy Way to Print Sheets of Address Labels Here at PC Knowledge for Seniors we re often asked how to print sticky address labels in

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Asymptotic Analysis (a) Applying definitions For each of the following, choose a c and n 0 which show f(n) O(g(n)). Explain why your values of c and n 0 work. (i) f(n) = 5000n

More information

CSCI-1200 Data Structures Spring 2018 Lecture 15 Associative Containers (Maps), Part 2

CSCI-1200 Data Structures Spring 2018 Lecture 15 Associative Containers (Maps), Part 2 CSCI-1200 Data Structures Spring 2018 Lecture 15 Associative Containers (Maps), Part 2 Review of Lecture 14 Maps are associations between keys and values. Maps have fast insert, access and remove operations:

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

Algebra of Sets. Aditya Ghosh. April 6, 2018 It is recommended that while reading it, sit with a pen and a paper.

Algebra of Sets. Aditya Ghosh. April 6, 2018 It is recommended that while reading it, sit with a pen and a paper. Algebra of Sets Aditya Ghosh April 6, 2018 It is recommended that while reading it, sit with a pen and a paper. 1 The Basics This article is only about the algebra of sets, and does not deal with the foundations

More information

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Harvard School of Engineering and Applied Sciences CS 152: Programming Languages Lecture 18 Thursday, March 29, 2018 In abstract algebra, algebraic structures are defined by a set of elements and operations

More information

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

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Spring 2016) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently. The Science of Computing I Lesson 4: Introduction to Data Structures Living with Cyber Pillar: Data Structures The need for data structures The algorithms we design to solve problems rarely do so without

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 07 Lecture - 38 Divide and Conquer: Closest Pair of Points We now look at another divide and conquer algorithm,

More information

Project 1 Balanced binary

Project 1 Balanced binary CMSC262 DS/Alg Applied Blaheta Project 1 Balanced binary Due: 7 September 2017 You saw basic binary search trees in 162, and may remember that their weakness is that in the worst case they behave like

More information

Macros & Streams Spring 2018 Discussion 9: April 11, Macros

Macros & Streams Spring 2018 Discussion 9: April 11, Macros CS 61A Macros & Streams Spring 2018 Discussion 9: April 11, 2018 1 Macros So far, we ve mostly explored similarities between the Python and Scheme languages. For example, the Scheme list data structure

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

CSE 12 Abstract Syntax Trees

CSE 12 Abstract Syntax Trees CSE 12 Abstract Syntax Trees Compilers and Interpreters Parse Trees and Abstract Syntax Trees (AST's) Creating and Evaluating AST's The Table ADT and Symbol Tables 16 Using Algorithms and Data Structures

More information

DISTRIBUTION. Week 11 Laboratory for Systems, Networks and Concurrency Uwe R. Zimmer. Pre-Laboratory Checklist

DISTRIBUTION. Week 11 Laboratory for Systems, Networks and Concurrency Uwe R. Zimmer. Pre-Laboratory Checklist DISTRIBUTION Week 11 Laboratory for Systems, Networks and Concurrency Uwe R. Zimmer Pre-Laboratory Checklist vvyou have read this text before you come to your lab session. vvyou understand and can utilize

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

Lecture 15 Binary Search Trees

Lecture 15 Binary Search Trees Lecture 15 Binary Search Trees 15-122: Principles of Imperative Computation (Fall 2017) Frank Pfenning, André Platzer, Rob Simmons, Iliano Cervesato In this lecture, we will continue considering ways to

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

Intro. Speed V Growth

Intro. Speed V Growth Intro Good code is two things. It's elegant, and it's fast. In other words, we got a need for speed. We want to find out what's fast, what's slow, and what we can optimize. First, we'll take a tour of

More information

The Dynamic Typing Interlude

The Dynamic Typing Interlude CHAPTER 6 The Dynamic Typing Interlude In the prior chapter, we began exploring Python s core object types in depth with a look at Python numbers. We ll resume our object type tour in the next chapter,

More information

Lab 10: OCaml sequences, comparators, stable sorting 12:00 PM, Nov 12, 2017

Lab 10: OCaml sequences, comparators, stable sorting 12:00 PM, Nov 12, 2017 Integrated Introduction to Computer Science Hughes Lab 10: OCaml sequences, comparators, stable sorting 12:00 PM, Nov 12, 2017 Contents 1 A last OCaml type, and its utility 1 1.1 Sequences in OCaml....................................

More information

(Refer Slide Time 3:31)

(Refer Slide Time 3:31) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 5 Logic Simplification In the last lecture we talked about logic functions

More information

Taskbar: Working with Several Windows at Once

Taskbar: Working with Several Windows at Once Taskbar: Working with Several Windows at Once Your Best Friend at the Bottom of the Screen How to Make the Most of Your Taskbar The taskbar is the wide bar that stretches across the bottom of your screen,

More information

(Refer Slide Time 5:19)

(Refer Slide Time 5:19) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology, Madras Lecture - 7 Logic Minimization using Karnaugh Maps In the last lecture we introduced

More information

Utility Maximization

Utility Maximization Utility Maximization Mark Dean Lecture Notes for Spring 2015 Behavioral Economics - Brown University 1 Lecture 1 1.1 Introduction The first topic we are going to cover in the course isn t going to seem

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination University of Illinois at Urbana-Champaign Department of Computer Science Second Examination CS 225 Data Structures and Software Principles Spring 2014 7-10p, Tuesday, April 8 Name: NetID: Lab Section

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

ENCM 339 Fall 2017: Editing and Running Programs in the Lab page 1 of 8 ENCM 339 Fall 2017: Editing and Running Programs in the Lab Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Introduction This document is a

More information

Computer Architecture Prof. Smruthi Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi

Computer Architecture Prof. Smruthi Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi Computer Architecture Prof. Smruthi Ranjan Sarangi Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture - 08 ARM Assembly Language Part I Welcome to the chapter

More information

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5 C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Introduction to Programming Language Concepts

More information

(Refer Slide Time 6:48)

(Refer Slide Time 6:48) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology Madras Lecture - 8 Karnaugh Map Minimization using Maxterms We have been taking about

More information

Week 2: Git and First Functions

Week 2: Git and First Functions Week 2: Git and First Functions Steven X. Han 2017-07-31 In this lab you will complete Lab 1 by submitting your work into git so that your tutor can access it. To do so successfully, read all explanations

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

Starting. Read: Chapter 1, Appendix B from textbook.

Starting. Read: Chapter 1, Appendix B from textbook. Read: Chapter 1, Appendix B from textbook. Starting There are two ways to run your Python program using the interpreter 1 : from the command line or by using IDLE (which also comes with a text editor;

More information

Course year Typeclasses and their instances

Course year Typeclasses and their instances Course year 2016-2017 Typeclasses and their instances Doaitse Swierstra and Atze Dijkstra with extra s Utrecht University September 29, 2016 1. The basics 2 Overloading versus parametric polymorphism 1

More information

Binary Search Trees, etc.

Binary Search Trees, etc. Chapter 12 Binary Search Trees, etc. Binary Search trees are data structures that support a variety of dynamic set operations, e.g., Search, Minimum, Maximum, Predecessors, Successors, Insert, and Delete.

More information

Java/RealJ Troubleshooting Guide

Java/RealJ Troubleshooting Guide Java/RealJ Troubleshooting Guide by Bob Clark / Sharon Curtis / Simon Jones, September 2000 Some of these tips you will come across during your practical sessions, however we felt it would be helpful to

More information

COMP 105 Homework: Type Systems

COMP 105 Homework: Type Systems Due Tuesday, March 29, at 11:59 PM (updated) The purpose of this assignment is to help you learn about type systems. Setup Make a clone of the book code: git clone linux.cs.tufts.edu:/comp/105/build-prove-compare

More information

Red-Black trees are usually described as obeying the following rules :

Red-Black trees are usually described as obeying the following rules : Red-Black Trees As we have seen, the ideal Binary Search Tree has height approximately equal to log n, where n is the number of values stored in the tree. Such a BST guarantees that the maximum time for

More information

Learn Linux in a Month of Lunches by Steven Ovadia

Learn Linux in a Month of Lunches by Steven Ovadia Learn Linux in a Month of Lunches by Steven Ovadia Sample Chapter 17 Copyright 2017 Manning Publications brief contents PART 1 GETTING LINUX UP AND RUNNING... 1 1 Before you begin 3 2 Getting to know Linux

More information

This book is about using Visual Basic for Applications (VBA), which is a

This book is about using Visual Basic for Applications (VBA), which is a In This Chapter Describing Access Discovering VBA Seeing where VBA lurks Understanding how VBA works Chapter 1 Where VBA Fits In This book is about using Visual Basic for Applications (VBA), which is a

More information

(Refer Slide Time: 1:43)

(Refer Slide Time: 1:43) (Refer Slide Time: 1:43) Digital Circuits and Systems Prof. S. Srinivasan Department of Electrical Engineering Indian Institute of Technology, Madras Lecture - 27 Pattern Detector So, we talked about Moore

More information

CS 1110, LAB 3: MODULES AND TESTING First Name: Last Name: NetID:

CS 1110, LAB 3: MODULES AND TESTING   First Name: Last Name: NetID: CS 1110, LAB 3: MODULES AND TESTING http://www.cs.cornell.edu/courses/cs11102013fa/labs/lab03.pdf First Name: Last Name: NetID: The purpose of this lab is to help you better understand functions, and to

More information

CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers

CIS 194: Homework 6. Due Monday, February 25. Fibonacci numbers CIS 194: Homework 6 Due Monday, February 25 Files you should submit: Fibonacci.hs This week we learned about Haskell s lazy evaluation. This homework assignment will focus on one particular consequence

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

2 Sets. 2.1 Notation. last edited January 26, 2016

2 Sets. 2.1 Notation. last edited January 26, 2016 2 Sets Sets show up in virtually every topic in mathematics, and so understanding their basics is a necessity for understanding advanced mathematics. As far as we re concerned, the word set means what

More information

Lecture 10 Notes Linked Lists

Lecture 10 Notes Linked Lists Lecture 10 Notes Linked Lists 15-122: Principles of Imperative Computation (Summer 1 2015) Frank Pfenning, Rob Simmons, André Platzer 1 Introduction In this lecture we discuss the use of linked lists to

More information

Exercises: Instructions and Advice

Exercises: Instructions and Advice Instructions Exercises: Instructions and Advice The exercises in this course are primarily practical programming tasks that are designed to help the student master the intellectual content of the subjects

More information

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return Recursion CS 1 Admin How's the project coming? After these slides, read chapter 13 in your book Yes that is out of order, but we can read it stand alone Quizzes will return Tuesday Nov 29 th see calendar

More information

Advanced Programming Handout 6. Purely Functional Data Structures: A Case Study in Functional Programming

Advanced Programming Handout 6. Purely Functional Data Structures: A Case Study in Functional Programming Advanced Programming Handout 6 Purely Functional Data Structures: A Case Study in Functional Programming Persistent vs. Ephemeral An ephemeral data structure is one for which only one version is available

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................

More information

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program

More information

(Refer Slide Time 00:01:09)

(Refer Slide Time 00:01:09) Computer Organization Part I Prof. S. Raman Department of Computer Science & Engineering Indian Institute of Technology Lecture 3 Introduction to System: Hardware In the previous lecture I said that I

More information

Variables and Data Representation

Variables and Data Representation You will recall that a computer program is a set of instructions that tell a computer how to transform a given set of input into a specific output. Any program, procedural, event driven or object oriented

More information

6. Relational Algebra (Part II)

6. Relational Algebra (Part II) 6. Relational Algebra (Part II) 6.1. Introduction In the previous chapter, we introduced relational algebra as a fundamental model of relational database manipulation. In particular, we defined and discussed

More information

(Refer Slide Time: 06:01)

(Refer Slide Time: 06:01) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 28 Applications of DFS Today we are going to be talking about

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015 CS161, Lecture 2 MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015 1 Introduction Today, we will introduce a fundamental algorithm design paradigm, Divide-And-Conquer,

More information

CIS 194: Homework 5. Due Friday, October 3, Rings. No template file is provided for this homework. Download the

CIS 194: Homework 5. Due Friday, October 3, Rings. No template file is provided for this homework. Download the CIS 194: Homework 5 Due Friday, October 3, 2014 No template file is provided for this homework. Download the Ring.hs and Parser.hs files from the website, and make your HW05.hs Haskell file with your name,

More information