CS 340 DATA STRUCTURES
Instructor: Xenia Mountrouidou
Course Objectives
At the end of this class you will be able to: Make design decisions on which data
structure is best to use regarding performance, memory, and implementation efficiency.
Devise or use the most efficient algorithm in your projects.
Understand algorithmic complexity. Think analytically and identify complexity of
a program.
2
CS 340
Course Objectives (cont.)
At the end of this class you will be able to: Apply object oriented programming
principles when you develop software. Use and understand third party code. Detect inefficiency of data structures and
algorithms of third party code. Develop projects using agile test driven
approach (Junit). Employ the Java API.
3
CS 340
Why do you need CS 340?
Scenario: You are a senior developer for e-bay. You are working on their e-commerce
application server! You drop code, you are a java guru, OO
programming is second nature to you… but you do not understand data structures and algorithms.
BIG DEAL! Everything runs perfectly. Until one day…
You need to use a sorting algorithm to sort all potential sellers of a product based in price or ranking.
4
CS 340
Why do you need CS 340?
Scenario (cont.): On every click for a product search, your
sorting algorithm will be used. You choose bubble sort. After all, it has a
cool name! Let’s see what happens: http
://www.cs.bu.edu/teaching/alg/sort/demoSoftware is not just coding… It is design, performance, memory consumptionIt is an art, a riddle to be solved with every project
5
CS 340
Lectures
We meet at 15:00-16:45, every Tues/Thurs, at Merritt Penticoff Science Bld, Room 130
Attendance will have a part in your grade. Attendance means: active participation!
Check the schedule in our webpage Reading and examples will be posted
online. Check the webpage for news frequently.
6
CS 340
How to get help
Join my office hours! Join the conversation on Piazza. Check our website frequently. Use the textbook:
“Data Structures: Abstraction and Design Using Java”, Second Edition by Elliot B. Koffman, Paul A. T. Wolfgang
Experiment with code. It’s fun…
7
CS 340
Grading
Midterm exam 20%Final exam 20%Homeworks 25%Programming projects 25%Class participation 10%Total 100%
Homework and Programming projects will be posted online
8
CS 340
Programming Projects
They involve Design Coding Testing Debugging
Some of these can be done in pairs Both team members will need to answer
detailed questions about the implementation
Each team member will evaluate his/her team mate
9
CS 340
Principles of Pair Programming
10
CS 340
12
Principles of Pair Programming All I Really Need to Know about pair
programming I Learned in Kindergarten Share everything. Play fair. Don’t hit people. Put things back where you found them. Clean up your own mess. Don’t take things that aren’t yours. Say you’re sorry when you hurt somebody.
CS 340
13
Principles of Pair Programming
Wash your hands before you eat. Flush. Warm cookies and cold milk are good for
you. Live a balanced life – learn some and think
some and draw and paint and sing and Dance and play and work every day some. Take a nap every afternoon. When you go out into the world, watch out
for traffic, hold hands and stick together. Be aware of wonder.
CS 340
Policies
Read the collaboration policy carefully. Late policy:
1st day late: 10% off 10% is reduced by every day the homework
is late
14
Java… a bit of history
CS 340
15
CS 340
16
Java timeline
http://www.youtube.com/watch?v=WAy9mgEYb6o
CS 340
17
Java Design Goals
Simple, object oriented, and familiar Robust and secure Architecture neutral and portable High performance Interpreted, threaded, and dynamic
CS 340
17
Java abbreviations
JDK: Java Development Kit JSDK: Java Servlet Development Kit JVM: Java Virtual Machine J2EE: Java Platform, Enterprise Edition. A
widely used platform for server programming.
CS 340
OOP or… Object Oriented Programming18
CS 340
Object-Oriented Programming Object-oriented programming (OOP) is
popular because: enables reuse of previous code saves time
If a new class is similar to an existing class, the existing class can be extended
This is called inheritance
19
CS 340
20
Java is object oriented
Old programming languages: code was executed line by line and
accessed variables or records Java
objects that come with their own methods When coding in Java one is always
thinking about “which object is running this code?”
Inheritance
Meat is a Food Meat has all the data
fields and methods defined by Food
Food is the superclass of Meat
Meat is a subclass of Food
Meat may define other variables and methods that are not contained in Food
Food
expirationDate()
Meat
percentageOfProtein()
CS 340
21
A Superclass and Subclass Example
Robot A robot has a
manufacturer processor disk parts processor speed
CS 340
22
Write the robot class
A Superclass and Subclass Example (cont.)
Robot A robot has a
manufacturer processor disk parts processor speed
Robot
String manufacturerString processorint diskSizeint numberOfPartsdouble processorSpeed
CS 340
23
A Superclass and Subclass Example (cont.)
Robot
String manufacturerString processorint diskSizeint numberOfPartsdouble processorSpeed
int getDiskSize()double getProcessorSpeed()int getParts()String toString()
CS 340
24
CS 340
A Superclass and Subclass Example (cont.)
Cylon A Cylon has all the
properties of Robot, manufacturer processor disk parts processor speed
plus, vision (pixels) hands (battle speed)
254
What is a Cylon class?
A Superclass and Subclass Example (cont.)
Cylon
double pixelsdouble battleSpeed
Robot
String manufacturerString processorint diskSizeint numberOfPartsdouble processorSpeed
int getDiskSize()double getProcessorSpeed()int getParts()String toString()
CS 340
26
CS 340
A Superclass and Subclass Example (cont.)
The constructor of a subclass begins by initializing the data fields inherited from the superclass(es)
super(man, proc, parts, disk, procSpeed);
which invokes the superclass constructor with the signature
Robot(String man, String processor, int parts, int disk, double procSpeed)
27
A Superclass and Subclass Example (cont.)
/** Class that represents a robot */
public class Robot {
private String manufacturer;
private String processor;
private int numParts;
private int diskSize;
private double processorSpeed;
public Robot(String man, String processor, int numParts, int disk, double procSpeed) { //constructor
manufactuer = man;
this.processor = processor;
this.numParts = numParts;
diskSize = disk;
processorSpeed = procSpeed;
}
}
28
Write the methods’
code
CS 340
A Superclass and Subclass Example (cont.)
public double getProcessorSpeed() { return processorSpeed; }
public int getDiskSize() { return diskSize; }
public int getParts() { return numParts; }
public String toString() {
String result = "Manufacturer: " + manufacturer + "\nCPU: " + processor + "\nBody parts: " + numParts + "\nDisk: " + diskSize + " gigabytes" + "\nProcessor speed: " + processorSpeed + " gigahertz";
return result;
}
}
29
CS 340
A Superclass and Subclass Example (cont.)
public class Cylon extends Robot
{
private double pixels;
private double battleSpeed;
public Cylon(String man, String processor, int parts, int disk, double procSpeed, double pix, double bSpeed) {
super(man, proc, parts, disk, procSpeed);
pixels = pix;
battleSpeed = bSpeed;
}
}
30
CS 340
Protected Visibility for Superclass Data Fields
Variables with private visibility (defined by the keyword private) cannot be accessed by a subclass
Variables with protected visibility (defined by the keyword protected) are accessible by any subclass or any class in the same package
By default variables are public, i.e., they can be accessed by any package
31
CS 340
Is-a versus Has-a Relationships In an is-a or inheritance relationship, one
class is a subclass of the other class In a has-a or aggregation relationship,
one class has the other class as an attribute
32
CS 340
Is-a versus Has-a Relationships (cont.)
public class Robot { private Memory mem; ...}
public class Memory { private int size; private int speed; private String kind; ...}
A Robot has only one Memory
But a Robot is not a Memory (i.e. not an is-a
relationship)
If a Cylon extends Robot,then the Cylon
is-a Robot
33
Top Related