- Prof. amr Goneid, AUC
1
CSCE 110 PROGRAMMING FUNDAMENTALS
WITH C++
- Prof. Amr Goneid
WITH C++ Prof. Amr Goneid AUC Part 13. Abstract Data Types (ADTs) - - PowerPoint PPT Presentation
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 13. Abstract Data Types (ADTs) Prof. amr Goneid, AUC 1 Data Modeling and ADTs Prof. Amr Goneid, AUC 2 Data Modeling and ADTs Data Modeling Abstract Data types
1
2
3
4
5
6
The word Algorithm comes from the name of Abu
An Algorithm is a procedure to do a certain task An Algorithm is supposed to solve a general, well-
7
8
9
Fundamental Data Types
10
The most important attribute of data is its type. Type implies certain operation. It also prohibits other
For example, + - * / are allowed for types int and
When a certain data organization + its operations are
11
1.
2.
12
13
ADT ADT ADT ADT ADT
Standard Types/Libraries User Built ADT’s
14
The first step in creating an ADT is the process of
Data Abstraction provides a complete
15
how the ADT will be implemented using native
how the relationships and fundamental
In Object Oriented Programming, ADTs are
16
17
18
groups collection selection packaging
19
Sequential, one-to-one relationship.
Can be implemented using arrays and linked lists
Used in problems dealing with:
Searching, Sorting, stacking, waiting lines. Text processing, character sequences, patterns Arrangements, ordering, tours, sequences.
20
Searching Hierarchy Ancestor/descendant relationship Classification
21
Networks Circuits Web Relationship Paths
22
23
24
Examples:
Stacks: Last-In-First-Out (LIFO) structures Queues: First-In-First-Out (FIFO) structures Tables: Retrieval by position.
25
A form of container that permits access by content. Support the following main operations:
Insert (D,x): Insert item x in dictionary D Delete (D,x): Delete item x from D Search (D,k): search for key k in D
26
Examples:
Unsorted arrays and Linked Lists: permit linear search Sorted arrays: permit Binary search Ordered Lists: permit linear search Binary Search Trees (BST): fast support of all dictionary
Hash Tables: Fast retrieval by hashing key to a position.
27
28
Examples:
Heaps and Partially Ordered Trees (POT) Major DS in HeapSort
29
elements between the sets.
nodes.
30
Support the following main operations:
Find (i): Find Parent (set) containing node (i) Union (i,j): make set (i) the child of set (j)
Examples:
Representation of disjoint collections of data Representation of Trees, Forests and Graphs
31
Can be used to represent any relationship and a wide
32
Can be used to represent any relationship and a wide
Well-known graph algorithms are the basis for many
Minimum Spanning Trees Graph traversal (Depth-First and Breadth-First) Shortest Path Algorithms
33
34
35
36
37
38
39
40
41
Evaluation of arithmetic expressions The Hanoi Towers game
42
43
Sorting a set of elements Selection of the kth smallest (largest) element
44
Find the shortest path between a source and a
destination
Find the exit in a Maze
45
Problem:
ADTs:
Data Structures:
46
Abstraction:
A homogenous sequence of elements with a fixed size that allows direct access to its elements.
Elements (members):
Any type, but all elements must be of the same type
Relationship:
Linear (One-To-one). Ordered storage with direct access.
Fundamental Operations:
create array store an element in the array at a given position (direct
access)
retrieve an element from a given position (direct access)
47
48
Read a fraction from keyboard Display a fraction on the screen Add Fractions
Subtract Fractions f = f1 – f2 (e.g. ½ - 1/3 = 1/6) Multiply Fractions
Divide Fractions
Reduce Fractions