1 / 33

CS 340 Data Structures

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.

kevyn
Download Presentation

CS 340 Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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.

  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

  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

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

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

  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

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

  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

  10. Principles of Pair Programming CS 340

  11. 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. 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: • 1st day late: 10% off • 10% is reduced by every day the homework is late CS 340

  14. Java… a bit of history CS 340

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

  16. 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. Awidely used platform for server programming. CS 340

  18. OOP or… Object Oriented Programming 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

  20. Java is object oriented • Old programming languages: • code was executed line by line and accessed variables or records • Java • objectsthat 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

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

  23. A Superclass and Subclass Example (cont.) • Robot • A robot has a • manufacturer • processor • disk • parts • processor speed Robot String manufacturer String processor intdiskSize intnumberOfParts double processorSpeed CS 340

  24. A Superclass and Subclass Example (cont.) Robot String manufacturer String processor intdiskSize intnumberOfParts double processorSpeed intgetDiskSize() double getProcessorSpeed() intgetParts() String toString() CS 340

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

  26. A Superclass and Subclass Example (cont.) Robot String manufacturer String processor intdiskSize intnumberOfParts double processorSpeed Cylon double pixels double battleSpeed intgetDiskSize() double getProcessorSpeed() intgetParts() String toString() CS 340

  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 thesignature Robot(String man, String processor, int parts, int disk, double procSpeed) CS 340

  28. A Superclass and Subclass Example (cont.) /** Class that represents a robot */ public class Robot { private String manufacturer; private String processor; private intnumParts; private intdiskSize; private double processorSpeed; public Robot(String man, String processor, intnumParts, int disk, double procSpeed) { //constructor manufactuer = man; this.processor = processor; this.numParts = numParts; diskSize = disk; processorSpeed = procSpeed; } } Write the methods’ code

  29. A Superclass and Subclass Example (cont.) public double getProcessorSpeed() { return processorSpeed; } public intgetDiskSize() { return diskSize; } public intgetParts() { 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

  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

  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

  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

  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 Cylonextends Robot,thenthe Cylonis-aRobot CS 340

More Related