Data Structures and Algorithm Design

Ähnliche Dokumente
Data Structures and Algorithm Design

Algorithm Theory 3 Fast Fourier Transformation Christian Schindelhauer

Algorithms & Datastructures Midterm Test 1

Bayesian Networks. Syntax Semantics Parametrized Distributions Inference in Bayesian Networks. Exact Inference. Approximate Inference

Number of Maximal Partial Clones

Introduction FEM, 1D-Example

Introduction FEM, 1D-Example

A Classification of Partial Boolean Clones

Java Tools JDK. IDEs. Downloads. Eclipse. IntelliJ. NetBeans. Java SE 8 Java SE 8 Documentation

Finite Difference Method (FDM)

Unit 4. The Extension Principle. Fuzzy Logic I 123

Algorithmische Geometrie

Tube Analyzer LogViewer 2.3

LiLi. physik multimedial. Links to e-learning content for physics, a database of distributed sources

Informatik - Übungsstunde

TSM 5.2 Experiences Lothar Wollschläger Zentralinstitut für Angewandte Mathematik Forschungszentrum Jülich

a) Name and draw three typical input signals used in control technique.

Informatik für Mathematiker und Physiker Woche 7. David Sommer

Weather forecast in Accra

Geometrie und Bedeutung: Kap 5

NEWSLETTER. FileDirector Version 2.5 Novelties. Filing system designer. Filing system in WinClient

Übungsstunde: Informatik 1 D-MAVT

4. Bayes Spiele. S i = Strategiemenge für Spieler i, S = S 1... S n. T i = Typmenge für Spieler i, T = T 1... T n

Informatik für Mathematiker und Physiker Woche 2. David Sommer

Algorithmen und Komplexität Teil 1: Grundlegende Algorithmen

DIBELS TM. German Translations of Administration Directions

!! Um!in!ADITION!ein!HTML51Werbemittel!anzulegen,!erstellen!Sie!zunächst!ein!neues! Werbemittel!des!Typs!RichMedia.!!!!!!

Accelerating Information Technology Innovation

Logik für Informatiker Logic for computer scientists

Teil 2.2: Lernen formaler Sprachen: Hypothesenräume

Divide & Conquer. Problem in Teilprobleme aufteilen Teilprobleme rekursiv lösen Lösung aus Teillösungen zusammensetzen

19. STL Container Programmieren / Algorithmen und Datenstrukturen 2

Attention: Give your answers to problem 1 and problem 2 directly below the questions in the exam question sheet. ,and C = [ ].

Introduction to Python. Introduction. First Steps in Python. pseudo random numbers. May 2016

Algorithmen und Datenstrukturen Musterlösung 5

Fundamentals of Electrical Engineering 1 Grundlagen der Elektrotechnik 1

Wer bin ich - und wenn ja wie viele?: Eine philosophische Reise. Click here if your download doesn"t start automatically

Ewald s Sphere/Problem 3.7

Extracting Business Rules from PL/SQL-Code

Handbuch der therapeutischen Seelsorge: Die Seelsorge-Praxis / Gesprächsführung in der Seelsorge (German Edition)

PONS DIE DREI??? FRAGEZEICHEN, ARCTIC ADVENTURE: ENGLISCH LERNEN MIT JUSTUS, PETER UND BOB

Outline. Best-first search. Greedy best-first search A* search Heuristics Local search algorithms

Introduction to Python. Introduction. First Steps in Python. pseudo random numbers. May 2018

Exercise (Part II) Anastasia Mochalova, Lehrstuhl für ABWL und Wirtschaftsinformatik, Kath. Universität Eichstätt-Ingolstadt 1

Order Ansicht Inhalt

Übung Algorithmen und Datenstrukturen

Creating OpenSocial Gadgets. Bastian Hofmann

Unit 1. Motivation and Basics of Classical Logic. Fuzzy Logic I 6

Klausur zur Vorlesung Vertiefung Theoretische Informatik Wintersemester

Copyright by Max Weishaupt GmbH, D Schwendi

Routing in WSN Exercise

Magic Figures. We note that in the example magic square the numbers 1 9 are used. All three rows (columns) have equal sum, called the magic number.

Functional Analysis Final Test, Funktionalanalysis Endklausur,

miditech 4merge 4-fach MIDI Merger mit :

FEM Isoparametric Concept

The process runs automatically and the user is guided through it. Data acquisition and the evaluation are done automatically.

Algorithmen I - Tutorium 28 Nr. 2

prorm Budget Planning promx GmbH Nordring Nuremberg

Mock Exam Behavioral Finance

Algorithms for graph visualization

Registration of residence at Citizens Office (Bürgerbüro)

DPM_flowcharts.doc Page F-1 of 9 Rüdiger Siol :28

FEM Isoparametric Concept

Algorithmus Analyse. Johann Basnakowski

Rekursion. Rekursive Funktionen, Korrektheit, Terminierung, Rekursion vs. Iteration, Sortieren

Programming for Engineers

Martin Luther. Click here if your download doesn"t start automatically

1D-Example - Finite Difference Method (FDM)

Transkript:

- University of Applied Sciences - Data Structures and Algorithm Design - CSCI 340 - Friedhelm Seutter Institut für Angewandte Informatik Contents 1 Analyzing Algorithms and Problems 2 Data Abstraction 3 Recursion and Induction 4 Sorting 6 Dynamic Sets and Searching 7 Graphs and Graph Traversals 8 Optimization and Greedy Algorithms 10 Dynamic Programming 13 NP-Complete Problems Institut für Angewandte Informatik 2 1

3 Recursion and Induction Recursive procedures Proving correctness Recurrence equations Recurrence trees Institut für Angewandte Informatik 3 Recursive procedures A recursive procedure is a procedure which calls itself, directly or indirectly Each individual procedure invocation at run time has its own storage space for the procedure s local variables This storage space is called activation frame Institut für Angewandte Informatik 4 2

Fibonacci function Institut für Angewandte Informatik 5 Fibonacci algorithm Institut für Angewandte Informatik 6 3

Dynamic nesting of blocks fib(3) fib(2) fib(1) fib(1) fib(0) f = 1 f = 0 f = 1 + 0 = 1 f = 1 f = 1 + 1 = 2 Institut für Angewandte Informatik 7 Tree of activation frames fib(3) fib(2) fib(1) fib(1) fib(0) Institut für Angewandte Informatik 8 4

Sequence of calls and returns Procedure calls: Preorder tree walk Return values: Postorder tree walk Institut für Angewandte Informatik 9 Proving correctness A proof of a program (procedure or function) is an argument along the block structure of the program A block is a section of program code with an entry point and an exit point It refers to local or nonlocal data Institut für Angewandte Informatik 10 5

Precondition, postcondition, and specification Institut für Angewandte Informatik 11 Control structures block 1 block 2 block sequence Institut für Angewandte Informatik 12 6

Control structures IF (condition) THEN ELSE WHILE (condition) DO trueblock falseblock block alternation loop Institut für Angewandte Informatik 13 Control structures function(x, y) function(x 1, x 2 ) block procedure call Institut für Angewandte Informatik 14 7

Correctness lemma forms Institut für Angewandte Informatik 15 Correctness lemma forms Institut für Angewandte Informatik 16 8

Correctness lemma forms Institut für Angewandte Informatik 17 Correctness lemma forms Institut für Angewandte Informatik 18 9

Binary Search Institut für Angewandte Informatik 19 Binary Search Institut für Angewandte Informatik 20 10

Recurrence equations A recurrence equation defines a function over ΙN, say T(n), in terms of its own value at one or more integers smaller than n A base case needs to be defined separately Institut für Angewandte Informatik 21 Fibonacci function Institut für Angewandte Informatik 22 11

Complexity of recursive Procedures Let n be the input size, and f(n) the nonrecursive complexity, ie to split up the problem into subproblems and to combine the solutions of the subproblems to a solution Let T(n) be the complexity of the recursive procedure Then T(n) is defined as a recurrence equation: T(n) = T(m) + f(n), and m < n Institut für Angewandte Informatik 23 Examples Fibonacci Algorithm: T(n) = T(n-1) + T(n-2) + 1 T(0) = T(1) = 1 Binary Search: T(n) = T(n/2) + 1 T(0) = 1 Institut für Angewandte Informatik 24 12

Fibonacci algorithm Institut für Angewandte Informatik 25 Binary Search Institut für Angewandte Informatik 26 13

Divide and Conquer Institut für Angewandte Informatik 27 Divide and Conquer The problem is divided recursively into subproblems of a fractional size of the problem T(n) = b T(n/c) + f(n) b 1 number of subproblems of size n/c, c > 1, branching factor f(n) some nonrecursive complexity Institut für Angewandte Informatik 28 14

Chip and Conquer The problem is chipped down recursively to a subproblem of a smaller size of the problem T(n) = T(n c) + f(n) c > 0, f(n) some nonrecursive complexity Institut für Angewandte Informatik 29 Chip and Be Conquered The problem is chipped down recursively to subproblems of a smaller size of the problem T(n) = b T(n c) + f(n) b 1 number of subproblems of size n c, c > 0, branching factor f(n) some nonrecursive complexity Institut für Angewandte Informatik 30 15

Recursion trees Recursion trees provide a tool for analyzing the complexity of recursive procedures for which a recurrence equation has been developed Node of a recursion tree: T(size) nonrec cost Institut für Angewandte Informatik 31 Divide and Conquer Recursion Tree Recurrence equation of Merge-Sort: T(n) = 2 T(n/2) + n Institut für Angewandte Informatik 32 16

Divide and Conquer Recursion Tree T(n) n T(n/2) n/2 T(n/2) n/2 T(n/4) n/4 T(n/4) n/4 T(n/4) n/4 T(n/4) n/4 Institut für Angewandte Informatik 33 Divide and Conquer Recursion Tree T(n) = n + 2 T(n/2) = n + 2(n/2) + 4 T(n/4) = 2n + 4 T(n/4) = =? Institut für Angewandte Informatik 34 17

Divide and Conquer Recursion Tree Summing up nonrecursive costs: depth 0: 1 n = n depth 1: 2 n/2 = n depth 2: 4 n/4 = n depth lg n: n 1 = n n ( lg n + 1) = θ(n lg n) Institut für Angewandte Informatik 35 Divide and Conquer (general case) Recurrence Equation: T(n) = b T(n/c) + f(n) Node depth of base-case nodes: n/c D = 1 D = lg n / lg c Number of nodes at depth D (ie leaves): L = b D lg L = D lg b = lg n (lg b / lg c) L = n E Critical exponent: E = lg b / lg c Institut für Angewandte Informatik 36 18

Master Theorem Institut für Angewandte Informatik 37 Divide and Conquer (special cases) Binary Search (b=1, c=2, f(n)=1): E = lg 1 / lg 2 = 0 und f(n) Θ(n 0 ) = Θ(n E ), thus T(n) Θ(log n) Merge-Sort (b=2, c=2, f(n)=n): E = lg 2 / lg 2 = 1 und f(n) Θ(n 1 ) = Θ(n E ), thus T(n) Θ(n log n) Institut für Angewandte Informatik 38 19

Chip and be conquered rec tree Recurrence equation of Fibonacci Algorithm: T(n) = T(n-1) + T(n-2) + 1 2 T(n-1) + 1 Institut für Angewandte Informatik 39 Chip and be conquered rec tree T(n) 1 T(n-1) 1 T(n-1) 1 T(n-2) 1 T(n-2) 1 T(n-2) 1 T(n-2) 1 Institut für Angewandte Informatik 40 20

Chip and be conquered rec tree Summing up nonrecursive costs: depth 0: 1 1 = 1 depth 1: 2 1 = 2 depth 2: 4 1 = 4 depth n: 2 n 1 = 2 n θ ( 2 n ) Institut für Angewandte Informatik 41 Chip and Be Conquered (general case) Recurrence Equation: T(n) = b T(n-c) + f(n) Node depth of base-case nodes: D = n / c Number of nodes at depth D: L = b D = b n/c Institut für Angewandte Informatik 42 21

Chip and Be Conquered (general case) Institut für Angewandte Informatik 43 Chip and Be Conquered (special cases) Fibonacci Algorithm (b=2, c=1, f(n)=1): T(n) = (0 d n/c) 2 d = 2 n+1 1 Θ(2 n ) b=1, f(n) Θ(n α ): T(n) Θ(n α +1 ) b=1, f(n) Θ(log n): T(n) Θ(n log n) Institut für Angewandte Informatik 44 22