Download presentation
Presentation is loading. Please wait.
Published byJody Dorsey Modified over 8 years ago
1
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY M. AMATO AND JORY DENNY 1
2
SYLLABUS https://parasol.tamu.edu/people/mghosh/Courses/221/Syllabus/syllabus.pdf https://parasol.tamu.edu/people/mghosh/Courses/221/Syllabus/syllabus.pdf 2
3
OBJECT ORIENTED DESIGN (CH 2) Object Oriented Design and Principles Abstract Data Types Encapsulation Inheritance Polymorphism Exceptions 3
4
OBJECT ORIENTED DESIGN AND PRINCIPLES (CH 2.1) Design Goals: Robustness : Capability to handle any type of inputs Adaptability : Can be used in various environments with minimal or no changes Reusability : Same code can be used as a component in various applications over time Design Principles: Abstraction: Abstract the complicated details in form of fundamental parts and operations Encapsulation: Coupling data with methods. Modularity: Component based design Inheritance: Hierarchical and “is-a type-of” relationship Polymorphism: Ability to take different form 4
5
ABSTRACT DATA TYPE (ADT) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data Error conditions associated with operations Mathematical model only with no details about the implementation : ADT specifies what each operation does not how it does it. Example: ADT modeling a simple stock trading system The data stored are buy/sell orders The operations supported are order buy(stock, shares, price) order sell(stock, shares, price) void cancel(order) Error conditions: Buy/sell a nonexistent stock Cancel a nonexistent order 5
6
ENCAPSULATION Bundling of data and associated methods as a type. Hiding the details and direct access to the underlying data. Class: Construct or the definition of encapsulated data and associated methods. User-defined types. class Person { private: string name; public: string GetName() { return name; } void SetName( string _n) { name = _n; } } Object: Instance of an object Person A; // A is an object of class Person or in other words type of A is Person 6
7
INHERITANCE Hierarchical organization of classes. Base class: The class from which another class is inherited. Derived class: The class that inherits Abstract classes: Base class with one or more virtual member functions Virtual member functions are abstract functions with no details. 7 Shape CircleTriangleSquare
8
POLYMORPHISM Different types of a variable Subtyping : Type of the variable is determined at runtime based on the instance. Eg: Shape* newShape = new Circle(); newShape->draw(); //Will call draw() function of Circle class and not of the Shape class. Parametric: Generics (templates) where code is written without any specific type. Eg: template T sum ( T a, T b) {} // Can be used as sum (3,4) and sum (4.5, 7.8) 8
9
EXCEPTIONS (CH 2.4) Attempting the execution of an operation of ADT may sometimes cause an error condition, called an exception Exceptions are said to be “thrown” by an operation that cannot be executed Example: removing an element from an empty container 9
10
ARRAYS AND LINKED LISTS (CH 3) Arrays (Ch 3.1) Singly Linked List (Ch 3.2) Doubly Linked (Ch 3.3) 10
11
ARRAYS Data structure containing a collection of same type Contiguous allocation in memory Limitation: The length or capacity of the array is fixed. Easy Random Access through index of the element (position of the element with respect to the first element in the array. Eg. A[3] indicates fourth element if the first element is stored in index 0. Insertions and deletion at arbitrary location would include rearrangement of the elements following the location. Eg. Removing an element at index 6 would involve moving elements at indices 7,8,9 to 6,7,8. 11
12
SINGLY LINKED LIST A singly linked list is a concrete data structure consisting of a sequence of nodes Each node stores element link to the next node No contiguous allocation of memory Accessing an element at an arbitrary location includes traversing the list from the first element. next elem node ABCD 12
13
DOUBLY LINKED LIST A doubly linked list provides a natural implementation of the Node List ADT Nodes implement Position and store: element link to the previous node link to the next node Special trailer and header nodes No contiguous allocation of memory Access at arbitrary position requires traversal of the list Easy insertion and deletion of element If the pointer to the element is known prevnext elem trailer header nodes/positions elements node 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.