Assignment 7. Functional implementation of linked listed

Slides:



Advertisements
Similar presentations
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
Advertisements

Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Pasco-Hernando Community College Tutorial Series.
DISCUSSION OF SOME QUESTIONS ON PRELIM 2 Lecture 23 CS2110 – Spring 2015.
Road Map Introduction to object oriented programming. Classes
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
1 Assignment 8. Implementing type integer Due on Tuesday, 4 December, by midnight (submitted electronically). Download class List and a skeleton of class.
CS4432: Database Systems II
Data Structures Using C++ 2E
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 9.
CS2110 Recitation Week 8. Hashing Hashing: An implementation of a set. It provides O(1) expected time for set operations Set operations Make the set empty.
IPAD Set Up. Gmail Account First, you need to set up a free gmail account with your name. If you have an existing one you may use that as long as: – A)
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
1 Lecture 09 Iterators and Enumerations Reading for these lectures: Weiss, Section Iterator Interface. Much better is: ProgramLive, Section 12.3.
Lists ADT (brief intro):  Abstract Data Type  A DESCRIPTION of a data type  The data type can be anything: lists, sets, trees, stacks, etc.  What.
Overview In this tutorial you will: learn different ways to conduct a web search learn how to save and print search results learn about social bookmarking.
AITI Lecture 20 Trees, Binary Search Trees Adapted from MIT Course 1.00 Spring 2003 Lecture 28 and Tutorial Note 10 (Teachers: Please do not erase the.
Analyzing Complexity of Lists OperationSorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) Insert(
Data Structures -1 st test- March 30, 2015 授課教授:李錫智.
CS/ENGRD 2110 SPRING 2015 Lecture 6: Consequence of type, casting; function equals 1.
COMP 103 Linked Lists. 2 RECAP-TODAY RECAP  Linked Structures: LinkedNode  Iterating and printing Linked Nodes  Inserting and removing Linked Nodes.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
30/10/ Iteration Loops Do While (condition is true) … Loop.
13-1 Sets, Bags, and Tables Exam 1 due Friday, March 16 Wellesley College CS230 Lecture 13 Thursday, March 15 Handout #23.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues (part 2)
SETS 2 – Union and Intersection. UNION of sets – to perform the union of two sets, we just list the elements of both sets. It is not necessary to repeat.
Tries Data Structure. Tries  Trie is a special structure to represent sets of character strings.  Can also be used to represent data types that are.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Arrays and ArrayList Files Most of these slides.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Tree-Structured Indexes Chapter 10.
1 Java Review Outline Java Primitives, Program Structure Operators, Control Flow, Loops Classes and Objects Arrays and ArrayList Most of these slides are.
Tree-Structured Indexes. Introduction As for any index, 3 alternatives for data entries k*: – Data record with key value k –  Choice is orthogonal to.
Emdeon Office Batch Management Services This document provides detailed information on Batch Import Services and other Batch features.
What are they, what do they do and what can I use them for.
Chapter 16: Linked Lists.
Unit 7 Learning Objectives
Review Array Array Elements Accessing array elements
C++ Programming:. Program Design Including
Introduction To Repetition The for loop
Some Eclipse shortcuts
Upsorn Praphamontripong CS 1110 Introduction to Programming Fall 2016
CS 5010 Program Design Paradigms “Bootcamp” Lesson 4.1
Recursion (Continued)
Conditions and Ifs BIS1523 – Lecture 8.
Introduction to Data Structures
Find in a linked list? first last 7  4  3  8 NULL
PC02 Consolidation Loading a witty quote…. PC02 Consolidation Loading a witty quote…
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Set-Builder Notation.
<INSERT_WITTY_QUOTE_HERE>
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Programming in JavaScript
Recursion (Continued)
Data Structures and Algorithms for Information Processing
Programming in JavaScript
Lists.
Data Structures & Algorithms
CSC 143 Binary Search Trees.
ITI Introduction to Computing II Lab-12
Presentation and project
Rewriting your function using map and foldr
Presentation and project
Tree (new ADT) Terminology: A tree is a collection of elements (nodes)
Presentation transcript:

Assignment 7. Functional implementation of linked listed Due on Sunday, 11 November, by midnight (submitted electronically). Download a skeleton class List from the assignment subpage of the course website. Class List MUST have the two constructors shown below. Introduction. In this assignment, you will write a functional implementation of linked lists --none of your methods will use the assignment statement. Setting the stage. Class List provides two fields: a value and the name of an instance of List. As usual, this can represent a linked list. /** An instance is a linked list. Its value is field element; the rest of the list is field next. An empty list is represented by null */ public class List { public Object element; public List next; /** Constructor: an instance with one node, which contains the value null */ public List() { element= null; next= null; } /** Constructor: a list with first element d and rest of the list n */ public List(Object e, List n) { element= e; next= n; } // = "o1 = o2" (they could both be null) public static boolean equals (Object o1, Object o2) { if (o1==null && o2==null) return true; if (o1==null || o2==null) return false; return o1.equals(o2); // = l1 with l2 appended to it public static List append(List l1, List l2) { if (isEmpty(l1)) return l2; return prepend(first(l1), append(rest(l1),l2)); The first constructor is there for technical reasons. Don’t worry about it. Next, we define some primitive methods: /** #1: = List l with x prepended to it */ public static List prepend(Object x, List l) /** #2: = the element of the first node of l. Precondition: l is not null */ public static Object first(List l) /** #3: = List l but with its first element removed */ public static List rest(List l) /** #4: = "list l is empty --i.e. null" */ public static boolean isEmpty(List l) Part I. Implement these methods (in class List) and test them until you are positive that they are correct. Do it incrementally. Write one at a time and test it. Remember: don’t use an assignment statement. Method append is a good one to look at to get the idea of writing methods in a functional manner. Part II. Implement the methods that are described below (place them in class List). They should be static. They should be recursive; they should not use the assignment statement. Of course, you can use the methods of Part 1. And, use method equals (given above) to test equality of objects. THESE METHODS SHOULD NOT REFERENCE FIELDS element and next!! Also, each method better have a suitable specification. 5. printList(List l). Print all the elements of list l on a single line, with a blank after each element. For an empty list, print a blank line. Return null. 6. isMember(Object o, List l). Return a boolean: the value of “Object o is a member of list l”. 7. deleteFirst(Object o, List l). Return a list that is like l except that the first occurrence of o has been deleted. If o does not occur in l, return a list with the same elements as l. 8. deleteAll(Object o, List l). Return a list that is like l except that all occurrences of o have been deleted. If o doesn’t occur in l, return a list with the same elements as l. 9. reverse(List l). Return a list that is the reverse of l. Please turn over and read the other side

Part III. A set is a collection of elements (but with no duplicates) Part III. A set is a collection of elements (but with no duplicates). We can implement a set in an instance of class List. In implementing a set in a List, we require: The List does not contains duplicates. The order of the elements in the List does not matter. Write (in class List) the following methods --without using the assignment statement. They should be static. Below, since the arguments of calls to these functions are sets, they do not contain duplicates and the order in which the values appear in them does not matter. If a method returns a List that represents a set, it should also satisfy these properties. 10. difference(List l1, List l2). Lists l1 and l2 contains sets. Return a list that represents the difference l1-l2 of these two sets: this is the set that contains the elements of l1 that are not in l2. For example, the difference of sets {2,5,3} and {3,6,4}, written as {2,5,3} - {3,6,4} is the set {2,5}. 11. union(List 1, List l1). Lists l1 and l2 contain sets. Return a list that represents the union of these two sets: this is the set of all elements that are in at least one of l1 and l2. 12. intersection(List 1, List l1). Lists l1 and l2 contain sets. Return a list that represents the intersection of these two sets: this is the set of all elements that are in both l1 and l2. Submitting your assignment At the top of your file List.java, put a comment that contains your name an netid. Submit your assignment electronically, as Assignment 7. Submit a folder that contains ONLY file List.java. Again. Submit a folder that contains ONLY a file List.java. We don’t want to see anything else. While this is not mandatory, it will help us if you put the 12 methods that you have to write in the order in which they were presented. We will preselect 5 of the 12 methods that you have to write to test. The same 5 methods will be used for all students. For each method, your grade will depend on: (1) A good Javadoc specification for the method. If you still don’t know what a good specification is (which means that you haven’t been listening or studying), look in the grading guide on the web page. (2) Whether the method works on our test cases. We will try all sorts of test cases, e.g. empty lists, lists with 1 element, lists with 2 elements, etc. So be sure you test your method well. (3) The presentation of your method --is it well indented, etc. In our sample solution, the bodies of the 12 methods to be written take under 50 lines. So the average number of lines per method body is just over 4. Work on one method at a time, testing it well before you move on to the next, and this assignment should not take too much time.