data types yukita/. 2 arithmetic funtions ans laws

Post on 18-Jan-2016

223 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Data Types

http://cis.k.hosei.ac.jp/~yukita/

2

Arithmeticfuntions ans laws

law) ve(commutati

law) (inverse )(0)(

law) ve(associati )()(

law)(identity 00

:

:

:

xyyx

xxxx

zyxzyx

xxx

minus

Izero

add

3

The Associative Law

add

add1 add

1add

4

The Identity Law

.II 1zerozero1

add

1

1

5

The Inverse Law

minus1

add

I! zero

Izero !

1minus

6

The Commutative Law

add

twist

add

.

7

Data Types

• Algebras such as groups, rings, etc. are familiar data types in mathematics.

• CS handles other data types other than those algebras.– stacks– queues– arrays– binary trees– other useful data structures

• A data type consists of various sets of data together with operations between them definable in a distributive category and equations expressible in a distributive category.

8

Stacks (Rough View)

),()(

:

)(),(

:

2121

2121

nn

nn

xxxxxx

SSpop

xxxxxxxx

SSpush

9

Pop revised to avoid stack underflow

. if ),(

if *

:

2121 nn xxxsxxx

oss

SISpop

10

Push revised for symmetry

nn xxxxxxxx

xox

o

SSIpush

oSIo

2121 ),(

),(

*

:

.* :

11

Axioms

.1

,1

:

:

S

SI

poppush

pushpop

SSIpush

SISpop

2. Axiom

1. Axiom

12

Definition.

.1

,1

satisfying

.:

,:

:operations ith twotogether w

set a is , of aor , of A

S

SI

poppush

pushpop

SSIpush

SISpop

S

stacks ofspace stacktype

13

Ex. 1. Infinite stacks

2121

2121

),(

),(

*

:

sequence infiniteor finite means

),(

*

:

xxxxxx

xox

o

SSIpush

xxxxxx

o

SISpop

14

Note

• Just from the axioms, we do not know whether the stacks are finite.

15

Definition. Stacks of X

.1

,1

satisfying

.:

,:

:operations ith twotogether w

set a is , of aor , of A

S

SXI

poppush

pushpop

SSXIpush

SXISpop

SXX

stacks ofspace stacktype

16

Ex. 2.

another. one of inverses are and

1

0*

:

.0 if 1

0 if *

:

. and {*}Let

successorrpredecesso

nn

Isuccessor

nn

nn

IIIrpredecesso

SIX

17

Notation

.by product theand

by 1 arrowidentity thedenote willWe

XYYX

XX

18

Ex. 3. The usual operation of pushing an element on a stack

SSXII

xssxsx

SSXISX

pushi

pushi

I

SX

isstack empty The

),(),(

19

Ex. 4. Imperative computing of the depth of a stack

)).(,(st idles program the),0,( state initial with theBeginning

.

)()()(

composite. following theisaction The

),(),(

)1,(),(

e.number typ a is

1

)()(

21

sdepthos

SRSRSRSRSR

RSSRSIRXSISR

roro

rxxrxx

RSRS

R

xSSR

RSoRprojIRpop

nn

20

Ex. 5. Tests on stacks

.

)()(

.1)( if 1

1)( if 0

:

!!!

2

IIIIIIII

SXXIXSIXIXSIS

sdepth

sdepths

IIStest

ItwistI

popXIpop

21

Arrays - the store function

.by dimplemente

]).[,],1[,],1[,],2[],1[(])[,],2[],1[,(

is oneth - The

. arrows need we, : define To

).),,((),,(

)(

have wecategory, vedistributi aIn

. if ][

, if ][ where),,(

:

21,1

1

11

1

npnswapn

nn

nnnn

nnn

nn

XXXXX

naiaxiaaanaaax

XX

i

XXnXXn

iaxaix

XnXXInXInX

ijja

ijxjaaaix

XXInXstore

i

22

Arrays - the read function

].[),(),(

:

order.in projectionth - ],[),(

:

],[),(

:

iaiaai

XXnXInread

niaia

XXn

iaai

XXInread

nn

n

n

23

Binary Treesx

y

p

z

q

u v

24

Two operations make and break

*.

),,(

:

is inverse The

.:

asoperation singlein put themor

.),,( :

,empty tree the:

:operations with , of esbinary tre ofset thebe Let

2121

2121

o

txtxtt

TXTITbreak

TTXTImake

xtttxtTTXTmake

TIo

XT

25

Def. Binary Tree

another. one toinverse arewhich

,: and :

operations with twoobject an is , of A type,

TXTITbreakTTXTImake

TX

treebinary

26

Queues

27

Pointers

28

Turing Machines

top related