Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 1. Introduction -Overview of course/housekeeping etc. -Review of key object-oriented concepts -Review of arrays and array lists ADS2 Lecture.

Similar presentations

Presentation on theme: "1 Chapter 1. Introduction -Overview of course/housekeeping etc. -Review of key object-oriented concepts -Review of arrays and array lists ADS2 Lecture."— Presentation transcript:

1 1 Chapter 1. Introduction -Overview of course/housekeeping etc. -Review of key object-oriented concepts -Review of arrays and array lists ADS2 Lecture 1

2 2 Algorithms and Data structures 2 (ADS2) Lecturer Alice Miller: Room S133, Course structure 22 lectures @ 2 per week (Monday @ 11.00, Weds @ 1pm, both in Maths 516) 5 X 2-hour labs @ 1 every other week (various times)-tutor start week 3 (week 19), i.e. wk beginning 25 th Jan. Assessment Degree exam (1.5 hours) in May - counts for 80% 2 x Assessed coursework - counts for 20% To be awarded credit in ADS2 need *at least* Attend 3 labs Submit 1 piece of assessed coursework Attend degree exam ADS2 Lecture 1

3 3 Materials lecture slides (outlines only, some bits missing). Available on moodle before lecture, may be modified after lecture Lab sheets + examples class sheets via moodle Course text (essential purchase) Goodrich and Tamassia, Data Structures and Algorithms in Java, 4 th edn, Wiley, 2007, £35 approximately Other references: any other ADS/DSA in Java book (from library, see Savitch from last semester, Another Java reference that has a nice view of things is Thinking in Java by Bruce Eckel. (See library) Moodle page (see later..) ADS2 Lecture 1

4 4 Also Plenty of opportunity in this course to give you little examples to do, to help solidify ideas (and hence less of me talking). Why dont I just go away and read the book myself? Why come to lectures? Helps to keep in step with the material, keep in touch with the assignments etc. … make friends? Cartoons: I try to stick one or two in a lecture. Send me any youd like me to include (must be clean and PC!) ADS2 Lecture 1 With this new blue screen graphics package, I can sit like this and superimpose a girlfriend…

5 5 ADS2 - The Context first course in Algorithms and Data structures for students with experience with programming in Java Introduces new concepts such as DS (data structures), ADTs (abstract data types) Algorithms to manipulate them (As), complexity analysis (to see how efficient the As are) recursion (a nice trick for writing short methods) Will assume you know the basics of Java, but will revise concepts before use ADS2 Lecture 1

6 6 Where does ADS2 fit in? OOSE2 will use some of the DS and As we introduce (hopefully not before we have done them!) project work in Levels 3 and/or 4 – use DS and As to get your programmes to run efficiently Alg3 - extends the As side, assumes knowledge of the DS and complexity analysis learned here. In fact, basic As and DSs important in whole range of courses! ADS2 Lecture 1 It's a demanding and crucial course - be prepared to work hard at it You can revise your Java as you go along.

7 JP2 Lecture 1 7 ADS2 - Modus operandi Lectures Mon 11-12, Weds 1-2 maths 516 Examples class Friday weeks 19, 22, 25 (we are now in week 17) Maths 516 2 hour lab session weeks 19,21,23,25,27 Lab sheets distributed in lectures and on moodle (actually lab sheet 1 should be there by the end of this week…). There are 5 labs, and 5 sheets (one per lab). Unlike OOSE Assessed work submission (via AMS) on date stipulated on assignment sheet (only 2/5 are assessed).. Model answers posted on moodle once submission deadlines past. Timetable/deadlines/lecture notes etc. posted on moodle: Log in to Algorithms and Data Structures ADS2 Lecture 1

8 Assessed Coursework Dates ADS2 Lecture 18 5 separate exercises, 2 of which are assessed. Two assessed exercises Ads2; critical facts are: Two assignments Each worth 10% of your final grade Each will require that you implement a program using data structures and algorithms studied in the lectures Electronic submission of your solution is due by 10:00 on the day following your lab during the week that the assignment is due Assignment 1 – available on 26 th Jan, due the week beginning 8 February Assignment 2 – available on 23 rd Feb, due the week beginning 8 March Note, OOSE is different, several labs devoted to each exercise. In ADS2, every lab has a different (smaller) exercise, only 2 are assessed, but need skills obtained by doing the others.

9 9 Mon lecture lab ?Weds lectureFriday examples class Week 17Mon Jan 11thWeds Jan 13th Week 18Mon Jan 18thWeds Jan 20th Week 19Mon Jan 25th labWeds Jan 27thFriday Jan 29th Week 20Mon Feb 1stWeds Feb 3rd Week 21Mon Feb 8th labWeds Feb 9th Week 22Mon Feb 15thWeds Feb 17thFriday Feb 19th Week 23Mon Feb 22nd labWeds Feb 24th Week 24Mon Mar 1stWeds Mar 3rd Week 25Mon Mar 8th labWeds Mar 10thFriday Mar 12th Week 26Mon Mar 15thWeds Mar 17th Week 27Mon Mar 22nd labWeds Mar 24th ADS2 Lecture 1

10 10 ADS2 - Rough Course Outline (may change!) Follows the course text (Goodrich + Tammassa) to some extent covers most of Chapters 1-7, 9-11) 1Introduction. Review of OO concepts, arrays, The ArrayList class 2 3Linked lists 4 5 6 Recursion 7 8Analysis tools 9 10ADTs, stacks and queues 11 12 Lists and iterators, the Java collections framework 13 14 Trees + search trees, B Trees 15 16 17 18 Fast Sorting Algorithms 19 20 Maps and Hash tables 21 22Revision ADS2 Lecture 1

11 11 Revision of OO concepts – See Goodrich chap 2 Classes: Everything is an object (apart from base/primitive types) Every object belongs to a class Class consists of data members, and methods Data members: the fields of the class Methods: constructors, accessors, mutators, other methods Methods that perform an action Methods that return a value New object created from a defined class using new operator + constructor ADS2 Lecture 1

12 12 Creating a new object myVariable = new MyClass(param1,param2,...) Causes the following: New object of type MyClass dynamically created in memory, all instance variables initialised to default value ( null for object variables, 0 for base types except false for boolean null character for type char ) Constructor for new MyClass object called with parameters specified, filling in meaningful values for instance variables and performing additional operations if necessary new operator returns a reference (memory address) to newly created object. Object variable myVariable refers to this newly created object ADS2 Lecture 1

13 Object references 13 Address of object space assigned to reference variable. Reference variable can be viewed as a pointer to some object. Never attempt to access the object directly. Only by using the methods from the class associated with the object Goodrich p. 9 the object the reference the reference variable ADS2 Lecture 1

14 Example (from JP2, lectures 6-7) 14 2 classes, Date and Student. public class Date { private int day; private String month; private int year; /** constructor to assign a given date value */ public Date(int d, String m, int y){ day = d; month = m; year = y;} /** no argument constructor */ public Date(){ day = 1; month = "January" ; year = 2000; } // copy constructor that takes an existing Date as parameter public Date(Date d){ =; this.month = d.month; this.year = d.year; } /** Accessor methods */ public int getDay(){return day;} fragment from Date class: ETC. ADS2 Lecture 1

15 15 fragment from Student class: public class Student { private String familyName, givenName; private String studentNumber; private Date birthDate; private boolean male; /*constructor */ public Student(String f, String g, String s, Date b, boolean m){ familyName = f; givenName = g; studentNumber = s; birthDate = new Date(b); male = m;} ETC. Includes methods to determine current age, and email address resp: public int age(){ /* return current age*/..} public String emailAddress(){ /* return email address*/..} ADS2 Lecture 1

16 16 public class TestStudent { public static void main(String[] args) { Student stud1, stud2; Date d1 = new Date(12, "October", 1989); Date d2 = new Date(13, "October", 1987); stud1 = new Student("Smith", "John", "0791234", d1, true); stud2 = new Student("Brown", "Jane", "0792345", d2, false); System.out.println(stud1 + " is aged " + stud1.age() + ", email " + stud1.emailAddress()); System.out.println(stud2 + " is aged " + stud2.age() + ", email " + stud2.emailAddress()); } Main program: ADS2 Lecture 1

17 17 Information Hiding and Encapsulation Savitch p. 197 Encapsulation means that the data and actions are combined into a single item (a class object) and the details of the implementation hidden. Information hiding and encapsulation deal with the same general principle: If a class is well designed, a programmer who uses a class need not know all the details of the implementation of the class but need only know a much simpler description of how to use the class ADS2 Lecture 1

18 18 APIs and ADTs API= application programming interface. API for a class is a description of how to use the class. If class is well designed (using encapsulation) a programmer need only read the API and not look at the details of code for the class definition. ADT = abstract data type. An ADT is a data type written using information-hiding techniques. We will build lots of ADTs. You will have seen APIs at: Main structural element in Java that enforces an API is interface = collection of method declarations with no data and no bodies. Classes implement interfaces. Next example illustrates the use of interfaces (will come onto ADTs in later lectures). In JP2 you saw interfaces mainly in GUI context. ADS2 Lecture 1

19 19 Example (Goodrich p.81) Create inventory of antiques in shop, catagorised as objects of various types with various properties. Sellable and/or transportable. Have interfaces Sellable and Transportable. Photograph is a class that implements Sellable BoxedItem is a class that implements both Sellable and Transportable Could extend to other classes, and other interfaces as required. ADS2 Lecture 1

20 20 Example : Antiques /**Interface for objects that can be sold */ //Goodrich p. 81 package antiques; public interface Sellable { /** description of the object. */ public String description(); /**list price in cents */ public int listPrice(); /**lowest price in cents we will accept */ public int lowestPrice(); } ADS2 Lecture 1

21 21 /**Class for photographs that can be sold*/ //Goodrich p. 81 package antiques; public class Photograph implements Sellable { private String descript; //description of this photo private int price; //the price we are selling private boolean color; //true if photo is in colour public Photograph(String desc, int p, boolean c){ //constructor descript = desc; price = p; color=c; } public String description(){return descript;} public int listPrice(){return price;} public int lowestPrice(){return price/2;} public boolean isColor(){return color;} } ADS2 Lecture 1

22 22 /**Interface for objects that can be transported*/ //Goodrich p. 81 package antiques; public interface Transportable { /**weight in grams */ public int weight(); /**whether the object is hazardous*/ public boolean isHazardous(); } ADS2 Lecture 1

23 23 /** Class for objects that can be sold, packed and shipped */ //from Goodrich p. 82 package antiques; public class BoxedItem implements Sellable, Transportable{ private String descript; //description of this item private int price; //list price in cents private int weight; //weight in grams private boolean haz; //true if object is hazardous private int height=0; //box height in centimeters private int width=0; //box width in centimeters private int depth=0; //box depth in centimeters public BoxedItem(String desc, int p, int w, boolean h){ descript = desc; price = p; weight =w; haz = h;} public String description(){return descript;} public int listPrice(){return price;} public int lowestPrice(){return price/2;} public int weight(){return weight;} public boolean isHazardous(){return haz;} public int insuredValue(){return price*2;} public void setBox(int h,int w,int d){ height=h; width=w; depth=d; } ADS2 Lecture 1

24 24 Note: Class can implement multiple interfaces (BoxedItem implements both Sellable and Transportable) This is multiple inheritance (according to GoTa p.83. Some people would not use this term for implements) In Java multiple inheritance is allowed for interfaces but not classes. Why? See JP2 lecture L2 slide 8. Could also create a new interface that combines the methods of both interfaces and adds more. See [GoTa] p. 83 Note: abstract class is like an interface but may have some method implementations and/or data. ADS2 Lecture 1

Download ppt "1 Chapter 1. Introduction -Overview of course/housekeeping etc. -Review of key object-oriented concepts -Review of arrays and array lists ADS2 Lecture."

Similar presentations

Ads by Google