Algorithms
About the course (objectives, outline,
recommended reading)
Problem solving
Notions
of Algorithmics (growth of
functions, efficiency, programming model,
example analysis)
Stacks, queues.
Instructors:
Iulia.Costin@cs.utcluj.ro
http://users.utcluj.ro/~jim/DSA
Objectives
Lectures
Laboratory sessions
Evaluation
Written exams
of written
Recommended books
Recommended books
Preiss. Data Structures and Algorithms with objectOriented Design Patterns in C++, John Wiley and Sons,
660 pages, 1999.
Outline (preliminary)
Introduction: algorithmics
and asymptotics. Lists,
stacks and queues
Trees, binary trees, binary
search trees
Basic ADTs for sets:
dictionary, hash tables,
mappings, priority queues
Advanced ADTs for sets: 23 trees, AVL trees, unionfiind sets
Directed graph ADTs:
single source shortest path,
all pairs shortest path,
traversals
Undirected graphs:
minimum cost spanning
trees (MST), MST
algorithms, traversals,
graph matching
Algorithm analysis and
design techniques: divide
and conquer, dynamic
programming, greedy
algorithms, backtracking,
local search algorithms
Sorting
Data Structures and
algorithms for external
storage. B-trees.
Problem Solving
10
Basic Notions
11
Statement of problem:
Selection sort
Insertion sort
Merge sort
(many others)
12
13
Analysis of algorithms
running time
memory usage (space)
number of accesses to secondary storage
number of basic arithmetic operations
network traffic
14
Growth of functions
15
Formally:
O( g(n) ) is the set of functions, f, such that
f(n) < c g(n)
and say
g(n)
16
Big-oh
O(g)
Examples:
n lg n + n = O(n2)
lgk n = O(n) for all k N
DSA - Lecture 1- T.U.Cluj-Napoca - M. Joldos
17
Big-omega
Example:
a n2 + b n + c = (n)
provided a > 0
18
Big-theta
(g(n)): class of functions f(n) that grow at same rate as
g(n)
Example:
n2 / 2 - 3 n = (n2)
We have to determine c1 > 0,
c2 > 0, n0 N such that:
c2 n2 n2 / 2 - 3 n c1 n2 for
any n > n0
Example:
Dividing by n2 yields:
c2 1 / 2 3 / n c1
This is satisfied for
c2 = 1 / 14, c1 = 1 / 2, n0 = 7.
19
constant
log n
logarithmic
linear
n log n
n log n
n2
quadratic
n3
cubic
2n
exponential
n!
factorial
DSA - Lecture 1- T.U.Cluj-Napoca - M. Joldos
20
21
T(n) copC(n)
running time
execution time
for basic operation
Number of times
basic operation is
executed
22
of size n
Set up summation for C(n) reflecting algorithms
loop structure
Simplify summation using standard formulas
23
Example (nonrecursive)
24
25
Example (recursive)
26
27
28
Stacks
29
30
31
Stacks - Relevance
Stack frame
32
Queues
33
34
35
Reading
36