110 likes | 248 Views
Tutorial 2 Abstract Data Types. Admin Stuffs. Some of you request to change tutorial class… Transfer within my own classes (T3, T4, T5, T6) is fine. Transfer between different tutors requires permission. Ask Dr Tan Sun Teck’s permission for such changes.
E N D
Admin Stuffs • Some of you request to change tutorial class… • Transfer within my own classes (T3, T4, T5, T6) is fine. • Transfer between different tutors requires permission. • Ask Dr Tan Sun Teck’s permission for such changes. • Refrain from asking lab assignments to me • I am not supposed to help you with debugging or finding the algorithm etc… • Bidding system not working (yet) • If this system is not good, I will be forced to change it…
Abstract Data Type (ADT) • Data Structure: • “Structure of Data”, structure makes life easier • Algorithm: • Step by step way to solve certain problem • Abstract Data Type • Data + Operations (Algorithms) to organize that data structure • Walls: We do not need to know the implementation details • Examples: Complex Number, Sphere, ColoredSphere:Sphere, List, etc. • Wait!! Contradictions?? • We are given so many implementation details here! Why bother with details? • In fact, we are going to do that throughout this module • To give you a strong theoretical foundation… • Later on, you will just use these ADTs for your programming tasks
Implementing ADT in Java: Class • Java class is used to implement these ADT • This is the basic pattern of a class implementation: • public class C { // save as C.java private (instance) attributes… public (instance) attributes, constructor, methods…} • Sometimes we use “Interface” • interface C_interface { // signature of public methods are mentioned here desired interfaces…} • public class C implements C_interface { // a guarantee that we will implement the methods implementation must adhere the agreed interface, otherwise we have compile error} • In main method: • public static void main(String[] args) { C cInstance = new C();}
Object Oriented Programming • We learned these OOP concepts via these two questions: • Q1: Programming using agreed interfaces; Abstraction provided by ADTs; Implementing ADTs in Java. • Q2: Software re-use, A demonstration of “Integration” of (F1_2008); (F1_Driver, F1_Team, F1_Championship); and (F1_Race)
Student Presentation • T3 • N/A • N/A • N/A • T4 • N/A • N/A • N/A • T5 • Tan Yan Hao • Tan Yan Hao • Tan Yan Hao • T6 • Wong Shiang Ker • Nguyen Duy Hoang • Nguyen Duy Hoang Better participation level is expected for tutorial 3 onwards!
Question 1 & 2 - F1 (1) The answer for these two questions are in the Java source codes!
Visit this Simulator (free) at Singtel Headquarter, Somerset
Question 1 & 2 - F1 (2) • Coded by your TA: • F1_2008.java • Coded by you: • Q1: • F1_Driver.java • F1_Team.java • F1_Championship.java • Q2: • F1_Race.java The bridge between the two: INTERFACE Airbus 380 Integration Problem: http://news.airwise.com/story/view/1169812254.html
Q3 – Compact Array • How to add? • Find first empty slot, insert it (bad). O(n) • Maintain an index of first empty slot, insert there, add the index by 1 (good). O(1) • How to add when full? • Create a new array, double the size, copy the entries to new array. • How to edit? • Search it from left to right, if found, replace the content. • As soon as you hit an empty slot, it means that the entry is not in the compact array. • How to delete? • Search it, delete the entry, shift everything on the right side of it to left by one! Tedious! • What are the potential issues with (b) and (d)? (see above)
That’s all for today • Next week, we will continue our lesson with Linked List. • Maybe a better data structure than “compact array”, especially for Q3. • Remember that the “best” data structure depends on the given scenario!