Presentation Introdiction To Data Structures 1463137384 181219
Presentation Introdiction To Data Structures 1463137384 181219
Presentation Introdiction To Data Structures 1463137384 181219
1
Data Structures - Introduction
2
Data Structures - Introduction
3
Data Structures - Introduction
4
Data Structures - Introduction
Abstract Concrete
Pseudocode Specific programming
Algorithm language
A sequence of high-level, Program
language independent A sequence of operations in a
operations, which may specific programming
act upon an abstracted language, which may act upon
view of data. real data in the form of
Abstract Data Type numbers, images, sound, etc.
(ADT) Data structure
A mathematical A specific way in which a
description of an object program’s data is represented,
and the set of operations which reflects the
on the object. programmer’s design
choices/goals. 5
Data Structures - Introduction
Introductions
Administrative Info
What is this course about?
Review: Queues and stacks
7
Data Structures - Introduction
8
Data Structures - Introduction
0
Q size - 1
b c d e f
front back
enqueue(Object x) {
Q[back] = x ;
back = (back + 1) % size
}
dequeue() {
x = Q[front] ;
front = (front + 1) % size;
return x ;
}
9
Data Structures - Introduction
b c d e f
front back
11
Data Structures - Introduction
12
Data Structures - Introduction
13
Data Structures - Introduction
14
Data Structures - Introduction
Correctness:
Does the algorithm do what is intended.
Performance:
What is the running time of the algorithm.
How much storage does it consume.
Different algorithms may be correct
Which should I use?
15
Data Structures - Introduction
16
Data Structures - Introduction
17
Data Structures - Introduction
Basis Step:
sum(v,0) = 0.
18
Data Structures - Introduction
19
Data Structures - Introduction
20
Data Structures - Introduction
Ignores “details”
What details?
CPU speed
Programming language used
Amount of memory
Compiler
Order of input
Size of input … sorta.
21
Data Structures - Introduction
Efficiency measure
how long the program runs time
complexity
how much memory it uses space
complexity
Why analyze at all?
Decide what algorithm to implement before
actually doing it
Given code, get a sense for where
bottlenecks must be, without actually
measuring it 22
Data Structures - Introduction
23
Data Structures - Introduction
2 3 5 16 37 50 73 75 126
26
Data Structures - Introduction
27
Data Structures - Introduction
28
Data Structures - Introduction
30
Data Structures - Introduction
31
32
33
34
Data Structures - Introduction
36
Data Structures - Introduction
f(n) = n3 + 2n2
g(n) = 100n2 + 1000
39
Data Structures - Introduction
Example:
100n2 + 1000 5 (n3 + 2n2) for all n 19
So g(n) O( f(n) ) 40
Data Structures - Introduction
42
Data Structures - Introduction
constant: O(1)
logarithmic: O(log n) (logkn, log n2 O(log n))
linear: O(n)
log-linear: O(n log n)
quadratic: O(n2)
cubic: O(n3)
polynomial: O(nk) (k is a constant)
exponential: O(cn) (c is a constant > 1)
43
Data Structures - Introduction
44
Data Structures - Introduction
There exists a n0 such that g(n) < c f(n) for all c and n n0
Equivalent to: limn g(n)/f(n) = 0
There exists a n0 such that g(n) > c f(n) for all c and n n0
Equivalent to: limn g(n)/f(n) =
45
Asymptotic Notation Mathematics
Relation
O
=
o <
>
47
Data Structures - Introduction
48
Data Structures - Introduction
Bound Flavor
Upper bound (O, o)
Lower bound (, )
Asymptotically tight ()
Analysis Case
Worst Case (Adversary)
Average Case
Best Case
Amortized 49
Data Structures - Introduction
50