Presentation is loading. Please wait.

Presentation is loading. Please wait.

2016-07-021 Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.

Similar presentations


Presentation on theme: "2016-07-021 Prof. I. J. Chung Data Structure #1 Professor I. J. Chung."— Presentation transcript:

1 2016-07-021 Prof. I. J. Chung Data Structure #1 Professor I. J. Chung

2 2016-07-022 Prof. I. J. Chung Data Structure program = algo. + d/s algo = logic (what) + control (how) algo : finite set of instructions which accomplish a given particular task (abstract form of pgm) d/s : object to organize and to manipulate data in computer system y = f(x) y : output f(x) : algorithm x : input algo. precond. postcond.

3 2016-07-023 Prof. I. J. Chung Data Structure specification of program : precondition & postcondition precondition : a set of conditions that must be true when a proc. is called if the algo. is to work properly. C++ : assert() eg. : assert(input >= 0); postcondition : a set of conditions to be true after the algo. terminates.

4 2016-07-024 Prof. I. J. Chung Data Structure I <- 0 S <- 0 N = N 0 >= 1 I < N f S = I I +1 S S + (I **3) 1 = 1 Λ S = Λ N = N 0 >= 1 /* m <= n */ precond. s = 0; for (i = m; i <= n ; i++) s += I; /* s is the sum of the #s from m to n */ postcond. L.I :

5 2016-07-025 Prof. I. J. Chung Data Structure data type kinds of data of vars for a PL eg. F : INT, REAL, LOGICAL, COMPLEX, DOUBLE, PRECISION,... PL/1 : CHAR, INT, … C, Ada : allows one to construct combinations of the built-in types Pascal : RECORD C : struct Program TD with Problem Decomposition decompose a task into subtasks until ∀ subtask is easier to solve Divide & Conquer : deviding of original problem into subproblems

6 2016-07-026 Prof. I. J. Chung Data Structure Steps of program 1) specification define the problem to be solved by C/S clearly & definitely, give precond. & postcond. 2) design construct an algo. & d/s (abstraction of program) 3) coding convert the algo. & ds. with the concrete, specific PL 4) testing & execution test the above program witht various data sets 5) maintenance over time, modify the ___ tested program whenever necessary for the new changed case problem

7 2016-07-027 Prof. I. J. Chung Data Structure D.S : logical / mathematical model of a particular data org. D.S D : domain F : function A : axioms ( semantics of operations ) Eg. : E = { nat_#, bool } F = { ZERO, SUCC, ADD, ISZERO } A =

8 2016-07-028 Prof. I. J. Chung Data Structure structure NATURAL_# dclZERO() → natural_# ISZERO ( natural_# ) → boolean SUCC ( natural_# ) → boolean ADD ( natural_#, natural_# ) → boolean EQ ( natural_#, natural_# ) → boolean for all x, y ∈ natural_#, let ISZERO (ZERO) = true : ISZERO(SUCC (X)) = false ADD(ZERO, y) = y, ADD(SUCC (x), y) = SUCC(ADD(x, y)) EQ(x, ZERO) = if ISZERO(x) then true else false EQ(ZERO, SUCC(y)) = false EQ(SUCC (x), SUCC(y)) = EQ(x, y) end end NATURAL_# A

9 2016-07-029 Prof. I. J. Chung Data Structure OOP : programming approach in which data occurs in packages, called the objects, where object ops are executed with member function (C++ : class) programming approach to support the creation of new d.t. & ops to manipulate those types object : encapsulated (packaged together, possibly hidden) data instance of a class OOP : objects have data members & member functions (C++ : objects are created by classes)

10 2016-07-0210 Prof. I. J. Chung Data Structure class of C++ : supports information hiding. ie, the user of C++ doesn ’ t have to know how the class is implemented. ie, C++ class can completely hide the knowledge of how the class is implemented. class : defines how to store [ (thru. fields) ] and access [ ( thru. methods) ] all objects of this type. class = data + member function [constructor : method to create a new object] class of C++ : data values are typically private. : can only manipulate class using public member functions

11 2016-07-0211 Prof. I. J. Chung Data Structure class : set of member vars & ops. ∃ 2 sorts of vars & ops 1)public : accessible by all mothods including those outside of the class defn. 2)private : accessible only by methods defined in the class ie, private member vars : we cannot directly access the information. the unique access way is to ____ function that we provide for the class. visible any where visible only with the class

12 2016-07-0212 Prof. I. J. Chung Data Structure ADT : set of ops with data objects mathematical d.t. for the inf. hiding of d.t. → @ a class that is presented to other programmers with inf. hiding mathematical abstraction of d.t. for implementation – ind. (inf, hiding) (inf. hiding, encapsulation of d.t.) defn : d.t. whose ops are ind. of its specific implementations

13 2016-07-0213 Prof. I. J. Chung Data Structure inf. hiding : A d.t. is organized in such a way that the spec of the objects and the specs of the ops on the objects is separated from the rep. of the objects & the implementation of the operations. spec + implementation separation (Ada : package, C++, class)

14 2016-07-0214 Prof. I. J. Chung Data Structure @ : nowhere in an ADT ’ s defn, is there any mention of how the operations is implemented → extension of modular & OOP design. objects s.a. list, set, graph with their ops can be viewed as ADT, just as int, real, booleans are d.t. These have ops, so does the ADT such as ⋃, ⋂, size, complement ADT classes & methods of C++ class : implementation of ADT in C++

15 2016-07-0215 Prof. I. J. Chung Data Structure + of ADT : 1)integrity : ADT supports a correct implementation of ops 2)reusability : ADT supports that data objects can be re-used in different user programs 3)extensibility : ADT provides more operations and enhances the efficiency of program 4)simplicity : ADT allows the user to free from the tedious task of implementation detail

16 2016-07-0216 Prof. I. J. Chung Data Structure data type : collection of objects with the operations that act on these objects collection of values (domains) with ops on these values basic d.t. : integer, double, string, etc to use a d.t. on a computer specific rep. is necessary. Eg. integer is typically rep. with 4 bytes. → the rep. of d.t. affects the storage size, precision, efficiency, etc. differences between ADT & d.s. d.s. : used to implements an ADT ADT : can be implemented with different structures. so, d.s. is a particular implementation of ADT

17 2016-07-0217 Prof. I. J. Chung Data Structure implementation of ADT C++ : define a class classes have member vars & member functions (ops) An object is a var where the d.t. is a class. var & ops of class 1)private : accessible only by methods defined in the class 2)public : accessible by all methods including those outside the class defn. To insure ∀ class object is properly initialized before any client use occurs, a construct is added to the class constructor : member function with 1)automatically invoked upon declaration 2)must be same name as class 3)no return value, not even void

18 2016-07-0218 Prof. I. J. Chung Data Structure ADT classes & Members Example class ADTList {// class header public :// public section ADTList () ;// class constructor boolis_emply() const;// methods c member f(n) can ’ t change the object instance int size() const; void remove_All(); void add (int item, int index=0); int get (int index) const; void remove (int index);

19 2016-07-0219 Prof. I. J. Chung Data Structure private ://private section static const int MAX_SIZE = 100; int items [MAX_SIZE];//array d.s. int numItem; };//end of class // this class is stored C++ file ADTList.h ADT using a class #include #include “ ADTList.h ”


Download ppt "2016-07-021 Prof. I. J. Chung Data Structure #1 Professor I. J. Chung."

Similar presentations


Ads by Google