UNIVERSITY OF LONDON (University College London) M.Sc. DEGREE 1998 COMPUTER SCIENCE D16: FUNCTIONAL PROGRAMMING. Answer THREE Questions.



Similar documents
Full and Complete Binary Trees

Big Data and Scripting. Part 4: Memory Hierarchies

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Analysis of Algorithms I: Optimal Binary Search Trees

Analysis of Algorithms I: Binary Search Trees

Binary Search Trees CMPSC 122

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

Binary Search Trees (BST)

Data Structure [Question Bank]

DATA STRUCTURES USING C

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Converting a Number from Decimal to Binary

How To Create A Tree From A Tree In Runtime (For A Tree)

Exercises Software Development I. 11 Recursion, Binary (Search) Trees. Towers of Hanoi // Tree Traversal. January 16, 2013

Why Use Binary Trees?

Algorithms and Data Structures

Data Structures and Algorithms

Data Structure with C

From Last Time: Remove (Delete) Operation

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

PES Institute of Technology-BSC QUESTION BANK

Parallelization: Binary Tree Traversal

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Functional Programming in C++11

Ordered Lists and Binary Trees

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

PLANET: Massively Parallel Learning of Tree Ensembles with MapReduce. Authors: B. Panda, J. S. Herbach, S. Basu, R. J. Bayardo.

The ADT Binary Search Tree

1. Domain Name System

Algorithms and Data Structures

Sample Questions Csci 1112 A. Bellaachia

Binary Heap Algorithms

In-Memory Database: Query Optimisation. S S Kausik ( ) Aamod Kore ( ) Mehul Goyal ( ) Nisheeth Lahoti ( )

Lecture 6: Binary Search Trees CSCI Algorithms I. Andrew Rosenberg

Chapter 14 The Binary Search Tree

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Binary Search Tree Intro to Algorithms Recitation 03 February 9, 2011

CSE 326: Data Structures B-Trees and B+ Trees

Unit Storage Structures 1. Storage Structures. Unit 4.3

Binary Trees and Huffman Encoding Binary Search Trees

Map Reduce / Hadoop / HDFS

Chapter 13: Query Processing. Basic Steps in Query Processing

Binary Trees. Wellesley College CS230 Lecture 17 Thursday, April 5 Handout #28. PS4 due 1:30pm Tuesday, April

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Lecture 10: Regression Trees

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Data Mining with R. Decision Trees and Random Forests. Hugh Murrell

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

10CS35: Data Structures Using C

Programming Languages in Artificial Intelligence

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Persistent Binary Search Trees

Fundamental Algorithms

Binary Search Trees 3/20/14

Package hive. January 10, 2011

External Memory Geometric Data Structures

Fun with Phantom Types

Algorithms Chapter 12 Binary Search Trees

Lightweight Fusion by Fixed Point Promotion

Eastern Washington University Department of Computer Science. Questionnaire for Prospective Masters in Computer Science Students

Fast Sequential Summation Algorithms Using Augmented Data Structures

Decision-Tree Learning

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

Google s MapReduce Programming Model Revisited

[Refer Slide Time: 05:10]

Applying Data Mining Technique to Sales Forecast

CSc 372. Comparative Programming Languages. 21 : Haskell Accumulative Recursion. Department of Computer Science University of Arizona

GRAPH THEORY LECTURE 4: TREES

6 March Array Implementation of Binary Trees

Classification On The Clouds Using MapReduce

Symbol Tables. Introduction

TOWARDS SIMPLE, EASY TO UNDERSTAND, AN INTERACTIVE DECISION TREE ALGORITHM

Optimal Binary Search Trees Meet Object Oriented Programming

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Regular Expressions and Automata using Haskell

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Data Mining Classification: Decision Trees

Fast nondeterministic recognition of context-free languages using two queues

Interconnection Networks Programmierung Paralleler und Verteilter Systeme (PPV)

Structural Design Patterns Used in Data Structures Implementation

Tail Recursion Without Space Leaks

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

6 Creating the Animation

Introduction to Data Structures and Algorithms

COURSE TITLE COURSE DESCRIPTION

Binary Heaps. CSE 373 Data Structures

Classifying Large Data Sets Using SVMs with Hierarchical Clusters. Presented by :Limou Wang

Transcription:

UNIVERSITY OF LONDON (University College London) M.Sc. DEGREE 1998 COMPUTER SCIENCE D16: FUNCTIONAL PROGRAMMING Answer THREE Questions. The Use of Electronic Calculators: is NOT Permitted. -1-

Answer Question 1 and any TWO other questions. 1. (a) Explain the terms lazy evaluation and list comprehension. [4] (b) What value does the following expression compute? last [(x ˆ 2) + 1 x <- [1..]; (x ˆ 2) < 5000000] last [] = error "last of empty list" last [x] = x last (x:xs) = last xs [6] What is a type? [2] Why will Miranda not allow the following function definition? dumb x = (x x) [6] (e) Given the following function definitions, number is the name of a type synonym: one :: number one f x = f x two :: number two f x = f (f x) three :: number three f x = f (f (f x)) Give the most general type synonym definition for number. [4] What is the most general type of the following function? operator a b = h h c x = a c (b c x) [6] Explain the operation of the function operator (in the context of the other definitions given above) by giving the evaluation steps of a simple application. Then explain in general terms what the function operator does (for example, could it be given a more descriptive name?). [6] [Total 34] [TURN OVER] -2-

2. (a) What are algebraic data types? Give examples of the different kinds of algebraic type and how they might be used. [5] (b) Define a type structure to represent binary trees in which the nodes of the tree hold number values and the leaves also hold number values. [4] Define a function to determine the height of a tree represented using your type, the height of a tree is the number of nodes along the longest branch from the root to a leaf. [9] Consider the following function defined for lists: > map_on_tails f [] = [] > map_on_tails f xs = (f xs) : (map_on_tails f (tl xs) (e) Define an analogous function on the trees represented by your type, a function is applied to every sub-tree within a tree. [11] Define a function which will take a tree and return a tree containing at each node the height of the corresponding sub-tree in the input tree. [4] 3. (a) Briefly explain, with examples, what is meant by the following terms: partial application case analysis structural induction [10] (b) Briefly explain the advantages of using Higher Order Functions. Illustrate your answer by giving the code (and type) for a higher-order function (call it gsort) which will sort a list of any type of object in any user-provided ordering. [10] Discuss, with examples, the role played by recursion in functional programming. Your answer should address (amongst other things) the following points: Recursive function definitions. Recursive types (both built-in and user-defined). Stack, accumulative and mutual recursion. [13] [CONTINUED] -3-

4. (a) Provide definitions, including types, for the two functions (from the Miranda Standard Environment) called foldr and foldl. [12] (b) What values do the following five expressions compute? foldr (:) [] [1,2,3] hd (foldr (:) [] [1..]) foldl (:) [] [1,2,3] foldl (swap (:)) [] [1,2,3] swap f x y = f y x foldl (swap (:)) [] [1..] swap f x y = f y x Under what circumstances are the functions foldr and foldl interchangeable? [8] What does the following function do and what is its type? [5] f x = foldr rcons id x [] rcons a f b = f (a:b) id x = x Demonstrate how f works by giving the intermediate evaluation steps of f applied to an argument. [8] [TURN OVER] -4-

5. (a) Give the syntax definition for a lambda-calculus expression (with constants but without types) and explain the operation of the three primary evaluation (reduction) mechanisms. Explain what a delta-rule is and how it is used. [7] (b) What is the Y combinator and why is it important? Give a definition for Y. [6] (e) Provide two evaluations of the following lambda-calculus expression, first using Normal Order evaluation and then using Applicative Order evaluation and comment on the results. (λx.((λx.(+ x 1)) 3)) (/ 2 0) [6] What are the advantages of using graph reduction instead of string reduction or tree reduction? [4] Provide a graph-reduction diagrammatic rule for evaluating the graph representing an application of the Y combinator in the most space-efficient manner. [4] (f) Briefly explain the main principles of a parallel graph reduction machine. [6] [END OF PAPER] -5-