Geoinformation Technology: lecture 10a Algorithms and Complexity - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

Geoinformation Technology: lecture 10a Algorithms and Complexity

Description:

Department of Geoinformation Science. Technische Universit t Berlin. WS 2006/07 ... developed at the Institute for Cartography and Geoinformation, Univ. of Bonn, ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 58
Provided by: Mars142
Category:

less

Transcript and Presenter's Notes

Title: Geoinformation Technology: lecture 10a Algorithms and Complexity


1
Geoinformation Technology lecture 10a
Algorithms and Complexity
  • Prof. Dr. Thomas H. Kolbe
  • Institute for Geodesy and Geoinformation Science
  • Technische Universität Berlin

These slides contain material developed at the
Institute for Cartography and Geoinformation,
Univ. of Bonn, Courtesy of Prof. Plümer, Dr.
Gröger
2
Area of a Polygon
2
(x3,y3)
(x4,y4)
F
(x2,y2)
(x5,y5)
(x1,y1)
3
Area Formula by Gauss
4
Iteration, For-Loop
BEGIN

5
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
f 0
6
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
FOR k1 TO 5 DO
for(k 1 k lt 5 k)
7
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
for(k 1 k lt 5 k)
BEGIN

8
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
(x6,y6)
for(k 1 k lt 5 k)

f f ((xk - xk1)(yk yk1))
f f ((xk - xk1)(yk yk1))
9
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
for(k 1 k lt 5 k)

f f ((xk - xk1)(yk yk1))
END

10
Iteration, For-Loop
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
for(k 1 k lt 5 k)

f f ((xk - xk1)(yk yk1))

flaeche f/2
flaeche f/2
11
Iteration, For-Loop
4
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
for(k 1 k lt 5 k)

f f ((xk - xk1)(yk yk1))

flaeche f/2
END

12
Iteration, For-Loop
4
(x3,y3)
(x4,y4)
(x2,y2)

(x5,y5)
(x1,y1)
f 0
for(k 1 k lt 5 k)

f f ((xk - xk1)(yk yk1))

flaeche f/2

13
Geoinformation Technology lecture 10b
Recursion
  • Prof. Dr. Thomas H. Kolbe
  • Institute for Geodesy and Geoinformation Science
  • Technische Universität Berlin

These slides contain material developed at the
Institute for Cartography and Geoinformation,
Univ. of Bonn, Courtesy of Prof. Plümer, Dr.
Gröger
14
Overview
  • The principle of recursion
  • Example Faculty function

15
Illustration of Recursion
16
The Principle of Recursion
3
  • A recursive definition reduces a problem to a
    smaller problem of the same kind.
  • A recursive function maps a recursive definition
    to a program / algorithm.

17
Example Factorial function
4
Definition For n ? 0 it is defined
18
Java Syntax
5
  • if (condition) statement1else statement2If
    the condition is true, execute
    statement1,otherwise execute statement2.
  • int my_function(...) ...... return
    integer_expression ..... Function Call
    int i my_function(...)
  • The function my_function returns the result of
    theinteger-expression, which follows the return
    keyword.

19
Factorial Function
6
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
20
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(4)
n 4
21
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
22
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
23
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
24
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
n 3
fak(3)
25
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
26
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
27
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
28
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(2)
29
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
30
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(1)
31
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
32
Factorial Function
7
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(0)
33
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
34
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
35
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(0) 1
36
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
37
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(1) 11
38
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(1) 1
39
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
40
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(2) 21
41
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(2) 2
42
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
43
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(3) 32
44
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(3) 6
45
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
46
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
47
Factorial Function
int fak(int n) if(n0) return 1 else
if (ngt0) return n fak(n-1) else
return -1
fak(4) 24
48
Geoinformation Technology lecture 10c
Algorithmic Complexity
  • Prof. Dr. Thomas H. Kolbe
  • Institute for Geodesy and Geoinformation Science
  • Technische Universität Berlin

These slides contain material developed at the
Institute for Cartography and Geoinformation,
Univ. of Bonn, Courtesy of Prof. Plümer, Dr.
Gröger
49
Asymptotic Complexity of Algorithms
20
  • Big Oh Notation (also called Landau symbol)
  • Definition
  • characterizes the asymptotical
    behaviour of function f for very large
    input lengths n.
  • f typically specifies the number of
    computation steps or storage units.

where
50
Properties of O(f)
  • Product
  • Sum
  • Multiplication with a constant

51
Big Oh Notation - Examples
  • The fastest growing term within a (finite) sum of
    functions determines the order of f(n)
  • O (log n) O (log(nc)), because they differ only
    by constant factor c
  • O (logx n) O (logy n) with x?y
  • but O(cn) ? O(dn) with c?d

52
Common Orders of Complexity Funktions
  • In increasing order of complexity
  • (as n increases to infinity c is an arbitrary
    constant)
  • O(1) - constant
  • O(log n) - logarithmic
  • O(n) - linear
  • O(n log n) - loglinear, quasilinear
  • O(n²) - quadratic
  • O(nc), cgt1 - polynomial
  • O(cn) - exponential (sometimes called geometric)
  • O(n!) - factorial (sometimes called
    combinatorial)
  • O(2cn) - double exponential

53
Inclusion
2
54
How fast grows... ?
n log n
n
log n
55
Nichts wächst so schnell ...
in Englishnothing grows as fast as exponential
exp n

n log n
... wie exponentiell!
56
Algorithmic Complexity - Examples
  • How complex is
  • Addition/Multiplication of numbers
  • with fixed lengths, e.g. double ab,
    ab O(1)
  • comparison a lt b O(1)
  • assignment a b O(1)
  • (conditional) jump while(a gt b) O(1)
  • access to array element a i O(1)
  • i-th element of a list (length n) O(n)
  • insertion at the beginning of a list O(1)
  • insertion at the beginning of an array O(n)

57
Worst Case Complexity (Examples)
  • Searching within
  • an unsorted array O(n)
  • a list O(n)
  • a binary search tree O(n)
  • an AVL tree (balanced tree) O(log n)
  • Sorting
  • with Quicksort O(n²)
  • with AVL trees O(n log n)
  • Searching a point within an appropriate
    structure O(log n)
  • Generation of an appropriate structure for
    points O(n log n)
Write a Comment
User Comments (0)
About PowerShow.com