L2- Introduction to Algorithms - 2016
L2- Introduction to Algorithms - 2016
L2 – Introduction to Algorithms
NGEN06(TEK230) –
Algorithms in Geographical Information Systems
Content
2
L2-Introduction to Algorithms
Shortest
path
algorithm 3
L2-Introduction to Algorithms
4
L2-Introduction to Algorithms
Algorithm properties
All algorithms that perform the same task are not equally
good. A good algorithm should preferably have the
following properties:
1. It should always give a correct answer (or it should at
least have known limitations and guarantees of the
quality of the result).
2. It should be easy to understand and implement
3. It should be efficient.
A trade off between the properties. Most algorithms that
are easy to understand and that always give the correct
answers are inefficient. Therefore, for many applications
these intuitive, or naive, approaches cannot be used.
5
L2-Introduction to Algorithms
6
L2-Introduction to Algorithms
7
L2-Introduction to Algorithms
– Extreme Edges
– Gift wrapping
Important considerations:
- Two points are never equal
- Three (or more) points are never collinear
8
L2-Introduction to Algorithms
9
L2-Introduction to Algorithms
10
L2-Introduction to Algorithms
Three loops
for each i do j
for each j do
bool addLine = true i
for each i do
for each j do
i
bool addLine = true
for each k (not equal to i and j) do
if k is not left of the line segment then
addLine = false
if addLine
add the line segment i to j to the convex hull 12
L2-Introduction to Algorithms
One line
segment of
for each i do the convex
for each j do hull found j
i
bool addLine = true
for each k (not equal to i and j) do
if k is not left of the line segment then
addLine = false
if addLine
add the line segment i to j to the convex hull 13
L2-Introduction to Algorithms
The problem is to find the first line segment in the convex hull.
This is normally solved by starting a horizontal line that passes
through the lowest point.
14
L2-Introduction to Algorithms
Start point
(first i)
i
15
L2-Introduction to Algorithms
16
L2-Introduction to Algorithms
Computational complexity
How can we measure the efficiency of an algorithm?
Computational complexity
17
L2-Introduction to Algorithms
Computational complexity
Here computational complexity refers to processing step
(time) in relation to the size of the input data.
18
L2-Introduction to Algorithms
Computational complexity
The computational complexity of the algorithm is said to be
O(f(n)) if there exists a constant C and an integer n0 such that
C*f(n) g(n) for all n > n0.
g(n) = “actual” processing time
n = amount of input data
19
L2-Introduction to Algorithms
Computational complexity
Why use O(f(n)) instead of g(n)?
- g(n) is maybe unknown.
20
L2-Introduction to Algorithms
Computational complexity
21
L2-Introduction to Algorithms
Computational complexity
22
L2-Introduction to Algorithms
Computational complexity
23
L2-Introduction to Algorithms
Computational complexity
24
L2-Introduction to Algorithms
Computational complexity
25
L2-Introduction to Algorithms
Computational complexity
26
L2-Introduction to Algorithms
Computational complexity
27
L2-Introduction to Algorithms
Computational complexity
For example an O(n*log n) – algorithm can be fast for certain applications (e.g.
sorting routines), but slow for other purposes (e.g. search).
28
L2-Introduction to Algorithms
NP-complete problems
29
The route was generated by the website Reil (2005).
L2-Introduction to Algorithms
Heuristic
31
L2-Introduction to Algorithms
Three loops
that in worst
case iterates
over “all” points
32
L2-Introduction to Algorithms
33
L2-Introduction to Algorithms
40
30
Gift wrapping
20
Extreme edges
10
0
10 30 50 70 90
Input points
34
L2-Introduction to Algorithms
Grid is
fraction of
millimeters.
The accuracy is higher than the accuracy of the data i.e. for
computations of area, length computations etc. the grid is
sufficiently dense…. 35
L2-Introduction to Algorithms
Choice of algorithms
Computational complexity describes the worst case scenario.
For example extreme edges:
Choice of algorithms
Computational complexity describes the worst case scenario.
For example extreme edges:
Choice of algorithms
Computational complexity describes the worst case scenario.
For example extreme edges:
Choice of algorithms
What algorithm is used?
40
L2-Introduction to Algorithms