QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February

Similar documents
QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

QUEEN MARY, UNIVERSITY OF LONDON

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

EXAM Computer Science 1 Part 1

EECS 2011 M: Fundamentals of Data Structures

Use the supplementary boxes on the last sheet if you want to change any answer.

COS 126 General Computer Science Spring Written Exam 1

CMSC 433 Section 0101 Fall 2012 Midterm Exam #1

CS 367: Introduction to Data Structures Midterm Sample Questions

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

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

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

CS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.

Slide 1 CS 170 Java Programming 1 More on Strings Duration: 00:00:47 Advance mode: Auto

Lab 14 & 15: String Handling

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

- Thus there is a String class (a large class)

CHAPTER 6 MOST COMMONLY USED LIBRARIES

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.

ANSWERS. Birkbeck (University of London) Software and Programming 1 In-class Test Feb Student Name Student Number. Answer all questions

Do not turn to the next page until the start of the exam.

Introduction to Programming Using Java (98-388)

Arrays in Functions!

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

SEMESTER 1, 2011 EXAMINATIONS. CITS1200 Java Programming FAMILY NAME: GIVEN NAMES:

SOLUTIONS. COMP103 Introduction to Data Structures and Algorithms

Do not turn over until you are told to do so by the Invigilator.

LAB 11: METHODS. CPCS The Lab Note Lab 11 Page 1. Statement Purpose:

1.00/ Introduction to Computers and Engineering Problem Solving. Final / December 13, 2004

Module Contact: Dr Geoff McKeown, CMP Copyright of the University of East Anglia Version 1

String. Other languages that implement strings as character arrays

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam.

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

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

Name CIS 201 Midterm II: Chapters 1-8

Examination Questions Midterm 1

Character Strings COSC Yves Lespérance. Lecture Notes Week 6 Java Strings

Week 4, Wednesday (Spring 2015). Dr. Yoder. Sec 051. Page 1 of 5

ESC101 : Fundamental of Computing

CIS 110 Introduction to Computer Programming Summer 2016 Midterm. Recitation # (e.g., 201):

CS313D: ADVANCED PROGRAMMING LANGUAGE

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2018 TRIMESTER 2 COMP 103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

5/23/2015. Core Java Syllabus. VikRam ShaRma

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

CSE331 Spring 2015, Final Examination June 8, 2015

Computer Science 210 Data Structures Siena College Fall 2018

CE221 Programming in C++ Part 1 Introduction

TEST (MODULE:- 1 and 2)

CSC 210, Exam Two Section February 1999

Software and Programming 1

Chapter 29B: More about Strings Bradley Kjell (Revised 06/12/2008)

Comments in a Java Program. Java Overview. Identifiers. Identifier Conventions. Primitive Data Types and Declaring Variables

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

CSIS 10B Lab 2 Bags and Stacks

PRACTICE MIDTERM EXAM #2

CS 302: Introduction to Programming in Java. Lecture 12

G52CPP C++ Programming Lecture 3. Dr Jason Atkin

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

CSE331 Winter 2014, Midterm Examination February 12, 2014

Java Foundations: Unit 3. Parts of a Java Program

Model Solutions. COMP 102: Test May, 2015

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

School of Computer Science & Software Engineering The University of Western Australia. Mid-Semester Test September 2017

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CS 132 Midterm Exam Fall 2004

1st Semester Examinations CITS1001 3

QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer

CS112 Lecture: Characters and Strings

CSCI 1226 A Test #1. Wednesday, 10 October, 2018 Name: Student #: General Instructions Read and follow all directions carefully.

CS171:Introduction to Computer Science II

SCHOOL OF COMPUTING, ENGINEERING AND MATHEMATICS SEMESTER 1 EXAMINATIONS 2015/2016 CI101 / CI177. Programming

EXAMINATIONS 2012 END-OF-YEAR SWEN222. Software Design. Question Topic Marks 1. Design Quality Design Patterns Design by Contract 12

Introduction to Programming (Java) 4/12

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

CS 1301 Ch 8, Part A

Java Classes and Objects

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

CSE 1223: Introduction to Computer Programming in Java Chapter 3 Branching

CIS 110 Introduction to Computer Programming Summer 2018 Midterm. Recitation ROOM :

COE 212 Engineering Programming. Welcome to the Final Exam Thursday December 15, 2016

Student Number: Computer Science 211b Final Examination. 28 April hours

Implementing a List in Java. CSE 143 Java. Just an Illusion? List Interface (review) Using an Array to Implement a List.

Searching and Strings. IST 256 Application Programming for Information Systems

Solutions to Quiz 1 (March 14, 2016)

THE UNIVERSITY OF WESTERN AUSTRALIA. School of Computer Science & Software Engineering CITS1001 OBJECT-ORIENTED PROGRAMMING AND SOFTWARE ENGINEERING

Object- Oriented Analysis, Design and Programming

Object Oriented Programming. Java-Lecture 6 - Arrays

OOP-Lecture Java Loop Controls: 1 Lecturer: Hawraa Sh. You can use one of the following three loops: while Loop do...while Loop for Loop

Last Name: Circle One: OCW Non-OCW

CS313D: ADVANCED PROGRAMMING LANGUAGE

Creating Strings. String Length

Class API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects

Test 1: CPS 100. Owen Astrachan. October 1, 2004

Addendum File Web Design and Development (CS506)

Final Exam Review April 18, 2018

Transcription:

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 13 th February 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: All answers to this test should be written on the test sheet, but you may use spare paper for rough working. Answer as many of the questions as you can. 1) Suppose that in Java class DrinksMachine and Can there are public methods with the following signatures: DrinksMachine methods: Can methods: void insert(int n) boolean isfull() int getbalance() void drink() int getprice() int volume() boolean cokesempty() Can presscoke() void loadcoke(can can) void setprice(int p) Suppose also we have variables mach1 and mach2 of type DrinksMachine, and c1 and c2 of type Can, and you can assume they have been initialised to refer to objects of the appropriate type, and suppose also we have variable n of type int which has been initialised. For each of the code fragments below, state whether it is valid or invalid code, where invalid code is code which would cause a compiler error. Valid/Invalid a) n = mach1.getprice(); b) n = mach2.setprice(n); c) c1 = mach1.presscoke(); if(c1.isfull()) c2 = mach2.presscoke(); d) if(insert(n)) c2 = mach2.presscoke() e) while(c1.volume()>0) c1.drink(); [Question continued on next page] Algorithms and Data Structures Test 13 th February 2006 Page 1

f) while(mach1.cokesempty()) mach1.loadcoke(mach2.presscoke()); g) n = mach1.presscoke().volume(); h) mach1.presscoke(); if(c1.isfull()) c2 = mach2.presscoke(); i) if(mach1.getprice()>n) mach1.setprice() = n; j) while(mach1.cokesempty()) { int p = mach2.getprice(); if(p>n) mach1.loadcoke(c1.volume()); } Use the space below for rough working Algorithms and Data Structures Test 13 th February 2006 Page 2

2) a) Write a Java static method slide which takes as its argument an array of integers and alters it destructively so that the last integer is put in the first place, and all other integers are moved up one place. So if the array starts off as: it becomes: 5 7 9 3 7 4 1 2 8 7 6 6 5 7 9 3 7 4 1 2 8 7 b) Write in the space below a Java static method which performs the same operation as in part a), but does it constructively. Algorithms and Data Structures Test 13 th February 2006 Page 3

3) a) Write a Java static method which takes an arraylist and an object and returns an arraylist containing all items from the original arraylist which are not equal to the argument object in the reverse order to the one they had in the original arraylist. For example, if the original arraylist contains Integer values as follows: 5 7 9 3 7 4 1 2 8 7 3 and the second argument is the Integer value 3, the arraylist that is returned is: 7 8 2 1 4 7 9 7 5 Your method should be generic to cover arraylists of all base types. b) Below is a Java method: public static <T> int meth(arraylist<t> a) { int n=0 for(int i=0; i<a.size(); i++) { T thing = a.get(i); int j=i+1; for(; j<a.size(); j++) if(a.get(j).equals(thing) break; if(j==a.size()) n++; } return n; } State in English what value this method returns: Algorithms and Data Structures Test 13 th February 2006 Page 4

4) a) Describe briefly the difference between a mutable and an immutable object. b) Explain briefly what is meant by aliasing and why this may be a problem with mutable but not immutable objects. c) Explain what the String method touppercase does. d) Assuming str1 is set to a string, and ch is set to a character which we know occurs at least twice in the string, write a fragment of code which sets variable str2 to the portion of str1 between the first and last occurrence of ch. So if str1 is hello world and ch is o, it should set str2 to o wo. You may use the String methods indexof which takes a character as its argument and returns the position of the first occurrence of that character in the string it is called on, and lastindexof which is similar, but it returns the position of the last occurrence of the character. Algorithms and Data Structures Test 13 th February 2006 Page 5

5) Write static methods to implement the following operations on objects of the generic type LispList as described in the course notes and lectures: a) addafter takes a list and two items and returns the list obtained by adding the second item after all occurrences of the first item in the original list. So, for example, with [2,3,4,5,3,2,3,4,7] and 3 and 8, the result will be [2,3,8,4,5,3,8,2,3,8,4,7]. b) drop, takes a list and an item and returns a list consisting of all those items from the original list after the first occurrence of the item. So, for example, with [2,3,4,5,3,2,3,4,7] and 4 the result is [5,3,2,3,4,7]. Algorithms and Data Structures Test 13 th February 2006 Page 6

Algorithms and Data Structures Test 13 th February 2006 Page 7