COSC A SU Assignment 1 (Abstract Data Types) Due: May 17 th, 2002

Size: px
Start display at page:

Download "COSC A SU Assignment 1 (Abstract Data Types) Due: May 17 th, 2002"

Transcription

1 COSC A SU Assignment 1 (Abstract Data Types) Due: May 17 th, 2002 This assignment is all about understanding the use of ADT s. You will work with several different ADT s, including one which will ultimately play a role in your project work. 1. Consider the ADT below, an attempt to reverse-engineer the Java class java.util.enumeration. One problem with this effort is that nextelement is a function with a side-effect. Rewrite the declaration to correct this problem. You may add or remove anything you see fit, but you must justify any and all changes. ENUMERATION -- series of elements, returned one at a time OBJECT, BOOLEAN hasmoreelements : ENUMERATION BOOLEAN -- True if this enumeration contains more elements nextelement : ENUMERATION / OBJECT -- returns the next element of this enumeration, error if no more nextelement(e:enumeration) require hasmoreelements(e) -- exception if no more elements exist none (can you add something here?) Solution: The basic solution is simple: we split a function with side-effects into a procedure with side-effects and a function to return the current value. nextelement will now be the procedure with a side-effect: moving a cursor forward. The new function to return the current value will be item. Now, item has to return the current item right from the start, even before nextelement is called for the first time, but it cannot work if the ENUMERATION is empty. Consequently, we need a new tool, empty, to determine if the ENUMERATION is in fact empty. NB: This does not make hasmoreelements redundant, since it only tells us that the ENUMERATION is or is not empty nextelement doesn t remove elements, after all, it just moves the cursor. As for axioms, there s little we can do, except to note that an ENUMERATION with more elements is clearly not empty. Since we re not given a way to control what is in the ENUMERATION (e.g., by adding things), we can t say anything about successive items, for example. ENUMERATION XQFKDQJHG -- series of elements, returned one at a time OBJECT, BOOLEAN XQFKDQJHG hasmoreelements : ENUMERATION BOOLEAN XQFKDQJHG -- True if this enumeration contains more elements nextelement : ENUMERATION / ENUMERATION VLGHHIIHFWVHFWV QRW DOORZHG LQ IXQFWLRQt FRQYHUW WR SURFHGXUH -- move cursor to the next element of this enumeration, error if no more item : ENUMERATION / OBJECT QHZ -- returns the current element of this enumeration, error if empty empty : ENUMERATION BOOLEAN QHZ -- True if this enumeration contains no elements at all nextelement(e:enumeration) require hasmoreelements(e) XQFKDQJHG -- exception if no more elements exist item(e:enumeration) require empty(e) QHZ -- exception if we look for the current element when none exist at all e : ENUMERATION hasmoreelements(e) empty(e) 2. Reverse-engineer an ADT from the Java class java.util.hashtable, i.e., write an ADT for which this class could be the implementation. Ignore the functions clone, entryset, keyset, putall, elements, keys, rehash, values, any inherited functions, and the Hashtable(Map) constructor. Also, consider put and remove to be void, rather 3311 Assignment 1 Sample Solution (long form) Page 1

2 than returning an Object (i.e., consider them to be commands). Write the declaration in the usual form (shown above). Solution: Although there are physical limits on allocating hash tables (e.g., is there enough memory to allocate a hash table of this size, or even any hash table at all?), and many of the functions require non-null (Eiffel: non-void) object references as arguments, ADT s are mathematical constructs, a realm where these issues don t apply. So, we will stay abstract and not worry about them. Of course, the size cannot be negative, the load factor must be positive, as stated in the documentation, and these are things we can and should look at. HASHTABLE -- maps keys to values OBJECT, BOOLEAN, INTEGER, STRING, FLOAT contains : HASHTABLE OBJECT BOOLEAN -- Test if any key maps into the specified value containskey : HASHTABLE OBJECT BOOLEAN -- True if the specified object is a key containsvalue : HASHTABLE OBJECT BOOLEAN -- True if one or more keys map to this value equals : HASHTABLE OBJECT BOOLEAN -- Compare the specified Object with this table for equality get : HASHTABLE OBJECT OBJECT -- Return the value to which the specified key is mapped hashcode : HASHTABLE INTEGER -- Return the hash code value for this table isempty : HASHTABLE BOOLEAN -- Test if this hashtable maps no keys to values size : HASHTABLE INTEGER -- Return the number of keys in this hashtable tostring : HASHTABLE STRING -- Return a string representation of this Hashtable object remove : HASHTABLE OBJECT HASHTABLE -- Remove the key (and its corresponding value) from this hashtable put : HASHTABLE OBJECT OBJECT HASHTABLE -- Map specified key to specified value (i.e., add them to this hashtable) clear : HASHTABLE HASHTABLE -- Clear this hashtable so that it contains no keys make : HASHTABLE (also: make : HASHTABLE) -- Construct empty hashtable with default capacity and load factor (0.75) make_sized : INTEGER HASHTABLE -- Construct empty hashtable with given capacity and default load factor make_sized_load : INTEGER FLOAT HASHTABLE -- Construct empty hashtable with given capacity and load factor As explained above, we ignore the need to check for Void arguments in get, put (both arguments), contains, containskey, containsvalue, equals, and remove, but the real code needs to include the test. Other than these, there are only two things to verify, being that the initial size and load factor are correct. put and remove are tolerant, so we don t need to verify that the key is or is not already present in the hashtable. make_sized(s:integer) require s 0 -- initial size cannot be negative make_sized_load(s:integer,f:float) require f > 0.0 s 0 -- initial size cannot be negative, load factor must be positive The thing to remember in the work with axioms is that even command functions (e.g., remove and put) don't actually change the hashtable but return a brand new object based on the old one, so if k is in h, remove(h,k) h. Not much can be said about hashcode. hashcode computes a number about which we know little, and which is used largely internally. We can t even guarantee that two hashtables will have different codes, although it is likely. As for tostring, the documentation states that the string returned reflects the entries, so changes are reflected in the value of tostring. An axiom below expresses that; it would be tempting to also say that putting the same entry in the second time does not change the string, but we have no information on the order in which entries appear, and if this would then change Assignment 1 Sample Solution (long form) Page 2

3 equals is not problematic as long as we remember that = here does not mean is coreferent ( i.e., refers to the same object ). h1,h2 : HASHTABLE equals(h1,h2) h1 = h2 -- mathematical interpretation (warning: not just a pointer comparison!) h: HASHTABLE, k,v: OBJECT get(put(h,k,v),k) = v -- after you put something in the table, get returns the same value again h : HASHTABLE isempty(h) size(h) -- empty tables have 0 size h : HASHTABLE, k, v: OBJECT get(h,k) v tostring(h) tostring(put(h,k,v)) -- the string displayed depends on values and keys h : HASHTABLE, k: OBJECT containskey(h,k) tostring(h) tostring(remove(h,k)) -- the string displayed depends on values and keys h : HASHTABLE, k: OBJECT containskey(h,k) containsvalue(h,get(h,k)) -- if a key is contained in the table, so is the corresponding value h : HASHTABLE, k: OBJECT containskey(h,k) contains(h,get(h,k)) -- if a key is contained in the table, so is the corresponding value h : HASHTABLE, k: OBJECT containskey(remove(h,k),k) -- a key is no longer in the hashtable after it is removed h : HASHTABLE, k,v: OBJECT containskey(h,k) (remove(put(h,k,v),k) h) -- putting and removing an old key (+ value) changes the table h : HASHTABLE, k,v: OBJECT containskey(h,k) (remove(put(h,k,v),k) = h) -- putting and removing a new key (+ value) leaves the table unchanged overall h : HASHTABLE, k,v: OBJECT containskey(h,k) size(put(h,k,v)) = size(h) the size increases by one if an item with a new key is added h : HASHTABLE, k,v: OBJECT containskey(h,k) size(put(h,k,v)) = size(h) -- the size is unchanged but putting in a value if the key already existed h : HASHTABLE, k: OBJECT containskey(h,k) size(remove(h,k)) = size(h) the size decreases by one if an existing item is removed h : HASHTABLE, k: OBJECT containskey(h,k) size(remove(h,k)) = size(h) -- the size is unchanged if we try to remove a non-existent item h : HASHTABLE size(clear(h)) = 0 -- clearing a table zeroes the size h : HASHTABLE, k,v: OBJECT containskey(put(h,k,v),k) -- a table contains a key after we put it in h : HASHTABLE, k,v: OBJECT containsvalue(put(h,k,v),v) -- a table contains a value after we put it in h : HASHTABLE, k,v: OBJECT contains(put(h,k,v),v) -- a table contains a value after we put it in h : HASHTABLE, k: OBJECT containskey(clear(h),k) -- a table contains no keys after we clear it h : HASHTABLE, v: OBJECT containsvalue(clear(h),v) -- a table contains no values after we clear it h : HASHTABLE, v: OBJECT contains(clear(h),v) -- a table contains no values after we clear it h : HASHTABLE isempty(clear(h)) -- a table is empty after we clear it h : HASHTABLE, k,v: OBJECT isempty(put(h,k,v)) -- a table is not empty if an item is added to it k: OBJECT containskey(make,k) -- no keys are contained in a fresh table i: INTEGER, k: OBJECT containskey(make_sized(i),k) -- no keys are contained in a fresh table i: INTEGER, f: FLOAT, k: OBJECT containskey(make_sized_load(i,f),k) -- no keys are contained in a fresh table v: OBJECT containsvalue(make,v) v: OBJECT contains(make,v) i: INTEGER, v: OBJECT containsvalue(make_sized(i),v) 3311 Assignment 1 Sample Solution (long form) Page 3

4 i: INTEGER, v: OBJECT contains(make_sized(i),v) i: INTEGER, f: FLOAT, v: OBJECT containsvalue(make_sized_load(i,f),v) i: INTEGER, f: FLOAT, v: OBJECT contains(make_sized_load(i,f),v) h : HASHTABLE, k: OBJECT containskey(h,k) (remove(h,k) = h) -- removing a nonexistent key/value pair does not change the table h : HASHTABLE, k: OBJECT containskey(h,k) (remove(h,k) h) -- removing an existing key/value pair changes the table isempty(make) -- a new table is empty i: INTEGER isempty(make_sized(i)) -- a new table is empty i: INTEGER, f: FLOAT isempty(make_sized_load(i,f)) -- a new table is empty size(make) = 0 -- a new table has 0 entries i: INTEGER size(make_sized(i)) = 0 -- a new table has 0 entries i: INTEGER, f: FLOAT size(make_sized_load(i,f)) = 0 -- a new table has 0 entries We might be tempted to add axioms like the following, but they are not valid for the reasons listed: h : HASHTABLE, k,v: OBJECT containsvalue(remove(h,k),v) -- removing a key means removing its value incorrect, since a value might be -- accessible via more than one key h : HASHTABLE, k,v: OBJECT containsvalue(remove(h,k),v) -- accessible via more than one key 3. The VEHICLE ADT, a work in progress, uses the ADT s POSITION and DIRECTION, and has four operations: make make some vehicle located at a particular position; the position cannot be Void location report on the position of the vehicle drive move the vehicle in some direction, to a new location; the direction cannot be Void fill_up tank up the vehicle with n litres of fuel; the amount must be 1 or more Write a declaration for this ADT in the mathematical format used in class, and above. If the above details are not enough to create the ADT, apply common sense and document your decisions. Solution: This is intended as a simple introduction to creating ADT s: rich enough to require all types of functions (creator, command, and query), one precondition, and one or two axioms. By applying a little imagination, more could be added, e.g., a query function to find out how much fuel is still in the vehicle. You may have been tempted to add other things, such as a fuel consumption rate, maximum fuel level, etc., and if you were, all the more power to you! The simplest ADT would be: VEHICLE -- allows us to simulate a vehicle POSITION, DIRECTION, INTEGER RU 5($/ LQVWHDG RI,17(*(5 KHUH DQG HYHU\ZKHUHHUH EHORZ location : VEHICLE POSITION -- where is the vehicle? drive : VEHICLE DIRECTION VEHICLE -- move the vehicle in a given direction fill_up : VEHICLE INTEGER / VEHICLE -- simulates adding n litres of fuel to the vehicle make : POSITION VEHICLE -- creates a vehicle located at a particular position fill_up(v:vehicle,n:integer) require n 1 -- have to fill up with at least one litre of gas 3311 Assignment 1 Sample Solution (long form) Page 4

5 v : VEHICLE, d:direction location(v) location(drive(v,d)) -- driving a vehicle changes its location v : VEHICLE, n:integer location(v) location(fill_up(v,n)) -- filling up a vehicle does not change its location -- (as long as you don t smoke when filling up ;-) If we add a fuel query function, we need to add the following items: fuel : VEHICLE INTEGER -- how much fuel does the vehicle have v : VEHICLE fuel(v) 0 -- can t have a negative amount of fuel v : VEHICLE, d:direction fuel(v) > fuel(drive(v,d)) -- driving uses up fuel v : VEHICLE, d:direction fuel(fill_up(v,n)) = fuel(v) + n -- filling up with n litres of fuel adds n litres to our amount of fuel If we knew more about DIRECTION and POSITION, we might reasonably add preconditions about them, e.g., the vehicle must be on Earth, but this is all we have, so we can t properly add such preconditions. This is good and bad good if we want to describe the Mars Rover, since even this mild precondition would be too restrictive, but bad if we want to have more complete preconditions. Note that some of the questions have red herings, including this one. References to Void are foreign to mathematics, and should not appear in the ADT. 4. In the project, you will be creating software to administer automated tests to students. Faculty members will use it to create tests like the pre-test you wrote in this course, including multiple-choice questions, true-false questions, and questions with a limited range of typed answers (e.g., numbers, single words, etc.). Students will use it to take tests and query their results. Staff members will also use it, when they need to access test results or update class lists, etc. A key ADT for the software will be a representation for the test itself, which must record the constituent questions and allow different forms of access to different people. Students registered in the course associated with the test may read the questions. Faculty members who are teaching the associated course may read the questions, but also alter them and add to the body of questions. Staff members may not read the questions, nor may they alter them in any way. Consider carefully what you believe should be in the TEST ADT, and write a declaration for it in the same form as used in the other questions. Solution: From the above summary, we can extract the following information, with some obvious musings (in subpoints): faculty create their own tests, can read/alter/add to questions faculty must also be able to take their own tests we can also assume they need to access results, otherwise the tests wouldn t be much use, and here we should consider whether they can just access overall results or responses to individual questions do we let faculty alter a test after anyone other than them has taken it? permitting this means that results before and after the change may not be comparable, so it s best not to allow alterations at that point tests have associated questions of different types students can take tests and query the results do we let students take a test twice? we ll assume no, for the time being when can students see their results? surely only after the test has been taken? what level of detail can students see in their results? if we need an audit trail (probably), then we need to record individual responses, but that doesn t mean students must be able to access the responses because of the simple nature of the answers, allowing later viewing of their own answers (and questions!) allows test takers to show their results (and questions!) to other test takers, introducing a strong risk of cheating; the simplest solution here is to only allow students to view overall scores, but to allow faculty to view everything staff members can access test results, can use the information to update class lists, but cannot read/alter questions implicitly, staff members also cannot add questions; as for updating class lists, this may be a red hering, since we ll see that class lists should probably be maintained separately students may only take tests if they are enrolled in the corresponding course so, students who drop the course cannot take tests any more, but can they still access their results? to simplify things, we ll say no 3311 Assignment 1 Sample Solution (long form) Page 5

6 Other issues may crop up, e.g., what do we do with faculty who take courses and thus are also students, or students who work part time in the department office and thus are staff? (In these cases, it may be simplest to require them to use two or more separate userids, but that s an issue to contemplate later.) The above list leaves us with the following list of candidate features: course identifier (query) take test (command) registered students can do this, and the lecturer of the course (you have to debug tests!), but not staff test taken (query) true if someone has taken the test already create a test (creator) lecturer only get or read questions (query) lecturer only alter questions (command) lecturer only add questions (command) lecturer only delete questions (command) not given above, but obvious counterpart to add lecturer only provide test results (query) students can only see overall result, but faculty can review individual responses test name (query) there will be more than one test per course usually, we can safely assume The following features seem like reasonable possibilities, but are not included for the reasons given: class list (query) this is properly recorded with the course, and thus is accessible via the course identifier lecturer (query) this is properly recorded with the course, and thus is accessible via the course identifier maintain class list (command) as noted, the class list belongs to the course record test results (command) on later reflection, we can see this would be a side-effect of taking the test collection of questions (query) although obviously necessary, we can t allow anyone but faculty to use it, since otherwise it would provide a backdoor to reading the questions; faculty already have get questions, however, so they don t need it, either We might also consider offering the following features, but they re not explicitly stated above: reorder questions (command) again, not given above, but obvious lecturer only Before we can list the functions, we have to consider arguments to the functions, specifically, whether the identity of the user will be passed to functions, in order to check permissions, or whether it should be assumed to be present in some sort of global value, or whether it should be checked at an altogether different level or through still another means. It turns out that we can restrict access to some features to specific classes in Eiffel, our target language, so some of the checking could be done that way, but we don t have access to that in the ADT. Since the only way you have to introduce users into the ADT is to use arguments, we ll assume that route. We also need to assume the existence of some as yet undefined ADT s (USER, QUESTION, SCORE, RESPONSE, COURSE), all but one of which are simply used as arguments or return values, and for which no functionality is assumed. By using these types, we stay general; later, these could be represented with standard types (e.g., USER represented as STRING), but going the other way would not be possible. We need to assume two obvious things about the COURSE ADT that it can provide information about the lecturer and the students registered in the course: TEST -- represents a test, with related questions, answers, and results BOOLEAN, INTEGER, STRING, USER, QUESTION, SCORE, RESPONSE, COURSE course : TEST COURSE -- course identifier take_test : TEST USER / TEST -- allows a user to take a TEST test_taken : TEST USER BOOLEAN -- true if the user has already taken the TEST -- (can be total, since we know unqualified people have not take the test) make : USER COURSE STRING / TEST -- lets user create TEST for a given course with a given name get_question : TEST USER INTEGER / QUESTION -- get a specific question from the TEST alter_question : TEST USER INTEGER QUESTION / TEST -- replace specific question with given one add_question : TEST USER QUESTION / TEST -- add given question delete_question : TEST USER INTEGER / TEST -- delete given question overall_score : TEST USER / SCORE -- lets user access own results individual_response : TEST USER USER INTEGER / RESPONSE -- lets lecturer access response of test taker to specific question 3311 Assignment 1 Sample Solution (long form) Page 6

7 individual_score : TEST USER USER INTEGER / SCORE -- lets lecturer access score of test taker on specific question name : TEST STRING -- TEST name, so we can tell them apart! count : TEST INTEGER -- number of questions on TEST take_test(t:test,u:user) require (registered(course(t),u) test_taken(t,u)) lecturer(course(t)) = u -- only registered students or course lecturer can take a TEST -- only lecturer can retake test (to try different possible scenarios) make(u:user,c:course,n:string) require lecturer(c) = u t : TEST (name(t) n course(t) c) -- only lecturer can create a TEST, and the test name must be unique for a course get_question(t:test,u:user,n:integer) require lecturer(course(t)) = u 1 n count(t) -- only lecturer is allowed, and then the question number must be valid alter_question(t:test,u:user,n:integer,q:question) require lecturer(course(t)) = u 1 n count(t) ( s: USER s u test_taken(t,u)) -- only lecturer can, but must be valid question #, and no one has taken test yet add_question(t:test,u:user,q:question) require lecturer(course(t)) = u ( s: USER s u test_taken(t,u)) -- only lecturer can, but only if no one has taken the test yet delete_question(t:test,u:user,n:integer) require lecturer(course(t)) = u 1 n count(t) ( s: USER s u test_taken(t,u)) -- only lecturer can, but must be valid question #, and no one has taken test yet overall_score(t:test,u:user) require (registered(course(t),u) lecturer(course(t)) = u) test_taken(t,u) -- only registered students or the lecturer of the course can access own results individual_response(t:test,f:user,s:user,n:integer) require lecturer(course(t)) = f registered(course(t),s) test_taken(t,s) 1 n count(t) -- only lecturer can see student response, and then student must be registered, must -- have taken test, and question # must be valid individual_score(t:test,f:user,s:user,n:integer) require lecturer(course(t)) = f registered(course(t),s) test_taken(t,s) 1 n count(t) -- only lecturer can see student response, and then student must be registered, must -- have taken test, and question # must be valid t : TEST, u: USER name(take_test(t,u)) = name(t) -- taking the test doesn t change the name of a TEST t : TEST, u: USER course(take_test(t,u)) = course(t) -- taking the test doesn t change the course t : TEST, u: USER count(take_test(t,u)) = count(t) -- taking the test doesn t change the count t : TEST, u: USER test_taken(take_test(t,u)) -- taking the test marks the test as taken for that user t : TEST, n: INTEGER, u: USER get_question(take_test(t,u),u,n) = get_question(t,u,n) -- taking the test doesn t change the questions t : TEST, q: QUESTION, n: INTEGER, u: USER name(alter_question(t,u,n,q)) = name(t) -- altering a question doesn t change the name of a TEST t : TEST, q: QUESTION, n: INTEGER, u: USER course(alter_question(t,u,n,q)) = course(t) -- altering a question doesn t change the course t : TEST, q: QUESTION, n: INTEGER, u: USER count(alter_question(t,u,n,q)) = count(t) -- altering a question doesn t change the count t : TEST, q: QUESTION, n: INTEGER, u: USER get_question(alter_question(t,u,n,q),u,n) = q -- after alteration, the altered questions is what we see t : TEST, q: QUESTION, u: USER name(add_question(t,u,q)) = name(t) -- adding questions doesn t change the name of a TEST 3311 Assignment 1 Sample Solution (long form) Page 7

8 t : TEST, q: QUESTION, u: USER course(add_question(t,u,q)) = course(t) -- adding questions doesn t change the course t : TEST, q: QUESTION, u: USER count(add_question(t,u,q)) = count(t) adding a question increases the count by one t : TEST, q: QUESTION, n: INTEGER, u: USER get_question(add_question(t,u,q),u,count(t)+1) = q -- questions are added to the end t : TEST, n: INTEGER, u: USER name(delete_question(t,u,n)) = name(t) -- deleting a question doesn t change the name of a TEST t : TEST, n: INTEGER, u: USER course(delete_question(t,u,n)) = course(t) -- deleting a question doesn t change the course t : TEST, n: INTEGER, u: USER count(delete_question(t,u,n)) = count(t) deleting a question decreases the count by one t : TEST, q: QUESTION, i,n: INTEGER, u: USER (i n i < count(t)) (get_question(delete_question(t,u,n),u,i) = get_question(t,u,i+1)) -- after deletion, questions after n are moved up one (i.e., #3 becomes #2, etc.) u: USER, c : COURSE, s: STRING count(make(u,c,s)) = 0 -- no questions are initially defined for a test u: USER, c : COURSE, s: STRING course(make(u,c,s)) = c -- we can retrieve the course used to create the test via course( ) u: USER, c : COURSE, s: STRING lecturer(course(make(u,c,s))) = u -- we can retrieve the lecturer used to create the test via lecturer(course( )) u: USER, c : COURSE, s: STRING name(make(u,c,s)) = s -- we can retrieve the name used for the test via name( ) One more thing we would like to represent with this ADT, but which appears to be impossible for us, is that the instant a student takes the test, no more changes may be made. This is implicit in the preconditions, but we d like to draw it out more obviously. Also, the lecturer has no control over when the test is taken, and theoretically it is possible for a student to take the test before any questions have been added! One way to fix this would be to formalise the permission-granting procedure, and add two features: ready and set_ready. Students would only be permitted to take tests which were ready, and only the lecturer would be allowed to set this value, via set_ready (which could only be used if the test had not yet been taken). There would be interesting changes which would follow from this (exercise left for the reader) Assignment 1 Sample Solution (long form) Page 8

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

Homework #10 due Monday, April 16, 10:00 PM

Homework #10 due Monday, April 16, 10:00 PM Homework #10 due Monday, April 16, 10:00 PM In this assignment, you will re-implement Dictionary as Map container class using the same data structure. A Map has an associated entry set and that set will

More information

A simple map: Hashtable

A simple map: Hashtable Using Maps A simple map: Hashtable To create a Hashtable, use: import java.util.*; Hashtable table = new Hashtable(); To put things into a Hashtable, use: table.put(key, value); To retrieve a value from

More information

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007

Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you

More information

CSE331 Autumn 2011 Midterm Examination October 28, 2011

CSE331 Autumn 2011 Midterm Examination October 28, 2011 CSE331 Autumn 2011 Midterm Examination October 28, 2011 50 minutes; 75 points total. Open note, open book, closed neighbor, closed anything electronic (computers, webenabled phones, etc.) An easier-to-read

More information

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003

Data abstractions: ADTs Invariants, Abstraction function. Lecture 4: OOP, autumn 2003 Data abstractions: ADTs Invariants, Abstraction function Lecture 4: OOP, autumn 2003 Limits of procedural abstractions Isolate implementation from specification Dependency on the types of parameters representation

More information

CSIS 10B Lab 2 Bags and Stacks

CSIS 10B Lab 2 Bags and Stacks CSIS 10B Lab 2 Bags and Stacks Part A Bags and Inheritance In this part of the lab we will be exploring the use of the Bag ADT to manage quantities of data of a certain generic type (listed as T in the

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor. 3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

More information

Equality for Abstract Data Types

Equality for Abstract Data Types Object-Oriented Design Lecture 4 CSU 370 Fall 2008 (Pucella) Tuesday, Sep 23, 2008 Equality for Abstract Data Types Every language has mechanisms for comparing values for equality, but it is often not

More information

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1)

Topics. Java arrays. Definition. Data Structures and Information Systems Part 1: Data Structures. Lecture 3: Arrays (1) Topics Data Structures and Information Systems Part 1: Data Structures Michele Zito Lecture 3: Arrays (1) Data structure definition: arrays. Java arrays creation access Primitive types and reference types

More information

Subclassing for ADTs Implementation

Subclassing for ADTs Implementation Object-Oriented Design Lecture 8 CS 3500 Fall 2009 (Pucella) Tuesday, Oct 6, 2009 Subclassing for ADTs Implementation An interesting use of subclassing is to implement some forms of ADTs more cleanly,

More information

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters.

2. You are required to enter a password of up to 100 characters. The characters must be lower ASCII, printing characters. BLACK BOX SOFTWARE TESTING SPRING 2005 DOMAIN TESTING LAB PROJECT -- GRADING NOTES For all of the cases below, do the traditional equivalence class and boundary analysis. Draw one table and use a new line

More information

Algebraic Specifications

Algebraic Specifications Object-Oriented Design Lecture 2 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 11, 2007 Algebraic Specifications Last time I said a word about the abstraction barrier, separating the clients from the implementors.

More information

Collections. Collections Collection types Collection wrappers Composite classes revisited Collection classes Hashtables Enumerations

Collections. Collections Collection types Collection wrappers Composite classes revisited Collection classes Hashtables Enumerations References: Beginning Java Objects, Jacquie Barker; The Java Programming Language, Ken Arnold and James Gosling; IT350 Internet lectures 9/16/2003 1 Collections Collection types Collection wrappers Composite

More information

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

CSE 331 Midterm Exam Sample Solution 2/18/15

CSE 331 Midterm Exam Sample Solution 2/18/15 Question 1. (10 points) (Forward reasoning) Using forward reasoning, write an assertion in each blank space indicating what is known about the program state at that point, given the precondition and the

More information

Assignment 4: Hashtables

Assignment 4: Hashtables Assignment 4: Hashtables In this assignment we'll be revisiting the rhyming dictionary from assignment 2. But this time we'll be loading it into a hashtable and using the hashtable ADT to implement a bad

More information

6.005 Elements of Software Construction Fall 2008

6.005 Elements of Software Construction Fall 2008 MIT OpenCourseWare http://ocw.mit.edu 6.005 Elements of Software Construction Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.005 elements

More information

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014 Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class

More information

Midterm Exam (REGULAR SECTION)

Midterm Exam (REGULAR SECTION) Data Structures (CS 102), Professor Yap Fall 2014 Midterm Exam (REGULAR SECTION) October 28, 2014 Midterm Exam Instructions MY NAME:... MY NYU ID:... MY EMAIL:... Please read carefully: 0. Do all questions.

More information

Collections. Collections. Collections - Arrays. Collections - Arrays

Collections. Collections. Collections - Arrays. Collections - Arrays References: Beginning Java Objects, Jacquie Barker; The Java Programming Language, Ken Arnold and James Gosling; IT350 Internet lectures Collections Collection types Collection wrappers Composite classes

More information

The class Object. Lecture CS1122 Summer 2008

The class Object.  Lecture CS1122 Summer 2008 The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

27/04/2012. Objectives. Collection. Collections Framework. "Collection" Interface. Collection algorithm. Legacy collection

27/04/2012. Objectives. Collection. Collections Framework. Collection Interface. Collection algorithm. Legacy collection Objectives Collection Collections Framework Concrete collections Collection algorithm By Võ Văn Hải Faculty of Information Technologies Summer 2012 Legacy collection 1 2 2/27 Collections Framework "Collection"

More information

3 ADT Implementation in Java

3 ADT Implementation in Java Object-Oriented Design Lecture 3 CS 3500 Spring 2010 (Pucella) Tuesday, Jan 19, 2010 3 ADT Implementation in Java Last time, we defined an ADT via a signature and a specification. We noted that the job

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

Abstract Data Types. Lecture notes accompanying COL106 (Data Structures), Semester I, , IIT Delhi

Abstract Data Types. Lecture notes accompanying COL106 (Data Structures), Semester I, , IIT Delhi Abstract Data Types Lecture notes accompanying COL106 (Data Structures), Semester I, 2018-19, IIT Delhi Amitabha Bagchi Department of CS&E, IIT Delhi August 13, 2018 1 What is an abstract data type Abstract

More information

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists Due on Tuesday February 24, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1 CMPSCI

More information

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print)

Computer Science 62. Bruce/Mawhorter Fall 16. Midterm Examination. October 5, Question Points Score TOTAL 52 SOLUTIONS. Your name (Please print) Computer Science 62 Bruce/Mawhorter Fall 16 Midterm Examination October 5, 2016 Question Points Score 1 15 2 10 3 10 4 8 5 9 TOTAL 52 SOLUTIONS Your name (Please print) 1. Suppose you are given a singly-linked

More information

Software Architecture. Abstract Data Types

Software Architecture. Abstract Data Types Software Architecture Abstract Data Types Mathematical description An ADT is a mathematical specification Describes the properties and the behavior of instances of this type Doesn t describe implementation

More information

Many strategies have been developed for this, but they often produce surprising results.

Many strategies have been developed for this, but they often produce surprising results. Interfaces C++ is among those languages offering multiple inheritance: a class may inherit from more than one direct superclass. This adds flexibility, but it also brings problems. A class may inherit

More information

Rules and syntax for inheritance. The boring stuff

Rules and syntax for inheritance. The boring stuff Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for

More information

Largest Online Community of VU Students

Largest Online Community of VU Students WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions

More information

1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation

1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation 1.00 Lecture 32 Hashing Reading for next time: Big Java 18.1-18.3 Motivation Can we search in better than O( lg n ) time, which is what a binary search tree provides? For example, the operation of a computer

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

CS 2506 Computer Organization II Test 1

CS 2506 Computer Organization II Test 1 Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other computing devices may

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we

More information

Solution READ THIS NOW! CS 3114 Data Structures and Algorithms

Solution READ THIS NOW! CS 3114 Data Structures and Algorithms READ THIS NOW! Print your name in the space provided below. There are 5 short-answer questions, priced as marked. The maximum score is 100. This examination is closed book and closed notes, aside from

More information

16 Multiple Inheritance and Extending ADTs

16 Multiple Inheritance and Extending ADTs Object-Oriented Design Lecture 16 CS 3500 Fall 2009 (Pucella) Tuesday, Nov 10, 2009 16 Multiple Inheritance and Extending ADTs We looked last time at inheritance and delegation as two ways to reuse implementation

More information

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013

09/02/2013 TYPE CHECKING AND CASTING. Lecture 5 CS2110 Spring 2013 1 TYPE CHECKING AND CASTING Lecture 5 CS2110 Spring 2013 1 Type Checking 2 Java compiler checks to see if your code is legal Today: Explore how this works What is Java doing? Why What will Java do if it

More information

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 104 (Spring 2014) Final Exam 05/09/2014 CS 104 (Spring 2014) Final Exam 05/09/2014 G o o d L u c k Your Name, USC username, and Student ID: This exam has 8 pages and 8 questions. If yours does not, please contact us immediately. Please read

More information

Lecture 8 Data Structures

Lecture 8 Data Structures Lecture 8 Data Structures 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning, André Platzer, Rob Simmons, Iliano Cervesato In this lecture we introduce the idea of imperative data

More information

Pointers, Arrays and Parameters

Pointers, Arrays and Parameters Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming

More information

The Java Type System (continued)

The Java Type System (continued) Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass

More information

CPS122 Lecture: Detailed Design and Implementation

CPS122 Lecture: Detailed Design and Implementation CPS122 Lecture: Detailed Design and Implementation Objectives: Last revised March 12, 2012 1. To introduce the use of a complete UML class box to document the name, attributes, and methods of a class 2.

More information

Exceptions and Design

Exceptions and Design Exceptions and Exceptions and Table of contents 1 Error Handling Overview Exceptions RuntimeExceptions 2 Exceptions and Overview Exceptions RuntimeExceptions Exceptions Exceptions and Overview Exceptions

More information

CMSC 341 Lecture 7 Lists

CMSC 341 Lecture 7 Lists CMSC 341 Lecture 7 Lists Today s Topics Linked Lists vs Arrays Nodes Using Linked Lists Supporting Actors (member variables) Overview Creation Traversal Deletion UMBC CMSC 341 Lists 2 Linked Lists vs Arrays

More information

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors Agenda

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

Unit 4: Client View of a Component Methods

Unit 4: Client View of a Component Methods Unit 4: Client View of a Component Methods Preview of Coming Attractions In this unit be sure to look for method/operation parameters/formal parameters arguments/actual parameters method header/method

More information

Counting Words Using Hashing

Counting Words Using Hashing Computer Science I Counting Words Using Hashing CSCI-603 Lecture 11/30/2015 1 Problem Suppose that we want to read a text file, count the number of times each word appears, and provide clients with quick

More information

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017 Inheritance Lecture 11 COP 3252 Summer 2017 May 25, 2017 Subclasses and Superclasses Inheritance is a technique that allows one class to be derived from another. A derived class inherits all of the data

More information

Lecture 16: HashTables 10:00 AM, Mar 2, 2018

Lecture 16: HashTables 10:00 AM, Mar 2, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 16: HashTables 10:00 AM, Mar 2, 2018 Contents 1 Speeding up Lookup 1 2 Hashtables 2 2.1 Java HashMaps.......................................

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

Stage 11 Array Practice With. Zip Code Encoding

Stage 11 Array Practice With. Zip Code Encoding A Review of Strings You should now be proficient at using strings, but, as usual, there are a few more details you should know. First, remember these facts about strings: Array Practice With Strings are

More information

Computer Science E-119 Fall Problem Set 3. Due before lecture on Wednesday, October 31

Computer Science E-119 Fall Problem Set 3. Due before lecture on Wednesday, October 31 Due before lecture on Wednesday, October 31 Getting Started To get the files that you will need for this problem set, log into nice.harvard.edu and enter the following command: gethw 3 This will create

More information

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40 Lecture 16 Hashing Hash table and hash function design Hash functions for integers and strings Collision resolution strategies: linear probing, double hashing, random hashing, separate chaining Hash table

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points Files to submit: 1. HW3.py This is a PAIR PROGRAMMING Assignment: Work with your partner! For pair

More information

CS121/IS223. Object Reference Variables. Dr Olly Gotel

CS121/IS223. Object Reference Variables. Dr Olly Gotel CS121/IS223 Object Reference Variables Dr Olly Gotel ogotel@pace.edu http://csis.pace.edu/~ogotel Having problems? -- Come see me or call me in my office hours -- Use the CSIS programming tutors CS121/IS223

More information

CPS122 Lecture: Detailed Design and Implementation

CPS122 Lecture: Detailed Design and Implementation CPS122 Lecture: Detailed Design and Implementation Objectives: Last revised March 3, 2017 1. To introduce the use of a complete UML class box to document the name, attributes, and methods of a class 2.

More information

CSE 331 Final Exam 3/16/15 Sample Solution

CSE 331 Final Exam 3/16/15 Sample Solution Question 1. (12 points, 3 each) A short design exercise. Suppose Java did not include a Set class in the standard library and we need to store a set of Strings for an application. We know that the maximum

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

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs

Prelim 2, CS :30 PM, 25 April Total Question Name Short Search/ Collections Trees Graphs Prelim 2, CS2110 7:30 PM, 25 April 2017 1 2 3 4 5 6 Total Question Name Short Search/ Collections Trees Graphs answer sort stuff Max 1 26 18 15 20 20 100 Score Grader The exam is closed book and closed

More information

C# and Java. C# and Java are both modern object-oriented languages

C# and Java. C# and Java are both modern object-oriented languages C# and Java C# and Java are both modern object-oriented languages C# came after Java and so it is more advanced in some ways C# has more functional characteristics (e.g., anonymous functions, closure,

More information

CSCI 200 Lab 1 Implementing and Testing Simple ADTs in Java

CSCI 200 Lab 1 Implementing and Testing Simple ADTs in Java CSCI 200 Lab 1 Implementing and Testing Simple ADTs in Java This lab is a review of creating programs in Java and an introduction to JUnit testing. You will complete the documentation of an interface file

More information

Software Design and Analysis for Engineers

Software Design and Analysis for Engineers Software Design and Analysis for Engineers by Dr. Lesley Shannon Email: lshannon@ensc.sfu.ca Course Website: http://www.ensc.sfu.ca/~lshannon/courses/ensc251 Simon Fraser University Slide Set: 2 Date:

More information

Program development plan

Program development plan Appendix A Program development plan If you are spending a lot of time debugging, it is probably because you do not have an effective program development plan. A typical, bad program development plan goes

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

Reliable programming

Reliable programming Reliable programming How to write programs that work Think about reliability during design and implementation Test systematically When things break, fix them correctly Make sure everything stays fixed

More information

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009

Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 Object-Oriented Design Lecture 23 CS 3500 Fall 2009 (Pucella) Tuesday, Dec 8, 2009 23 Odds and Ends In this lecture, I want to touch on a few topics that we did not have time to cover. 23.1 Factory Methods

More information

Programming Assignment 1

Programming Assignment 1 CMPS 101 Algorithms and Abstract Data Types Programming Assignment 1 Introduction The purpose of this assignment is threefold: to make sure everyone is up to speed with Java, to practice modularity and

More information

Java Map and Set collections

Java Map and Set collections Java Map and Set collections Java Set container idea interface Java Map container idea interface iterator concordance example Java maps and sets [Bono] 1 Announcements This week s lab based on an example

More information

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS Computers process information and usually they need to process masses of information. In previous chapters we have studied programs that contain a few variables

More information

Recursively Enumerable Languages, Turing Machines, and Decidability

Recursively Enumerable Languages, Turing Machines, and Decidability Recursively Enumerable Languages, Turing Machines, and Decidability 1 Problem Reduction: Basic Concepts and Analogies The concept of problem reduction is simple at a high level. You simply take an algorithm

More information

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class:

More on Classes. The job of this method is to return a String representation of the object. Here is the tostring method from the Time class: More on Classes tostring One special method in Java is the tostring method. The method (regardless of which class it s added to) has the following prototype: public String tostring(); The job of this method

More information

Prelim 2, CS2110. SOLUTION

Prelim 2, CS2110. SOLUTION Prelim 2, CS2110. SOLUTION 7:30 PM, 25 April 2017 1. Name (1 point) Write your name and NetID at the top of every page of this exam. 2. Short Answer (26 points.) (a) Asymptotic complexity. 8 points. Be

More information

Proofwriting Checklist

Proofwriting Checklist CS103 Winter 2019 Proofwriting Checklist Cynthia Lee Keith Schwarz Over the years, we ve found many common proofwriting errors that can easily be spotted once you know how to look for them. In this handout,

More information

CSCI 200 Lab 3 Using and implementing sets

CSCI 200 Lab 3 Using and implementing sets CSCI 200 Lab 3 Using and implementing sets In this lab, you will write a program that manages a set of workers, using the Worker hierarchy you developed in Lab 2. You will also implement your own version

More information

Hashing. Reading: L&C 17.1, 17.3 Eck Programming Course CL I

Hashing. Reading: L&C 17.1, 17.3 Eck Programming Course CL I Hashing Reading: L&C 17.1, 17.3 Eck 10.3 Defne hashing Objectives Discuss the problem of collisions in hash tables Examine Java's HashMap implementation of hashing Look at HashMap example Save serializable

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

(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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley In Brief: What You Need to Know to Comment Methods in CSE 143 Audience o A random person you don t know who wants

More information

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops

CONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops COMP-202 Unit 4: Programming with Iterations Doing the same thing again and again and again and again and again and again and again and again and again... CONTENTS: While loops Class (static) variables

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

Semantics via Syntax. f (4) = if define f (x) =2 x + 55.

Semantics via Syntax. f (4) = if define f (x) =2 x + 55. 1 Semantics via Syntax The specification of a programming language starts with its syntax. As every programmer knows, the syntax of a language comes in the shape of a variant of a BNF (Backus-Naur Form)

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

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

csci 210: Data Structures Maps and Hash Tables

csci 210: Data Structures Maps and Hash Tables csci 210: Data Structures Maps and Hash Tables Summary Topics the Map ADT Map vs Dictionary implementation of Map: hash tables READING: GT textbook chapter 9.1 and 9.2 Map ADT A Map is an abstract data

More information

Lecture 5: Implementing Lists, Version 1

Lecture 5: Implementing Lists, Version 1 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 5: Implementing Lists, Version 1 Contents 1 Implementing Lists 1 2 Methods 2 2.1 isempty...........................................

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

Object-Oriented Software Construction

Object-Oriented Software Construction 1 Object-Oriented Software Construction Bertrand Meyer Reading assignment 2 OOSC2 Chapter 10: Genericity 3 Lecture 4: Abstract Data Types Abstract Data Types (ADT 4 Why use the objects? The need for data

More information

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011

CMPSCI 187: Programming With Data Structures. Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 CMPSCI 187: Programming With Data Structures Lecture 12: Implementing Stacks With Linked Lists 5 October 2011 Implementing Stacks With Linked Lists Overview: The LinkedStack Class from L&C The Fields and

More information

6.001 Notes: Section 1.1

6.001 Notes: Section 1.1 6.001 Notes: Section 1.1 Slide 1.1.1 This first thing we need to do is discuss the focus of 6.001. What is this course all about? This seems quite obvious -- this is a course about computer science. But

More information

Catalan Numbers. Table 1: Balanced Parentheses

Catalan Numbers. Table 1: Balanced Parentheses Catalan Numbers Tom Davis tomrdavis@earthlink.net http://www.geometer.org/mathcircles November, 00 We begin with a set of problems that will be shown to be completely equivalent. The solution to each problem

More information

Review of Important Topics in CS1600. Functions Arrays C-strings

Review of Important Topics in CS1600. Functions Arrays C-strings Review of Important Topics in CS1600 Functions Arrays C-strings Array Basics Arrays An array is used to process a collection of data of the same type Examples: A list of names A list of temperatures Why

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

Documentation Nick Parlante, 1996.Free for non-commerical use.

Documentation Nick Parlante, 1996.Free for non-commerical use. Documentation Nick Parlante, 1996.Free for non-commerical use. A program expresses an algorithm to the computer. A program is clear or "readable" if it also does a good job of communicating the algorithm

More information