Professional Documents
Culture Documents
• Introduction
• Linear data structure
DATA STRUCTURE • List, Stack, Queue
• Nonlinear data structure
• Tree, Hash Table, Heap
INTRODUCTION
Introduction Introduction
• What is a Data Structure? • What is a Data Structure? Real
• A way of organizing data so that it can be used world
effectively. data
Data structure
2 3
Introduction Introduction
5
• What is a Data Structure? Real
• Why data structure?
world
7 • Essential ingredients in creating fast powerful
data Fraction (Real algorithms (programs)
world) • Help to manage and organize data (in a very nature
Fraction (Data structure) way)
• Make code cleaner and easier to understand
denom: int
nominator: int
Data structure
• Data structure can make difference between having
an okay product and an outstanding one.
4 5
Introduction Introduction
• Abstract Data Types vs Data Structures • Example
• An abstract Data Type (ADT) is an abstraction of a • Mode of transportation to get from point A to point
data structure which provides only the interface to B
which a data structure must adhere to.
• There are many specific modes of transportation to
• The interface does not give any specific details about get from point A to point B, such as: walking,
how something should be implemented or in what biking, … Which one do you choose?
programming language.
6 7
Introduction Introduction
• Examples • How to build a data structure?
• Basic building blocks: primitive data type (int, …)
Abstraction (ADT) Implementation (Data structure) • Grouping methods: create a complex block from
List makes Q be an empty set simpler ones
• Index-based: Array (static or dynamic)
• Name-based: Structure (e.g., struct in C)
Queue Linked List Based Queue • Linking mechanism: Pointer, Cursor
Array based Queue
Stack based Queue
Vehicle Golf Cart
Bicycle
Smart Ca
8 9
Computational Complexity
Introduction
Analysis
• Quiz • Two important questions of programmers:
• Create a data structure (in C language) to store a 2D • How much time does this algorithm (program) need
triangle defined by its three vertexes. to finish?
• How much space does this algorithm (program) need
for its computation?
10 11
Computational Complexity Computational Complexity
Analysis Analysis
• Big-Oh notation: O(f(n)) • Complexities ordered in from smallest to largest
• Upper bound of the complexity in the worst case, where n is the input size:
helping to quantify performance as the input size • Constant: O(1)
become arbitrarily large. • Logarithmic: O(log(n))
• Ex: 3n2 + n + 4 = O(n2) • Linear: O(n)
• Linearithmic: O(nlog(n))
• Quadric: O(n2)
• Cubic: O(n3)
• Exponential: O(bn), b>1
• Factorial: O(n!)
12 13
14 15
Computational Complexity Computational Complexity
Analysis Analysis
a = 4; i = 0; i = 0; i = 0;
b = 2; while (i < 11) while (i < n) while (i < n)
c = a + 7*b + 2; i = i + 1;
i = i + 1; i = i + 3;
16 17
18 19
Computational Complexity Computational Complexity
Analysis Analysis
for (i = 0; i < n; i++) for (i = 1; i <= n; i++)
for (j = 0; j < n; j++) for (j = 1; j <= i; j++)
cnt += 1; cnt += 1;
20 21
T(n) =?
22 23
THANK YOU
24