Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 340 DATA STRUCTURES Instructor: Xenia Mountrouidou.

Similar presentations


Presentation on theme: "CS 340 DATA STRUCTURES Instructor: Xenia Mountrouidou."— Presentation transcript:

1 CS 340 DATA STRUCTURES Instructor: Xenia Mountrouidou

2 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

3 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. CS 340 3

4 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. CS 340 4

5 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/demo http://www.cs.bu.edu/teaching/alg/sort/demo Software is not just coding… It is design, performance, memory consumption It is an art, a riddle to be solved with every project CS 340 5

6 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 webpagewebpage  Reading and examples will be posted online.  Check the webpage for news frequently. CS 340 6

7 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… CS 340 7

8 Grading  Homework and Programming projects will be posted online CS 340 8

9 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 CS 340 9

10 Principles of Pair Programming CS 340 10

11 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

12 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

13 Policies  Read the collaboration policy carefully.  Late policy:  1 st day late: 10% off  10% is reduced by every day the homework is late CS 340 14

14 Java… a bit of history CS 340 15

15 16 Java timeline  http://www.youtube.com/watch?v=WAy9mgEYb6o http://www.youtube.com/watch?v=WAy9mgEYb6o CS 340

16 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 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

18 OOP or… Object Oriented Programming 18 CS 340

19 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 CS 340 19

20 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?” CS 340

21 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

22 A Superclass and Subclass Example  Robot  A robot has a  manufacturer  processor  disk  parts  processor speed CS 340 22 Write the robot class

23 A Superclass and Subclass Example (cont.)  Robot  A robot has a  manufacturer  processor  disk  parts  processor speed Robot String manufacturer String processor int diskSize int numberOfParts double processorSpeed CS 340 23

24 A Superclass and Subclass Example (cont.) Robot String manufacturer String processor int diskSize int numberOfParts double processorSpeed int getDiskSize() double getProcessorSpeed() int getParts() String toString() CS 340 24

25 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) CS 340 254 What is a Cylon class?

26 A Superclass and Subclass Example (cont.) Cylon double pixels double battleSpeed Robot String manufacturer String processor int diskSize int numberOfParts double processorSpeed int getDiskSize() double getProcessorSpeed() int getParts() String toString() CS 340 26

27 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) CS 340 27

28 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

29 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; } CS 340 29

30 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; } CS 340 30

31 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 CS 340 31

32 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 CS 340 32

33 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 CS 340 33


Download ppt "CS 340 DATA STRUCTURES Instructor: Xenia Mountrouidou."

Similar presentations


Ads by Google