CMSC 155
Spring 2014
Homework 4 (130 points available)
DUE:MidnightFriFeb7
AlwayshandinyourcodePLUShowyoutesteditandtheresults
obtained.
41. Write test code that instantiates some student and course objects and prints them out. Each
student has a name and

Math Class
The Math class contains many useful functions, some
shown below. Note that it does NOT have to be imported
in order to be used; it's automatically included (like the
System class and String class).
Function
Returns
Math.sqrt(x)
square root
Mat

Algorithms
"First, solve the problem. Then, write the code." John
Johnson
Key Concepts:
Algorithms should be:
Correct
Efficient
Common Algorithms
Accumulators
All, At Least One, How Many, Which
Minimum, Maximum
Decompose Programs into Functions
C

Arrays
Key Concepts:
Declaring & Initializing Arrays
Default Values
Accessing Array Elements
Index starts at 0
length
Cannot be changed
Arrays of Objects are better than "Parallel Arrays"
Iterating Through Arrays for-each loop
Always use a for-e

Selection Sort and Insertion Sort
Key Concepts:
Sorting Bounded Numbers is easy
Pigeonhole Sort Look at each element once; O(n)
Selection Sort
Find smallest, second-smallest, etc.
Insertion Sort
Sort first 2 elements, first 3 elements, etc.
Select

Maps
Key Concepts:
Collection of Pairs of Elements
Indexed by Keys
Each Key Maps to a Value
Keys are Unique
Using Maps in Java
Map
A map is a data structure that holds key to value
mappings.
Keys are used for indexing into the map
Accessing or mo

Aliasing
Key Concepts:
Objects store Memory References
Assignment between objects creates Aliases
Two variables that refer to the same object
Changing the instance variables of one changes the other!
Copying Classes need a method to create an object

Arrays as Objects
Key Concepts:
Arrays as Objects
Copying arrays
Testing arrays for equality
Copying Parts of Arrays
Use System.arraycopy
Inserting and Deleting Elements
Use System.arraycopy
Variable Number of Arguments
Using Arrays to Replace M

Static Variables and Methods
Key Concepts:
final cannot be changed
Instance variables and local variables can be final
Methods and classes can be final (see "Inheritance"
later)
Static Variable
Variable shared by all objects of the class.
CAN be mo

Merge Sort and Quick Sort
Key Concepts:
Merge Sort
Repeatedly split collection of items into 2 halves until the sub-lists
become small, then repeatedly merge them into sorted lists.
Quick Sort
Repeatedly split collection of items into those less than

Sorting in Java
Key Concepts:
sort methods
Arrays.sort
Collections.sort
Class must implement Comparable
contains a compareTo method
returns an integer indicating which item is "bigger"
The sort functions are written so that they can
operate on ite

Interfaces
Key Concepts:
An interface contains abstract methods (method headers).
A class implements an interface.
Provides actual code for the method headers in the interface.
An interface variable can reference any object that is instantiated
from

Searching
Key Concepts:
Linear Search
Time taken increases in proportion to the number
of elements.
Binary Search
Time taken increases in proportion to the LOG of
the number of elements.
Much faster than Linear Search, but can only
be used if data i

Multi-Dimensional Arrays
Key Concepts:
Two-Dimensional (2-D) Arrays
Array of arrays
An array whose elements are arrays.
Each element corresponds to a row of the 2-D array.
Print using deepToString or a nested for-each loop.
Regular Arrays
All rows

Testing for Equality
Suppose the Book class has instance variables for the author,
title, and date of the book.
Book x = new Book("Joe Soap", "My Life", 1970);
Book y = new Book("Joe Soap", "My Life", 1970);
x = y will return false
This is because x and

Static & Dynamic Typing
A language is statically typed if type-checking is done at
compile-time. This requires the programmer to declare types.
Types are associated with variables.
E.g. Java
int x makes x an int.
x is ALWAYS an int.
A language is dy

Inheritance
Key Concepts:
extends(keyword used to denote inheritance of class or interface)
super (refers to object in subclass as if it were in parent class)
Overriding (method in subclass is called instead of method in parent
class)
Object class (a

Samantha and Esteban
CMSC 155
Spring 2014
Homework 10 (130 points available)
DUE:MidnightFriMar28
"ifyoucan'tprogramit,youhaven'tunderstoodit.David Deutsch
Handinallcodeafter#108.
101.
Modify the Student class (and Course class, if necessary) so that each

CMSC 155
Spring 2014
Homework 12 (120 points available)
DUE:MidnightFriAPR11
I have always wished for my computer to be as easy to use as my
telephone; my wish has come true, because I can no longer figure
out how to use my telephone. - Bjarne Stroustrup,

CMSC 155
Spring 2014
Homework 13 (125 points available)
DUE:MidnightFriAPR18
131. Implement the remove method for the OurLinkedList class. You may use your own
code or the code on Scholar.
The method should remove an element at a specified position, as fo

CMSC 155
Spring 2014
Homework 14 (110 points available)
Due:MidnightFriAPR25
"Talkischeap.Showmethecode."LinusTorvalds
141. Use Radix Sort to sort the following strings alphabetically. SHOW ALL STEPS! (15 points)
computer science comb compare scene compli

CMSC 155
Spring 2014
Homework 1 (150 points available)
Deadline:MidnightFriJan17
1.
Read the syllabus and let me know if you have any questions. Done
2.
Visit my office (Carver 201) during an office hour (or any time when I'm there).
Done
3.
Overloading o

Samantha Schwarz And Scott Henry
CMSC 155
Spring 2014
Homework 6 (125 points available)
DUE:MidnightFriFeb21
We want to modify the Student class to enable a student to add and drop courses.
Make the following changes. You dont need to provide answers for

CMSC 155
Spring 2014
Homework 7 (120 points available)
DUE:MidnightFriFeb28
If debugging is the process of removing bugs, then programming
must be the process of putting them in. - Edsger Dijkstra
71. Consider the function mystery below.
public static int

CMSC 155
Spring 2014
Homework 5 (130 points available)
DUE:MidnightFriFeb14
Write and test a method that has as parameters an array of integers and two floating point
numbers and returns true if ALL the integers in the array are strictly between the two n

Linked Lists in Java
Key Concepts:
Linked List Class
Methods (add, remove, get, etc)
Looping use for-each loop
Doubly-Linked Lists
Wrapper Classes
Integer for int, Double for double, etc.
List Interface
Implemented by both ArrayList and LinkedLis

Recursion
Key Concepts:
Functions that call themselves
Direct vs Indirect Recursion
Base case and recursive case
How Recursion Works
Each call has its own copies of parameters & local
variables
Structural Recursion
A class defined in terms of itse