Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object...

41
Computer Science for Engineers Lecture 7 Object Orientation – part 5 Preview Prof. Dr. Dr.-Ing. Jivka Ovtcharova Dipl. Wi.-Ing. Dan Gutu 11 th of December 2009

Transcript of Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object...

Page 1: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Computer Science for Engineers

Lecture 7Object Orientation – part 5

Preview Prof. Dr. Dr.-Ing. Jivka Ovtcharova

Dipl. Wi.-Ing. Dan Gutu

11th of December 2009

Page 2: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 2

Example for an activity diagram (1)

• Solution description:

• Algorithm:1: Go to the first person.

2: Ask for its age.

3: Memorize its age.

4: As long as not all persons were questioned, repeat steps 4.1 - 4.3:

4.1: Go to next person.

4.2: Ask for its age.

4.3: If its age is smaller than the memorized age, memorize this age.

5 The youngest person is „memorized age“ years old.

• Task: determine the age of the youngest person in a line.

Page 3: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 3

Example for an activity diagram (2)

• Solution with UML (Activity diagram):

Go to first person

Start

Input: Ask for age

Memorize age

Output: youngest person is‘memorized age‘ years old

[all persons questioned== true]

[all persons questioned == false]Go to next person

Input: ask for its age

Memorize new age[requested age < memorized age]

[requested age >= memorized age]

Page 4: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 4

3.3.2. Example: Modeling a M&S System

3.3.1. Introduction

Outline

Lecture Content

3. Object orientation

3.3. Methods of the OO Analysis and Design

1. Preface

3.1.1. Introduction

3.1.2. Objects and classes

3.1. Introduction and basic concepts

3.1.3. Attributes of object orientation

3.2. Object-oriented modelling with UML

3.3.2. Use Case models

3.2.3. Static models

3.2.4. Dynamic models

3.2.1. Intro

3.2.5. Summary

2. Basics

Page 5: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 5

Why Software-Engineering?

• Ariane 5: Failure of its first flight on 4th of June1996:

Rocket blows itself up 36 sec after start

• Source of failure: software

• Parts of the software were taken from Ariane 4

• Ariane 5 can accelerate faster: variable overflow

• Steering system breaks down, status message to navigation system

• Navigation system interprets this as flight data

• Because of „serious deviation from course“ the rocket blows itself up

[Source: Wikipedia]

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 6: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 6

What is Software Engineering?

• The area of computer science that deals with the methods and tools for an engineering-type design and implementation of software

• Software engineering is performed today almost exclusively with help of special software tools (so called CASE-Tools)

• Special methods of software engineering are dependent on the basic principles of program development, such as structured or object oriented programming

• The process of software engineering contains all of the phases, from problem specification up to the final use of the program or program systems

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 7: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 7

Software Engineering

• Emerged from the software crisis (NATO conference 1968)- Software costs > hardware

- Lack of transparency in the software development process

- Engineering view on the software development process

• High quota of failed software projects (CHAOS study)- Study on success/failure of software projects

- Only about 17% of all software projects are successful regarding

Costs

Timeframe

Requirements

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 8: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 8

Software Engineering - Model 1

• Water fall model

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Requirements analysisValidation

Software developmentValidation

ImplementationValidation

Integration and testsValidation

Usage and maintenanceValidation

Page 9: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 9

Software Engineering - Model 2

• V- Model

- Military software development

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Requirements definition

Preliminary design

Detailed design

Module implementation Module test

Integration test

System test

Commissioning Use case scenarios

Test cases

Test cases

Test cases

Page 10: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 10

Software Engineering - Model 3

• Prototype Model

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Requirements analysis

Softwaredevelopment

Implementation

Integration and tests

Usage andmaintenance

Page 11: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 11

• Spiral model

Software Engineering - Model 4

[Beister 08]

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Determine objectivesSolution variantsBoundary conditions

Next phase planning

Evaluate solution alternativesOvercome riscs

Prototype creation

Development andverification

Implementation

RequirementsDevelopmentplan

Integration and test plan

Page 12: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 12

Rational Unified Process (RUP)

• Rational Unified Process (RUP) is an object oriented process model for software development. It is also a commercial product of the Rational Software company - which since 2002 has been a part of IBM.

• RUP uses Unified Modeling Language (UML) as the notation language

• The life-cycle of RUP is divided into 4 principle phases:

- Inception (conceptualization: determine project extent)

- Elaboration (Design: develop convertible architecture)

- Construction (Implementation: fill the architectural skeleton with functionality)

- Transition (Product transfer: transfer application to the user environment)

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 13: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 13

Rational Unified Process: Dynamic Structure

Distribution of tasks in small steps (Iterations)

Source: IBM - Rational

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 14: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 14

Phases of the Rational Unified Process: Inception and Elaboration

• Inception (Conceptualization)

- Specification of the vision for the end product

- Specification of the essential transactions

- Definition of the project extent

- Project costs and risks

- Finish: Life Cycle Objective Milestone

• Elaboration (Design)

- Specification of product characteristics

- Design of architecture

- Design of the necessary activities and resources

- Finish: Life Cycle Architecture Milestone

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 15: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 15

Phases of the Rational Unified Process: Construction and Transition

• Construction (Implementation)

- Generation of the product

- Development of the architecture

- Result: manufactured product

- Finish: Initial Operational Capability Milestone

• Transition (Product transfer)

- Release of the product to the user

- Test of the quality level

- Delivery, Training, Customer Support, Maintenance

- Finish: Release Milestone

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 16: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 16

Phases of the Rational Unified Process

• The results of the phases are the so called Milestones:- Lifecycle objectives milestone: Vision including a rudimentary use

case model, (essential functionalities), tentative architecture, identification of important risks, design of the engineering phase

- Lifecycle architecture milestone: Architecture prototype, detailed use case model, design of the construction phase

- Initial operational capability milestone: Design models and Beta-Release of the Software

- Product release milestone: Release in production quality

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 17: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 17

Disciplines of RUP: Static Structure

• The disciplines (interchangeably used with working steps) orient themselves to special roles within the developing team, and are administered by certain people or groups

• In detail, these disciplines are:

- Central work stepsBusiness Modeling

Requirements

Analysis & Design

Implementation

Test

Deployment

- Supported work stepsConfiguration & Change Management

Project Management

Environment

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 18: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 18

Rational Unified Process

Sou

rce:

IBM

-R

atio

nal

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 19: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 19

Business Modelling

• Define the core problem:

- Which functions should the system offer?

- How should the operating surface behave?

- How efficient, safe, … must the system be?

• Define the relevant environment:- type, number of users

- available hardware, previous software

• Estimate feasibility- Technical, personal capacity

- Costs (and uses)

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 20: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 20

Requirements

• Purpose of the system

• Desired functions

• Correct / false input, corresponding reactions

• Configuration of the operating surface

• Efficiency - goals

• Document requirements

• Protection / Safety aspects

• Standards to use

• Time plan, expenditure estimate, risk estimate

(approx.)

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 21: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 21

Analysis and Design

• Rough system structure- Analyze the components

- Define teamwork

- Test design vs. requirements

• Describing the components- Purpose and role of a component

- Service offered from one component

• Relationships between components- Which components can use the other ones

- Forming of design decisions

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 22: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 22

Implementation and tests

• Implement the components- Choose data structures

- Choose algorithms

- Formulate in the programming language

• Document the components- How do the components accomplish their tasks?

- Establish implementation alternatives

• Test components (vs. design)

- Arrange the test environment, gather test data

- Perform a run through of the test

- Verification

• Test externally programmed components3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 23: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 23

Deployment

• Application- Install the system for the customer

- accommodate

- Inspection by the customer

- Transfer of the system

- Train the User

• Maintenance- Correct errors

- Modify: functionalities adapt/ better

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 24: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 24

Application of UML in RUP - Disciplines

Diagram type Diagram Disciplines

Use case Use case diagram Business modeling

Requirements

Static model Class diagram Analysis & Design

Instance diagram Implementation

Dynamic model Collaboration diagrams Analysis & Design

Sequence diagrams Requirements

Analysis & Design

Implementation

State diagrams Requirements

Analysis & Design

Activity diagrams Requirements

Analysis & Design

3.3.

Met

hods

of O

O A

naly

sis

and

Des

ign

3.3.

1 In

trodu

ctio

n

Page 25: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 25

Recommended Literature

[Prie00] M. Priestley: Practical Object-oriented Design with UML, MacGraw-Hill, 2000

[Booc99] I. Jacobson, G. Booch, J. Rumbaugh: The Unified Software Development Process, Addison-Wesley, 1999

[Otte05] Prof. Dr.-Ing. Martin Otter: Vorlesung „Objektorientierte Modellierung mechatronischer Systeme“, DLR, 2005 Web: http://www.eat.ei.tum.de/lehre/otter-vorlesungen.html

[HiKa99] M. Hitz, G. Kappel: „UML@Work“, dpunkt.verlag, 1999

[HrRu02] Hruschka,P., Rupp, C.: Agile Softwareentwicklung für embedded Real-Time Systeme, Hanser Verlag, 2002

[GHJV01] Gamma, E., Helm, R., Johnson, R., Vlissides, J.: „Entwurfsmuster –Elemente wiederverwendbarer objektorientierter Software“, Addison-Wesley Verlag, 2001

Page 26: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Computer Science for Engineers

Lecture 7Data structures – part 1

Preview Prof. Dr. Dr.-Ing. Jivka Ovtcharova

Dipl. Wi.-Ing. Dan Gutu

11th of December 2009

Page 27: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 27

Outline

Lecture Content

3. Object orientation

1. Preface

2. Basics

4. Data Structures

4.2. Graphs

4.3. Use of Graphs

5. Algorithms

4.1. Introduction

4.4. Trees

4.5. Use of Trees

4.6. Linked Lists

4.7. Queues and Stacks

Page 28: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 28

Definition of the Term4.

Dat

a St

ruct

ues

4.1

Intro

duct

ion

• According to definition 1.1 from lecture 1, computer science is the science that concerns itself with the structure, effectiveness, construction principles, and applications of information processing systems as well as their usage.

• In order to complete these tasks, computer science developed a formalism, which allows verified characteristics and exceptions to structures, effectiveness, and principles.

• This formalism and the possibility for their verification are prerequisites for a systematic data processing, which can be automatized through a computer.

Page 29: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 29

Data Structures - Examples

• A data structure in computer science is a specific form to manage data and link the structures with one another, so that it’s possible to access the data and especially manipulate it in an applicable manner.

• Data structures are always linked with certain operations to allow these manipulations.

• Application examples are

- Data pool systems

- Networks

- Lists of assembly parts

- Telephone book

- Pictures

Source: www.witaf.at

Source: GWDG

Source: irc.rz.uni-karlsruhe.de

4. D

ata

Stru

ctue

s

4.1

Intro

duct

ion

Page 30: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 30

Data Structures

• The different types of data structures are applicable for different specific tasks according to their characteristics, linked operations, and implementation.

• Decision criteria are, for example

- Amount of data to be managed

- Data fluctuation

- Necessary access possibilities

- Run time behavior of the data access

- Alterability of the data structure

4. D

ata

Stru

ctue

s

4.1

Intro

duct

ion

Page 31: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 31

Outline

Lecture Content

3. Object orientation

1. Preface

2. Basics

4. Data Structures

4.2. Graphs

4.3. Use of Graphs

5. Algorithms

4.1. Introduction

4.4. Trees

4.5. Use of Trees

4.6. Linked Lists

4.7. Queues and Stacks

Page 32: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 32

A graph is a formation of vertices that are connected through edges.

Graphs are visually described through images and through mathematical structures. This general definition allows the description of complex associations and characteristics

Graph (1)4.

Dat

a St

ruct

ures

4.2

Gra

phs

vertex

edge

Page 33: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 33

Definition 3.1: G = (V,E) is a graph if and only if

1. V is heap (vertices)

2. E ⊆ { {v1,v2} | v1,v2∈ V } (edges)

example

Nomenclature

Graph (2)

G1 :V = {v1,v2,v3}

E = { {v1,v2} , {v2,v3}}

In the graph G2 = ({v1},{v1})

the edge e1 = {v1} is a loop.v1

e1

G2 :

v1 v2e1 v3

e2

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 34: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 34

Definition 3.2: Let G = (V,E) and G´ = (V´,E´).

G´ is a subgraph of G if and only if

E´ ⊆ E and V´ ⊆ V ( ⇔ G´ ⊆ G )

example

Subgraph

V = {v1,v2,v3,v4}

E = { {v1,v2} , {v1,v3} , {v1,v4} , {v3,v4} , {v2} }

G3 :v1

v2 v3

e1 e4

e3

v4

e5

e2 G3´ : v1

v2

e1

e3

V´ = {v1,v2}

E´ = { {v1,v2} , {v2} }

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 35: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 35

Definition 3.3: A path π in G is a sequence of π = (v0,v1, … ,vn) with

∀0 ≤ i < n : {vi, vi+1} ∈ E

Example

Nomenclature

Path

G4 : π = (v1,v4,v3)

v1 v2e1 v4

v3e2 e3

e4

e5

n = |π| = Length of π

Start(π) = v0

End(π) = vn

The total of all paths π in G is Path(G)

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 36: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 36

Definition 3.4: The path π in G is a circle if and only if

Start(π) = End(π)

example

Nomenclature

Circle

A path π is a simple edge circle, when each edge on the path π is contained only once in the path

G4 :

v1 v2e1 v4

v3e2 e3

e4

e5

π = (v2,v4,v3,v2) is a circle π = (v1,v4,v2) is NOT a circle

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 37: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 37

Definition 3.5: the branching factor d for a graph G and a vertex v is the number of edges connected with the vertex v.

d(G,v) = #(v´ ∈ V | {v,v´} ∈ E)

The branching factor d for a graph G gives the maximal branching factor for all vertices.

d(G) = Max( d(G,v) )

example

Branching factor

G5 :

v ∈ V

v4

v1

v2 v3

d(G5,v3) = 2

d(G5,v4) = 1

d(G5) = 5

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 38: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 38

Edge Quantifier

G6 :

v1 v2 v3

g(v1, v2) = 2

g(v2, v3) = ∞

g(v1, v3) = 5

A graph G was previously described by the amounts E and V and can also be described through the input of a weight function g.

Let G = (V, E) and g : V x V → R be the weight function.

therefore: g(v1, v2) = ∞ ⇒ {v1, v2} ∉ E

g(v1, v2) ≠ ∞ : weight of the edge {v1, v2} ∈ E

That means that an edge is an element of the graph when the weight is smaller than ∞ .

example

2

5

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 39: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 39

Definition 3.6: A directed graph G is a pair G = (V,R) with

1. V is a heap (vertices)

2. R ⊆ V x V (directed edges)

(The order of the vertices in an edge gives the direction)

example

Directed Graphs

V = {v1,v2,v3,v4}

R = { {v2,v1} , {v3,v1} , {v1,v4} , {v3,v4} , {v2, v2} }

G6 :v1v2

v3

v4

4. D

ata

Stru

ctur

es

4.2

Gra

phs

Page 40: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 40

KVV – bus and street car map

Example of a Graph (1)4.

Dat

a St

ruct

ures

4.2

Gra

phs

Page 41: Computer Science for Engineers - KIT€¦ · Computer Science for Engineers Lecture 7 Object Orientation ... CSE-Lecture – Ch. 3 and 4 - WS 09/10 ... Outline. Lecture Content. 3.

Prof. Dr. Dr.-Ing. Jivka Ovtcharova – CSE-Lecture – Ch. 3 and 4 - WS 09/10 - Slide 41

How do I get from the main train station to the university (path)?

Example of a Graph (2)

How much time do I need for this path (edge quantifier)?

Start(π) = Hauptbahnhof

End(π) = Kronenplatz / KIT Campus Süd

path π = {Hauptbahnhof, Poststraße, Augartenstraße, Kongresszentrum, Ettlinger Tor, Marktplatz, Kronenplatz / KIT Campus Süd}

Gπ = (V,E)⊆ KVV (Gπ is the subgraph of the line graph)

weight(Gπ) = Σ g(e) = 12 (Sum of all edge weights)

Gπ :

2 1 2 3 3 1ME UKAPH

e ∈ E

4. D

ata

Stru

ctur

es

4.2

Gra

phs