Download as pdf or txt
Download as pdf or txt
You are on page 1of 301

KOSTAS DIMITRIOU rns & MARKOS HATZITASKOS wsc

ADVANCED COMPUTER
SCIENCE
For the IB Diploma
Program
(I AETLE]
KOSTAS DIMITRIOU Phd & MARKOS HATZITASKOS wmsc

ADVANCED COMPUTER
SCIENCE
For the IB Diploma
Program
(International
Baccalaureate)

¥ HIGH LEVEL COMPUTER SCIENCE &5


1
KOSTAS DIMITRIOU Pha & MARKOS HATZITASKOS wmsc

For the IB Diploma


Program
(International
Baccalaureate)
Published by Express Publishing

Liberty House, Greenham Business Park, Newbury,


Berkshire RG19 6HW, United Kingdom
Tel.: (0044) 1635 817 363
Fax: (0044) 1635 817 463
email: inquiries@expresspublishing.co.uk
www.expresspublishing.co.uk

© Express Publishing, 2016

Design and lllustration © Express Publishing, 2016

First published 2016

Made inEU
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form, or by any means, electronic, photocopying, or otherwise, without the prior
written permission of the publishers.

This book is not meant to be changed in any way.

ISBN 978-1-4715-5233-5
Copyright page

List of licensed 1B material used:

DP Computer Science Guide (first exams 2014):

Topic 5—Abstract data structures


5.1 Abstract data structures
Thinking recursively
3.1.1 Identify a situation that requires the use of recursive thinking.
3.1.2 Identify recursive thinking in a specified problem solution.
3.1.3 Trace a recursive algorithm to express a solution to a problem.
Abstract data structures
3.1.4 Describe the characteristics of a two-dimensional array.
3.1.5 Construct algorithms using two-dimensional arrays.
5.1.6 Describe the characteristics and applications ofa stack.
3.1.7 Construct algorithms using the access methods of a stack.
5.1.8 Describe the characteristics and applications ofa queue.
5.1.9 Construct algorithms using the access methods of a queue.
5.1.10 Explain the use of arrays as static stacks and queues.
Linked lists
Linked lists will be examined at the level of diagrams and descriptions. Students are not expected to construct
“nked list algorithms using pseudocode.
5.1.11 Describe the features and characteristics ofa dynamic data structure.
5.1.12 Describe how linked lists operate logically.
5.1.13 Sketch linked lists (single, double and circular).
Trees
Sinary trees will be examined at the level of diagrams and descriptions. Students are not expected to construct
=z algorithms using pseudocode. Tracing and constructing algorithms are not expected.
5.7.14 Describe how trees operate logically (both binary and non-binary).
5 Define the terms: parent, left-child, right-child, subtree, root and leaf.
16 State the result of inorder, postorder and preorder tree traversal.
5.7.17 Sketch binary trees.
Applications
5 .7.18 Define the term dynamic data structure.
.18 Compare the use of static and dynamic data structures.
= 7.20 Suggest a suitable structure for a given situation.

Topic 6—Resource management


5.1 Resource management
System resources
=77 Identify the resources that need to be managed within a computer system.
=72 Evaluate the resources available in a variety of computer systems.
=73 Identify the limitations ofa range of resources in a specified computer system.
=7 £ Describe the possible problems resulting from the limitations in the resources in a computer system.
Bole of the operating system |
7 5 Explain the role of the operating system in terms of managing memory, peripherals and hardware
es.
=7 7 Outline OS resource management techniques: scheduling, policies, multitasking, virtual memory, paging,
me=rrupt, polling.
=7 2 Discuss the advantages of producing a dedicated operating system for a device.
= Outline how an operating system hides the complexity of the hardware from users and applications.

Topic 7—Control
7.1 Control
Centralized control systems
7 7.7 Discuss a range of control systems.
= 7 Z Outline the uses of microprocessors and sensor input in control systems.
Evaluate different input devices for the collection of data in specified situations.
< Explain the relationship between a sensor, the processor and an output transducer.
7.1.5 Describe the role of feedback in a control system.
7.1.6 Discuss the social impacts and ethical considerations associated with the use of embedded systems.
Distributed systems
7.1.7 Compare a centrally controlled system with a distributed system.
7.1.8 Outline the role of autonomous agents acting within a larger system.

D—Object-oriented programming
D.4 Advanced program development
D.4.1 Define the term recursion.
D.4.2 Describe the application of recursive algorithms.
D.4.3 Construct algorithms that use recursion.
D.4.4 Trace recursive algorithms.
D.4.5 Define the term object reference.
D.4.6 Construct algorithms that use reference mechanisms.
D.4.7 Identify the features of the abstract data type (ADT) list.
D.4.8 Describe applications of lists.
D.4.9 Construct algorithms using a static implementation of a list.
D.4.10 Construct list algorithms using object references.
D.4.11 Construct algorithms using the standard library collections included in JETS.
D.4.12 Trace algorithms using the implementations described in assessment statements D.4.9-D.4.11.
D.4.13 Explain the advantages of using library collections.
D.4.14 Outline the features of ADT’s stack, queue and binary tree.
D.4.15 Explain the importance of style and naming conventions in code.
KOSTAS DIMITRIOU Phd & MARKOS HATZITASKOS wmsc

For the IB Diploma


Program
(International
Baccalaureate)
Kostas Dimitrou Dedication

70 mg/ _som p/m/u?{//; a/n/o/ my a/afuf/b/ié/ 4%&

orer /m/je/ /fll/a/f ./mre &ma

Markos Hatzitaskos Dedication

70 a// mfi f//'e/ma{v //b/n/ /»/e%ao/ Me 7%‘; /m% a /éd/é

%a é/wmf/ W/b/fl&fifu ave.


Preface

fostas Dimitriou holds a PhD in Spatial Decision Support Systems and Environmental
Planning, and has taught computer science courses in various undergraduate and
oostgraduate University courses. He has participated in many scientific conferences and
workshops, twenty research projects, and presented sixty scientific articles. He has been
z=aching the IB computer science in the Hellenic American Educational Foundation since
2002. He is a Microsoft Certified Educator, Microsoft Expert Educator, Microsoft Expert
Education Trainer and Microsoft Innovative Educator Fellow. {kdimitriou@haef.gr}

Markos Hatzitaskos holds an MSc in Advanced


Computing and has taught computer science
courses throughout all school levels (from primary to high school and the I.B.). He has been
==2ching in the Hellenic American Educational Foundation since 2011. In his
free time,
wnenever that might be, he develops mobile applications and attends the Athens School
of
=02 Arts as an undergraduate. {markosh@haef.gr}

7= authors would like to thank the Board of Directors and the Administration of the
—=llenic American Educational Foundation an (HAEF)
ideal working for providing
=nwironment. Thanks are also due to Kostas Ziogas who gave us some valuable advice. Both
=uthors would like to express their gratitude to the employees of Express Publishing and
=soedially to our friend Tzeni Vlachou.

“ne= authors would like to acknowledge the ongoing, valuable support of Sophia Arditzoglou
,
—%ZF IB coordinator, over the years. A lot of Computer Science students contributed with
+= uzble ideas, comments and suggestions on early drafts. The computer science class of
Z21< encouraged us to start this book.

o= purpose of this document is to facilitate learning and help our colleagues and CS
stucents around the world. This book is based on the IB computer science syllabus and
"= ows the IB computer science syllabus. The authors did their very best to cite all resources
—==c_Ifyou find a source that is not properly cited please report it to the authors. This book
w=s inspired by the book™
Jones, R & A. Meyenn. (2004). Computer science Java Enabled.
‘~==rnational Baccalaureate. Series, IBID press, Victoria.

F -2m=s, R & Meyenn, A. (2004). Computer science Java enabled. International Baccalaureat
e. Series,
=2 press, Victoria.
The following IBO documents were used during the development of this book:

1. International Baccalaureate Organization. (2004). IBDP Computer Science Guide.


International Baccalaureate Organization. (2012). IBDP Computer Science Guide.
International Baccalaureate Organization. (2012). IBDP Approved notations for
developing pseudocode.
International Baccalaureate Organization. (2012). IBDP Java Examination Tool
Subset.
International Baccalaureate Organization. (2012). IBDP Pseudocode in examinations.
of Contents

5 — Abstract data structures..


1 &oswract data structures ..........
SReking recursively................
=11-5.1.3Recursive thinking
===tract data structures
Z<-5.1.5Two dimensional arrays..
i

P I /A LaCKS i eveeeresoroeomnareeens
S1E2-5.19Queues
= 110 Arrays as static stacks and queues
Dl lists....
5 I 11 Features and characteristics of a dynamic data structur
e ..
= 112 Operation of linked lists
= 113 Sketch linked lists

S 114 Logical operation of trees


= 115 Binary-tree related terminology...
S 115 Tree traversal

5 118 Definition of the term dynamic data structure ...


=1 13 Comparison of static and dynamic data structures
=120 Suitable structures .

= 21 Identification of critical resources


= 2.2 Availability of resources
= 13 Limitation of resources

o= of the operating system...


=15 Role of the Operating System (0S)
S15-6.1.7 OS resource management techniques ....
= 1.8 Dedicated OS for a device ...
£21.20S and complexity hiding....
=2 of chapter example questions with answers
. E=pter References ................. Searats et Ceeesesitesy

BRRREORE
- iolILEE Seseseeas s eenenee 95
#.1 Control. e Seb e taas o eeeeeeseeattessene e seatteea
e satennnnaee
aeea esnseeaannr
ssta essnnsessen
as sensns 95
C=ntrzlized control systems
7.2.1 A range of control systems
7.1.2 The uses of microprocessors and sensor input
in control systems
7.1.3 Different input devices for the collection of data in
specified situations
7.1.4 The relationship between a sensor, the processor and an
output transducer o
7.1.5 The role of feedback in a control system
..106

7.1.7 Comparison of centrally controlled systems with distributed systems


.
7.1.8 The role of autonomous agents acting within a larger
system
End of chapter example questions with answers..
Chapter References

Topic D — Object-oriented PrOSramMMing Fotie s oo


e ol -
Toollused. ey s e e |

D.4.2 Application of recursive algorithms.


D.4.3 Construction of algorithms that use recursion .
D.4.4 Trace of recursive algorithms

D.4.6 Construct algorithms that use reference mechanisms..


D.4.7 Identify the features of the Abstract Data Type (ADT)
list
D.4.8 Describeithelapplicationsiof Iists ... 000+
[0 el gl 1 ot 10
D.4.9 Construct algorithms using a static implementati
on of a list ..
D.4.10 Construct list algorithms using object referen
ces ............
D.4.11 Construct algorithms using the standard library collect
ions included in JETS.
D.4.12 Trace algorithms using the implementations describ
ed in assessment statements
D.4.9-D.4.11
D.4.13 Explain the advantages of using library collections ..

Appendix A — Stacks & Queues .............. TSR M e s e 285


A.1 Stack implementation using the Arraylisteclass
HSRYE Binmouailifo 08 285
A.2 Queue implementation using the ArrayList class
RIS AN o el a il 287
Chapter 1
TOPIC 5 — ABSTRACT DATA STRUCTURES

1 Most IB compatible pseudocode examples of this book have been tested using the EZ

=
1
i
i
Pcode practice tool found at:
1
1 https://dl.dropboxusercontent.com/u/275979/ibcomp/pseduocode/pcode.html
1
i This excellent tool was developed by Mr. Dave Mulkey. The authors wish to express
i
i their gratitud&to the developer of this valuable educational resource.
.

=
> Topic 5 — Abstract data structures?

5.1 Abstract data structures

Thinking recursively

5.1.1 - 5.1.3 Recursive thinking


Exit skills. Students should be able to

| Identify a situation that requires the use of recursive thinking. Identify recursive
nking in a specified problem solution. Trace a recursive algorithm to express a
olution to a problem.

Recursion is when a method calls itself until some


terminating condition is met. This is accomplished without
any specific repetition construct, such as a while or a for
loop. Recursion follows one of the basic problem solving
techniques, which is to break down the problem at hand into
smaller subtasks. Any algorithm that may be presented in a
recursive manner can also be presented in an iterative
manner and vice versa. In most cases, recursive algorithms
are considered as harder to code.

Towers of Hanoi?

In order to gain a firm understanding of the basic idea, as well


as the application of recursion, the following example
Image 5.1: The Towers of Hanoi game

! International Baccalaureate Organization. (2012). IBDP Computer Science Guide.


2 Towers of Hanoi. (2015, November 17). In Wikipedia, The Free Encyclopedia. Retrieved 14:03,
November 17, 2014, from https://en.wikipedia.org/wiki/Tower_of Hanoi
presents what is known as the Towers of Hanoi. The Towers of Hanoi is a puzzle that
consists of three rods and a number of discs of different sizes, which can slide onto any rod.
The puzzle starts with the discs in a neat stack in ascending order of size on the first rod, the
smallest at the top, as shown in Image 5.1. The goal of the puzzle is to move the stack of
discs from the first rod to the third rod, obeying the following rules:

A disc may not be placed on top of a smaller one.


Only one disc may move on every move.
A disc may not be moved if it is not the top disc on a stack.
e For temporary storage, the third rod may be used.

There are various approaches that can solve the Towers of Hanoi problem, including both
iterative and recursive solutions. We will be concentrating on a recursive solution, by
recognizing that this puzzle may be solved by breaking it into smaller and smaller similar
puzzles, until a solution is reached.

Assume that the rods are named A, B and C and that n represents the number of discs (with
1 being the smallest, at the top, and n being the largest, at the bottom). A recursive solution
to the Tower of Hanoi problem, in order to move n discs from rod A to rod C could be the
following:

e Move n-1 discs from rod A to rod B, leaving disc n


in rod A.
e Move disc n from rod A to rod C.
e Move n-1 discs from rod B to rod C.

The algorithm above is recursive as it is applied again and


again in both the first and the third steps for n-1 discs. At
some point n will be equal to 1 and a single disc will be
moved from rod A to rod C, resulting in an algorithm with
finite number of steps.

A working example of this algorithm is examined. Figure 5.1


represents the three rods (named A, B and C) as well as
three discs, stacked on top of each other in rod A. The
algorithm goes as follows:

Move green disc from A to C.


Move orange disk from A to B.
SEOED
B SRl

Move green disk from C to B


Move grey disk from A to C
Move green disk from B to A
Move orange disk from B to C
Move green disc from A to C

Fi 5.1: St f th 5 ; :
e i i The recursive algorithm for the solution of the Towers of
Hanoi problem is also presented in Figure 5.2. Pay
attention to the fact that a sub-procedure called moveDiscs is used. moveDiscs takes four
arguments. The number of the discs (n), the rod the discs are to be moved from (from), the
rod to which the discs are to be moved to (dest), as well as the rod that will not be used i
(aux). The arguments of the moveDiscs sub-procedure (that is, n, from, aux, dest) should not i
be confused with the name of the rods used previously (A, B and C).

moveDiscs(n, from, dest, aux)

moveDiscs(n-1, from, dest, aux)

moveDiscs

Move disk n from from to dest

moveDiscs(n-1, aux, from, to)

Move disk 1
Return
from from to
dest

Figure 5.2: The Towers of Hanoi flowchart

Snowflakes

The Koch snowflake is a mathematical curve which is based on the Koch curve, developed by
the Swedish mathematician Helge von Koch.

This mathematical curve can be constructed by starting with an equilateral triangle. Using
recursion each line segment changes using the following steps:

1. divide the initial line segment into three sub-segments of the same length.
draw an outward pointing equilateral triangle that has the middle segment from
step (1) as its base.
delete the line segment that is the base of the triangle from previous step.
The following algorithm expressed in IB pseudocode creates a 400 by 461 window and draws
a Koch fractal:

//Three curves that shape an equilateral triangle


//pen originally is heading at 90 degrees (x axis)
//the method pen.goForward is supposed to control
//a pen that plots line segments on the screen
//the method pen.turnLeft is supposed to change the original
//heading of the pen counter clockwise by the degrees given as a parameter.
//the method pen.turnRight is supposed to change. the original
//heading of the pen clockwise by the degrees given as a parameter.
method Draw_Koch_fractal(N)
width = 400//width of the window
height = 2*width/Math.sqrt(3)//calculation of the height of the window
size = width/Math.pow(3.0, N)//size of each drawing step
al
pen position
initi = pen.setposition(0, width*Math.sqrt(3)/2, 0)
//calculation of the initial pen position (0,114)
pen.setWindowSize (width, height) //initialization of the window
koch fractal (N)//call of the Koch_fractal method
pen.turnrRight (120) //turn right by 120 degrees
koch_fractal (N)//call of the Koch fractal method
pen.turnRight (120) =
koch fractal (N)
end method

method koch_ fractal (n)


if (n == 0) then
pen.goForward (size)
else
koch fractal (n-1)
pen. turnLeft
(60)
koch fractal (n-1)
pen.turnRight (120)
koch_fractal (n-1)
pen. turnLeft(60)
koch~fractal(n—1)
end if
end method
output Draw_Koch_fractal(N)

/’ .

The following table depicts the snowflakes produced by the above algorithm for N=0 to 5:
The following program uses recursion to create the method addIntUpTo (n) for n>0 that
will add all numbers from and including n down to 1. For example, if addIntUpT(4)
o is
called, the result would be:4 + 3 + 2 + 1 = 10

method addIntUpTo
(n)
if (n == 1) then
return 1
else
return n + addIntUpTo (n-1)
end if
end method

This method is a recursive function since it calls itself. On each call, the argument is reduced
by one (every time addIntUpTo is called, its argument is n-1). n-1 calls are made until the
terminating conditionn = 1 is met.

Programming Example 2: Example o{f:fire‘ctfisiqn.

Wheat is going to be the output of the following algorithm?

method foo (n)


if (n <= 1) then
return 1
else
return foo(n-1) + foo(n-2)
end if
end method

output foo (5)

Answer: 8

Programming Example 3: Exal "blé*dfféc;fifiqn. i

What is going to be the output of the following algorithm?

method foo(n, m)
if (n <= 1) OR (m <= 1) then
return 2
else
return foo(n-1, m) + foo(n, m-2)
end if
end method

output foo (5,4)

Answer: 30

What is going to be the output of the following algorithm?

method foo(n, m)
output "value of n=", n, "value of m =", m
if (n <= 1) OR (m<=1l) then
return 2
else
return foo(n-1, m-n)+foo(n, m-2) =
end if
end method

output "Output is", foo(3,2)

Answer:

value of n= 3 value of m = 2
value of n= 2 value of m = -1
value of n= 3 value of m = 0
Output is 4

Programming Example
5: E» cample of recursion.

What is going to be the output of the following algorithm?

method Foo (X,Y)


= if X < Y then
return Foo (X+1,Y-2)
else if X = Y then
return 2*Foo (X+2,Y-3)-3
else
return 2*X+3*Y
end if
end method
output "Output is", Foo(3,12)

Answer:

Output is 47
Abstract data structures

5.1.4 - 5.1.5 Two dimensional arrays

Exit skills. Students should be able to"

Describe the characteristics of two-dimensional arrays.


) Construct algorithms using two-dimensional arrays.

A one-dimensional array should be considered as a single line of elements. However, in


many cases, data comes in the form of a data table. Each element in a 2D array must be of
the same type, either a primitive or object type. Take, for example, five exam scores of a
student, as a data record, and represent it as a row of information. The data records for ten
students, would then be a table of 10 rows. Below is the visualization of this collection of

- Alot of information and examples of two-dimensional arrays can be found in the book
~ Core Computer Science for the IB Diploma Program’.

Index 0 Index 1 Index 2


Index 0 98 68 65
Student 2 Index 1 7 7 88

- Student 10 Index 9 88 86 90

Table 5.2: Two dimensional array Scores

2D arrays are indexed by two subscripts. The indices must be integers. The first one refers to
<he row, while the second to the column. Scores[1][1] refers to Exam 2 of the second
student. Its value is 77.

. /This program will use the array Scores which is a 2D ARRAY.


//It will print the contents of the array.
/5 students with 5 exams each
Scores =
[[S88,68,65,73,67],
177,77,88,78,901,
153,63,74,85,72],
177,717,68,78,91],
128,86,90,56,81]1
i STUDENT = 0
=EE2M = 0
Zoop STUDENT from O to 4
output STUDENT +1, "Student”
loop EXAM from 0 to 4
output "----", "Exam ", EXAM+l, Scores[STUDENT] [EXAM]
end loop
==d loop
OUTPUT

1 Student
---- Exam 1 98
—--—- Exam 2 68
—--—- Exam 3 65
—--—- Exam 4 73
---- Exam 5 67
2 Student
---- Exam 1 77
---- Exam 2 77
---- Exam 3 88
---- Exam 4 78
---- Exam 5 90
3 Student
—--—- Exam 1 53
---- Exam 2 63
---- Exam 3 74
---- Exam 4 85
---- Exam 5 72
4 Student
--—- Exam 1 77
---- Exam 2 77
---- Exam 3 68
---- Exam 4 78
---- Exam 5 91
5 Student
--—- Exam 1 88
-—-- Exam 2 86
---- Exam 3 90
---- Exam 4 56 g
---- Exam 5 81

Scores =
[[98,68,65,73,67],
[77,77,88,78,90],
[53,65,74,85,72],
[77,77,68,78,91],
[88,86,90,56,81]]
STUDENT = 0
EXAM = 0
loop STUDENT from 0 to 4
output STUDENT +1, "Student”
loop EXAM from 0 to 4
if (Scores[STUDENT] [EXAM] mod 10 = 5) then
output "----", "Exam ", EXAM+l, Scores[STUDENT] [EXAM]
end if
end loop
end loop

OUTPUT
1 Student
---- Exam 3 65
2 Student
3 Student
---- Exam 2 65
---- Exam 4 85
4 Student
5 Student

3 Programming Example 8: Finds and outputs the number of “8”s each score contains. It also
outputs the total number of appearance of digit “8”.

Scores =
[[98,68,65,73,67],
[77,77,88,78,90],
[77,77,88,78,91],
[88,86,90,56,81]]
STUDENT = 0
EXAM = 0
TCOUNTER = 0
loop STUDENT from 0 to 3
output STUDENT +1, "Student"
loop EXAM from 0 to 4
X=1
COUNTER = 0
X = Scores [STUDENT] [EXAM]
loop while X>0
if X mod 10 = 8 then
COUNTER = COUNTER + 1
TCOUNTER = TCOUNTER +1
end if
X = div (X, 10)
end while 2
output "----", "The grade of exam ", EXAM+1, "has",
COUNTER, "eight(s)"
end loop
end loop
output " A total of ", TCOUNTER, "eights appear in all grades"

OUTPUT

1 Student
—--- The grade of exam 1 has 1 eight(s)
---- The grade of exam 2 has 1 eight(s)
---- The grade of exam 3 has 0 eight (s)
---- The grade of exam 4 has 0 eight(s)
—--- The grade of exam 5 has 0 eight(s)
2 Student
---- The grade of exam 1 has 0 eight(s)
—---- The grade of exam 2 has 0 eight (s)
---- The grade of exam 3 has 2 eight (s)
—---- The grade of exam 4 has 1 eight(s)
—---- The grade of exam 5 has 0 eight (s)
3 Student
—--- The grade of exam 1 has 0 eight(s)
---- The grade of exam 2 has 0 eight(s)
---- The grade of exam 3 has 2 eight(s)
---- The grade of exam 4 has 1 eight(s)
---- The grade of exam 5 has 0 eight(s)
4 Student
---- The grade of exam 1 has 2 eight(s)
---- The grade of exam 2 has 1 eight(s)
---- The grade of exam 3 has 0 eight(s)
——--- The grade of exam 4 has 0 eight(s)
—-—- The grade of exam 5 has 1 eight(s)
A total of 12 eights appear in all grades

5.1.6 - 5.1.7 Stacks


Exit skills. Students should be able to':

Describe the characteristics and applications of a stac


Construct algorithms using the access methods ofa
Trace algorithms that use stacks.

Characteristics

A stack stores a set of elements in a particular order and allows access only to the last item
inserted. Items are retrieved in the reverse order in which they are inserted. The stack is a
Last-In, First-Out data (LIFO) structure. The elements of a stack may be numbers, Boolean
values, characters, objects, arrays, strings, etc.

Stacks utilize three methods:

1. push(). Pushes an item onto a stack.


2. pop().Removes and returns the last item entered in the stack.
3. isEmpty (). Tests if a stack is empty. It will return true if stack contains no
elements.

Suppose we want to add the elements 5, 4, 3 in a stack named Numbers. The following
diagram explains this situation:

|i Stackis initially empty. f


i
{
§
{

b
| Numbers.push (5)
| 5 was added to the stack.

= N S B e}
| Numbers .push(4)
|
| 4 was added to the stack

5
| Numbers .push (3)
3 was added to the stack

I
Suppose we want to remove all the elements from the stack.

The following example presents this situation:

3 | Stack contains 3 numbers.


4
5
e —— y‘

2 Top element was removed from the stack. This element was |
5 the number 3. 3 was assigned to variable X |

X = Numbers.pop ()
~ Top element was removed from the stack. This element was
S - the number 4. 4 was assigned to variable x
T ————— S L |

Top element was removed from the stack. This element was
the number 5. 5 was assigned to variable X. Stack is empty.

Aoplications :

o The back button of a web browser uses a stack to function. Every time a URL is
visited it is stored on a stack. The last address that was visited is on the top of the
stack. The first address that was visited during the current web session is on the
bottom of the stack. If one selects the Back button, he/she begins to visit the
previous pages they have visited in reverse order.
» Microprocessors usually use a stack to handle methods. Suppose a method, A, which
returns an integer, with parameters b and ¢ of type integer, is called. In Java this
would look like this:

int ¢ = A(a, b);


The method header would look like this:

public static int A(int b, int c)


The method body should look like this:

{method body
return r}
When As called, its return address, as well as b and c are pushed onto the microprocessors
sz=c<. When the method returns z, the return address and the parameters (arguments) are
zooped off the stack. The overall process is more complicated, but further explanation is
==yond the scope of this book.
e Recursive methods also utilize the system stack to keep track of each recursive call.
This block of memory is used to store temporary data required for program

execution. The calls are nested inside each other. Initially, all recursive calls are
unfolded and pushed onto the stack, until the base case is reached and then all
recursive calls are popped from the stack, when necessary. In the following example
the left-hand code fragment will return 4. The right-hand code fragment will
generate a run time error because the recursive program will never reach the

terminating condition.

public class Rec_Demo public class Rec_Demo


{ {
public static int question(int n)| public static int question (int n)
{ {
if (n <= 0) if (n <= 0)
return -2; return -2;
else else I
return (question( return (question (n#100)+3);
} 1

public static void main(String[] public static void main(String[]


a) a) |
{ {
int 1 = question(111); int 1 = question(111);
("1=
System.out.println "+1); System.out.println("1l= " + A
} }
} }
OUTPUT OUTPUT
1=4 java.lang.StackOverflowError:null

Algorithms

Programming Example 9: Use of a staék, an arrdy and a collection.

//==== Reverse and store ===


// This algorithm uses an array, a stack and a collection.
// It reads names from the array, reverses them,
// using the stack, and stores the contents of the stack
// inside the collection.
/!
NAMES = ["Kostas", "Markos", "Anna", "Mary", "Takis"]
NAMES_C = new Collection()
STACK_NAMES = new Stack ()
I=0

loop I from 0 to 4
STACK_NAMES .push (NAMES [I])
end loop

output "Add names in the collection:"


output "=====
loop while NOT(STACK_NAMES.isEmpty())
NAME = STACK_NAMES.pop()
NAMES_C.addItem (NAME)
output NAME, "was entered in the collection"
end loop
output ""
output "Names stored in the collection:"

loop while NAMES C.hasNext ()


output NAMES_ C.getNext ()
end loop

OUTPUT

24d names in the collection:

Tzkis was entered in the collection


¥=ry was entered in the collection
2Znna was entered in the collection
M=rkos was entered in the collection
Eostas was entered in the collection

“he following program uses 4 stacks to solve the Towers of Hanoi problem:

//Declaration and initialization of variables


= new Stack() //a new stack
new Stack() //a new stack
new Stack() //a new stack
new Stack() //a new stack
new Array() //auxiliary array
T

to use in display method


new Array() //auxiliary array to use in display method
new Array() //auxiliary array to use in display method
= [SPa, SPb, SPc, SPd] //an array of four stacks
e

KO
nn
b m
Hopooo

OO0OO0OWN
Il
ib i
nn

5 //the number of disks


s

!%‘
S
']

I3
i

a=
H
o

o
B

(]
0
b

3
®

H
o

=
©
o
//The following method is the starting point
//of the program
method TowersofHanoi
(n)
loop I from 0 to n-1
m = n-I
PEGS[1] .push (m)
end loop
display()
move(n,1,2,3)
end method

//This is a recursive method used to solve the problem


method move(n, a, b, c)
if n>0 then
move(n-1, a, c, b)
t = PEGS[a] .pop()
PEGS[c] .push (t)
display()
move (n-1, b, a, c)
end if
end method

//The following method is used to visualize the


//pegs and the disks. Three auxiliary arrays are
//used so as to display the contents of each stack.
method display()
output ""
output " | A | B | C |"
loop I from 0 to NUM-1
daa[I] = PEGS[1].pop()//put the elements of the stack to an array
dbb[I] = PEGS[2].pop()//put the elements of the stack to an array
dce[I] = PEGS[3].pop()//put the elements of the stack to an array
end loop

loop I from 0 to NUM-1


da = daa[I]
db = dbb[I]
dc = dcc[I]
fl = String(da)//covert to string
if £f1 == "null" then
fl="-"
end if
£2 = String(db) //covert to string
if £2 == "null" then
fF2="—n
end if
£3 = String(dec) //covert to string
if £3 == "null" then
£3=1om
end if
output=UEIWETE SIS W ED - ) . f3, TN
end loop

loop I from 0 to NUM-1


m = NUM-1-I
PEGS[1] .push(daa[m]) //put the elements of the array daa back to the stac
PEGS[2] .push(dbb[m]) //put the elements of the array dbb back to the stack
PEGS[3] .push(dcc[m]) //put the elements of the array decc back to the stac
end loop
end method
vw L v 1| UH M
UH N Ve v AN
R Ly
me 1l a1 MmN a1
MmN monl o MeEHNmS
a1 dHNm Qe o1l 11
|| dsn 1 aAHNwn g 1ol
g
w S 2 8 % 2 8
-
vl Vel VvNmSn |l
I veem ol U 1l vNn I
oL vam
me <t 1 Mmoo ma Mo
N 1 @ me Mmoo
dam il o1l L T N |
-l g 1 g1l g1l
dowin 11l
4 2 q S =
@ & =
vawm i1 U Ve |
UM vNMm L UMl v
AL
mea e me morn Mo
me M me s 1
morornt
gl gaNm 1 Ao
gl Aoan il a0
doamn | A=l
~ © S S = S % 8
UHNI I Vs I VMmN 1
VUHNM v v 1ol
Ot ve
FORMATED OUTPUT

meNmS ol mo Mmoo
MmN @ Moy 1
morr
@ 1 o1 CHNm g1
A HNMmIIn aun ol @i 1l ol
2 S s & Q
5 0 o
5.1.8-5.1.9 Queues
‘ Exit skills. Students should be able to'"
| Describe the characteristics and applications of queues.
| Construct algorithms using the access methods of queues.

Characteristics of queues

A queue stores a set of elements in a particular order and allows access only to the first item
inserted. Items are retrieved in the order in which they are inserted. The queue is a First-In,
First-Out (FIFO) data structure. The elements of a queue may be numbers, Boolean values,
characters, objects, arrays, etc.

Queues utilize three methods:

1. engqueue (). Puts anitem into the end of the queue.


dequeue (). Removes and returns the first item entered in the queue.
3. isEmpty (). Tests if a queue is empty. It will return true if queue contains no
elements.

Suppose we want to add the elements 5, 4 and 3 in a queue named Numbers.

The following example presents this situation:

\:Dj Queue initially empty

. Numbers . enqueue (5)


| ~ 5 was added to the queue
7 Numbers.enqueue (4)
4 was added to the queue
Numbers .enqueue (3)
3 was added to the queue

Suppose we want to remove all the elements from the queue.

The following example presents this situation:

Queue contains 3 numbers

X = Numbers.dequeue ()
. First element was removed from the queue. This element
was the number 5. 5 was assigned to variable X.
X = Numbers.dequeue
()
First element was removed from the queue. This element
was the number 4. 4 was assigned to variable X.
X = Numbers .dequeue () {
First element was removed from the queue. This element
was the number 3. 3 was assigned to variable X. Queue is
_empty.
Applications of queues

e Queues are used to model physical queues, such as people waiting in line at a

supermarket checkout.
e The print queue displays the documents that are waiting to be printed. These

documents will follow the first-send first-print policy.


e When sending data over the internet, various data packets wait in a queue to be
sent.
o A server usually serves various requests. In most cases these requests are stored in a
queue. The first-come first-served request procedure is followed.

Algorithms that use queues

Programming Example 11: Use of a queue and arrays.

all students
A small school uses two buses to transport students. As soon as the buses arrive,
The
enter a queue and a teacher uses a registry to check which students are present.
the
following algorithm uses two arrays to represent the school buses, a queue to represent
queue, and an array to represent the registry:

BUS1 = ["Roger", "John", "Nikos", "Marion", "Hellen"]


BUS2 = ["Nora", "Bill", "Eliza", "Takis", "Alex"]
REGISTRY = ["Alex", "John", "Elina", "Nikos", "Leo", "Marion",
"Hellen", "Nora", "Bill", "Eliza", "Takis", "Roger"]
STUDENTS = new Queue () //Queue for Students
A= nn
I=0
= 1
FOUND

//copy students from BUS1l


loop I from 0 to 4
STUDENTS
. enqueue (BUS1[I])
end loop

//copy students from BUS2


loop I from 0 to 4
STUDENTS
. enqueue (BUS2[I])
end loop

loop while NOT (STUDENTS.isEmpty())


A = STUDENTS.dequeue ()
loop I from 0 to 12
if REGISTRY[I] = A then
FOUND = 1
end if
end loop
if FOUND = 1 then
output A, "is not absent"
end if
end loop

OUTPUT

4
Roger is not absent
John is not absent
Nikos is not absent
Marion is not absent
Hellen is not absent
Nora is not absent
Bill is not absent
Eliza is not absent
Takis is not absent
Alex is not absent

Programming Ekarhhle 12: Use of queues, arrays and a collection.

A supermarket has two express cashiers. The array CASHIER1 contains the customers that
enter the queue CUSTOMER1, while the array CASHIER2 contains the customers that enter
the queue CUSTOMER2. The TIME collection stores the names of the customers that
waited
more than 60 secs, counting from the moment that their turn to be served had come.
The
supermarket administration wishes to minimize the waiting for these two
express cashiers. A
questionnaire is sent by email, from the administration of the supermarket, to the
customers stored in the collection TIME to understand why this situation took place. A
message that outputs the overall slower express cashier is output at the end
of the day.

CASHIER]1 = ["Roger", "John", "Nikos", "Marion"]


CASHIER2 = ["Nora", "Bill", "Eliza", "Takis"]
CUSTOMERL = new Queue () //Queue for CUSTOMER1
CUSTOMER2 = new Queue () //Queue for CUSTOMER2
TIME = new Collection()
A=
B=0
c1 =0
c2=0
I=0
Dl =0
D2 =0
TOT B = 0
TOTC = 0
FOUND = 1

//copy CUSTOMER1 from CASHIERL


loop I from 0 to 3
CUSTOMERI.enqueue(CASHIERl[I])
end loop

//copy CUSTOMER2 from CASHIER2


loop I from 0 to 3
CUST . enqueu
OM e (CASHI
ER ER2[I]
2 )
end loop

loop while NOT(CUSTOMERl.isEmpty())


D1 = (CUSTOMERLI . dequeue () )
Cl = Math.floor ((Math.random() * 100) + 1)// use of random function
to generate random times between 1 sec to 100 sec
if C1>60 then //only customers waiting more than 60 secs enter the
collection
TIME.addItem(D1)
"end if
TOTB = TOT_B + C1
end loop

loop while NOT (CUSTOMER2.isEmpty ())


D2 = (CUSTOMER2.dequeue
())
C2 = Math.floor((Math.random() * 100) + 1)
if C2>60 then
TIME.addItem(D2)
end if
TOT_C = TOT_C + C2
end loop

TIME.resetNext
()
loop while TIME.hasNext()
output TIME.getNext
()
end loop

if TOT_B > TOT _C then//outputs the slower cashiexr


output "CASHIER] is slower"
else
output "CASHIER2 is slower"
end if

A POSSIBLE OUTPUT

Roger
John
Bill
Eliza
CASHIER2 is slower

5.1.10 Arrays as static stacks and queues


Exit skills. Students should be able to':

i
| Explain push and pop operations, and test on empty/full stack.
| Explain enqueue and dequeue operations, and test on empty/full queue.
{

Algorithms to implement stacks using an array

The program starts with an array of 10 elements. The methods used are the following:
push ()

this method is used to add elements in the stack. Inserting an element increments high by 1
and adds the element in this array position. The high is incremented before the insertion of
the new item takes place.

pop ()
this method returns the value of the top element and then decrements high. It serves to
remove the top element from the stack. The item removed actually remains in the array but
is inaccessible.

isempty ()
it is based on the high variable. It returns true (1) if the stack is empty.

isfull()
itis based on the high variable. It returns true (1) if the stack is full.

size ()
it is based on the high variable. It returns the number of elements stored in the stack.

s _array = new Array () OUTPUT:


s_array = [0,0,0,0,0,0,0,0,0,0] Message: stack is empty
maxgizess 10 Message: stack is full
high = -1 :
n=0
high =9
POP(EE e e e e L e
push (1) s_array contains :
push(2)
push (7)
1,2,7,9,10,9,33,29,11,49
push (8) T
pop () size of stack = 10
push (9) Vs
push (10) stack contents display and removal
Eusn)
push (33)
T 1]
push (29) 49
push (11) 11
push (49) 29
push (10) 33
9
outputiECestss s ¥ 10
output "high = ", high
output "-----—--—-—— 4 9
output "s_array contains :", s array 7
outputEEEE e EE T i 2
output "size of stack = ", size() 1

S I
LI i
output "stack contents display and Explanation:
removal" This algorithm uses the s_array to
output implement a stack The methods used
LI are push (), pop (), isempty()
loop while isempty() = 0O : < e g
e isfull () and size () .
output n
end loop When this algorithm starts an array of
output ten elements is created.
LI maxsize variable is used to hold the
maximum stack size, high variable is
method push (n) used to point the array position that is
if (isfull() == 1) then the top of the stack.
output "Message: stack is full"
else The first pop () instruction generates a
high = high + 1
“Message: stack is empty” output.
s_array[high] = n
end if
end method push (1), push(2), push(7),
push (8) instructions add four
method pop () elements in the stack.
if (isempty() == 1) then
output "Message: stack is empty"
pop () instruction removes 1 from the
else
high = high - 1 stack.
return s array[high+1]
end if push (9), push (10), push (9),
end method push (33), push (29), push (11),
push (49) instructions add 7 elements
method isempty()
if (high == -1) then in the stack. The stack is now full.
return 1
else push (10) instruction causes
return 0 “Message: stack is full “ message to be
end if
displayed.
end method

method isfull
() Instruction “output "high =
if (high == maxsize-1) then " high”
return 1 prints the number 9 which is the array
else position used to point the end of the
return 0 queue.
end if
end method
Instruction “output s_array
method size () contains :", s_array” outputs
return high+l the contents of the actual array used.
end method The numbers 1,2,7,9,10,9,33,29,11,49
are printed.

The size of stack is 10

After a “stack contents display and


removal” message a loop that removes
and outputs all elements of stack is
used. 49,11,29,33,9,10,9,7,2,1 are
printed.
Progi-amming Exampl'e 14: Convert integer to binary using a stack.

//This algorithm uses a stack to convert an integer to its binary


equivalent

//Declaration of variables
s_array = new Array()
s2_array = new Array()
s_array = [0, O, O, O, O, O, O, O, O, O]
maxsize = 10
high = -1
x=0
y=20
n=20
t =0
2 dig value = 0
number = 123

output "Convert number ", number

//Call method convert in binary


convert to_binary(number) //max number is 1023

//Use of an auxiliary array to properly output the result


output " "
output "Final result"
loop a from 0 to 9
s2_array[a] = s_array[9-a]
end loop
output s2_array

method convert to_binary (x)


output "Calculations"
loop while x > 0
Yy = x mod 2
push(y) //use of push method
x = div(x,2) //division of x over 2
end loop
//the next loop will use the isempty method
loop while isempty() = 0
t = pop() //use of pop method
dig value = Math.pow(2, (high+l)) //2*(high+1)
output "Binary digit number", high+l," (" ,dig_value,")", "is", t
end loop
end method

method push (n)


if (isfull() == 1) then
output "Message: stack is full"
else
high = high + 1
s_arrayl[high] = n
end if
end method
method pop ()
if (isempty() == 1) then
output "Message: stack is empty"
else
high = high - 1
return s_array[high+1]
end if
end method

method isempty()
if (high == -1) then
return 1
else ;
return 0
end if
end method

method isfull
()
if (high == maxsize-1) then
return 1
else
return
end if
end method

OUTPUT

Calculations
Binary digit
Binary digit
Binary digit
Binary digit
Binary digit
Binary digit
Binary digit

Final result
0,0,0,1,1,1,1,0,1,1

Algorithms to implement queues using an array

Prdgfian‘iming Example 15: Irfi:ilementafion of .quéue*usingf,an array.


When using an array to implement a queue, insertion takes place at the REAR index, while
deletion takes place at the FRONT index only. At the beginning both FRONT and REAR are
0.
When entering the first element, FRONT remains 0, while REAR become
s 1. When entering
another element, FRONT again remains 0, while REAR become
s 2. When entering yet
another element, FRONT remains 0 and REAR becomes 3. If we remove an element
, FRONT
becomes 1 and REAR remains 3. If we remove another
element, FRONT becomes 2 and REAR
remains 3. If we remove yet another element, both
FRONT and REAR become 0, since the
queue is empty.

The following algorithm implements this


approach. Unfortunately, this array-based
implementation is tricky. It works well when entering elemen
ts and then removing them all
before entering new elements again. This is not the case when
adding and deleting data in a
random order since the end of the array will eventually be
reached and an out-of-bounds
exception will be raised.

g_array = new Array ()


gq_array [0F05 0, 80FN.0 S0 0] 0, 0, 0]
FRONT = 0
REAR = 0
SIZE = 10
n=20
dequeue
()
enqueue (71)
enqueue (1)
enqueue (2)
enqueue (112)
enqueue (14)
enqueue (52)
enqueue (67)
enqueue (14)
enqueue (52)
enqueue (62)
dequeue
()
dequeue
()
dequeue
()
dequeue
()
dequeue
()
dequeue
()
enqueue (61)

output "Queue contents display"


output "---—--——-—— 2
if (FRONT == REAR) then
output "Message: queue is empty"
else
loop I from FRONT to REAR-1
n = q_array[I]
output n
end loop
end if
output "---—-—-—— i
method enqueue (N)
if REAR == SIZE then
output "Message: queue is full"
else
g_array[REAR] = N
REAR = REAR + 1
end if
end method

method dequeue
()
if FRONT == REAR then
output "Message: queue is empty"
else
N = g_array[FRONT]
if (FRONT+l == REAR) then
REAR = 0
FRONT = 0
else
FRONT = FRONT + 1
end if
end if
end method

OUTPUT

Message: queue is empty


Message: queue is full
Queue contents display

As we can see the queue contains only 4 elements. Although the array can hold 10 elements
the FRONT is now 7 and the REAR is 10 so enqueue (61) will generate the queue is
full message. This situation can be solved by using a circular implementation of a queue.

Algorithms to implement a circular queue using an array

The problem with the previous implementation is that the new elements are added to
successively higher-numbered positions in the array. When elements of the queue are
deleted, the FRONT index increases and this process continues until the queue runs out of
space. The array might have free positions at the indices that are smaller than the FRONT
index, but these positions are unusable. The following circular implementation of a queue
solves this problem:
[11] [0] [11] [0]
[10] [10] 20 1]

[9] [2] [9] [2]

[8] [31 (8] [3]

[7] [4]
[6] [5] [6] [5]
FRONT= 0 ADD 20
REAR = -1 FRONT= 0
REAR =0

[11] [0]
[10] [1]

[9]

(8]

[7]
[6] [5]
DELETE 20 ADD
ADD 30 30,40,50,60,70,80,90,100,110,120,130
FRONT =1 FRONT =1
REAR=1 REAR =11
[0]
140

REAR =0
This is the benefit of a circular queue.
Item 140 was inserted in the array index 0.

Figure 5.3: Explanation of the operation of a circular queue

The following algorithm starts with an array of 10 elements. The methods used are the

following:

enqueue ()
This method is used to add elements to the queue. Inserting an element increments rear by
1 and inserts the element in the new array position where rear points to. If rear is at the
end (top) of the array, then rear should be set to -1 before the addition of the element
takes place. This means that a wraparound takes place and the next element will be placed
at the start (bottom) of the array. Finally, the variable that holds the number of elements,
nelements, is incremented by 1.

dequeue ()
This method is used to remove elements from the queue. A temporary variable, temp, is

used to hold the value of £ront. £ront is then incremented by 1. If front equals to the
array length, then a wraparound takes place and 0 is assigned to £ront. Finally, the variable
that holds the number of elements, nelements is decremented by 1.

isempty ()
This is based on the nelements variable. It returns true (1) if the queue is empty.

isfull ()
This is based on the nelements variable. It returns true (1) if the queue is full.

size()
This is based on the nelements variable. It returns the number of elements stored in the
queue.
g _array = new Array ()
Output:
q array = [0, O, O, O, O, O, O, O, O, O] Message: queue is empty
//you can replace the previous two front = 1
lines
rear = 5
//with g array = new Array(10) g_array contains
maxsize = 10
1,2,7,8,9,10,0,0,0,0
front = 0
rear = -1
nelements = 0
n =0
dequeue ()
removal
enqueue (1)
enqueue (2)
enqueue (7)
enqueue (8)
dequeue ()
enqueue (9)
enqueue (10)

output "front = ", front


output "rear = ", rear Explanation:
output "q array contains :", q_array This algorithm uses the q_array
output "--------— L to implement a circular queue. The
output "size = ", size() methods used are: enqueue (),
output "---—-—-----— v
dequeue (), isempty (),
output "queue contents display isfull
() and size() .
and
removal"
output "------—-- 0 When this algorithm begins, an
loop while isempty() = 0 array of ten elements is created.
n = dequeue ()
maxsize variable is used to hold
output n
end loop the maximum queue size, the
output "----—---——-— v front variable is used to point to
the start of the queue, the rear
variable is used to point to the end
method enqueue (n)
of the queue and nelements is
if isfull() = 1 then
output "Message:
used to hold the total number of
queue is full"
else elements stored in the queue.
if (rear == maxsize-1) then
rear = -1 The first dequeue () instruction
end if
generates a “Message: queue
rear = rear +1
is empty” output.
q_array[rear] = n
nelements = nelements + 1
end if enqueue
(1), enqueue (2),
end method enqueue (7), enqueue (8)
instructions add four elements in
method dequeue
()
the queue.
if isempty() = 1 then
output "Message: queue is empty"
else dequeue () instruction removes 1
temp = g _array[front] from the queue.
front = front + 1
if (front==maxsize) then
enqueue
(9) and enqueue (10)
front = 0
end if add two elements to the queue.
nelements = nelements - 1
return temp Instruction output "front =
end if ", £ront prints the number 1
end method which is the array position used to
point to the front of the queue.
=ethod isempty()
if (nelements
return 1 Instruction output "rear = ",
else rear prints the number 5 which is
return 0 the array position used to point to
end if o
the end of the queue.
end method

method isfull () Instruction output "size = ",


if (nelements maxsize) then size () outputs size = 5, which
return 1 is the size of the queue.
else
return 0
Instruction output "q_array
end if
=nd method contains:", g_array outputs
the contents of the actual array
=method size () used. The numbers
return nelements 1,2,7,8,9,10,0,0,0,0 are printed.
end method
After a “queue contents
display and removal”
message, a loop that removes and
outputs all elements of queue is
used.2 7 8 9 10 are printed.
Linked lists

5.1.11 Features and characteristics of a dynamic data structure

Exit skills. Students should be able to®

Linked lists will be examined at the level of diagrams and descriptions. Students are not
expected to construct linked list algorithms using pseudocode.

Suppose you want to develop a program to handle a variable number of airplanes that arrive
at an airport every day. The array based implementation has the disadvantage that
its size
must be predetermined. The size of the array must be determined before the actual use of
the array. Declaring a large array means allocating an amount of memory that might
be not

next
I O >

S node

Figure 5.4: A node of a linked list

utilized, while declaring a small array means that the array may run out of
space during the
execution of the program. The solution to this inconvenient situation is to use dynamic
allocation of memory. The resulting data structure will be flexible enough to shrink
or grow,
as the request for data storage decreases or increases respectively. This
provides the
programmer with the ability to control the amount of memory that is utilized.

In programming, a node is a basic unit (object) that contains both data and a pointer. A
pointer is a field of the node whose value points to another object, stored in some other
memory location. Each node in a linked list stores a pointer to the next value of the linked
list. Thus, every node requires memory for both its data and its pointer. THE NULL
pointer is
a special pointer that points to nothing, meaning that it has no pointee. The NULL
pointer is
drawn as a diagonal line between the left lower corner and the right upper corner of
the
pointers variable box.

Figure 5.5: The NULL pointer


5.1.12 Operation of linked lists

Exit skills. Students should be able to*

Describe how linked lists operate logically.

A linked list is constructed from a series of nodes. Every node of the list is a distinct object
that contains both data, as well as a reference (pointer) to the next node. A reference refers
10 an object’s address in the RAM. In C++ we use pointers, while in Java we use references.

A linked list is very different from an array. Although they are both used to create lists, their
operational characteristics are completely different. In an array, each element resides in a
particular position which can be directly accessed using an index. In a linked list, a particular
element can only be accessed by following the references (pointers) of all the previous
element. In a way, linked lists resemble a chain. There is no way to access an element
directly. One can only access every element in turn, starting with the initial one in the list.

It is important to stress the difference between the logical representation, which refers to
how the data and the links are “seen” by the programmer, and the physical representation,
which refers to the underlying mechanisms that store the data in RAM. The physical
representation includes details like memory addresses, type of data, number of bytes used,
the way the pointers are handled etc. This is another example of abstraction where all
unnecessary details are hidden.

Key Characteristics of a linked list:


/

e To traverse a linked list, you start at the first node and then go from node to node,
following each node’s pointer to find the next node.
e A node with a specific key value can be found by traversing the list. Once found, a
node’s data can be accessed.
e Alinked list consists of a sequence of nodes.
e Each node contains data and a pointer.
e Alinked list may be empty.
e The length of a linked list is the number of elements that it contains.
e The last node contains a null pointer.
e Anode’s successor is the next node.
e Anode’s predecessor is the previous node.

ee
Header node
I List:

Figure 5.6: A diagram of linked list with four elements


In the previous Figure the existence of a dummy header node, which is just an initial node
that exists at the front of a linked list even when the list is empty,
is assumed. Its purpose is
to point at the first element and to keep the linked list from
being null. This node doesn’t
contain any data, but only a pointer.

Representing linked lists with pseudocode

Suppose we have an object named student with the following


properties:
Name (of type) string
Surname (of type) string
ID (of type) integer

A node object will have one additional field to store informa


tion about the reference to the
next node of the linked list:

Next (of type) pointer (or reference)

So the node of a single linked list that is used to store studen


t objects should have the
following fields:

Name (of type) string


Surname (of type) string
ID (of type) integer
Next (of type) pointer (or reference) //reference to the next node

Itis clear that the node is not only the data that it stores, but
it also includes a pointer.

Another approach would be to create two classes. A studen


t class and a node class. In this
approach the data are not placed directly in the node. A refere
nce is used in the node object
to represent the student’s data.

node
Student
Student sl //reference to student
Name of type string
object Next of type pointer (or Surname of type string
reference)
ID of type integer

Table 5.3: Pseudocode for the two classes

It is important to mention that the ID will be used as


the key value. So all linked list
operations (finding, inserting, deleting etc.) will be implem
ented according to this key.

5.1.13 Sketch linked lists

Exit skills. Students should be able o

l NG lmked Ilsts (single, double and circular).


Sketch diagrams UGS
| e
e
adding a data item to linked list.
deleting specified data item.
e modifying the data held in the linked list.
® searching for a given item.
Single linked lists

Empty linked list Header


L _List: Hfi o

r
L_List: >

Header

L_List: Hmp NULL

Header

L List: | @

Figure 5.7: Possible representations of an empty linked list (IL_List).

Adding (inserting)

After an element

Rl

L_List:

2 Jotrl - | ale
Figure 5.8: Adding an element involves 4 steps: (a) find the node you want to insert after, (b) create the new
node, (c) copy the pointer from the node that’s already in the list, (d) change the pointer in the node that’s
already in the list to point to the inserted node.

At the beginning

D e
(Wb

- T[T
L_List:

Figure 5.9: Inserting to the head involves the following steps: (a) create the new node, (b) make the new node
point to the old first, (c) make header node point to the inserted node.

33
At the

L _List:

Figure 5.10: Inserting to the tail involves the following steps: (a) create the new node, (b) make the new node
point to ng’!l, (c) make the old last node point to the new inserted node.

Deleting
After an element

L List:

Figure 5.11: To delete a node, just change the link in its previous node to point its next node.

At the beginning

L _List:

Figure 5.12: To delete the first node, change the link in the header to point to the next (second) node.

At the end

[T [T
L_List:

Figure 5.13: To delete the last node, change the pointer of the previous (second to last) node to point to NULL.

Modifying
To modify the data of a node one can follow two different procedures:
1. Delete the node and insert a new node with different data in the same position
of the list
2. Find the node and change its data by replacing it with the new data
Searching
To search for a specific element, in a sorted or unsorted linked list, linear search must be
followed. Starting from the first node, all elements are examined until the desired element is
found. If the element is not in the linked list, an appropriate message is returned.

Sorted linked list


Before discussing the advantage= of sorted linked lists, it is useful to examine a program that
keeps all array elements sorted, in descending order, at all times. Keeping a list sorted makes
it possible to apply binary search, when searching for a data item.

Programmihg Exanip’le/ 16: Keeping an a‘r’réil sorted.

The following program starts with an empty array of 10 elements. When an element is
inserted, the correct location is found in order to keep the array sorted in a descending
order. Deletion works by shifting elements, with higher index numbers, to fill in the gap left
by the deletion process. To find the position of an element to be deleted, binary search is
applied. The advantage of using an ordered array becomes apparent when binary search is
applied, since it performs much faster than a sequential search.

ARRAY = new Array (10) OUTPUT


n_elements = 0
element = 0 A inserting 4
searchKey = 0 A
C_index = 0 inserting 8
found = 0 8,4,/ rrrrrs
inserting 5
insert (4) 85,4
insert (8) inserting 12
insert (5) 28 DA
insert (12) inserting 34
insert (34) 341278175 4TS
insert(18) inserting 18
insert (15) 34,18,12,8,5,4,,,,
insert(23) inserting 15
insert (77) 34,18,15,12,8,5,4,,,
insert (1) inserting 23
del (15) 34,23,18,15,12,8,5,4,,
del (23) inserting 77
insert(99) 77,34,23,18,15,12,8,5,4,
del (11) inserting 1
del (4) 77,34,23,18,15,12,8,5,4,1
deleting 15
method insert (element) 77,34,23,18,12,8,5,4,1,
output "inserting", element deleting 23
j=0 77,34,18,12,8,5,4,1,,
k=0 inserting 99
loop while (j < n_elements 99,77,34,18,12,8,5,4,1,
AND ARRAY[j]>element) deleting 11
g5 = gl 11 not found
end loop deleting 4
k = n _elements 99,77,34,18,12,8,5,1,,
loop while k > j
ARRAY[k] = ARRAY[k-1]
k=%k -1
end loop
ARRAY[j] = element
n_elements = n elements + 1
output ARRAY
end method

method del (searchKey)


output "deleting", searchKey
LOW = 0
HIGH = n _elements % 1
C index = 0
m = 0
found = 0
loop while (LOW <= HIGH)
C_index = div ((LOW + HIGH), 2)
if (ARRAY[C_index] == searchKey)
then
found = 1
loop m from C_index to
n_elements - 2
ARRAY [m] = ARRAY [m+1]
end loop
ARRAY[n elements - 1] = "»
n_elements = n elements - 1
output ARRAY
else if (ARRAY[C_index] >
searchKey) then
LOW = C_index + 1
else
HIGH = C _index - 1
end if
end loop
if (found = 0) then
output searchKey, "not found"
end if
end method

Sometimes, it is very useful to maintain a sorted linked list. In such a linked list, all data are
stored according to a key value. A programmer can use a sorted linked
list in the same way
that a sorted array is used. Although a linked list is more difficult to
implement than a sorted
array, the advantages of a sorted linked list is that the elements do not need to be moved,
but only pointers need to be altered. This results in a high speed element insertion
, which, in
addition to the fact that the linked list can easily expand to any size that
is supported by the
available RAM, makes linked lists ideal in various situations. To insert an element in a sorted
linked list, one must first search through the linked list until he/she finds
the correct place to
insert the new element. After that, the element can be inserted in the usual manner
described above.

Double-linked lists

In a double-linked list each node contains data, a pointer to its successor, and
a pointer to its
predecessor. The header node points to the first node and to the
last node of the list. If the
linked list is empty, the pointers point to NULL. The first node and
the last node of such a list
are directly accessible without traversal, and allow traversal
of the list from the beginning or
the end. The pointers of each node allow traversal of the list in either direction. Another
advantage of a double-linked list is that deletion and insertion before a node, become
easier. A serious disadvantage of the double-linked list is the additional space used. The
double-linked list requires two pointers per node, and so it needs twice as much overhead as
the singly linked list. Applicatichs of double-linked lists include web browsers, where the
back and forward buttons are used for backward and forward navigation, implementation of
undo and redo functions etc.

B IL:

Figure 5.14: A double-linked list

ircular-linked lists

A circular list is a linked list in which the last link points back to the first link. In such a list it is
=asy to loop and access all nodes circularly, and one has the ability to traverse the entire list
starting from any node. The implementation of the circular-linked list is more complex and
=xtra caution is needed so as not to end up in an infinite loop. Applications of Circular-linked
“stsinclude OS time sharing algorithms and multiplayer games.

L_List:

L List:

............................................................................................................ e
Sinary trees will be examined at the level of diagrams and descriptions. Students are not:
=xpected to construct tree algorithms using pseudocode. Tracing and constructing:
a'gorithms are not expected. .
Trees combine the quick insertion and deletion of linked lists, as well as the quick searching
of an ordered array. Tress in general are fascinating dynamic data structures that have been
studied as abstract mathematical entities. They belong to the graph category and consist of
nodes that are connected by edges. In algorithms, nodes (usually circles or rectangles)
represent values or objects and the edges (lines) represent the way the nodes are

related/connected. In Java, edges are represented by references while in C++ by pointers.

Top node

levelioWwsli=r=r s = i i Car Company

Levelffow X ne s raenanl 8odleSillcsar


oo oo win i Manufacturing |

Level/row 3 === Europe |- Other countries F=—=---

\
\
\ Level/row 4

Figure 5.17: A tree used to represent an abstract model of a hierarchical structure.

The top node is connected to two or more nodes on the next row. These nodes are
connected to more nodes on the next row. The resulting shape looks like a “real tree” that
was turned upside-down. Trees, in general, may have more than two children per node.
However, a binary tree may have 0, 1 or 2 children.
5.1.15 Binary-tree related terminolegy

Exit skills. Students should be able tol:

fiLe nght-chrld, subtree, ¢:Tsls and ieaf

children is called a leaf.


[ The level of a particular node refers to how many generatxons the node is|
from the root. If we assume the root is Level 1, then its children will be
Level 2, its grandchildren will be Level 3, etc.
Number of edges from the top node to the deepest leaf (i.e. the one that
|s furthest away).
AII nodes except ‘from the root which has no parent node, have exactly
Parent
. one edge running upward to their parent node.
Suppose one wants to travel from node to node, along the edges that link
Path
them The sequence of nodes that are travelled is called a path.
Root The node at the top of th tree is called the root.
|Any node may be considered to be the root of a subtree. That subtree will
Subtree
. consist of the node’s descendants. Sy
' To traverse means to visit all the nodes of the tree in some Specnfled
Traversing
order. =
' To visit a node means to arrive at a node for the purpose of performlng
Visiting - some operation on the node. If an algorithm passes over a node on the
__path from one node to another then it is not considered a visit.
Table 5.4: Some common terms used in bmary tree

A is the root node.


Bis the parent of D and E.
Fand G are the children of C.
E is the right-hand child of B.
Fis the left-hand child of C.
D, E, F, and G are leaves.
The level of E is 3.
The height of the tree is 2.
The ancestors of node E is A and B.
The descendants of node C is F,
and G.
8 is the root node of the subtree
consisted of B and its descendants,
DandE.
Figure 5.18: A binary tree and the equivelant terminology
A tree that has at most two children is called a binary tree.

o
Figure 5.19: A binary search tree

A recursive definition of a binary tree is the following: Every binary tree has only one root.
Each node of the tree can be considered as the root of a subtree of the tree. Consequently,
every tree consists of a root and one or more subtrees. Each subtree is a tree.
In a binary tree when a node’s left-hand child has a key less than its parent and a node’s
right-hand child has a key greater than or equal to its parent, then the tree is a binary search
tree. These trees keep their keys in sorted order and allow fast lookup of data. The binary
search algorithm can be applied when looking for a particular key in the tree.

Representing a binary tree using pseudocode

Suppose we have an object named Student with the following properties:

Name of type string


Surname of type string
ID of type integer

A Node object will have two additional fields to store information about the references to
this particular node’s children:

Left Child of type Node


Right Child of type Node
So the Node of a tree that is used to store Student objects should have the following fields:

Name of type String


Surname of type String
ID of type Integer
Left Child of type Node //reference to Node’s left-hand child
Right_clg.ld of type Node //reference to Node’s right-hand child

It is clear that the Node encompasses more than just the data that it stores (i.e.: the Name,
Surname and ID). It may also include references to its children, if any.

Another approach would be to create two separate classes: a Student and a Node class. In
this approach the data are not placed directly in the Node. A reference is used in the Node
object to represent the student’s data.

- Node object Student object


Student sl //reference to student Name of type string
| cbject Surname of type string
- Left Child of type node ID of type integer
Right Child of type node
Table 5.5: Pseudocode for the two classes

It is important to mention that the ID will be used as the key value. As such, all tree
operations (finding, inserting, deleting etc.) will be implemented according to this key.

5.1.16 Tree traversal


Exit skills. Students should be able to':

31 r,e,s-uh: of inorder, preord:

Traversing a tree means to visit each node in a specified order. There are three ways to
implement tree traversal: inorder, preorder and postorder. All traversals work with all binary
trees, not only with binary search trees. But it is important to mention that the inorder
traversal of a binary search tree will visit all the nodes in ascending order, according their
key values.

Inorder traversal algorithm

It is assumed that the tree is not empty. The algorithm initially starts with the root node as
an argument and performs the following recursive steps:

1. The algorithm calls itself to traverse the node’s left-hand subtree.


© 2. The algorithm visits the current node.
The algorithm calls itself to traverse the node’s right-hand subtree.

In pseudocode this algorithm looks like:

in_Order (localRoot)

if (localRoot != null) then


in Order (localRoot.Left
Child)
output localRoot.ID //ID is the key value
in_Order (localRoot.Right Child)
end if

This rec@rsive method is first called with the root of the tree as an argument, as such:

in_Order (root)

Preorder traversal

It is assumed that the tree is not empty. The algorithm initially starts with the root node as
an argument and performs the following recursive steps:

1. The algorithm visits the current node.


2. The algorithm calls itself to traverse the node’s left-hand subtree.
i 3. The algorithm calls itself to traverse the node’s right-hand subtree.

In pseudocode this algorithm looks like:

pre_ Order (localRoot)

if (localRoot != null) then


output localRoot.ID //ID is the key value
pre Order (localRoot.Left
Child)
pre Order(localRoot.Right
Child)
end if

This recursive method is first called with the root of the tree as an argument, as such:

pre_Order (root)

Postorder traversal

It is assumed that the tree is not empty. The algorithm initially starts with the root node as
an argument and performs the following recursive steps:

1. The algorithm calls itself to traverse the node’s left-hand subtree ¥


2. The algorithm calls itself to traverse the node’s right-hand subtree
3. Visit the node //Recall that visit a node means to perform an action

In pseudocode this algorithm looks like:

post_Order (localRoot)

if(localRoot != null) then


post Order(localRoot.Left Child)
post_Order (localRoot.Right Child)
output localRoot.ID //ID is the key value
end if
This recursive method is first called with the root of the tree as an argument, as such:

post Order (root)

Binary search tree Binary tree

Inorder: ABCDEFG-sorted in ascending order Inorder: DBEAFCG


; Preorder: DBACFEG Preorder: ABDECFG
| Postorder: ACBEGFD Postorder: DEBFGCA
Table 5.6: Examples of tree traversals

Tree traversal - a practical approach

Figure 5.21: Diagram that illustrates empirical tree traversal

The approach presented in Figure 5.21 is very useful and can be used during examination to
answer tree traversal questions. Suppose every node is illustrated as a circle and has four

points at 0, 90, 180 and 270 degrees. The names of these points are N for 0°, E for 90°, S for
180° and W for 270° respectively. Figure 5.21 illustrates an orange coloured path that circles
the tree starting from the root. The path tightly follows the outline of the tree without
intersecting with any path or node.
In-order traversal: following the path, if you are able to approach the point
S of a node then
print the name of the node: ABCDEFG

Post-order: following the path, if you are able to approach the point E
of a node then print
the name of the node: ACBEGFD

Pre-order: following the path, if you are able to approach the point W
of a node then print
the name of the node: DBACFEG

Infix, prefix and postfix notation

A binary tree can be a valuable tool to symbolize an algebraic expression that involves
operands and operators (+, -, /, *). The root holds an operator, and the other
nodes of the
tree hold either an operand or an operator. Each subtree is an algebraic
expression. Three
notations may be used: infix, prefix or postfix.

e In the infix notation an operator is placed between two operand


s.
® Inthe postfix notation the operator follows the operands.
e In the prefix notation the operator comes before the operands.

In the infix notation an algebraic expression such as X*(6+Y)/Z means:

e ADD 6 AND Y TOGETHER.


® MULTIPLY THE RESULT OF THE ABOVE OPERATION BY X.
e DIVIDE THE RESULT OF THE ABOVE OPERATION BY Z.

It is clear that precedence of operations, left associativity and brackets play an important
role.

In the postfix notation (a.k.a. reverse polish notation) operators


are written after their
operands. The expression given above can be written as X6 Y +
* Z /. Brackets cannot be
used to change the order of evaluation of operators which is
always left-to-right. So in
postfix notation, operators act on values that are immediately to
the left of them. For
example:

e THE+USESTHEG6ANDY.
e THE * USES THE RESULT OF THE ADDITION AND X,
® THE / USES THE RESULT OF THE MULTIPLICATION AND Z.

In the prefix notation (a.k.a. polish notation) operators are written


before their operands.
Operators are evaluated from left-to-right and brackets are unneces
sary since operators act
on the two nearest values to the right. The expressions given
above can be written as:
/*X+6YZ. In this example:

e THE+USES6ANDY.
e THE * USES THE RESULT OF THE ADDITION AND X.
® THE / USES THE RESULT OF THE MULTIPLICATION AND THE iz
X*Y+Z/2 Xz iz
| X (2N
YA X 20!
[ X*(Y+Z/2) XYZ2[/+* Xy /z2l]
Table 5.7: Examples of different notations
=~
Traversing a binary tree (expression tree) using preorder would generate the prefix notation
while traversing an expression tree using postorder would generate the postfix notation.

Expression Expression Expression


(infix). (prefix). (postfix).
3 Tree
inorder postorder preorder
traversal traversal traversal
(2+3)*6 36 23+t6*

1 7/9)+5)*6 *+/7956 79/5+6*

#=J6)/(632) | / /46 *632| 46/632*/

2%6)+3)/6 | /+
* 8636 86 *3+6/

Table 5.8: Various expressions their notations and the equivalent binary trees’

*Tool used: http://cstar.iiit.ac.in/~kkishore/DSVL/exp6/exptree.swf


5.1,17 Sketch binary trees

Exit skills. Students should be able to®

Adding a new data item in a binary search tree.

Adding a new data item means to add a new object. An object is added in the correct
position of the tree as a node according to its key value. Thus, adding a new data item is
similar to adding a new node.

Searching for a particular data item in a binary search tree

Searching for a particular data item involves comparing the


value to be found with the key
value of a node, and following:

e that node’s left-hand child if the search value is smaller than the
current node’s key
value.
® the node’s right-hand child if the search value is greater than the
current node’s key
value.

Finding the minimum value in a binary search tree

Move to the left-hand child of the root.


Then move to the left-hand child of that child.
SRS

Repeat the process until you find a node that has no


left-hand child.
The key value of that node is the minimum value in the binary
search tree.

Finding the maximum value in a binary search tree

1. Move to the right-hand child of the root.


2. Then move to the right-hand child of that child.
3. Repeat the process until you find a node that has no right-hand child.
4. The key value of that node is the maximum value in the binary search tree.

Adding one or more new nodes to a binary search tree.

To insert a new nodeinto a binary search tree, follow the


steps:
1. Ifthe binary search tree is empty, insert the new n
e at the root.
2. If the binary search tree is not empty, f
to be
follow the r to the parent of the node
inserted. The parent will be a leaf node. Insert the new
node, according
to the following rules:
a. |If the key of the new node is smaller than the key
of the parent node,
then connect the new node as the parent’s left-h
and child.
b. If the key of the new node is greater than the key
of the parent node,
then connect the new node as the parent’s right-
hand child.
To follow the root, simply compare the key value of the node that needs to be inserted with !
the root’s node key value. If it is smaller, then move to the left-hand subtree. If it is greater, :
then move to the right-hand subtree. Continue with the next node and repeat the above :
process, until a leaf node is reached.

Duplicate keys
To deal with duplicate keys two methodologies may be applied:

1. The first and safest is to forbid the existence of duplicate keys. The candidate
numbers of IB students, the tax identification numbers, the car license and
registration numbers etc. are all unique and are used as key fields for searching,
deleting and adding operations.
The second is to modify the insertion process so as to insert a node with a duplicate
key as the right-hand child of the node with the same key. This will cause minor
problems during the searching process, since when the first node, with a given key,
is found the searching algorithm will stop and return the requested data. Of course
this problem is solvable. A new searching algorithm may be put in place to
accommodate for the existence of duplicate keys. However, the new searching
algorithm would be a bit more time-consuming, as it would need to keep on
searching the tree even after the first node, with a given key, was found.

Removing one or more nodes.

Deleting a node is important in many tree applications and involves three cases:
1. The node to be deleted has no children:
The node can just be deleted. The appropriate child field in the parent node must be
changed to point to NULL, instead of pointing to the node that needs to be deleted.
The node to be deleted has one child:
Just connect the parent of the node to be deleted directly to the child of the node to
be deleted. Change the appropriate reference in the parent (Left Child or
Right_Child) to point to the deleted node’s child.
The node to be deleted has two children:
Replace the node to be deleted with the node that has the largest value in its left-
hand subtree (inorder successor) or the node with the smallest value in its right-
hand subtree (inorder predecessor).

Example of adding and deleting nodes in a binary search-tree

The following table provides a detailed example of inserting and deleting operations in a
binary search tree:
Inserting 0123:
® The tree is empty so 0123 is the
root node.
Inserting 1123:
e 1123>0123 50 1123 goes to the
right. .

Inserting 0045:
e 0045<0123 so 0045 goes to the
left.

Inserting 1456:
® 1456>0123 so move right to
1235
® 1456>1123 so 1456 goes to the
right.

Inserting 8765:
® 8765>0123 so move right to
1123.
¢ 18765>1123 so move right to
1456.
® 8765>1456 so 8765 goes to the
right.

Inserting 0013:
e 0013<0123 so move left to
0045.
e 0013<0045 so 0013 goes to the
left.
Inserting 0234:
0234>0123 so move right to
1123.
0234<1123 so 0234 goes to the
right.

Inserting 0785:
0785>0123 so move right to
1123.
0785<1123 so move left to
0234.
0234<0785 so 0785 goes to the
right.

Inserting 0026:
0026<0123 so move left to
0045.
0026<0045 so move left to
0013.
0026>0013 so 0026 goes to the
right.

» Inserting 0047:
0047<0123 so move left to
0045.
0047>0045 so 0047 goes to the
right.
Deleting 8765:
8765>0123 so move right.
8765>1123 so move right to
1456.
8765>1456 so move right.
The key is found it is the child of
1456.
Delete 8765.

Deleting 0013:
0013<0123 so move left to
0045.
0013<0045 so move left.
The key is found; it is the child
of 0045 and has 0026 as its
child.
Delete 0013 and connect 0045
to 0026.

Deleting 0045:
0045<0123 so move left to
0045.
The key is found; it is the child
of 0123 and has two children.
The greater value of its left-hand
subtree is 0026. Delete 0045
and let 0026 to take its position.

Deleting 1123:
0123<1123 so move right to
1123.
The key is found; it is the child
of 0123 and has two children.
The greater value of its left-hand
subtree is 0785. Delete 1123
and let 0785 take its position.
Deleting 0123:
This is the root.
Replace it with the greater value
of its left-hand subtree.
Delete 0123 and let 0047 to take
its place.
Balanced trees

An unbalanced tree is a tree whose left or right-hand subtree has a lot more nodes than the
other subtree. Binary search trees become unbalanced because of the order in which the
data items are inserted. In most cases, insertion of data items with random key values result
in, more or less, balanced trees. However, if the data items inserted present an ascending or
descending sequence of their key values, then the trees becomes unbalanced. For example,
if one enters the data items with key values 1, 2, 3, 4, 5 0r 5, 4, 3, 2, 1 then he/she will have
an unbalanced binary tree. But if one enters 3, 1, 5, 2, 4 then he/she will have a balanced
tee.

Figure 5.22: Two unbalanced and one balanced (on the right) tree with the same data items.

Inserting 1, 2, 3, 4, 5 0r 5, 4, 3, 2, 1 are two extreme cases that both result to trees with no

branches. These trees act like linked lists. One has to search (on average) through half the
items to find the data item that he/she is searching. So instead of O(logN), of a balanced
tree, one ends up with the O(N) of a linked list. Searching through 100000 items in an
unbalanced tree requires 50000 comparisons. In a balanced tree this would require only 17
comparisons.

Suppose one wanted to insert '"ABCDEFGHIJKLMOPQRSTUVWXYZ" in two different binary

search trees, Figures 5.23 and 5.24. To find J in the first binary search tree he/she would

need to follow the path ¥, G, S, B, P, 0, L, I, K, J (9 comparisons). To find J in the second


tree he/she would need to follow the path X, B, F, K, I, J (5 comparisons).
Figure 5.23: Unbalanced tree®

s
1

/ o e
P z P
A
P

o
N e
2
L 5

A o = i o
{5 G 1 L Q (5]

o)

Figure 5.24: Better balanced tree

—e

* Tool used: http://www.algomation.com/algorithm/


binaw—tree—i nsert-delete—display
Applications

5.1.18 Definition of the term dynamic data structure


341 skllls Students should be able to':

Define the term dynamtc data structure.

as required by its elements.


A dynamic data structure changes its “size at execution time
data structure.
Allocation and de-allocation of memory is controlled by the

5.1.19 Comparison of static and dynamic data structures


Exit skills. Students should be able to':

Compare the i of statlc and dynamxc data structures.

STATI C
_DYNAMIC.
4} Memory is allocated at complle time. The
Memory is allocated to the data structure size is predefined and can never change
dynamically i.e. at run-time. An example of | during run-time. An example of a static
a dynamic data structure is a stack . data structure is a stack implemented using |
lmplemented using linked lists.
[RarrayS Sue
Advantages W Advantages i
o The memory aliocatlon is flxed and
as such there will occur no problems |

Makes the most efficient use of RAM when adding or removing data
as it only uses as much memory as it items.
needs. Easier to program as there is no
One does not need to know or need to check upon the data
structure size.
decide upon the size of the data
structure in advance. The space reserved in RAM will
always be available, in order to be
used by the data structure.
Dlsadvantages 2 , ~ Disadvantages
Given that the memory allocation is Can be very inefficient as the
dynamic, it is likely that the structure memory for the data structure is
will 'overflow' should it exceed its predefined.
allowed limit or 'underflow' should it Even when the array has no data
become empty. elements in it, it still takes up the
In most cases algorithms with RAM space that was allocated at
compile time.
dynamic data are slower, during
execution, than algorithms with Sometimes it is difficult to predict
static data structures. the required array size.
Random access is not allowed and In a sorted array, inserting a new
elements should be visited element in the correct position or
_deleting an existing one, requires
sequentially.
} e As such, there is no way to shifting of other elements.
| implement binary search. |
| e More complicated to program as the
1 software needs to keep track of its }
| size and data item locations at all ?
0 times. e iy
Table 5.10: Comparison of dynamic and static data structures

; . TS
o e
e . ;
) i Worst | Worst
i
| Deletion
Deletion Access | Search Inserj
o | o@ | om o Oln).

| Ologin) | Ollogla) O O O O | o)
Laliee
| Double- { | | |
Linked | O OM | 0@) f
Leilisty Wt r e |
% Queue | O(n) Tem o(1)
[ singly- | |
| Linked = O(n) O(n)

R o0 o 0@ | o | o)
Table 5.11: Efflc:ency of various data structures

5 1 20 Sultable structures

structures can be
An Abstract Data Type (ADT) is just an abstract conceptual tool. All data
an array and an
used to implement ADTs. A (static) linked list can be implemented using
list using an
array-type structure can be implemented using a linked list. Building a linked
array is the option for primitive level languages and assembly languages that require fixed
are conceptual
size data structures and do not support dynamic memory allocation. ADTs
es that are used to
models that abstract their fundamental data structures (the data structur
implement them) and are used with some specific purpose in mind.

either by using arrays or


Stacks and queues are examples of ADTs that may be implemented
a queue is to have
linked lists as their fundamental data structures. The important thing for
() and a dequeue () method. This can be achieved regardless of the use of an
an enqueue
of a stack the
array, a linked list or a double-ended linked list. For a dynamic implementation
push () method would be implemented using the Linked List. insertFirst(data)
pop() method would be implemented using the node =
call, while the
Linked List.deleteFirst() call. The user of the stack just uses the methods, without

bothering with the details of the implementation (abstraction for the user), while the
programmer, who has actually implemented the stack methods, knows the underlying
programing mechanisms.

, the nodes are stored in


Binary trees can be represented using arrays. In the array approach
matches the
an array and are not linked by references. The index of the node in the array
cosition in the tree. The node at index 0 is the root node, the node at index 1 is the root’s
‘=%-hand child, and so on. This method is not very efficient. Empty nodes and deleted nodes
‘=zve holes in the array, occupying RAM, and when the deletion of a node involves moving
subtrees, a lot of elements of the array must change position, resulting in a very time
consuming operation.

Data
BENEFITS DRAWBACKS
structure
Fast insertion L Slow search
Array Fast access of an element with a Slow deletion
. B knownlindeX Fixed size
2 Slow deleti
Ordered More efficient search than unsorted o ; eletl.on
s - Slow insertion
Wy L ; Fixed size
Models physical stacks
StStack 3 ;
provides Last-In, First-Out (LIFO). Slow accessto
5 othe ent:
ootieyclements
Models physical queues
Queue P Slow access to other elements
Provides First-In, First-Out (FIFO).
Fast insertion
Linked list Slow search
Fast deletion
Fast search
Binary search
Fast insertion
tree
| Fastdeletion
h&

5E
End of chapter example questions with answers

Example 1

Question

The following table shows basketball players and scores, from a game.

(James
7
Mark | 8
b Jeffrfir 15
[ Jehni F 4
_Ronald 5

1. Construct a binary tree that will store the data of the table, given above, in the order
of scores.
2. Construct the diagram of a linked list that will store the table data in ascending
order.
3. Compare the use of the binary tree with a linked list.
4. State what will happen if we enter the scores data, in a binary search tree, in the
following order: John, Ronald, James, Mark, Jeff.

Answer

1. The resulting binary search tree will be:

S g
& =
T ©o

2
= £S =
2 £o
& ?—_' S t
=
&= ®= %e ®=

Ronald
| Right Pointer

Right Pointer
Left Pointer

Left Pointer
2. The resulting linked list will be:

=Gl

3. Differences between the two data structures


a. Binary search can be applied in binary search trees while linear search
can be applied in linked lists. So it is faster to search a balanced binary
search tree. 3
b. A binary search tree uses two pointers for each node while a single
linked list only one. So, a linked list needs less storage
4. The binary search tree will become unbalanced and the search for an element
will be the same as in the linked list.

Example 2

Question

State three disadvantages of a recursive algorithm.

Answer

e ltis more difficult to write.


e Itis more difficult to maintain.
e An overflow error may occur if the stack runs out of space.

Example 3

Question

Explain how an element stored in a linked list could be found.

Answer

1 Start from the beginning (head) of the list.


2 Follow the pointer to the first node.
3. Compare the data in this node with the data to be found.
4. |f the data is found, stop.
5. If the data is not found, follow the pointer of this node to the next node.
6. Repeat from step 3 until the data is found or the end of the list is reached.
Example 4

Question

How is a queue best characterized?

Answer

First-In First-Out

Example 5

Question

Given an empty queue Queue, what does it look like after the following instructions?

Queue. enqueue (6)


Queue . enqueue (8)
Queue.dequeue ()
Queue. enqueue (3)
Queue.dequeue ()

Answer

Example 6

Question

What is the reason for using a "circular queue”?

Answer

Reuse empty space.

Example 7

Question

Suppose there is a circular array-based queue implementation is capable of holding 10


elements. Show the array after the following code is executed:

loop m from 1 to 7
enqueue (m)
end loop
loop m from 1 to 7
enqueue (dequeue () )
end loop
Answer

Example 8

Question

of holding 10
Suppose there is a circular array-based queue implementation capable
elements. Show the array after the following code is executed:

loop m from 1 to 3
enqueue (m)
end loop
loop m from 1 to 2
enqueue (dequeue () )
end loop
loop m from 1 to 2
engueue (dequeue () )
end loop

Answer

front = 4
rear = 6

2 8 L |
Circular Queue contents 2, 3, 1

Example 9

Question

Is it possible to implement a queue using two stacks?

Answer

, at any time, must be


Yes. Two stacks are needed: an input and an output stack. All elements
are pushed in the
either in the input or the output stack. When enqueuing, the elements
and pushed
input stack. When dequeuing, all the elements are popped from the input stack
stack to get the
onto the output stack. The top element is then popped from the output
g elements
dequeued element. To add (enqueue) more elements one must pop the remainin
element(s).
from the output stack, push them to the input stack and add (push) the new
Example 10

Question

Which type of traversal always gives the sorted sequence of the elements in a binary
search
tree?

Answer

Inorder traversal

Example 11

Question

What is the maximum number of children that the largest element of a binary search tree
must have?

Answer

Example 12

Question

What is the maximum number of children that the smallest element of a


binary search tree
must have?

Answer

Example 13°

Question

Draw a binary search tree such that:

e each node stores a single number and


e apreorder traversal yields 6, 3, 4,13, 10, 9, 11, 14 and
® apostorder traversal yields 4, 3, 9, 11, 10, 14,13, 6.

® Tool used: http://btv.melezinek.cz/binary-search-tree.html


Answer

Example 14°

Question

Draw a binary tree such that:

each node stores a single number and


an inorder traversal yields 30, 20, 4, 15, 9 and
a preorder traversal yields 20, 30, 15, 4, 9.

Answer

Example 15

Question

What value does method a return when called with a value of 4?

a (number)

© Tool used: http://btv.melezinek.cz/binary-search-tree.html


if (number <= 1) then
return 1
else
return a * a(number - 1)
end if

Answer

24 (i.e.: 4%3%2%1 = 24)

Example 16

Question

Which of the following data structures is not a dynamic data structure?

Array.
Binary tree.
A

Linked list.
Stack.

Answer

Array

Example 17

Question

Describe why the use of recursion is memory-intensive.

Answer

When a recursive method calls itself, all previous method calls are still open. The call
stack
(or execution stack) is composed of many stack frames (or activation records). Each
stack
frame relates to a method call. All stack frames of the previous method calls still occupy
space in the execution stack.

Example 18

Question

Identify the type of linked list that:


1. starts with a pointer to the first node and
2. contains a pointer from each node to the next node and
3. in which the pointer in the last node points to the first node.
Answer

Circular, singly-linked list.

Example 19

Question

Do binary search trees always have the same shape for a particular set of data?

Answer

No, it depends on the order in which the values were inserted.

Example 20

Question

A piece of software finds the probable origin of a last name. When a user enters his/her last
name he/she can find its origin. The following table shows some examples:

Lastname
Loy . Wene
Peters | Athens
| Woodcock | Hertford
| Angel |

1. Construct the binary tree that stores the data from the table above in alphabetical
order by last name.
2. Construct a linked list to represent the same data in alphabetical order by last name.

Answer
Right Pointer

Farmery
Left Pointer

York

Angel Peters
Right Pointer

Right Pointer
Left Pointer

Left Pointer

London Athens
Right Pointer

Right Pointer

Carpenter Woodcock
Left Pointer

Left Pointer

K1t e Hertford
Angel 8l haticle Woodcock

Pointer

Pointer
tondon SRS a1V Athens e lTg et

Example 21

Question

An application records the personal best times (in minutes) of competitors in a tournamen
t.
The program stores the data as they arrive in a sorted linked list according to the best times.
Part of the data structure is given below:

(i Waodcock
Pointer

Pointer

NULL
Carpenter had a best time of 12 minutes. Explain how this new node should be added
t§ the
above linked list.

Answer

A new node is created with the data of the competitor:

(&= et
Pointer

TEMP
Then, the pointers are adjusted:

o=t

NULL
Carpenter

The resulting linked list is the following:

TS Pointer Woodcock
Pointer
Pointer

NULL
Example 22

Question

State three applications of queues in computer science.

Answer

1. Simulation of processes.
2. Transfer of data between 1/O devices (e.g.: keystrokes of keyboard).
3. Job queue that contains jobs to run.

1523
Example 23

Question

State three applications of stacks in computer science.

Answer

1. In evaluating expressions.
To store return addresses.
3. To copy the parameters of a method onto a parameter stack before performing a
method call.

Example 24

Question

Calculate the value of the following postfix expression:

234 +t85 -

Answer

2%(3+4)-5=9
Chapter References
Guide.
International Baccalaureate Organization. (2012). IBDP Computer Science
edia. Retrieve d
Tower of Hanoi. (2015, November 17). In Wikipedia, Free Encyclop
_of_Hanoi
14:03, November 17, 2014, from https://en.wikipedia.org/wiki/Tower
from
Sedgewick, R., & K. Wayne. (2016). Stacks and Queues, Retrieved 10 July 2016,
http://introcs.cs.princeton.edu/java/43stack/
10 July 2016, from
Sedgewick, R., & K. Wayne. (2016). Binary search trees, Retrieved
http://algs4.cs.princeton.edu/32bst/
Java
Shaffer, C. (2009). Practical Introduction to Data Structures and Algorithms,
Edition, Prentice Hall.
Lafore, R. (2002). Data Structures and Algorithms in Java, Second Edition, SAMS.
from
Jinks, P. (2012). Infix, Postfix and Prefix, Retrieved 1 August 2016,
http://www.cs.man.ac.uk/”pjj/cleZ/fix.html
Parlante N. (2000). Pointers and Memory, Retrieved 5 July 2016, from
http://cslibrary.stanford.edu/lOZ/PointersAndMemory.pdf
.com/
Rowell, E. (2016). Big-o, Retrieved 10 July 2016, from http://bigocheatsheet
10. Kothapalli, K. (2016). Expression trees, Retrieved 15 July 2016, from
http://cstar.iiit.ac.in/'“kkishore/DSVL/exp6/exptree.swf
kil Parlante N. (2001). Linked List Basics, Retrieved 15 July 2016, from
http://cslibrary.stanford.edu/103/LinkedListBasics.pdf
12, Parlante N. (2001). Binary trees, Retrieved 15 July 2016, from
http://cslibrary.stanford.edu/llO/BinaryTrees.htmI
£ Meech, D. (2016). Algomation, Retrieved 1 August 2016, from
http://www.aIgomation.com/algorithm/binary—tree-insert—delete—display
from
14. Galles, D. (2016). Data Structure Visualizations, Retrieved 15 August 2016,
https://www.cs.usfcaAedu/"gal|es/visuaIization/AIgorithms.htmI
15. Melezinek, J. (2016). Binary Tree Visualizer, Retrieved 15 July 2016, from
http://btv.melezinek.cz/binary-search—tree.htm!
16. Dimitriou K. Hatzitaskos M. (2015). Core Computer Science for the IB Diploma
Program. Athens: Express Publishing. More information at:
e—ib—
https://www.expresspublishing.co.uk/gr/en/content/core-computer—scienc
diploma-program
17. Halim, S., F. Halim, et al. (2016). Visualgo, Retrieved 1 August 2016, from
http://visualgo.net/
Chapter 2
TOPIC 6 — Resource management

Topic 6 — Resource management

6.1 Resource management

System resources

6.1.1 Identification of critical resources

Exit skills. Students should be able to':

System resources include computer hardware, software, trained personnel and supporting
infrastructure. A critical factor when dealing with computer systems is the management o®
resources. Most resources present limited availability and should be managed with caution
In most cases the Operating System (OS) is responsible for the successful management of
hardware and software resources. Different computer systems have dissimila
specifications, capabilities and purposes to fulfill. Some critical hardware resources include

Primary memory

All processed data and instructions and all resulting data have to be stored in the primany
memory. Primary memory
is directly connected to the processor and feeds the processar
with the required data by the fetch, decode, execute cycle data and instructions (Machins
Instruction Cycle). Sometimes the primary memory is also referred as Immediate Access
Store. Primary memory should be considered as an addressable matrix of cells with a unigus
address for each and every cell.

RAM and Cache memory


All data and instructions held in RAM may be altered at any time. There are two types o
chips used for RAM: static RAM and dynamic RAM. Static RAM is a type of semiconduciar
memory that holds data for as long as there is power supply to the memory circuits. Da=
stored in a dynamic RAM semiconductor gradually leaks away and needs to be refreshez
periodically. DDR-SDRAM (Double Data Rate - Synchronous Dynamic RAM) is a typica:
example of semiconductor technology used to build RAM chips in modern PCs. Static RAM =
more expensive, needs more transistors per byte but is faster than DRAM. Both SRAM anz
DRAM are volatile and used concurrently nowadays. DRAM is used in large quantities =

! International Baccalaureate Organization. (2012). IBDP Computer Science Guide.


primary memory while SRAM is used in small quantities to speed up the overall performance
by the caching technique, which balances the speed of DRAM with that of the much faster
much faster SRAM is placed between the processor and the DRAM and
processor. The
processor
directly feeds the processor. Data is moved from DRAM to SRAM and then to the
y-used
and vice versa. This process has maximum benefits and performance when frequentl
data in SRAM is not
instructions and data are stored in SRAM. The task of storing the correct
while level 2
always an easy task. Level 1 cache memory is usually built onto the processor
the larger DRAM.
cache memory is on a separate chip located between the processor and

ROM
Read Only Memory (ROM) is non-volatile and slower than RAM. ROM is used to hold critical
Basic Input Output
instructions used to start up a PC. A common use of ROM is to hold the
hold the entire OS
System (BIOS) which makes it possible for a PC to boot and sometimes to
of CP/M 2.2 for
for old small home computers (e.g.: Personal CP/M ROM-based version
home computers developed by Digital Research Inc. and MSX Small ROM-based
small
for Z80 home computers developed by Microsqft Corp.). ROM is also
version of MS-DOS
used in embedded microprocessors, microcontrollers and control systems.

Secondary storage
hardware
Secondary storage, auxiliary storage and backing store are terms that refer to
data integrity, low cost, mass storage capacity and permanent storage. There
that provide
are two broad types of secondary storage devices: the first uses direct access while the
second uses sequential access.

Direct access storage techniques


that fall into this category have the ability to access, retrieve and store any
The devices
particular data without having to read through all previous data. Floppy disks, CD-ROMs,
Hard disks, DVDs, USB sticks etc. belong to this category.

Sequential access storage techniques?


The devices that fall in this category have to read sequentially through all previous data
before locating the requested data. Magnetic tapes, which belong to this category, are not
It is a major
only used in old science fiction movies, and are certainly not a dead technology.
storage medium and recently IBM Research and Fuji Film have produced a magnetic tape
with a record density of 123 billion bits of uncompressed data per square inch. This
technology allows secure storage for 30 years, built-in data encryption, low cost and less
energy consumption. Magnetic tapes are ideal for backup purposes.

Processor speed
computer is
A processor repeats the fetch, decode, execute cycle continuously as long as the
ce of a
turned on. MIPS (Million Instructions Per Second) is used to measure the performan
not take
processor. MIPS is only an approximation of a processor’s performance since it does
operand
into account the fact that sometimes a single instruction may operate on many

2 |BM sets new tape storage record. (13, April, 2015). In New Atlas. Retrieved 19:05, June 13, 2016,
from http://www.gizmag.com/ibm—tape-storage—record/36931/
fetches and stores, some instructions have a higher effectiveness than others, and soms
processors have the ability to execute several instructions simultaneously.

Processor Clock Frequency (Master Clock MCLK)


= Average number of clock Cycles Per complete Instruction (CPI) » 1000000
cycles/second million instructions

G
S
Jewmne s 7
|
The clock rate refers to the frequency at which the processor is running and is commonly
used as a rough indicator of the processor’s performance. The unit used is hertz and in the
case of multicore processors the clock rate is the same for all cores. The clock rate of
modern processors is measured in gigahertz (GHz). It is very important to mention that the
clock rate should not be used as a perfectly reliable measure of the performance of different
processor families. :

Figure 6.1: Installation of a modern processor in a CPU socket on the motherboard

Bandwidth

Memory bandwidth is the rate at which data can travel from SRAM and DRAM to the
processor and vice versa and is essential to the performance of a CPU. It is expressed in
millions of bits per second or in Mb per second (Mb/s). The peak theoretical bandwidth,
which is typically one word per bus cycle, is not the same as the sustained memory
bandwidth, which is less and is affected by various design features.
Screen resolution

21l digital television sets, computer monitors, tablet touch-screens and mobile phone
screens have a maximum number of distinct pixels that can be used to display video,
pictures, text etc. This is mentioned as Maximum resolution = Widthx Height, where Width is
the number of distinct pixels in the horizontal dimension and Height is the number of
distinct pixels in the vertical dimension. Most devices can support a number of different
resolutions. A rule of thumb is that higher resolutions need more memory and more
processing power.

1920 pixels 3840 pixels

2160 pixels
1080 pixels

Full HD Ultra HD
(FHD) (UHD/4K)
7680 pixels
4320 pixels

Full Ultra HD
(FUHD/8K)
Figure 6.2: TV display with resolution comparisons

Disk storage

Disk storage is a general category of metal or plastic storage plates on which data can be
recorded. The rotating disk(s) are mounted on a central spindle. Common disk storage
devices are the hard disk drive (HDD), the floppy disk drive (FDD) and various optical disc
drives. Nowadays HDD, solid state drives (SSD) and solid state hybrid drives (SSHD) are the
main disk storage systems used in most computers. SSDs are very expensive, very fast, more
durable and consume less energy.
HDDs are very cheap, present slower
boot times, can cover all storage
requirements and are cost-effective.
SSHD share the benefits but also the
disadvantages of HDDs and SSDs and
they probably provide the best
affordable combination of perform-
ance characteristics.

Sound processor

Sound cards facilitate the input,


Figure 6.3: Hard disk
process and output of audio signals.
In most cases they are integrated
onto the motherboard, while some
advanced models are sold as separate
cards that use an expansion slot of
the motherboard. Professional sound
cards act like audio interfaces and are
hosted in external rack-mountable
units and connect through USB,
FireWire, or an optical cable. Sound
processors have the ability to convert
analog sound to digital files, digital
files to analog sound and process Figure 6.4: Sound card
multiple audio channels.

Graphics processor

General-purpose processors
are not efficient at running demanding computer-generat=z
imagery algorithms. This is the primary reason for the evolution of GPUs (Graphics
Processing Units). Modern GPUs are massively parallel processors, very efficient ==
manipulating and processing graphics and
images. Their technical characteristics make
them ideal for running algorithms that require
processing of large blocks of graphics data and
computer generated imagery. Their
rapid
evolution has been driven by the video game
entertainment industry, which is a fast growing
sector with great potential. Faster GPUs are sold
as separate cards that use an expansion slot of
the motherboard, while some low-end models
are embedded on the
or motherboard are Figure 6.5: Graphics card
integrated with the main processor circuit.
Network connectivity

Some computers have various network connectivity capabilities. A laptop which is equipped
with both a wired Network Interface Card (NIC) and a wireless NIC will outperform a tablet
which is only equipped with a wireless NIC. In this case, the laptop presents a better network
connectivity solution. On the other hand, a lot of modern tablets are 4G enabled meaning
that they have SIM (Subscriber Identification Module) card slots. This greatly enhances their
ability to work and stream various media on the move.

6.1.2 Availity of resources


ills. Students should be able to*:

Evaluate the resources available in a variety of computer systems.

Together with supercomputers, mainframes, or “big iron” are the flagships of computing.
They are used by large organizations for critical applications, to handle large-bandwidth
communication, bulk data processing such as census, industry, defense, consumer statistics,
enterprise resource planning and large-scale transaction processing. IBM is the leading
company in the sector of mainframe production and in 2015 announced the production of
7132, Mainframes are the largest computer systems available and are typically housed in

isolated, air-conditioned rooms. Mainframes are equipped with extremely great processing
power, vast amounts of RAM, arrays of disks and backup tapes, and serve hundreds of user
terminals. They are able to handle high volumes of input and output and run a lot of
different applications concurrently.

Figure 6.6: Mainframe

3 The digital revolution demands a better server. In IBM. Retrieved 20:05, June 14, 2016, from
http://www-03.ibm.com/systems/z/hardware/z13.html
Supercomputers

They are very fast and expensive, and


focus on mathematical calculations,
weather forecasting, climate research,
molecular modelling, scientific and
engineering applications. The perfor-
mance of a supercomputer is meas-
ured in floating-point operations per
second (FLOPS). New supercomputers
exceed 10 PFLOPS drawing on the
power of more than 30000 processors.
The first supercomputers were comp-
act designs that used the local
parallelism approach, while the latest
designs are considered as massively Eiglrel6 7: Asupercomputer,
parallel systems equipped with multiple arrays of computers and processors.

Servers

A server is software, hardware, or both and provides various services to clients. The client-
server model is fundamental in computer networking and modern servers serve database,
file, email, game, application etc. requests from various clients. Servers need multiple
network connections for advanced performance, a lot of RAM to support multiple requests.
fault tolerance and ease of repair without the need of shut down, advanced backup
facilities, superior security characteristics and various automation capabilities.

PCs
Microcomputers and home computers were the first terms used to describe what we now
call Personal Computers (PC). Years ago the computer hierarchy had three classes:
mainframes, minicomputers and microcomputers. The term PC is widely used to describe 2
device capable of supporting the computational needs of one user at a time. Nowadays PCs
are inexpensive solutions that can run various software applications. Popular 0Ss for PCs
are MS Windows, MacOS and LINUX.

Laptops

The rapid change in working patterns and the increased need for mobility have favored the
popularity of mobile devices. Modern laptops are not a compromise in comparison to a PC.
Moreover, they have long-lasting batteries that can be used to support hours of computing.
Laptops, mobile workstations, desktop replacements, sublaptops, notebooks and
subnotebook are terms used to describe mobile PCs with different weights and dimensions,
as well as graphic-displays, processors, RAM, secondary storage and battery capabilities. It
is important to mention that most laptops include input devices like a camera and a
microphone and output devices like speakers. Touch-screens are now widely used as input
devices and facilitate tasks such as drawing and editing.
Tablets

A tablet is a mobile computer equipped with a touch-screen display which is used as both an
input and an output device. Tablet users can take advantage of the touchscreen to enter text
using the virtual keyboard or the built-in handwriting-recognition facility. The use of various
gestures completely replaces the need for a mouse, while finger and stylus pens are widely
used in all applications. i0S, Android and Windows are the major OS for tablets. Hybrid
tablets have a detachable keyboard and closely resemble laptops. Tablets are equipped with
sensors like fingerprint, three-axis gyro, GPS and accelerometers, front and rear cameras,
Bluetooth for connecting peripherals, Wi-Fi for networking and powerful batteries.
Specifications for high-end tablets include 2732x2048 pixels display, 12.9” screen, 128 GB
internal storage, 3 GB RAM, slot for 16 to 128 GB microSD (Secure Digital) memory card,
octa-core processor, 12.0 MP camera and 24-bit/192kHz sound. Various developers can
develop apps for tablets and distribute them online through application stores like Apple’s
App Store and Google’s Android Play/Store.

PDAs

Personal digital assistants (PDA), were used until 2010 as electronic agendas, calendars and
personal information systems. Nowadays smartphones offer all the capabilities once
provided by PDAs. Common OS for PDAS were Palm OS, BlackBerry OS and Windows CE.

Cell phones

A smartphone or smart phone is a mobile phone (portable


telephone) whose hardware components and software are
managed by a mobile operating system. Nowadays smartphones
combine features of PCs, PDAs, cameras, media players and GPS
navigation units. All smartphones can access the Internet, are
equipped with touchscreens that enable the user to interact
directly with what is displayed, can run third-party applications
and have photographic capabilities that approach those of mid-
level point-and-shoot cameras. They also support high-speed
mobile broadband through 4G LTE, Wi-Fi connection and
Bluetooth connection. They also feature RFID solutions, motion
sensors, a fingerprint sensor, accelerometer, gyro sensor,
proximity sensor, compass, barometer and heart rate monitor,
as well as mobile payment transactions and geotagging ' Eure&-8:Asmartphone
mechanisms. Modern smartphones use i0S, Windows and Android OSs. Various developers
can develop apps for smartphones and distribute them online through application stores like
Apple’s App Store and Google’s Android Play/Store. Specifications for high-end smartphones
include 1440x2560 pixel display, 64 GB internal storage, 4 GB RAM, slot for 16 to 128 GB
microSD (Secure Digital) memory card, octa-core processor and 24-bit/192kHz audio.
Digital cameras

A digital camera encodes images and videos


digitally and stores them in the attached
memory card for later reproduction. High-end
products have a 30.4 Megapixels sensor and are
equipped with an LCD viewfinder,
as well as a
GPS sensor. They support various image formats,
such as JPEG and RAW, as well as video formats,
such as MP4. They can record
and 4K video
connect to a computer system through a USB
interface or Wi-Fi connection. They may also
Figure 6.9: A digital camera
include HDMI output, analog stereo audio
output and analog video output (NTSC/PAL). All the signal processing and control functions
ofa digital camera are performed by a dedicated specialized processor.

6.1.3 Limitation of resources

Exit skills. Students should be able to’:

Sometimes when a computer system is active the request for services exceeds the
availability of resources. Memory is a typical example
of system resources. Every time one
opens an application the OS is reserving a particular amount of memory
that the program
needs to operate. If a PC is equipped with 8 GB of RAM, the available memory to run
various
applications is around 6 GB because the OS and various programs that load during
the
startup process utilize a total of 2 GB. Although the OS will do its best to satisfy ones
requests, the launching of more and more applications will lead to an "Out of Memory™
message or a very slow computer.

In computer-generated imagery (CGl), rendering is the process of generating a 2D or 3D


graphic and exporting it to an image file. It also refers to the process of
adding effects during
the video editing process, in order to generate a final product. The rendering
process
involves complex mathematics and the solution of the rendering equation. This integral
equation must be solved by rendering software to produce realistic graphics. Although
the
advances in personal computer resources allow an image to take less time to render
than
before, state-of-the-art image quality needs specialized solutions, such as
render farms.
These high performance computer systems are used by professionals to render
computer
generated imagery.

A single core single processor system may not be able to perform demanding tasks
or run
complex mathematical models efficiently. A multicore or a multiprocessor system
may be
more efficient. A single processor systemmay have an IC (Integrated Circuit) with multiple
cores. In a multiprocessor system two or more ICs are mounted on the motherbo
ard. Each
core. A multiprocessor system is more expensive, needs
IC could have more than one
usually runs multiple programs faster, whereas a multicore
complex configuration and

system usually runs a single is considered as the best choice for


program faster and
that the comparison takes place
everyday users. This, oversimplified, statement assumes
It is important to keep in mind
between ICs with the same characteristics and clock speeds.
is shared by all the cores.
that in a multicore system, the main cache memory

standalone GPUs. A single GPU is what most


A computer system may have one or more
different
users opt for. It is an economical and powerful option that can serve as many as 4
and provide gaming capabilities. If someone wants to play an
monitors, play HD video,
using a single GPU may not allow the game to run
action game in a 4K resolution then
GPUs can generate disturbing noise and high temperatures,
smoothly. However, multiple
of the same type do not result in a
especially under load. In most cases, two or three GPUs
double or triple increase in the performance respectively.

6.1.4 Problems with insufficient resources


Exit skills. Students should be able to

in the resources of a
| Describe the possible problems resulting from the limitations
computer system.

program at a time. This single


Thirty years ago, few computers could process more than one
common and the loading and running of each program
program operation was the most
resources were scarce and it
was supervised by a simple OS like MS-DOS. Computer system
took a long time to complete tasks that needed more than a single program to run in order

to be completed.

and complex type of computer


As computer systems evolved, a slightly more sophisticated
processing. In batch processing some programs are
operation appeared called batch
need of any intervention from
batched together and then executed as a group, without the
while the others are waiting for
the user. Only one program is actually running at a time,
runs, and so on, until all the
their turn. When it completes, the next program in the queue
programs in the batch are run.

programs could be loaded in


As computer systems evolved even more, and more than one
of operation emerged, called
main memory at the same time, ready to execute, a new type
ms may be loaded in the main
multiprogramming. In multiprogramming two or more progra
only one program will actually be executed by the CPU at any one point
memory. However,
programs will be waiting for their turn. The idea behind
in time. All the other
(i.e. CPU idle time should be
multiprogramming is to maximize the use of CPU time
is performing input/output tasks
minimized). For example, if the currently running program
the screen) the CPU will be idle,
(eg. waiting for input from the user or drawing an image on
control to one of the other
since it will not be needed. A multiprogramming OS will give
, thus reducing CPU idle time.
programs residing in the main memory and needs to execute
Even with multiprogramming, if there a number of programs loaded in the main memory
and all are CPU intensive, without any idle time for I/O operations, the last program will
have to wait for all the other programs to finish, before executing. Another problem that
needs to be dealt with when there are multiple programs residing in main memory is
memory fragmentation as programs are moved from and to the memory. Unix, developed
by Bell Laboratories of AT&T, was one of the first OSs that supported multiprogramming. In
a multiprogramming time-sharing environment, a lot of different users share a computer
system simultaneously. This situation can cause numerous security problems, such as
stealing/copying another’s user programs/data or using system resources without proper
accounting. In any case, the degree of security in a multiprogramming system is less
compared to the security in a single-user dedicated system.

Further system development and evolutions introduced a new type of operation callea
multitasking. Multitasking is similar to multiprogramming with the subtle difference that
tasks or processes (instead of whole programs) are performed simultaneously and share 2
common resource, for example one CPU. Each task finishes; before another takes up the
CPU, as was the case in multiprogramming. However, tasks are a lot “smaller” than
programs and as such are completed very quickly. Both multiprogramming and multitasking
operating systems are Central Processing Unit time sharing systems. In older systems
multiprogramming allowed .one program as a whole to run until it was completed, while in
newer systems multitasking best manages the utilization of CPU resources with the use of
program fragments called processes. Since tasks are completed in a timely fashion, the
illusion of parallelism is achieved. That is, all programs running on a computer appear to be
operating at the same time to the user. What is happening however, is that small tasks, from
each program, are completed very quickly by the CPU, making the programs appear as =
they are all operating at the same time.

Multiprocessing refers to the hardware and means that a computer system has more than
one CPU cores. This might mean multiple CPU dies or even multiple cores in one or mor=
CPU dies. Since multiprocessing refers to hardware, whereas multiprogramming anz
multitasking refer to software, a system can be both multiprocessing, as well a=
multiprogramming or multitasking.

Multithreading is the ability of a program or an operating system to execute different paris


of a program, called threads, simultaneously. The program has to be designed by th=
programmer in such a way that all the threads can be executed at the same time withous
interfering with each other. It is important
threads of a single to mention that several
process can share the CPU, in a single CPU system, or run in parallel in a multiprocessing or
multicore system. Multithreading is widely used in applications that encompass a GUI. For
example, in such an application, if a task requested by the user needed a long time =
complete (because it was a complex mathematical computation or a network call, etc.), the
GUI would be unresponsive (“freeze”) until the task was completed. Multithreading, on the
other hand, would allow the GUI of the application to be responsive and the user to have =
better experience.
Another advanced mode of operation is multi-access, where a lot of users can interact with

2 one computer system through their terminals. The computer system may execute a

number of programs and the connected users can interact with these programs. This mode
on of a number of
of operation, of a computer system, allows the simultaneous connecti
istics: (a) multiline
terminals. Such a system must embrace the following functional character
with the remote
communication capabilities that will support simultaneous dialogues
to instantly switch
zerminals; (b) concurrent execution of various programs with the ability
(c) ability to quickly
from executing the program of one client to executing that of another;
all data from
£ind and make data stored on the hard disks available; (d) ability to protect
above mentioned
unauthorized access. Unix OS supports multi-access and provides the
characteristics.

Role of the operating system

6.1.5 Role of the Operating System {0S}


Exit skills. Students should be able to': D
LB aaassRR R el D O
e e LT el Lo g s T !
Explain the role of the operating system R
and hardware interfaces. Gt
Operating Systems (0Ss) can be classified as single
user, multi-user, multiprocessing, multitasking and

multi-threading. Most OS are now written in C or


C++ while older OS were written in low level
languages. A few critical operations that are very
important for the performance of an OS are still

written in assembly. All 0Ss are collections of

software and belong to the system software. An OS


is a system, meaning that the collection of software
that form an OS collaborate towards a common goal.
Any computer system is a collection of hardware and
software resources which provide input, process and
output services. The OS is the core software that
coordinates all these resources, on top of which all

other software applications reside. The OS controls


the execution of all other software. For example, it
will locate where an application is saved on the HD,
calculate the amount of RAM needed for the Figure 6.10: Different levels of a computer

application to run, allocate the correct amount of


RAM for the application, copy the application to the allocated RAM, etc.
Managing memory and processes

Usually, a computer’s RAM is small compared to its secondary storage. M=


management is the act of managing computer memory and every instruction tma
executed in the arithmetic and logic unit (ALU) was previously loaded from the RAM anz.
the hard drive directly. Thus, the RAM is a scarce resource that should be pre:
efficiently and carefully managed by the OS in order to achieve the best perfo
possible. Only vital data should be kept in the RAM; the rest should be kept in sec
memory.

Programs that quit should return the memory that they had been allocated while ru
The OS should guarantee that this will happen, because otherwise those resources wors©
available to any other programs. This situation is rare and is called a memory leak.
resource leak. The OS should dynamically allocate portions of memory to applications
their request and also free them for reuse when no longer needed by the application. T
crucial since, in modern computer systems, a lot of processes are running at any one pa
time.

During the operation of any computer system, the OS should track the location o¢
programs within its RAM and convert the logical into actual physical addresses, wh=rs
those addresses are needed by a process. A logical address is a reference to a storec
and is used by the program that generated this reference, while a physical address =
actual address of one memory cell. Address binding is the process of mapping a ‘oz
address to a physical address. A program may be loaded in different physical addr=sss
while running, and the use of address binding helps to keep track of where the pro
located in RAM. Since the logical address is known, the physical address of a process ca=
be located. Using these techniques the OS keeps track of programs in memory.

Swapping is the general term of a mechanism in which a process or blocks of program


can be swapped temporarily out of RAM and into a hard disk, and then, later, broughz
into RAM to continue their execution.

Paging is the underlying mechanism of virtual memory implementation, which allows


modern OS to utilize the, much greater in size, secondary storage as if it was RAM. Trh= &
copies as much data as possible into RAM, and leaves the rest on the disk. When the 2
requests data from the disk, it exchanges a quota
of data (called a page) in RAM w=s &
quota of data on the disk. This is extremely helpful when data to be loaded in RAM is gz
in size than the available RAM. The secondary storage used in this case is usually a hara
drive capable of providing direct access to these memory pages. Excessive page swaos
causes thrashing that results to poor system performance.

Multitasking systems use slicing to effectively manage all running programs. A slice o=
time-slice is the time allocated to each user in a multi-access system or to a program =
multitasking system. The OS uses an interrupt mechanism which suspends a process tha &
executed by the ALU and invokes a mechanism to identify the next process to be execu==
The interrupt handler is scheduled to allow the OS to switch between processes when ===
time-slices expire. The mechanism used to select the next process is called a scheduler
s run once, during every time-slice, to choose the next process to run. The collaboration
oetween the interrupt and the scheduler allows for the processor’s time to be shared
oetween a number of different processes and is a vital component of multitasking systems.
n a modern multitasking OS, the operating system can store and restore the state of a
orocess or thread, so that execution can be resumed from the same point at a later time.
The scheduler performs selections that satisfy the scheduling policy's priority constraint.
When a high priority takes over from the lower priority task currently running, it is known as
preemptive scheduling. When the scheduler selects a ceased lower priority task to resume,
=he task continues from the stored state.

2t any specific time, processes can be separated into two groups: those that are waiting for
nput or output and those that need to use the CPU. The processes that are waiting for input
or output do not need to use the CPU, allowing other processes to do so. When the
requested data becomes available, and thus the input or output has completed, an interrupt
s generated and the paused processes return to their executing phases and may use the
€EPU.

Managing peripherals

input and output devices vary in their characteristics, come from different vendors and
oresent different technical challenges. Their speed of communication also varies, even when
they belong to the same industry standard. For example, USB 1.0, released in 1996,
supported data rates of 1.5 Mbit/s to 12 Mbit/s and USB 1.1, released in 1998, fixed
problems identified in 1.0. USB 2.0, released in 2000, supported data rates of 280 Mbit/s,
while USB 3.0, released in 2008, supported data rates of 4 Gbit/s. Finally, USB 3.1, released
in 2013, supports data rates up to 10 Gbit/s. The OS uses a special program called a device
driver to handle all internal and external hardware, input and output peripherals and
storage devices. Each device connected to a computer system utilizes a device driver in
order to communicate with the OS. This piece of software acts like a bridge that facilitates
the communication between the particular piece of hardware and the operating system. A
device driver is coded by the product manufacturer and guides the OS as to how to use the
particular device. Manufacturers usually provide free up-to-date device drivers and most
device drivers are operating-system-specific. The use of device drivers is another example of
abstraction since the OS does not need to know the technical details about every piece of
hardware that needs to exchange data.

Managing hardware interfaces

The operating system hides the complexity of hardware resources from users while it also
manages the interaction of processors, memory, data storage and 1/0 devices. It acts like an
interface that handles "interrupts" generated by the 1/O controllers and shares /O between
programs using the CPU. This is also is another example of abstraction. The OS efficiently
manages low level hardware in a way that application software can take advantage of
installed hardware. For example, when typing a document, the word processor application
does not bother with the drivers of the keyboard or the video adapter used. That is an
example of abstraction. The OS multiplexes the hardware components for all application
software and hides all unnecessary details from the user and the application software.
Marager
Fle Adion View Help
@dimi0iEm @
v & KostasDell
> & Audio inputs
and outputs
>3 Batteries i
> ) Bluetooth
~ B3 Computer
I ACPIx64-based PC |
Intel(R) Serial 10 DMA Controlier
v Diskdrives i
i JetFlash Transcend 12568 USB Device | DiverVerson: 10.0:10586.0 !
a Samsung SSD 850 EVO 50068 | Digtal Sgner crosclt Windows |
> I Display adapters §
5 3§ Firmware |
> b Human Interface Devices i To viow defods aboutth
diver e
> =3 IDE ATAVATAP controflers fles. | |
{
> 3 Imaging devices Toupdao
the diversoitwereforthisg.
> K3 Keyboards.
Hicmsoft Corporation
> @ Miceand other pointing devices Fthe device fals after updating the
back tothe previously indaled
Heversion: 10.0.10586.0 $h2_release 151029-
> B Monitors dmf 5 : = S
{ 5 | Copight @ Microsoht Comorati
Al ighis on.
resarved
> [ Nebwork adapters i Disabies the selected davice. ) Digtal Signer- Microsoft Windows
> [ Portable Devices
> 55 Print queues
> T Procewsors i |
> B Software devices ! e T
> & Sound, video and game controllers | oK L;

k162272470 Semvie ControtManager 5 = Opensavedlag..


| Device Manager-Ssm | @ formaton 162212200 Senvice Control Marager 5 None
| v B Windows Logs B nformation OT-Jun-1622722 P 1P crte Customview.
UserPop.
| 6] Applicaion informtion Tdom- 162272200 by
20001 7o0s) hEs e
| ] Security Jinformation.
201 )
TT-Jun-16 10157 PM, Sesvice Control Manager 7045 None l Clearlog..
{ {1 etup | @ioformation TT-Jun-16 1016 PM Service Controt Manager
| Epen 1 @ofonnation ™5 None {]F Fiter Cument Log...
16 10755 M. UsePop 20001 (0s)
i £ romardedbvents
(1 tormation O7-Jun- 1510155 PM. {1 properties
| B Apptcton
and Services 9 | 3ot omation G 511371 UserPrp
e Gt ansger 200 Goos)
705 None
|
| “-‘é“;h 1} Diformation OT-un-16 1238509 Kemal-General 16 None
B
[ A O-hun16 123724 P Kemel-Genersl I sove
i Events ..
16 None o AmechaTeskTos Log..
| Herdvarebventy
| @ menepionr x View >
| Mo @ nvek
||
[l e ,
e
cror i| S e o o A pro o GO o i CL510 =
; 5
| Subseriptons 1 anflmsum;
|
e TATORINYTED 51510 o e Loabin Using U9 g ot ot Unsiie S0 : =
T Attch Tk To This Event..
(Unavaiable). This securty permission can be modified using the Comoonent Services dminirative
ool s & Cony 5
| 1§ LogNsme: Sptem
Source: DisrbutedCOM 3 SaveSelected Event..
logged Oramtsaserzem B raten
Evene o015 Tk Cotegory: None
i otem Enox Kepeords: Clasic . 3
i Usen SYSTEM. Computer: KostasDell
i OpCode: Info.

Figure 6.12: Event viewer of Windows 10.

6.1.6 - 6.1.7 0S resource management techniques

Exit skills. Students should be able to:

The techniques of multitasking, virtual memory and paging have been discussed in the
previous section.
Scheduling

Most OSs have a special application called “Task Scheduler” that is used to create and
manage common tasks that the computer should carry out at specific times. These tasks
include virus scans, backups, defragmentation etc.

D Tekscheduler S
e Adion View Help

Tiggers ~
Uihenthe ks erested or mocified
Wihenthetaskis crested o mocifed
Wi the tesiis rested or mocified » CresteTe
Ao o of wy e
Aoy o of sy user § Iport Tk
ihen compte i dle | {8 DiplayAl Runing Tosks
Vihen computer i de £ Enable At Tk History.
DPCODRapl.. Ready ATIZ3 A crery Seturdey of very week starting 02 Ape-16 e
O PCORetLa... Ready O event-Log: Applicaion,Source: PC-Doctor Launche, Event I: 1 =
e S e S e e e View »
@ A
B Hep

Autror, Moot Corporation i


enabled onty when the cache flex » End
& Disbie
Bt
5 Propeier
R velete
When rurming the task, use the following user account: g Hep
im
& Aun oniy when uses i logged on
R whether user s fogged on o ot
Do notstore psvord. The task willorly have acces o local resources
R with highest prvieges
Hidden Configurefor. 3

Figure 6.13. The Task Scheduler of Windows 10

The process scheduler is part of the operating system and decides on the next tasks to be
admitted into the CPU and thus the next process to run. Operating systems may feature up
to three separate scheduler types (short-term, medium-term and long-term). The scheduling
criteria that affect the selection of the best scheduling algorithm for a particular situation
include CPU utilization, throughput, turnaround time, waiting time and response time. The
most common CPU scheduling algorithms are:

First-Come First-Serve Scheduling, FCFS


s

Shortest-Job-First Scheduling, SJF


ER I OB I

Priority Scheduling
Round Robin Scheduling
Multilevel Queue Scheduling
U

Multilevel Feedback-Queue Scheduling


U

Policies and account management

In many cases more than one user has access to a personal computer. Moreover, in a
corporate computer network, there could be thousands of people who have access to the
network's data. In all cases, an operating system is responsible for setting up accounts for
each user who will utilize the computer or network resources. A user account defines the
privileges and access rights of a particular user. A user name and a password is used to gain
legitimate access to a computer or a network and to prevent unauthorized access by people
who do not have the permission to use the services and the facilities.
& suton
5 X
3 Accounts
find a setting 2
Your email and accounts x
Require sign-in|
fyouvebeenaway. whl Please reenter your password
Work access :
When PC wakes up frd
We need to verify the password for your Microsoft account.
Family & other users
Hadsaebyy
Password
Syncyour settings kdim@haefgr
Char account pd S -
Password.

Forgot my password

PIN
Create a PiN to use in p|
P you sign in |

Picture passwor
StnintoWindons

o -

Figure 6.14: User accounts settings of Windows 10

Interrupts

An interrupt is a signal from a device or from a program


within the computer that causes the
OS to stop the current task and decide what to do
next. Various interrupts are generated
and have different priorities. When a printer runs out of paper a “printer
unavailable”
hardware interrupt will be triggered to inform users that the printer
is not available for
printing. The multitasking principle, described in this chapter,
is based on software
interrupts. In general a hardware interrupt occurs when an 1/0 operation has finished
performing a function, while a software interrupt occurs when
a program requests various
services from the 0S.

i Task Manager
File Options View
Processes Performance App history Startup Users Details Services

6% 62% 1% 0%
Name CPU Memory Disk Network |
! Microsoft account 3.1% 568 MB 0 MB/s 0 Mbps
[8] Desktop Window Manager 1.1% 67.9 MB 0 MB/s 0 Mbps
[ System and compressed memory 0.9% 0.1 MB 0.1 MB/s 0 Mbps
> g Task Manager 0.5% 19.5MB 0 MB/s 0 Mbps
[5] store 04% 404MB OMB/s OMbps
[®7 System interrupts 3 0.1% 0MB 0 MB/s 0 Mbps
afl WMI Provider Host 0% 244 MB 0 MB/s 0 Mbps

Figure 6.15: Various system interupts presented in the


Task Manager (Windows 10)
Polling

Polling is the periodic checking of devices, by a central device to sample their status (i.e. see
what state they are in and identify whether they are still connected or want to exchange
data). The CPU periodically checks certain registers, actuators or sensors to see if some
request has been made. If, for example, a device is ready to transmit data, then polling will
identify this situation.

| Polling and interrupts: Polling is when one checks his/her smartphone periodically, to
1
. see if any notification has come up, while interrupt is when a notification arrives to
. ones smartphone and the smartphone vibrates to inform him/her.

6.1.8 Dedicated OS for a device

Exit skills. Students should be able to': -

There are two general approaches when developing a dedicated OS for a device:

e The first approach is to take an existing OS and adapt it for the particular device. The
advantage of this approach is that the end user deals with a familiar interface. The
disadvantage is that the final product will not be optimized for this particular
purpose. For example, if one plans to develop an OS for a mobile device, using an
existing OS that was developed for desktop computers, as its base, this may lead to
various obstacles since the mobile device may not have all the resources and
capabilities of a desktop computer.
e The second is to design an OS that will fit the particular needs of the device exactly.
This.approach would lead to an OS optimized for this particular device and purpose.
For example, when developing an OS for an embedded system, characteristics such
as small size (in bytes), quick responsiveness to external interrupts, real-time
scheduling policy and fast, lightweight, processes are very important and should be
taken into consideration. When developing an OS for a cell phone, considerations
about the efficient use of the battery and RAM, as well as the small touchscreen size
and the overall small device size should be made.

Examples of dedicated OSs:

Android is a the name of the mobile Operating System currently developed and owned by
Google. It is based on the Linux kernel, and designed mainly for touchscreen mobile devices,
such as tablets and smartphones. Android is one of the best-selling OSs for handheld
devices, and has the largest installed base. It is written in C, C++ and Java, and offers users
access to Google’s own services like Google Search, Maps, Translate, YouTube and Gmail.
Figure 6.16: Android Nougat replica in front of Google office on June 30, 2016.

Symbian is a mobile OS designed for smartphones. It was written in C++ and original’y
developed as a closed-source OS for PDAs in 1998 by Symbian Ltd. Symbian was used &+
many mobile phone brands, like Samsung, Sony Ericsson, and Nokia, but is defunct as of Mzy
2014.

TinyOS is a free and open-source, embedded, component-based, OS and platform for low-
power wireless devices, such as those used in wireless sensor networks and home
automation. It is written in the nesC programming language.

Tizen is an OS based on the Linux kernel and the GNU C Library implementing the Linux A=
It is written in C, C++ and HTML, and is a project within the Linux Foundation. The Technic=
Steering Group that governs this project include Samsung and Intel. It works ==
smartphones, PCs, cameras, tablets, in-vehicle infotainment devices,
Tu:z smart
smartwatches, Blu-ray players, printers, refrigerators, air conditioners, etc. Its purpose is ==
offer a consistent user experience across devices and promote smart home solutions.

Embedded Configurable Operating System (eCos) is a free and open-source, real-time, 0%


that was engineered to serve embedded systems and applications which need only ome
process with multiple threads. It is easily customizable to specific application specificazioms
of run-time performance and hardware requirements. It is written in C and C++.

Lo
6.1.9 0S and complexity hiding
Exit skills. Students should be able to':

Outline how an operating system hides the complexity of the hardware from users
and applications.

As we have already seen earlier in this chapter the OS hides the complexity of the hardware
from the users. This is a typical example of abstraction. The use of device drivers and the
management of hardware resources are not the only examples of abstraction related to OS
function.

Drive letters

In the following picture, drive C is a SSHD and D is a USB device. So letters C and D
correspond to real devices. Desktop, documents, downloads, 101__05, BOOK etc. on the
other hand refer to folders (locations). The user uses the icons to select the desired folder
without bothering with the complexity that lies beneath this simple selection (Figure 6.17).

B3| s iThsPC
Computer View

c v 4 O3 ThisPC
s+ Quickaccess S v Folders (6)

o - "R P E =
123 Desktop i = i E : ]

3 Downloads Desktop Documents Downloads Music Pictures Videos

fst] Pictures Devices and drives {2)


o

it ook S
| Python27 Windows DIMITRIOU
S to print @ ©

¢& OneDrive

Figure 6.17: File explorer of Windows 10.

Virtual memory

A user of Microsoft’s Windows 10 has the capability to alter the settings of virtual memory.
After that, the OS will handle the page file, when required, in the best possible manner, in
order to maximize the performance of the system. Once again the OS hides this complexity.
1> Control Panel > Syster
and Security s System

| Virtszal Memory X
[ Aomatically manage paging file size for all drives:
Paging file size for each drive
8.
| Diive [volumeLaber] Ao
{
Paging File Sim (ME) e
Choose how to sllocste processor resources.
s
J Adjust for best performance of:
,(% @ Programs O Batkground services,

Selected drive: € Windows) | ot ety


Space svailable: 260385 B ""’*S
® Custorn e it S
A paging filei the hard disk that Windows di

Iniial e (ME): | Total paging tie sie for il dives:


s
e
Waderasen
size (ME): | 1024 |
i
OSysemameagede . &
OMopagingie B
e {
Total paging file size for all drives: |
Wi sllows: 16 ME |
Recomamendest: 1O MB |
o Cmelyallecmed H1ME Lt
ense Terny

Figure 6.18: Use of virtual memory in Windows 10

Input devices

Various input devices are controlled by the OS using their device drivers. The user simply
uses these devices and can change their settings without knowing any details about how
they operate at a hardware level.

v o3 Imaging devices
s Inteqrated Webcam
v Keyboards
StandardPS/2 Keyboard
v @ Wice znd cther pointing devices
@ Dt Youchpad
@ Wicrosoft Arc Mouse (Mouse and Keyboard Center)
@ whicrosoftPS72 Mouse
Figure 6.19: Screenshot showing various input devices in the device manager

The Java virtual machine

The Java architecture allows code to run on any machine on which the Java Virtual Machine
interpreter has been installed. In Java architecture, all details of making the code function on
a specific hardware platform are handled by the Java Virtual Machine (JVM). This is another
example of abstraction.
End of chapter example questions with answers

Example 25

Question

What are the two main categories of software?

Answer

Application and system software.

Example 26

Question

State some main tasks of the operating system.

Answer

recognizing input from the keyboard,


sending output to the display,
managing files and directories on the secondary memory,
controlling peripheral devices such as disk drives and printers,
warranting that different applications running at the same time do not interfere
with each other and
providing a platform on top of which application software can function.

Example 27

Question

State two types of operating system strategies?

Answer

Batch and timesharing.

Example 28

Question

‘What is a resource in a computer system?

Answer

Aresource is anything that can be allocated and managed by a computer system.


Example 29

Question

State some examples of resources.

Answer

CPUs, input/output devices and RAM.

Example 30

Question

Explain why the problem of resource allocation is complex?

Answer

Modern computers run several applications simultaneously. All these


applications need to
compete for the limited computer resources available, thus produci
ng a complex problem of
resource allocation.

Example 31

Question

Describe an example of abstraction relating to resource allocation.

Answer

When allocating resources, all details of how the hardware operate


s are hidden. The
programmer writes an application without bothering with all these
details.

Example 32

Question

What is the difference between a program and a process?

Answer

Although the terms are used interchangeably a process is basicall


y a program in execution.

Example 33

Question

What is the process life cycle?


Answer

When a process executes, it passes through start, ready state, waiting state, running state
and terminated.

Example 34

Question

Explain what is a running process, a ready process and a waiting process.

Answer .

The running state means that a process has all the resources it needs for execution and the
operating system has given it permission to use the processor and execute its instructions.

The ready state means a process has all the resources it needs, but is waiting to be assigned
10 a processor.

The waiting state means a process is waiting for a resource, such as input from the user or a
file to become available.

Example 35

Question

What is deadlock?

Answer

Deadlock is a situation that can arise when two processes hold resources and request other
resources, from each other, at the same time. Process A holds a resource that process B
wants, while process A requests a resource that process B holds. The result is that neither
can continue.

Example 36

Question

What is fragmentation?

Answer

Fragmentation is a phenomenon or state in which memory is used inefficiently and is broken


up in small pieces. This leads to files and programs being divided up and stored in various
areas throughout the memory, which results to slower computer systems, when these files
and programs need to be accessed. This happens because processes, which occupy different
amounts of memory, are constantly allocated and deallocated to and from the memory.
Example 37

Question

Explain how a PC can run processes


which are larger than the available RAM?

Answer

The system can use secondary storage


as if it was primary memory. This is know
n as virtual
memory.

Example 38

Question

What is the difference between mainframe


computers and supercomputers?

Answer

A supercomputer has as a dedicate


d purpose to run demanding prog
rams (e.g. scientific
research or engineering models).
It holds great processing power in
order to execute a
program as quickly as possible. It
always runs at maximum performa
nce, solving a particular
problem. Its performance is measured in Float
ing Point Operations per Second (FLOP
S).
A mainframe typically runs multiple
programs concurrently requested by
many concurrent
users . It processes huge amounts of
external data and its performance
is measured in
Millions of Instructions per Second
(MIPS).

Example 39

Question

What is the file manager of an 0S?

Answer

The file manager is responsible


for the management and maintena
nce of the secondary
memory (e.g.: USBs, SSHDs, hard disks
). It provides:

e folders and directories to organize


files,
¢ commands to create and delete fold
ers and directories,
® commands to read and write to
a file,
® commands to set protection to
a file,
® commands to set and change the
ownership of a file or folder,
® commands to delete a file.
Example 40

Question

Describe the difference between physical primary memory, virtual memory, and logical
memory.

Answer

Physical primary memory is the memory available by a computer to execute processes.


Virtual memory is a technique through which applications that require space larger than the
available RAM can be executed by using disk memory as if it was primary memory. Logical
memory is an abstraction of the computer’s different types of memory that facilitates
programming.

Example 41

Question

Why is RAM not suitable for permanent program storage or backup purposes?

Answer

RAM is a volatile memory, while disk drives can store data permanently.

Example 42

Question

State one advantage of multi-core processing over multi-processor systems.

Answer

Communication between processors on the same chip is faster than processors on separate
chips.

Example 43

Question

Why is a high level language suitable to implement an operating system?

Answer

The code can be written faster and is easier to understand and maintain.
Chapter References

A% International Baccalaureate Organization


. (2012). IBDP Computer Science Guide
2. .
IBM sets new tape storage record. (13,
April, 2015). In New Atlas. Retrieved
19:05 ,
June 13, 2016, from http://www.gizma
g.com/ibm—tape—storage»record/36931/
The digital revolution demands a better server. |n IBM. Retrieved 20:05, June 14
2016, from http://www—03.ibm.com/sy ”
stems/z/hardware/zl3.html
Arnheim, R. (1969). Visual Thinking. Unive
rsity of California Press, USA.
Bishop, P. (1987). Computer science. Nelso
n. Australia.
Bradley, R. (1999). Understanding
computer science for advanced level.
Nelson
Thores, UK.
Brookshear, J. (2012). Computer science
an overview. Addison-Wesley. USA.
Dale, N. and J. Lewis. (2013). Computer
science illuminated. Jones & Barlett
Learning, UK.
Sanders, D. (1988). Computers today
. McGraw-Hill, Singapore.
10. Silver, G. & Myrna Silver. (1993). Computers and information processing.
HarperCollins, USA.
1% Willis, N. & John Kerridge. (1983). Introduction to computer architecture. Pitman
Publishing, UK.
12 Wise, H. (1981). Computer Architectu
re. Blackie, UK.
Chapter 3
TOPIC 7 — Control

» Topic 7 — Controlt

7.1 Control

Centralized control systems

7.1.1 A range of control systems

51 skllls Students should be able to"

Discuss a range of controlsystems

A control system? is one or more devices that guide other devices or systems.
This allows for
the completion of various tasks in an automatic manner, without any human intervent
ion.
Control systems are set up once and can then perform the actions
have been that they
programmed to do in an automatic manner,relieving humans from repetitive and mundane
tasks, as well as increasing productivity and efficiency. Control systems
may include sensors
to gain feedback from the environment and motors to control
any actuators in an
appropriate manner.

An example of a control system is


contained in the automatic doors that
can be found in various locations, such as
supermarkets. Instead of humans
manually having to open and close these
doors, a motion sensor is located at the
top of the automatic doors, which allows
the control system to become aware of
any motion. The sensor may use infrared
: or microwave signals that bounce off of
Image 7.1: Automatic doors objects to determine motion. After
receiving feedback from the
environment, the sensor forwards its signal to a microprocessor and allows the control
system to operate its actuators to open the doors only when motion is detected.
Furthermore, more advanced automatic doors include photocell sensors that can tell if
LI
lnternatlonal Baccalaureate Organization. (2012). IBDP Computer Science
Guide.
% Control System. (12, May 2016). In Wikipedia, The Free Encyclopedia. Retrieved
19:05, May 13, 2016,
from https://en.wikipedia.org/wiki/Control _system

1)
someone is at the door, so that the doors do not close on them. This results in a control
system that is very convenient, as well as efficient, when one considers that doors cannot
now be left open accidentally, which may be costly when a heating or air-conditioning
system is operating. Furthermore, automatic doors allow access to both the elderly and the
disabled, since both might find it difficult to open or close a manual door.

Control systems are mostly input, process, output systems. That means that an input is
provided to the system, which is processed by some algorithm, and an action is performed.
The results of the action can then be measured by the control system (through the use of
sensors) and feedback can be provided as input. The control system can then act upon the
new input and the cycle continues as seen in Figure 7.1.

i
Input —
T rer S
e ——
" Feedback
Figure 7.1: Control System

There are some circumstances however where an action might need to take place while the
control system is performing some other action. For example, when a second person
approaches an automatic door while it is closing, a signal must be sent to the control system
to re-open the doors. In this situation the signal sent to the control system is known as an
interrupt. An interrupt is a signal sent to the control system indicating that the system needs
to attend to the specific signal immediately.

A number of control systems are considered below. All of them use computer systems in
order to operate and so depict the many possibilities for control systems with developments
in computer systems.

e Heating system: In any such


control system, be it in a car, a
house or any other place, an
initial temperature is given as
input by the user (eg. 24°C). That
input signifies the ideal value of
the output and the goal of the
control system. That is, the
control system will aim to reach
the value provided by the user. Image 7.2: Smart heating system

Sensors allow the control system


to measure the temperature of the environment and determine any actions that =
might need to perform, in order to reach the desired temperature. For examp's.
given an actual temperature of 18°C (as input from the sensors) and a desira=
temperature of 24°C (as input from the user), the control system would turn on e
heater until the input from the temperature sensors was equal to the desired us=r
temperature. At that point, the heater would turn off and would turn on again onn
a
when the actual temperature falls below the desired temperature. Having such
than
control system allows for the conservation of energy and is more efficient
turning a heating systemon and off manually. This is because the automatic system
ate for
would reach the desired temperature once and then turn on to compens
in a manual
even a small drop in the desired temperature. On the other hand,
and turning
system, since there would not usually be a user holding a thermometer
on and off, every time the temperature fell or rose above the desired
the system
the energy wasted would be greater. Furthermore, newer “smart”®
temperature,
the user
heating systems also have the potential to connect to the Internet, allowing
system of
to operate them from afar. For example, one could turn on the heating
as one leaves work, so that the temperature is ideal when the user
his/her house
arrives home.
Taxi meters: Initially, taxi meters were
mechanical, bulky and made a

characteristic ticking sound. Through- s


out the years, and through the use of _ : PRI A BT

computer-operated control systems,


taximeters have improved, preventing
fraud as well as providing a number of
helpful features. For example, receipts
are automatically issued when a fare is
completed. Seat sensors detect the
presence of passengers in order to
prevent passenger journeys that do
not operate the taximeter. Credit
cards are supported, as well as radio
communication and GPS systems, so

to assist drivers, provide security, and


better calculate distance. Taxi meters
have become more efficient, less

error-prone, and automatic, relieving Image 7.3: Old and new taxi meters
the driver from hassles that could
distract him/her from driving.
Elevators: Primitive elevators date back to ancient times and were notoriously

and mostly used to move objects, instead of people. As engineering


dangerous
improved, so did elevator technology.

19:25, May 13,


3 smart thermostat. (19, April 2016). In Wikipedia, The Free Encyclopedia. Retrieved
2016, https://en.wikipedia.org/wiki/Smart_thermostat
Developments in computer systems
also played a significant role and
many modern elevators are
controlled by computer operated
control systems. An elevator control
system takes in a number of sensor
readings as well as the desired
destination, in order to turn a winch
motor with the correct number of
revolutions so that the elevator car
reaches its destination. The system
needs to know the initial and the
Image 7.4: Elevator
desired destinations, as well as the
location of each floor. The system
reads the desired destination from the user and uses sensors to detect the current
location, as well as the location of each floor. In many systems, a load (weight)
sensor may also exist that tells the control system how full the car is, so that the
computer system in control may use this information accordingly (ex. not stop to
take more passengers without unloading some current passengers). Finally,
elevators also include automatic doors that open and close only when the elevator
car is at specific floors. They also use motion sensors, as discussed before, to
prevent doors from closing on people entering or exiting the car. Many elevators
include a stop button, that stops the elevator car from moving in emergency
situations (for example, when a dress is caught between the elevator doors). When
pressed, this button sends an interrupt signal to the processor of the control system,
requesting its immediate attention, and stopping the car. As such, even though
elevators are control systems that are being used every day, efficiently and securely,
a number of inputs from sensors and complex algorithms are constantly executed by
control systems to make this possible.
Washing machines: The first washing
machines date back to the mid 18"
century, when manually rotating
drum washers were first introduced.
Washing machines with electro-
mechanical timers appeared in the
mid 20" century, making automatic
washing possible. In the late 20%
century, washing machines with
control systems driven by computer
Image 7.5: Washing machine
systems were first introduced. In
modern washing machines, sensors are used to determine and control the load size,
water level, temperature, as well as the user interface. All these sensors allow for a
finely-tuned washing cycle that better suits the needs of the clothes, as well as take
into account the environment by consuming less electricity and water. Furthermore,
modern washing machines are safer, since the door is controlled by a computer
system that locks it during operation, avoiding accidents. If the door is opened
before the washing machine has finished, or if the stop button is pressed, an

interrupt signal is sent to the processor of the control system, requesting its

immediate attention, and stopping the washing machine.


Process control: Process control
refers to the control of one or more
variables (such as temperature) in a
system. It strives to maintain the
output of a specific process within a
desired range. Open and closed loop
(feedback) controllers exist. An
example of an open loop controller
is a tank with a manual valve that
controls the heat dissipated by a coil
Image 7.6: Tank with temperature gauge
used to heat the liquid in the tank. In
this scenario, there is no feedback as
to the temperature of the liquid at any one point in time. Only if the relationship
between the heat dissipated by the coil and the temperature increase of the liquid is
known, can one be certain of the liquid’s temperature. On the other hand, in a
closed loop (feedback) controller, the actual temperature of the liquid is detected,
using temperature sensors, and the coil temperature is adjusted to achieve the

desired liquid temperature. In this example, the valve can either be an on/off valve
or a variable one. With an on/off valve the valve is turned on until the desired liquid
temperature was reached, then turned off, and on again after the temperature
dropped below the desired temperature. With a variable valve, the heat through the
coil is proportional to the difference between the current and the desired liquid
temperatures. The coil initially has a higher temperature, that slowly lowers, as the
liquid temperature reached the desired temperature. Developments in computer
systems allow for the automatic adjustments of the valve in order to achieve the
desired temperature, with minimal or no human interaction. If an error happened

with the valve so that it did not work as expected (for example, it did not turn off
and the desired liquid temperature was exceeded by an undesirable amount), an
interrupt could be sent to the processor, indicating that the processor would need to
bring the system to a hold immediately.
Device drivers: Device drivers are computer programs used to control a computer
device of any kind, from keyboards and printers to graphics and sound cards. These
computer programs allow operating systems (OS) and other programs to access the
devices with a layer of abstraction (i.e. without needing to know how the actual
devices are used). The computer bus usually connects the drivers with the devices,
allowing the drivers to send commands and receive data. Since drivers are
developed specifically for each device, they are hardware-dependent, as well as
operating-system specific, so that they are as efficient as possible.
Domestic robots: Domestic robots using
computer guided control systems are already
appearing in households. Vacuum, pool and
gutter cleaning robots are examples of
autonomous domestic robots that one might
come in contact with in everyday houses. A
number of sensors are packed within these
robots to provide “intelligent” behavior. For
example, vacuum cleaning robots use a suite
of sensors to map and find their way around
rooms that may include clutter and
furniture. Using various cameras they can
create house maps, using landmarks, and
know their current position as well as
previous locations. Furthermore, they can
return to their charging base whenever
necessary, and complete the cleaning
afterwards. Sensors can also detect the Image 7.7: Cleaning robot
material on which the vacuum is currently on
and perform appropriate kinds of cleaning. All these possibilities would not be
available without closed-loop computer-controlled systems.
GPS systems: Every day millions of
people use GPS systems to find their
way around cities, mountains or
even the sea. Whether used to find
a new café or guide a missile, GPS
systems are required to work
efficiently, precisely and with near
100% availability (no down time).
The GPS system is a large, complex,
computer controlled system that
includes both hardware and Image 7.8: GPS satellite system

software elements and needs


constant maintenance and support to work in such an effective manner as it does. It
uses around 30 satellites in orbit around the Earth, as well as a number of extra
satellites that are “fail-safes” (if one of the satellites fails, one of the extra satellites
will take its place until the first one is fixed). These solar-powered satellites circle the
Earth twice per day. A GPS receiver allows a user to know exactly where he/she is on
Earth. It includes a sensor that locates four or more of the GPS satellites, figures out
its distance to each one, calculates the time difference between the satelites and
uses a mathematical principle called trilateration to deduce its location.
Furthermore, modern GPS systems also receive input from their users, pinpointing
their desired destinations, as well as map data that may be updated through
software updates.
e Traffic lights: Traffic lights play a key role in road safety. They manage traffic,
prevent accidents and allow pedestrians to cross
roads without jeopardizing the
their lives. Traffic lights are usually control system
s operated by computer systems
and can be either “fixed time” or “dynamic control”.
o Fixed time: As the name suggests,
fixed time
traffic lights are open
loop control systems, in that they
do not receive any feedback from
the environment in order to alter
their performance.
They are
configured to change color after a
given period of time and they do
so repeatedly. Fixed time traffic
lights can be implemented with an
electro-mechanical signal control-
ler and as such does not neces-
sarily need a computer system.
o Dynamic control: Using a closed
loop control system to provide
feedback on the amount of traffic
passing by, dynamic control traffic
Image 7.9: Traffic light with sensor
lights can adapt their settings
appropriately, following some algorithm. These kinds of traffic lights are
operated through computer systems and would not be available otherwise.
They can use one of the two different types of sensors to detect traffic
conditions:
either embedded into the surface of the road or mount
ed on the traffic light
itself (or some other high position). The sensors that
are embedded into the
surface of the road have the ability to sense when a car passes over it.
Mounted sensors are less expensive and can provide the same feedback,
including real-time photos or video.

7.1.2 The uses of microprocessors and sensor


input in control systems
Exit skills. Students should be able to*:
| These should be ri elated to the examples suggested above
.

Today, most
modern control systems use microprocessors
in order to efficiently and
effectively read sensor input, process it accord
ing to an algorithm, and finally perform some
action(s).

A microprocessor, as its name suggests, is a


“small” processor, that contains most, or all,
of a
central processing unit (CPU) functions on a single
chip or integrated circuit (IC). Like a CPU,
a microprocessor performs arithmetic and logic operations, as well as any other data
operations necessary, through the use of registers. This is described in detail in Topic 2 —
Computer Organization in the Core Computer Science for the IB Diploma Program book”.
Therefore, it is a programmable, input-process-output device that also includes some
internal memory.

Various types of microprocessors exist, all of which have been developed with some specific
purpose in mind:

e General purpose: Capable of running a wide range of different programs and usually
integrated into a larger system. The CPU found in a desktop computer is a general
purpose microprocessor. Desktop computers also include various peripheral devices,
as well as external memory, all of which the microprocessor needs to interact with.
e Embedded controller or microcontroller: Microcontrollers are usually stand-alone
chips that may include the main elements of a larger system, such as RAM and ROM,
although smaller in capacity. These controllers are designed to perform some
precise task(s) and do not need, or cannot include, a whole computer system.
Microcontrollers may be found in most of the control systems described in section
7.1.1. Automatic doors, heating systems, taxi meters, elevators, washing machines,
domestic robots, GPS systems and traffic lights, all use microcontrollers to function
in an efficient and timely manner. Microcontrollers, in general, need less power to
function and are smaller in size, compared to desktop computers. They can be
integrated into smaller, lower powered electronic devices.
e Graphics processing unit (GPU): Computer graphics have become so detailed and
realistic in recent decades that an additional, special kind of microprocessor, is
included in most computer systems to handle them. This type of microprocessor is
known as the GPU and includes hardware to allow for faster handling of graphics
related mathematics (such as matrix multiplication and vector arithmetic). GPUs are
responsible for calculating and rendering polygons and pixels on the screen.

Microprocessors improve control systems in a number of ways. First of all, they can
process input data much faster than a human ever could and as such they can react to
changes in the input quickly. Control systems that depend on microprocessors are
automated and as such are error-free compared to manual or mechanical systems.
Furthermore, they can operate throughout the year with little to no off-time (down
time) and in conditions that are harsh or dangerous for humans.

Of course, since embedded microprocessors are pre-programmed systems that follow


some specific algorithms, they would probably not be able to operate in the most
effective way or at all (in an unexpected event). Moreover, as microprocessors need
power to operate, the system would not be able to function if there was a power
shortage.

* Dimitriou K. Hatzitaskos M. (2015). Core Computer Science for the IB Diploma Program. Athens:
Express Publishing. More information at: https://www.expresspublishing.co.uk/gr/en/content/core-
computer-science-ib-diploma-program
In order for microprocessors to perform any processing, they need to receive input. For
that to be accomplished sensor input is needed. A sensor converts continuous physical
(analogue) quantities
(such as speed, temperature, humidity, pressure, etc.) into
discrete digital signals using an analogue-to-digital converter (ADC). These signals can
then be read as input by microprocessors. The input is processed, according to some
algorithm(s), and output is returned.

Although a wide variety of sensors exist’, all of which share a number of common
properties determining their quality:

® Accuracy: Determines whether the measurement of the physical quantity and


therefore the final delivered digital signal is accurate (for example, a
temperature of 18°C should not be measured as 19°C).
® Range: Determines the acceptable range of the physical quantity within which
the sensor may acquire readings (for example, a temperature sensor might be
able to accurately operate between -30°C to 60°C, bqt not above or below those
temperatures).
® Resolution: Determines the smallest increment that the sensor may detect (for
example, one temperature sensor might be able to determine increments of 1°C
accurately, measuring whether the temperature is 17°C or 18°C, while another
might be able to determine increments of 0.1°C accurately, measuring whether
the temperature is 17.0°C or 17.1°C.

Sensors should also have two more characteristics, without which their readings would be
useless. Firstly, sensors should be insensitive to any other physical conditions present that
could influence the reading. For example, when measuring a temperature, the measurement
should not be affected by wind. Secondly, the sensors should not influence the measured
property in any way. In our temperature-measuring example, the sensor should not
dissipate heat into the environment and influence the temperature around the sensor.

7.1.3 Different input devices for the collection of data in specified situations
Exit skills. Students should be able to

Scenarloswill bebased on famnhar situations to students.

As described in the previous section, sensors are usually an integral part of control systems
and act as input devices. A growing list of available sensors exists® that can measure
anything from density to heat and motion to magnetic fluctuations. Sensors sense a physical
property and then transform it into an electrical signal.

® List of sensors. (19, April 2016). In Wikipedia, The Free Encyclopedia. Retrieved 19:30, May 13, 2016,
https://en.wikipedia.org/wiki/List_of_sensors
Useful Information: An Analogue to Digital Converter or ADC is used by every system
that uses sensors to convert continuous analogue data to discrete digital signals
handled by a microprocessor. ADCs cannot read and convert all the data that is
acquired by the sensors, but rather convert analogue data from sensors every few
milliseconds (depending on the sensor). This way, the data converted by the ADCs and
handled by the microprocessor is actually a sample (a part) of the actual physical
quantity being measured. Depending on how frequently the sampling is performed by
the ADCs, a lot of information might be lost.

The main sensor categories are discussed below. This list is non-exhaustive and more
categories are available®. Even in the categories presented, a large number of different
sensors usually exist.

Sensor types may be:

e Sound: Sound sensors, as the name suggests, detect sound waves and are widely
used in microphones.
e Motion: Motion sensors detect moving objects. They are widely used in
security/alarm systems, as well as automated lighting control, so that the lights are
only on when necessary to conserve energy.
e Vibration: Vibration sensors detect vibrations and are placed on surfaces that can
vibrate. They are widely used in security/alarm systems (placed on windows), as well
as acoustic musical instruments (instead of microphones).
e Optical/lmage: A wide variety of optical sensors exist, depending on the physical
quantity measured. Two widely-used optical sensors are the following:
o Active pixel sensor (APS): Used in almost all digital cameras, they contain
an array of pixel sensors that can imprint light.
o Infrared (IR): Used to sense invisible radiant energy with longer wavelengths
than those of visible light. Widely used in security/alarm systems to detect
motion at night, where visibility is low or non-existent.
e Pressure: Pressure sensors detect pressure. They are used in a variety of settings,
including touch-screen devices, as well as the automotive industry (they regulate the
engine power according to the pressure on the pedals) and others.
e Temperature: Temperature sensors detect temperature. They are widely used
within thermostats to control the temperature of a given setting.
e Proximity: Proximity sensors can detect the presence of nearby objects without any
physical contact. They are widely used in cars to help drivers reverse or park.

7.1.4 The relationship between a sensor, the processor and an output transducer
Exit skills. Students should be able to':

Describe the relationship between a sensor, the process and an output transducer.
Technical hardware details are not expected.
In the previous chapter, we learnt how a sensor senses continuous, physical (analogue)
quantities (such as speed, temperature, humidity, pressure, etc.) as analogue signals. It then
transforms these analogue signals into discrete, digital ones using an analogue-to-digital
converter (ADC). These signals can then be read as input by processors. The input is
processed according to some algorithm(s), and output is delivered.

A processor performs arithmetical and logical operations and is the core element of any
computer system. It receives input, in electrical form, from a number of sensors (from
sensors on a tracking device, such as a mouse, to motion sensors above automatic doors)
and performs some sort of output (from moving a mouse cursor to opening doors).

In the process of sensing physical quantities, using sensors, and transforming them into
analogue signals, a conversion takes place. The device that converts one form of energy to
another is called a transducer. Transducers, in computer systems, are responsible for
converting physical quantities (such as speed, temperature, humidity, pressure, etc.) into
electrical signals, as well as vice versa. The conversion process from one form of energy to
another is called transduction.

Sensors can be categorized as transducers, as they sense a physical quantity and transform it
into another form of energy (typically an electric signal). However, other devices (apart from
sensors) can be categorized as transducers. The most common of these are called actuators
and are used during the output. Actuators are the devices responsible for moving some kind
of mechanism. They are transducers in that they receive some form of energy (usually
electric current) and convert it into motion. Control systems use actuators to perform some
actions in an environment (for example, a mechanical motor in an automatic door is an
actuator that receives electric current and converts that form of energy into kinetic energy
so that the motor moves and the doors open).

Input Signal ' Transducer § G { Fransducer Output


(Sensor) | ‘ pr=s! B LI
Physical | ‘ (ex. motion)
quantity

ADC: Electronic DAC: Electronic


signal signal
Figure 7.2: Input, process, output and transducers

Figure 7.2 depicts how a control system that uses a processor works as an input, process,
and output device. An input signal is recorded by a sensor, which transforms the physical
quantity into an electrical signal. Since it converts one form of energy to another, the sensor
is a transducer. The electrical signal is further converted into an electronic signal, using an
analogue-to-digital converter (ADC), so that it may be processed by the processor. After the
processor runs any necessary algorithm(s) on the input data it outputs an electronic signal.
That output is converted into an electrical signal, using a digital-to-analogue converter
(DAC), so that it may be used as input to an actuator. The actuator will convert the electrical
signal into motion. Since the actuator converts one form of energy to another, it is a
transducer.

7.1.5 The role of feedback in ontrol system


Exit skills. Students should be able to"

| Describe the role of feedback in a control system.


| LINK Connecting computational thinking and program design.

Feedback was discussed in section 7.1.1 and described in Figure 7.1. Feedback refers to the
process where information about the result of an output, from a control system, is used as
part of the new input to the control system in order to determine the best course of action
for the next output. Feedback is a loop as shown in Figure 7.1.

Feedback is essential to control systems that need to react to their environment and its
changes. For example, as discussed in section 7.1.1, there can be two kinds of traffic lights,
fixed time and dynamic control. Fixed time traffic lights do not take the environment into
account and just change color after a pre-programmed amount of time. On the other hand,
dynamic control traffic lights use sensors to take the environment into account every time
the lights change color. Imagine the following scenario: A dynamic control traffic light uses a
sensor to identify when no cars are near and changes the car lights from green to red, so
that the pedestrians can pass. This action is the output. The traffic light then receives
feedback from this action (a line of cars starts forming) and uses that feedback as input in
order to turn the car lights green again when a long line has been formed. The input first
affected the output (no cars, so the car lights turned red), the output affected the input (a
line formed), and the new input affected the output (the car lights turned green). After a
while, the output would affect the input again. The feedback keeps the system in a stable,
working state avoiding long queues on the road and helping pedestrians cross safely.

Another example of how important feedback is in a control system, and how it keeps the
system stable, was described in section 7.1.1, during the discussion about process control.

7.1.6 Social impacts and ethical considerations associated with the use of
embedded systems
Exit skills. Students should be able to:

i S/E For example, tagging prisoners, surveillance, CCTV, improved safety systems.
e Electronic tagging (tagging prisoners)® ’: Offenders that have been found guilty of
minor offences, inmates that are entitled to leave time (vacation time away from the
correctional center), or individuals under house arrest may be “tagged” with the use
of electronic monitoring devices.
Overcrowding of correctional facilities impacts their ability to provide effective
rehabilitation. Minor offences can be efficiently dealt with using prisoner tagging.
Each individual wears a bracelet or anklet that uses GPS to allow correctional |
officers to monitor their location at all times. Tampering with the device or trying to
remove it raises an alarm.
Electronic tagging has been shown to effectively deter crime, as well as save habitual
offenders from a continued life of crime. Monitored offenders were less likely to
abscond or commit new offences than those not monitored. Electronic tagging
benefits society immensely by reducing crime rates, reducing the money spent on
crime. There are a number of “hidden” costs surrounding any crime; for example,
the time spent by police officers to solve it, instead of working to prevent possible
future crimes. One should also consider court rooms and lawyer’s time, as well as
the occupation of prison cells and the need for the creation of further correctional
facilities if the number of offenders increases.
Electronic tagging could also improve the rehabilitation and reintegration of
offenders, by allowing them to leave the correctional facilities sooner (or not enter
at all), maintain gainful employment, as well as contact with their families.
However, there is plenty of criticism concerning prisoners’ electronic tagging. First of
all, one could argue that it is a very lenient form of punishment. Furthermore, it
does not physically restrain offenders and allows them to perform further illegal
actions, if they want to. Having a large number of offenders outside the correctional
facilities with electronic tags needs a large task force of individuals that can monitor
them and intervene whenever necessary. If the offender performs an illegal action
and raises an alarm (but the task force does not have enough officers to intervene
because they are all occupied with other tasks), the idea behind the electronic
tagging is rendered useless.
Another argument against the
tagging of offenders is that wear-
ing an electronic tag may add
psychological pressure to the
wearer, especially to the younger
offenders.
Apart from offenders, electronic
tagging could be used to monitor
the whereabouts of people with
health problems such as dementia Image 7.10:
A CCTV camera
(ex. Alzheimer’s disease). Finally,

® Electronic tagging. (26, February 2016). In Wikipedia, The Free Encyclopedia. Retrieved 19:30, May
16, 2016, https://en.wikipedia.org/wiki/Electronic_tagging
7 prisoner e-tagging a 'resounding success'. (23, May 2012). In iTWeb. Retrieved 19:08, May 28, 2016,
http://www.itweb.co.za/index.php?option=com_content&view=article&id=55068
electronic tags could also be placed on immigr
ants, preventing them from staying in
a country illegally.
Surveillance, CCTV (Closed Circuit Television):
Over the past years a large number of
cameras have been installed on highways and cities
in various countries around the
world. CCTV cameras can often be spotted on top of or near traffic lights and
intersections, in parks, outside shops or any other position. People are now so
accustomed to them that they do not even notice
their existence. Recent advances
in computer graphics and artificial intelligence have enabled CCTV systems to use
algorithms for facial recognition, as well as licens
e plate recognition, to locate or
follow a target.
CCTV supporters claim that by using this survei
llance technique, street and shop
crimes are reduced, drivers follow the rules of the
road, and in general individuals
are not tempted to perform illegal acts.
However, there are a number of questions to
be answered:
o0 How many CCTV cameras should operate in an area
before surveillance
becomes excessive, to the point of loss of privacy?
o Can the information from surveillance techn
iques ever be misused or fall in
the wrong hands?
o Do surveillance techniques actually reduce crimes
or do they just alter it (for
example, move it to some other non-surveilled
area, or within households,
where CCTV cannot be installed yet)?
o Should workplaces install CCTV cameras or other electronic means to
monitor their workers?
o Should schools install CCTV cameras or other
electronic means to monitor
both students and teachers?
© Are citizen rights more important than preven
tion of potential wrongdoing?

Surveillance has a myriad of social impacts and


ethical considerations that must be
taken into account. Most forms of electronic
surveillance systems are embedded
control systems.
Improved safety systems: After any system, from an elevator to a car, has been
developed and deployed into the wider world,
it is subject to everyday use. This use
may not always be as intended.
For example, too many people may enter
an
elevator, increasing its weight, beyond what
can be handled by the elevator’s motor.
Another example could be a car driven into a wall.
Safety systems are put in place so
as to avoid such unfortunate events. Howev
er, since everyday life is full of
unexpected events that cannot be predicted, safety systems improve in order to
anticipate them as much as possible. Sometimes these events are properly dealt
with. For example, when too many people enter an elevator, a warni
ng light comes
on and the elevator does not move until enough
people have left. Another example
could be the airbags deployed during a car crash
to protect the passengers.
In general, safety systems are put
into place to protect anything that
might be harmed when something
does not go as planned. Safety
systems are upgraded and improved
when they are used but fail for some
reason. For example, front airbags
were developed to avoid injuries
during car crashes. However, in a
number of accidents, cars had been
struck from the sides. The
passengers were injured, since the
front airbags did not protect them.
Side airbags were created to
minimize harm in these accidents.
The airbag, as a safety system, was P s
improved. Car brakes are a similar Image 7.11: Airbag safety system
case of the new safety system being
improved from the failure of the previous safety system. Forcefully using the car
brakes resulted in the locking of the wheels which generated the car skidding, which
led to a larger distance covered before the car stopped, compared to when the

wheels did not lock. Following these observations, the Anti-lock Braking System
(ABS) was developed, to improve the car braking safety system, by preventing the

wheels from locking and skidding. This way the stopping distances decreased.

Distributed systems

7.1.7 Comparison of centrally controlled system.


Exit skills. Students should be able to™:

Compatre centrally controlled systems with distributed systems.


Technical hardware details are not expected.

In its simplest form, a centrally controlled system is a system with a dedicated computer

system that is responsible for all the necessary calculations, as well as anything else that
needs to be performed so that the control system can function. On the other hand,
distributed systems have multiple computers, with each one performing part of the
necessary calculations, as well as anything else needed for the control system to function.
There are arguments to be made for both systems.

e Centralized systems: All computer resources reside in a single computer system.

Client devices need to be able to connect efficiently and effectively to that single
computer system.
The benefits are (usually) lower operational costs (as each client needs minima
hardware), greater security (as all data is centrally stored), less administrative
overhead and backup complexity (since all
resources are in a single location), as wel'
as greater overall control.,
One of the disadvantages is that clients need
to connect to the central system o
perform any necessary actions, making
the connection a probable point of failur
e. =
the single computer system or the connection
to it fails, the whole system is not able
to function effectively.
® Distributed systems: Computer resources
are distributed across various systems
ana
each system is self-sustaining for the
most part. A central system may exist
tha:
coordinates the
rest of the systems in some way, but
each system has all the
necessary resources to perform any necessary
action on its own, without needing to
communicate with the central system every time. Even if there is no connection o
the central system, there would be no catastrophic failure and the distributed
system, as a whole, would still function correctly. Distributed systems are easily
expandable since self-sustained systems
may be added or removed at any point
in
time without affecting the overall system.
The disadvantage to this approach is (usually) its cost. It requires additiona!
hardware to be present at each system,
so that it can operate on its own, as well
as
special software that allows each system
to do so. Backup of the system requires
more bandwidth or resources at each site,
adding to the cost and the complexity of
the system. Security can also be an issue, since
it is more difficult to control ang
secure a number of systems than a single
one.

Cost is a variable factor when comparing centralized to distributed systems.


al, In gener
distributed systems require additional hard
ware that increases the cost of the whole
system.
However, centralized systems require
a single computer system that is very
powerful in
order to efficiently and effectively coord
inate the system as a whole. As such, the
very powerful computer system and its cost of 2
maintenance may be higher than the
cost of the
additional hardware needed in distributed
systems, or vice versa.

Here is an example
of traffic signal control systems®, which may be either centrally-
controlled or distributed:

e Centrally controlled systems:


Every light on each intersection depends
on the
availability of an effective communications
network. Every light needs to be able to
communicate with the central computer
in a real-time fashion and will not be able
to operate, at least as effectively, if the
communication is lost. If the central
computer stops operating, all the intersections are affected and stop operating
effectively. Fault-tolerant systems exist, with two identical
central computers, so
that if one fails the other can take over.
Also, a central computer has a maxi
mum
load limit, meaning that it cannot be respo
nsible for real-time coordination of an
unlimited number of traffic lights at inter
e L e sections. A central control system is
not
® Traffic Signal Control Systems. (2011).
In United States Department of Transporta
Innovative Technology Administration. tion, Research and
Retrieved 18:50, May 20, 2016,
http://ntl.bts.gov/lib/jpodocs/edldocs1/
13480/ch3.pdf
easily expandable and requires a significant amount of investment in order to do so.
However, centralized real-time adaptive control algorithms may easily be installed
and real-time surveillance of the system allows for better control of the system.
Distributed systems: A powerful and robust control system at the intersection is
responsible for the traffic lights. It does not receive or transmit mandatory real-time
control commands over the communications network. It can even operate when the
central computer (that is responsible for the grid of traffic signal control systems) is
not available. Connection to the central computer is limited and only necessary for
synchronization purposes. Expansion of the system is easy, just by adding new traffic
lights and their infrastructure, and does not affect the rest of the system.
Centralized real-time adaptive control algorithms and surveillance are not available,
but may be substituted by local adaptive control algorithms runnig at each
intersection.

tem

Exit skills. Students should be able to™:

[ Explain the role of autonomous agents acting within a larger system.


l Technical hardware details are not expected.

Agents can be anything that can perceive its environment, through sensors, and act upon it,
through effectors. Examples of agents may be humans (that have eyes, ears and other
sensors) to robotic agents (that have cameras, sonars and other sensors) and software
agents (that have sensors in the form of bits and can sense their digital environment through
those sensors).

Autonomous agents are entities operating on


behalf of an owner (usually a user or another
program) with a degree of autonomy and
with minimal to no interference from the
owner. These agents follow algorithms
supplied by the owner to achieve some
desired goal(s). Examples of autonomous
agents include autonomous robots, software
agents that search the world wide web,
software computer viruses, etc. Autonomous

agents perform actions that depend on their Image 7.12: Autonomous agent (car)
own “experiences” through their sensors.
They can apply different sets of pre-programmed actions in different situations and even
build their own set of actions through learning algorithms. Autonomous agents display
artificial intelligence in that they need to “reason” according to their acquired knowledge.
The representation of knowledge is a key-concept for those agents.
The environment within which agents operate plays a significant role in the desz
implementation and effectiveness of the agents. Most of the times, agents do not hawe
complete control over their environments. They can
perceive and influence some of ===
environment, and the environment may then influence
the agents in return. The complex=
of the agent’s decision-making is affec
ted by the properties of the environmen
t?:
e An environment may be accessible or inaccessible, and
may or may not be able ==
obtain complete and accurate infor
mation of the environment. Most real
worie
environments fall under the inaccessib
le category, where the environment
is too bE
for an agent to be able to sense it as a whole
and senses only a subset.
® An environment may be deterministic or non-deterministic, according to whethar
an agent’s action will have a pre-defined,
guaranteed, effect without any possibit=y
of uncertainty or not. In a determinis
tic environment, the next state of ===
environment is determined by its current
state and the agent’s action. Most re=
world environments fall under the non-deterministic categ
ory, in that they are oz
complex, are affected by various elements,
and probably ever-changing.
® An environment may be episodic or non-episodic, accor
ding to whether an agent =
actions are divided into “episodes” or
not. If they are divided into “episodes”,
the
next episodes do not depend
on the previous episodes and an actio
n’s output wt
not depend on what actions the agent took befor
e. Most real world environmenz=
fall under the non-episodic category,
in that the agent’s earlier actions
affect tme
future actions.
® An environment may be static or dynamic,
and may or may not change while
the
agent is deliberating an action. Most
real world environments fall under the
dynamc
category, in that an environment is
independent of the agent and does
not wait far
an agent’s action before it changes.
® An environment may be discrete or continuous, depending on the number o
distinct and clearly defined states that it may or may not be in. Most real wori=
environments fall under the continuous
category.

Useful Information: The book “Artificia


l Intelligence: A Modern Approach”®®
by Stuart
Russell and Peter Norvig is a great
read and resource that goes well beyo
nd the I8
syllabus. Chapter 2, which deals with
Intelligent Agents can be read at link:-
http://www.cs.berkeley.edu/”russell/ g
aima1e/chapter02.pdf

Having understood the meaning of


autonomous agents and their environment, a number oF
examples follow illustrating the role of auto
nomous agents within a larger system.

e
° Stuart Russell, Peter Norvig. Artificial
Intelligence: A Modern Approach, Upper
Jersey, 1995) Saddle River (New

112
Autonomous agents in space missions'’: Autonomous agents may be of help in both
unmanned and manned missions. One type of unmanned mission that needs to take
place every day, all day (24/7) is the control and coordination of satellites orbiting
Earth. Before the use of
autonomous agents, 2-3 persons
were needed per satellite. With
the increase in the number of
satellites this led to a large
number of staff responsible for
their control, which resulted
(amongst other things) in a large
financial burden.
Another type of unmanned
missions with difficult and/or Image 7.13: Autonomous space agent
restricted time frame commu- 1
nication with the device(s) launched in space, are the deep space missions. Sending
a message from Earth to a planet far away, such as Mars or Jupiter, takes minutes or
even hours, and may only be available for only a few hours per day. The bandwidth
of the connection is also limited. As such, these devices cannot be controlled in a
real-time manner. However, they need to be able to act in a real-time manner, as
well as be able to face any situations when communication with Earth is unavailable.
Autonomous agents allow deep space mission devices to perform real-time tasks
when connection to Earth is limited or non-
existent, preventing pitfalls and unwanted
situations.
In manned missions, the crew spends a long
period of time, each day, in monitoring and
maintaining. Monitoring is a repetitive and
mundane task. Furthermore, most mistakes in
manned missions are made by humans that may
let something go unnoticed due to negligence or
tiredness. Autonomous agents can be
responsible for monitoring both everyday tasks,
as well as human actions while performing some
maintenance tasks.
Of course, it is impossible to take into account all
the possible events that could occur. As such,
autonomous agents that do not request human
intervention in unfamiliar circumstances could Image 7.14: Probable future
: S autonomous agent picker robot
lead to errors and to the detriment of a mission.

% Stefan Biittcher. Autonomous Agents in Space Missions. Course project for C5886 — Multi-Agent
Systems for Real-World Applications, University of Waterloo, Spring 2004. Retrieved 19:25, May 31,
2016, http://stefan.buettcher.org/cs/cs886/project.pdf
© Autonomous agents in warehouses™!: Autonomo
us agent robots named “Kiva” (or
Amazon robots or bots) are already operating in Amazon'’s warehouses. These
robots carry shelves of products to human worke
rs, who in turn pick the items that
need to be shipped. This automation allows for
the shipping of a far larger number
of items to costumers than just using human workers. Apart from these bots,
Amazon created the Amazon Picking Challenge (APC), in which
researchers
competed for building a new bot that would be able to perform the item picking
process, instead of human workers. The challenge was hard and most teams failed
completely, while the ones that managed to perform better
still performed a lot
worse than humans. However, the challenge
showed that these difficulties might
soon be overcome. In all likelihood, bots contr
olled by autonomous agents will soon
be used in warehouses around the world.
® Autonomous agents in cars'® > *. The idea of fully auto
nomous cars has been a
worldwide endeavor for many years. The DARPA (Defense Advanced Research
Projects Agency) Grand Challenge was the
first ever competition to formalize this
aim, offering prize money to the team able to
build a driverless car that could avoid
obstacles and reach a certain goal. Since that time,
a number of autonomous vehicle
prototypes and tests have been conducted, in
both urban and rural settings, with
increasing success. Autonomous agents are the “brain” of every such autonomous
vehicle. Agents use sensors to read informatio
n about the car’s internal and external
states, processthe information, and act on it. Agents need
to act correctly in an
inaccessible, non-deterministic, non-episod
ic, dynamic and continuous environmen
t
that is extremely complex.
® Autonomous agents in video games™: As video games have improved in quality
throughout the years and the industry has
grown to be one of the most important in
the entertainment business, games have pushe
d the barriers further in various fields
of computer science (including graphics and
f T
artificial intelligence), in order to get better
,
more realistic appearances and behaviors.
This need for complex and sophistica
ted
environments cannot depend on pre-
programmed elements that loop or always
repeat the same patterns of behavior.
Agents need to be installed reacting in a .
manner that will not repeat over time. Image 7.15: Autonomous agents in games

eO R E
- Amazon, robots and the near-future rise
of the automated warehouse. (26, January
TechRepublic. Retrieved, 18:00, May 31, 20186, 2016). In
http://www.techrepublic.com/article/amazon—ro
and-the-near-future-rise-of-the-a utomated-w bots-
arehouse/
** DARPA Grand Challenge. (25, April 2016).
In Wikipedia, The Free Encyclopedia. Retrieved
May 31, 2016, https://en.wikipedia.org/wiki/ 19:52,
DARPA_Grand_Chal!enge
2 Autonomous car. (26, May 2016). In Wikipe
dia, The Free Encyclopedia. Retrieved 19:55,
2016, https://en.wikipedia.org/wiki/Autonomous May 31,
_car
Google Self-Driving Car project, https://www.goo
gle.com/selfdrivingcar/
** Thannia Blanchet. Autonomous Agents in Video
games. Retrieved 19:25, May 31, 2016,
http://www.cs.unm.edu/"‘pdevineni/papers/Blan
chet.pdf
End of chapter example questions with answers

Exercise 1: A control system is used to control an elevator car to allow people to go to their
desired floor in a building.

1 Identify various types of sensors in this system.


Identify other pieces of hardware, other than sensors, that are part of the
control system.
Outline the sequence of steps that will take place within the compute
r control
system, when a person presses the button to call the elevator.
Define the term interrupt, as well as a situation in which it may occur
in this
system.

Answer to Exercise 1:

Three sensors that will be present in this system are: proximity, motion and
pressure. :
Other pieces of hardware may include a microprocessor, actuators, transducers,
as well as analogue-to-digital and digital-to-analogue converters.

When a person presses the button, the pressure sensor is activated.


The signal is sent to the
microprocessor that determines when the
elevator car should arrive at the floor where the person resides.
A signal is sent to the actuators/transducers to move the car to
the floor
on which the person pressed the button.
After arriving on the floor, another signal is sent to the
actuators of the
automatic door to open the car doors.
After a fixed time and if there is no other input in the motion
sensor of
the automatic doors, the doors close.
Assignal is sent to the actuators to move the car to the desired
floor.
After arriving on the floor, another signal is sent to the
actuators of the
automatic door to open the car doors so that the person steps
out.

This sequence of steps is a simplified version of what might happen


in
real life, since a microcontroller must take into account a number of
other factors. For example, other people may need to be served
at the
same time or an indication that the maximum elevator car weight was
reached.
A signal sent to the processor (by either software or hardware)
requesting the
processor’s immediate attention to a specific event is an interrupt. An example
of where this might be used in the elevator control system is the
following. After
the elevator reaches a desired floor and opens its automatic doors
to unload
and load people, the doors start closing. At that point a person
that wants to
enter the elevator puts his/her foot between the two closing
doors. A (light or
pressure) sensor would sense that the doors did not close
and that there is an
object between them and would send an interrupt to the processor to open the
doors.

Exercise 2: Discuss how computer control systems have been used throughout industries to
replace human workers in various accounts.

Answer to Exercise 2: Computer control systems can work 7 days a week, 24 hours a day
(24/7), all year round. They also work tirelessly and accurately, performing monotonous
tasks without any complaints. They can also be used
in dangerous environments, such as
radioactive, or where there are a lot of fumes, fires, etc., or in environments that cannot be
(easily) reached by humans, such as deep sea, space, etc. The initial cost of a computer
control system is usually considerable, but once set up, the system will be more economical
in the long run. Also, it will reduce labor cost, may increase the quality of work, as well as
performance and productivity. Finally, since there will be fewer workers involved, safety will
increase. However, such systems may lead to an increase of unemployment and workers
made obsolete will need to retrain in order to find a different kind of job.

Exercise 3: Describe how a GPS device can locate its position.

Answer to Exercise 3: Read section 7.1.1.

Exercise 4: Describe how control traffic lights can function dynamically.

Answer to Exercise 4: Read section 7.1.1.

Exercise 5: An intersection of a main road and a secondary road is regulated by a set of


traffic lights. The secondary road is a one way street. Pedestrian lights are also present
allowing people to cross the secondary road.

e By the press of a button, the pedestrian lights, as well as the traffic lights on the
main road change to green (Go), while the traffic lights on the secondary road turn
red (Stop), allowing people to cross the road.
e If no pedestrians want to cross and there is a vehicle on the secondary road, the
pedestrian lights and the traffic lights on the main road turn red (Stop) and green
(Go) on the secondary road.
e Otherwise, on all other accounts, every two minutes the traffic lights on the main
road, as well as the pedestrian lights, change from green (Go) to red (Stop), while
the traffic lights on the secondary road change from red (Stop) to green (Go), and
vice versa.
Traffic lights

Main road

®
Button Pedestrian lights

Secondary road

1. Suggest how the sensors and the microprocessor controlling the traffic lights

may “sense” a vehicle approaching on the secondary road and perform all the
necessary steps.
2. Define the term interrupt, as well as a situation in which it may occur in this
system.

The intersection is located in a small town, far from any major cities. As such, its
communications network is not very good and is constantly unavailable.

3. The traffic lights installed in the intersection can either belong to a centrally
controlled system or a distributed one. Discuss the advantages and
disadvantages of both.

Answer to Exercise 5:

a. Either a touch/weight sensor in the road or a camera on top of the

traffic lights may be installed to detect an approaching or waiting vehicle


on the secondary road.
.~ b. An analogue-to-digital converter is used to convert the analogue signal
from the touch/weight sensor to its digital counterpart. The same
applies to the camera.
c. The digital signal (either the weight or an image) is processed by the
microprocessor.
d. Finally, a signal is sent to the traffic lights so that the pedestrian and the
main road traffic lights turn red (Stop), while the traffic lights on the
secondary road turn green (Go).
2. A signal sent to the processor (by either software or hardware), requesting the
processor’s immediate attention to a specific event, is an interrupt. An example
of where this might be used in the traffic lights control system is the following:
A vehicle approaches from the secondary road and the sensors send a signal to
the microprocessor. At the same time, a pedestrian that wants to cross the
secondary road presses the pedestrian
lights button. An interrupt signal is sent
to the microprocessor requesting the processor’s
immediate attention, changing
the traffic lights on the secondary road to red (Stop), while
the pedestrian lights
turn green (Go).
3. Since the intersection is located in a small town,
far from any major cities, and as
such, its communications network is not very good
and is constantly unavailable,
running the town’s traffic lights on a distributed system
may lead to poor traffic
light performance due to connection failures. Even if a powerful central
computer is installed, if the connection to the traffic lights
is not reliable, the
traffic lights would not function properly. For further
advantages and
disadvantages read section 7.1.7.

Exercise 6: Discuss the ethical and social implications of forcing


people to carry GPS devices.
Provide specific examples.

Answer to Exercise 6: Read section 7.1.6.

Exercise 7: Discuss the ethical and social implications of countries and/or individuals
installing CCTV cameras throughout cities and/or around
their homes.

Answer to Exercise 7: Read section 7.1.6.

Exercise 8: A number of control systems may be used around


the house such as:

® smart heating systems that turn on/off automaticall


y as needed
® automatic doors/windows that open/close or even lock
as needed
e lighting that turns on/off/dim or even changes colors as
needed
e air conditioning that turns on/off as needed
® automatic cleaning that turns on/off as needed

1. Discuss how a user may access these systems.


Discuss two advantages of incorporating such technology
inside the house.
Answer to Exercise 8:

1. The control systems described, as well as any other


control system centered around
the house could be accessed and controlled in one of
the following ways:
® Via aremote control:
o May be misplaced within the house.
o Needs batteries or to be charged to function.
o Portable enough to access the systems from anywhere
in the house.
e Via a fixed remote control:
o Installed on a wall in the house.
o The user knows where the control is, as he/she cannot move it.
o Does not need batteries to operate.
e Via computer/smartphone:
o May be misplaced or lost.
Needs to be charged to function.
Requires internet/Wi-Fi connection to function.
Control systems may be accessed from far away.
Extremely portable.

2. The advantages of incorporating such technology inside the house include the
following:
a. Cost reduction: By scheduling exactly when these control systems function,
one can control expenses, reduce costs and save energy.
Improved comfort: By scheduling exactly when these control systems
function, one can cater for his/her specific needs. For example, he/she can
turn the heater on just before leaving work and arrive to a warm house.
Chapter References

International Baccalaureate Organization. (2012). IBDP Computer Science


Guide.
Control System. (12, May 2016). In Wikipedia, The Free Encyclopedia. Retrieved
19:05, May 13, 2016, from https://en.wikipedia.org/wiki/Control_system
Smart thermostat. (19, April 2016). In Wikipedia, The Free Encyclopedia. Retrieved
19:25, May 13, 2016, https://en.wikipedia.org/wiki/Smart_thermostat
Dimitriou K. Hatzitaskos M. (2015). Core Computer Science for the IB Diploma
Program. Athens: Express Publishing. More information at:
https://www.expresspublishing.co.uk/gr/en/content/core—computer—science-ib—
diploma-program
List of sensors. (19, April 2016). In Wikipedia, The Free Encyclopedia. Retrieved
19:30, May 13, 2016, https://en.wikipedia.org/wiki/List_of_sensors
Electronic tagging. (26, February 2016). In Wikipedia, The Free Encyclope
dia.
Retrieved 19:30, May 16, 2016, https://en.wikipedia.org/wiki/Electronic_tagging
Prisoner e-tagging a 'resounding success'. (23, May 2012). In iTWeb. Retrieved
19:08, May 28, 2016,
http://www.itweb.co.za/index.php?option=com_content&view:article&id:S5
068
Traffic Signal Control Systems. (2011). In United States Department of
Transportation, Research and Innovative Technology Administration.
Retrieved
18:50, May 20, 2016, http://ntl.bts.gov/lib/jpodocs/ed]docsl/l3480/ch3.pdf
Stuart Russell, Peter Norvig. Artificial Intelligence: A Modern Approach
, Upper
Saddle River (New Jersey, 1995)
10. Stefan Blittcher. Autonomous Agents in Space Missions. Course project
for CS886 —
Multi-Agent Systems for Real-World Applications, University of Waterloo
, Spring
2004. Retrieved 19:25, May 31, 2016,
http://stefan.buettcher.org/cs/csSSG/project.pdf
alil, Amazon, robots and the near-future rise of the automated warehouse.
(26, January
2016). In TechRepublic. Retrieved, 18:00, May 31, 2016,
http://www.techrepublic.com/article/amazon—robots-and-the-near~future—ri
se-of—
the-automated-warehouse/
125 DARPA Grand Challenge. (25, April 2016). In Wikipedia, The Free Encyclope
dia.
Retrieved 19:52, May 31, 2016,
https://en.wikipedia.org/wiki/DARPA_Grand_ChaIIenge
13. Autonomous car. (26, May 2016). In Wikipedia, The Free Encyclopedia.
Retrieved
19:55, May 31, 2016, https://en.wikipedia.org/wiki/Autonomous_car
14. Google Self-Driving Car project, https://www.google.com/selfdrivingcar/
157 Thannia Blanchet. Autonomous Agents in Videogames. Retrieved 19:25,
May 31,
2016, http://www.cs.unm.edu/’“pdevineni/papers/Blanchet.pdf

el
Chapter 4
TOPIC D - Object-oriented programming

3 Topic D - Object-oriented programming?

Tool used
All Java programs were written and tested in Bluel, which can be downloaded from the
following link:

http://www.bluel.org/

The Bluel development environment was created by the University of Kent and is ideally
suited for students.

Useful Information: Although it is assumed that all students who choose


to take Topic v
1
D — Object Oriented Programming have mastered (up to a point) coding 1
in Java, there 1
is no easy or slow introduction in the syllabus content. 1
1
1
As such, it is up to the students or the teachers to find books, online material or 1
1
presentations on programming with Java. This is not always easy to do and although i
1
there is a plethora of tutorials on the Internet, some may be very 1
advanced, some 1
may not be complete and some may not even be accurate. As such, 1
a list of helpful 1
1
resources are given below. These free resources are most 1
helpful and should be at 1
least considered by any student learning Java. They are presented 1
in the order in 1
which they should be studied. They also include exercises. 1
1
1
1
1
1. Introduction to Java Programming: 1
1
http://www.ntu.edu.sg/home/ehchua/progra mming/java/Jla_Int 1
roduction.h 1
1
tml 1
i
2. Java Programming Tutorial: 1
1
http://www.ntu.edu.sg/home/ehchua/programming/java/JZ__Basic 1
s.html 1
3. Java Exercises: I
1
1
https://www3.ntu.edu.sg/home/ehchua/programming/java/JZa_Bas
icsExerci 1
i
ses.html 1
1
4. Java —Tutorial: 1
i
1
http://www.tutorialspoint.com/java/index.htm 1
1
i
D.4 Advanced program development

D.4.1 The term “recursion”

Exit skills. Students should be able to’:

R term recursion.

Recursion was identified and explained in sections 5.1.1 to 5.1.3, “Thinki


ng recursively”.
Situations where recursion is useful were presented and recursive
algorithms were traced.

Recursion is a specific approach to problem solving in computer science. In this approach,


the solution to a problem depends on solutions to smaller instanc
es of the same problem.?

In programming, recursion happens when a procedure (method) calls


itself until some
terminating condition is met. This is accomplished without
any specific repetition construct,
such as a while or a for loop. Recursion
follows one of the basic problem solving
techniques, which is to break the problem at hand into smaller subtask
s (divide and
conquer). Most algorithms that may be presented in a recursive manner
may also be
presented in an iterative manner and vice versa.

D.4.2 Application of recursive algorithms

Exit skills. Students should be able to®

| Understand that recursion can be applied to a small subset


of programming problems
| to produce elegant solutions.
Understand that recursive algorithms are rarely used in
el (o [ol- 1
INK Think abstractly, think recursively.

In some cases, recursive algorithms can produce “simpler” and


“cleaner” code compared to
their iterative counterparts if used wisely. This code is easier
to understand and maintain
and, as such, useful to have, when possible. Sometimes “simpler” and “cleaner” code is
preferred even if it is not the most efficient. Below, a number
of algorithmic examples are
compared, solved in both iterative and recursive version
s:

® Factorial: A factorial function is defined mathematically as


follows:
_ { 1,ifn=0
= rm=-1Lifn>0

41 = 4*3%2*1*1 = 24, The following two code snippets find the


factorial of a positive
integer number n. The left-hand is an iterative version, while the right-hand is a
recursive version.
e e
% Recursion (computer science). (27, May 2016). In Wikipedia,
The Free Encyclopedia. Retrieved 13:39,
June 3; 2016, https://en.wikipedia.org/wiki/Recursion_(computer
_science)
e e Recursive version

public int fact(int n) { | public int fact(int n) {

int answer = 1; if (n == 0) return 1;

for (int i = 2; i <= n; i++) ! return n * fact(n - 1);


{ }
answer = answer * i;
}
return answer;

Both of these versions are “simple”, “clean” and can be understood easily enough.
The iterative version is a little longer and uses a while loop, while the recursive
version includes a base case (when n is equal to 0) and calls itself n times. Each time
the recursive version calls itself, it causes some memory to be allocated.

Figure D.1 presents how memory is allocated every time a recursive function calls
itself, assuming that the factorial of number 4 is to be found (so fact (4) is called).
After fact (4) needs toreturn 4 * fact(3).To do that, fact(3) is called, while
fact (4) is still running (it has not returned yet, since it has called fact(3)).
fact (3) needs to return 3 * fact(2) and so fact(2) is called (with fact (4)
and fact (3) still running). fact (2) needs to return 2 * fact(1). So, fact (1)
is called that needs to return 1 * fact(0). n == 0 is the base case and so
fact (0) simply returns 1. The base case is the case that stops the recursion from

Memory used
>

25 Eaei (1)

Aot (3

4*fact (3)

Figure D.1: Memory allocation in recursive function


running infinitely. It does not call another fact
method. At this point, fact (4),
fact(3), fact(2), fact(l) and fact(0) are all taking up space in the
memory. Finally, fact (0) first returns, so fact (1) may then return
, so fact (2)
may return, so fact(4) may return at the end with the final result
. The recursive
version of the factorial algorithm to compute the factorial of
n generates n-1
recursive calls, rendering this algorithm inefficient compared to its iterative
implementation.

As it is becoming apparent, calling methods


recursively uses up memory quickly and
can result in the system stack running out of
memory (as explained in sections 5.1.6-
5.1.7). In this example, this could happen if a large number were given to the
recursive version of the factorial algorithm.
Recursion is a powerful concept and tool
that allows for elegant, simple solutions to problems, but may result in inefficient
algorithms if not used wisely.

® Fibonacci: A Fibonacci function is defined


mathematically as follows:

0,ifn =0
F, = Lifn=1
Foa+ Fpsifn>1

Every number after 2 is the sum of the preceding two numbers. So, the first
Fibonacci numbers are the following: 1,
1, 2, 3, 5,8,13,21..

The base cases of a recursive algorithm


would be F, and Fi.

public int fib(int n) { public int £ib(int n) {


int fib = 0;
int temp = 1; i if (n < 2) return n;
for (int i = 0; i < n; i++) { return fib(n-1) + f£ib(n-2);
£ib = fib + temp;
}
temp = fib;
}
return fib;
}

Comparing the iterative to the recursive


version for the Fibonacci numbers, one
can
appreciate the simplicity and cleanness
of the recursive code. The recursive codei
s a
lot more intuitive and can be easily understood. It resembles the mathematical
definition closely and it is also shorter than its iterative version. As such, the
recursive version of the algorithm that computes Fibonacci numbers is much more
elegant. Unfortunately, the time difference required for the computation of a

Useful Information: It might be useful to


return to section 5.1.3, where a recursive
1

algorithm was traced to express a solution


]
to a problem.
)
5
1
number between these two versions is enormous, with the iterative
Fibonacci
version being a lot faster.

Euclidean greatest common divisor (GCD): A Euclidean GCD function is defined

mathematically as follows:

xifx =y
Forx,y > 0,gcd(x,y) = y9cd(x,y — x),ifx <y
ged(x—y,y),ifx>y

It is probably the oldest recorded recursive algorithm in history (around 300 B.C.). To
find the greatest common divisor of two numbers, x andy:

o Subtract the smaller of the two numbers from the larger one repeatedly,
until the resulting difference d is smaller than the smaller of the two initial
numbers, x and y.
Repeat the same steps with d and the smallest of the two numbers from the
previous step.
Continue until the two numbers are equal. That number is the GCD of the

two initial number.

For example, if initial x is 420 and y is 96 then the algorithm would work as follows:

Step 1: 420—96 = 324,


324 -96 =228,
228 —96 =132,
132 - 96 = 36.
Therefore d = 36.
96 —36 =60,
60— 36 = 24.
Therefore d = 24.
36 —24 =12,
Therefore d = 12.
24 —-12 =12.
Therefore d = 12 and both the smallest of the two numbers of this
step (24 and 12) and d are 12.

As such, 12 is the GCD of 420 and 96.


Iterative version BCT VRV o] o

public int ged(int m, int n) { | public int gcd(int m, int n) {


while (m != n) { | if (m == n) {
if (m > n) { | return n;
m=m - n; | } else if (m < n) {
} else { return ged(m, n-m);
n=n-m; } else { //m > n.
} return ged(m-n, n);
}
return m; !
}

Both of these versions are simple, clean and can be understood easily enough.
However, the recursive version follows the mathematical definition and as such it is
probably easier to think of and implement in the first place. On the other hand,
the
recursive version does call itself multiple times, taking up more memory
space.

Towers of Hanoi: The Towers


of Hanoi is a
puzzle in which the elegance of recursion shines
through, compared to an iterative method.
This classic game consists of three vertical pegs
attached to a board, as depicted in Image D.1.
The pegs are usually labelled in some way. (ex.
A, B, and C). A number of n disks that
have a
hole in their centers, so that they can slide onto
the pegs, are mounted on peg A, from largest (at
the bottom) to smallest (at the top). The
objective of the game is to move all disks from
peg A to peg C, one at a time, without having a
larger disk on top of a smaller one at any point in
time. Image D.1 presents the initial configuration
of the game with 7 disks on peg A, a middle state
in which the disks are placed in various pegs, and
the final configuration of the game, the winning
state, with 7 disks on peg C. Image D.1: The Towers of Hanoi
This seemingly complicated problem becomes
easy when seen through the lens of a recursive
approach. There are only three steps that need to be performed in order
to solve it:

Step 1: Move the smaller n-1 disks from peg A to peg B.


Step 2: Move the remaining disk from peg A to peg C.
Step 3: Move the smaller n-1 disks from peg B to peg C.

The solutions to the Towers of Hanoi problem for one (n=1), two
(n=2) and three
disks (n=3), using the above algorithm, are outlined below:
o For one disk, where n=1:
[Step 2]
Ato pegC
1. Move the one disk from peg
n-1, for n=1, is equal to 0).
(steps 2 and 4 do nothing since
o Fortwo disks, where n=2:
peg B. [Step 1]
1. Move the top disk from peg A to
Ato peg C. [Step 2]
2. Move the remaining disk from peg
peg C [Step 3]
3. Move the top disk from peg B to
o For three disks, where n=3:
peg G
1. Move the top disk from peg A to
[Step 1]
peg A to peg B.
Move the second disk from
D
peg B
Move the top disk from peg C to
[Step 2]
B EO

Ato peg C. =%
Move the remaining disk from peg
Sip oo

peg A
Move the top disk from peg B to
[Step 3]
peg C.
Move the second disk from peg B to
A to peg C.
Move the top disk from peg
move 4
up from moves 1 to 3, step 2 from
Step 1 of the algorithm is made
and step 3 from moves S5to7.
using recursion,
to the Towers of Hanoi problem
In order to implement the solution to another. That
would move n disks from one peg
a method would be needed that
parameters:
and would include the following
method could be called moveDisks
char to, char excl)
(int n, char from,
moveDisks

disks to be moved.
o nwould represent the number of
which the disks would move
o f£romwould represent the peg from
h the disks would move
o to would represent the peg to whic
move
that would not be used for the
o excl would represent the peg
to its designated
the single disk would be moved
When n would be equal to 1, then recursion.
This would be the base case of the
peg and moveDisks would stop.
i problem, in a
that would solve the Towers of Hano
The three steps described above
ribed above, as
using the moveDisks method desc
recursive manner, are rewritten
follows:
(n-1, A, B, C)-.
g moveDisks
Step 1: Move the smaller n-1 disks usin
eDisks (1, &, C, B).
Step 2: Move the remaining disk using mov
moveDisks(n-1, B, C, A).
Step 3: Move the smaller n-1 disks using

of Hanoi problem could be


into account these three steps, the Towers
Taking
er:
implemented in the following mann
from,char to,char excl)
void moveDisks (int n,char
public static
{
if(n == 1) {
System.out.println(“Move disk from “ + from + “ to ™ + to);
} else {
moveDisks (n-1, from, excl, to);
moveDisks (1, from, to, excl);
moveDisks (n-1, excl, to, from);

An example output of the above code for


three disks that are to be moved from peg
A to peg C would be the following:

1. Move disk from A to C.


2. Move disk from A to B. [Step 1]
3. Move disk from C to B.
4. Move disk from A to C. resww—p [Step 2]
5. Move disk from B to A,
6. Move disk from B to C. [Step 3]
7. Move disk from A to C.

An iterative version of the Towers of


Hanoi algorithm is much more complicate
than the elegant, simple and clear solution d
presented above. Usually, if statements,
loops, arrays and/or queues are needed for such
an implementation®.

Through the previous examples one can understand that recursion can be applied to a
number of programming problems to produce simple and elegant solutions. However,
because recursive algorithms are usually very inefficient, when
compared to their
iterative counterparts, it is important to note that recursive
algorithms are rarely used in
practice. In real life computer systems, that have a
fixed amount of resources, the
algorithms used should be as efficient
as possible in order for the system as
a whole to be
as efficient as possible. In real life,
the elegance, “cleanness” and “simp
licity” of an
algorithm usually come second to effic
iency.

D.4.3 Construction of algorithms that


use recursion
Exit skills. Students should be able Lok
This is limited to a method that retu
rns no more than one result and cont
one or two recur ains either
sive calls.
FIEINTe Connecting computational thinking
L and program design.
5 %54

In section D.4.2 a number of recursive algorithms were described


d. In this as well as trace
section, a simple recursive algorithm
is constructed that can be used for the
evaluation of
exponents of a number (i.e. raising a base
number to a power).

Raising a base number a to the powe


r of n is defined mathematically as
follows:
Cetsse ee S A
® Peter Smith. An iterative solution to
Towers of Hanoi. Course Comp 151, Calif
Northridge, September 2002. Retri ornia State University
eved 22:20, June 5, 2016,
http://www.csun.edu/'“psmith/lSlhand
outs/hanoi3out.pdf
The base number a is multiplied n times by itself.
The following example depicts 3 raised to the powers of 0, 1, 2, 3 and 4 respectively:

o 3R
of 3:-3-13
e 3ERERilg
o 3¥=3%3%3=27
e 3%=3%3%3%3=81

A recursive relation may be deduced and defined as: a® = a*a™?!. The base case for this
recursive relation is when a®, which always equals to 1.
The example of 3 raised to the powers of 0, 1, 2, 3 and 4 respectively, described through the
lens of the deduced recursive relation a® = a*a™?, is presented below:

SRk
o3t =3 %30 i3% 1i=3
o 3?=3%3'=3%3%3°=3%3%1=9
o 33=3%32-3%3%3'-3%3%3+30-3%3%3%1=77
e 3%-3%33-3%3%32=3%3%3%30-3%3%3%3%30=3%3%3%3%7=8]

From the examples, the recursive relation deduced, as well as the base case, the recursive
algorithm could be written in Java in the following manner:

public static int power(int a, int n)


{
//Base case
if(n == 0) {
return 1;

} else {

//Recursive step
return a * power(a, n-1);
}
} E

In any recursive algorithm there is always a base case. Otherwise the algorithm would not
stop and would continue forever or until the resources of the computer system running the
algorithm would deplete. As such, there usually exists an if.else statement, that
determines whether the base case or the recursive step needs to run. It is very important
that the base case is always checked first (in this example, the if (n == 0) clause is run
before the else clause).

D.4.4 Trace of recursive algorithms


Exit skills. Students should be able to"

All steps and calls must be shown clearly.


LINK Connecting computational thinking and program design.
In section D.4.2 a number of recursive algorithms were described as well as traced. In this
section the simple recursive algorithm that was
constructed in section D.4.3, which can be
used for the evaluation of exponents of a numbe
r (i.e. raising a base number to a power), is
traced for when base 3 is raised to the power
of 2. The Java method power that was
implemented in section D.4.3 is used (i.e. power (3, 2) is called). The trace table is
presented below:

)
power (3, e

There are five steps in the above trace table. power


(3, 2) is called, n is not equal to zero,
and 3 * power (3, 1) is returned. However, before it can return, power (3, 1) needs to
be called. So, power (3, 1) is called, n is not equal to zero, and 3 * power (3, 0) is
returned. However, again, before it can return, power (3, 0) needs to be called.
power (3, 0) is called and this time n is equal to zero, so 1 is returned. power (3, 1)
returns3 * power (3, 0) = 3 * 1 = 3.Finally, power (3, 2) returns3 * power (3,
l) =3 * 3 =09,

power (3, 2) power (3, 1) power (3, 0)

e () ()

Figure D.2: Tracing the power (3, 2) method

It is very important to understand that a recurs


ive method will keep on calling itself, and
consuming more system memory, until the
base case is reached. At that point the last
method called will return, and only then will the second-to-last method return and
until the initial method can return the final so on
result. When the base case is reached and the
methods called return, one by one, in the reverse order they were called, the memory
allocated to those methods will be deallocated and
freed.

D.4.5 Define the term object reference

Exit skills. Students should be able to:


| Define the term o bject reference, as typified
by simple classes that are self-
LT
TEN

Reference signifies a value that point


s to or refers to some
data. That data is present either
in the computer’s memory or its data stora
ge, and may be accessed through the refer
For example, take the following simple ence.
program into consideration:

public class HelloWorld5Times


{
public static void main (Str
ing[] args) {
int times = 5;

for(int i = 0; i < times; i++) {


System.out.println(“Hello World!”) ;
}
}
}
A variable named times exists that dete
rmines how many times the for loop is going to
run and how many times the “Hello World!” message is going to appear
as output.
times is a name that refers to the number
5 in this example. Since times is
an int, itis a
primitive data type. That means that
the variable references a memory
location and in that
locat ion the value is stored. So, 5 is store
d in the memory location that is referenced by
times.

In a similar manner, object reference signi


fies a value that refers to some memory
that holds another memory location wher location
e an object’s details are stored. For
example, take
into consideration the following simpl
e object, which describes a (book
or magazine)
publisher:

public class Publisher


{
//Instance variables
private String name, address, website;
pPrivate int telephone;

//Constructor
public Publisher(string name, String address,
int telephone, String website)
{
setName (name) ;
setAddress (address) ;
setTelephone(telephone);
setWebsite (website) ;
}

Public String getName() {


return name;
}
public void setName (String name) {
this.name = name;
}
public String getAddress()
{
return address;
}
Public void setAddress (String address) {
this.address = address;
}
public String getWebsite() {
return website;
}
public void setWebsite (String website) {
this.website = website;
}

public int getTelephone() {


return telephone;
}
public void setTelephone (int telephone) {
this.telephone = telephone;
}

}
The Publisher object includes four private properties/instance variables (three of type
String and one of type int). These instance variables cannot be accessed directly but can
be accessed indirectly through the use of the get/set methods. Every Publisher is defined
as having a name, address, telephone number and a website. The constructor method
Publisher (String name, String address, int telephone, String website)
therefore takes in four parameters. These parameters populate the instance variables of the
current object using the set methods. These set methods (ex. setName (String name))
make use of the this keyword. The this keyword works as a reference to the current
object instantiation and therefore the current object’s instantiation variables. For example,
if there are two Publisher objects pl and p2, pl has its own instance variables,
unaffected by p2’s instance variables.

The Publisher object is used by the following simple program to create a Publisher and
output its details. p is a variable that refers to the publisher object created. Every object of
this type includes some instance variables that
accessed using themay be
object.propertyName rule if they are public. For example, the publisher’s name of the
publisher object referenced by p could have been accessed through p.name if the
property name was public. However, most object properties, as is the case in our example,
are private. As such, they can only be accessed
This through the get/set methods.
approach is safer as it allows various checks to be completed before a property is read or
set. For example, when setting a telephone number there may be some rules that need to
be followed, such as that telephone numbers cannot be negative numbers. These rules may
be placed inside the setter method of the telephone variable (i.e. setTelephone (int
telephone)). Accessing or setting a variable directly may lead to undesired results.

public class ObjectReferenceExample {


public static void main (String[] args) {
Publisher p = new Publisher (“Express Publishing”,
“Gardenias 25, Aharnes, Menidi”,
00302102120800,
“https://www.expresspublishing.co.uk”);
System.out.println(“Publisher ™ + p.getName() + “ with
address “ + p.getAddress() + %, telephone number Sk
p.getTelephone() + “ and website ™ + p.getWebsite()) ;

is only a
It is important to understand that a reference is distinct from the data itself. It
name used to refer to the data.

D.4.6 Construct algorithms that use reference mechanisms


Exit skills. Students should be able to*

| Construct algorithms that use reference Gl

the Publisher example described in the previous section, D.4.5, a new


Expanding on
er
ObjectReferenceExample class is defined below, which creates two Publish
object
variables p1 and p2 that refer to two different Publisher objects. Each Publisher
has its own instance properties.

public class ObjectReferenceExample {


public static void main (String[] args) {
Publisher pl = new Publisher(“Express Publishing”,
“Gardenias 25, Aharnes, Menidi”,
00302102120800,
“https://www.expresspublishing.co.uk”);

Publisher p2 = new Publisher (“Random Publishing”,


“Random St. 42, Random Location”,
0015100000000,
“https://www.randomPublishing.com”);

System.out.println(“Publisher “ + pl.getName() + “ with


address “ + pl.getAddress() + “, telephone number “ +
pl.getTelephone() + ™ and website “ + pl.getWebsite()):

System.out.println(“Publisher “ + p2.getName() + ™ with


address “ + p2.getAddress() + %, telephone number “ +
lephone( ) + © and website “ + p2.getWe bsite()) :
p2.getTe

}
The output of the above program would be:

Publisher Express Publishing with address Gardenias 25, Aharnes,


Menidi, telephone number 00302102120800 and website
https://www.expresspublishing.co.uk
Publisher Random Publishing with address Random St. 42, Random
Location, telephone number 0015100000000 and website
https://www.randomPublishing.com
Searching and sorting algorithms

This section presents algorithms that may use reference mechanisms, such as linear search,
binary search, bubble sort and selection sort. An array named students of Student
objects is taken into consideration. The Student with grade 85 is found, with the use of
the searching algorithms, while the array is sorted in descending grade order, with the use
of the sorting algorithms. Each Student object has two instance variables (name, which is a
String that holds the name of the student, and grade, which is an int that represents the
student’s grade). For simplicity, it is assumed that no two Student objects may have the
same grade in this particular students array. The Student object is defined as follows:

public class Student


{
//Instance variables
private String name;
private int grade;

//Constructor
public Student(String name, int grade)
{
setName (name) ;
setGrade (grade) ;
}

public String getName() {


return name;
}
public void setName (String name) {
this.name = name;
}

public int getGrade() {


return grade;
}

public void setGrade (int grade) {


this.grade = grade;
}

e Linear search: Searches every element of the student array. If the search key
matches an element, its index is returned. Otherwise -1 is returned. Since linear
search is used to find the student with score 85, the search key in this example is the
grade of the student.

public int sequentialSearch(Student student, int[] students)


{
boolean found = false;
int place = 0;

while (place < students.length && !found)


{
if (student.getGrade() == students[place].getGrade()) {
found = true;
} else {
place = place + 1;
}
}
if (found) {
return place;
} else {
return -1;
}

A similar algorithm was presented in Topic 4.2.1 — Searching, sorting and other
algorithms on arrays in the Core Computer Science for the IB Diploma Program
book”®. However, whilst in that version of the searching algorithm only integers (or
other primitive data types) were compared, in the algorithm presented above
objects are compared. Objects cannot be compared in the same manner as primitive
data types. That is, one cannot test for equality between two objects by simply using
the equality operator (==). So, in order to determine if the student in the array is the
one that is being searched for (i.e. has a score of 85), the grade instance variable of
the student object is compared to the grade of the student at the place
position in the array. The equality operation is displayed in red letters.

e Binary search: Searches a sorted version of the students array for the student with
score 85. For binary search to work, the array under examination needs to be
sorted. In this example, the array is sorted in descending grade order (i.e. the
student with the best grade is first, whilst the student with the worst grade is last).
The binary search algorithm checks the middle element in the array. If that element
matches the search key, it is returned and the algorithm stops. Otherwise, the
algorithm determines if the element to be found could be located “to the right” or
“to the left” of the middle element and proceeds to repeat the aforementioned
algorithm for that portion of the array, disregarding the rest of the elements.

public int binarySearch (Student student, int[] students)


{
boolean found = false;

int low = 0;
int high = nums.length -1;
int middle = 0;

while (high >= low && !found) {


middle = (low + high) / 2;

if (student.getGrade() > students[middle].getGrade()) {


high = middle - 1;
} else if (student.getGrade() < students[middle].getGrade()) {
low = middle + 1;
} else {

* Dimitriou K. Hatzitaskos M. (2015). Core Computer Science for the IB Diploma Program. Athens:
Express Publishing. More information at: https://www.expresspublishing.co.uk/gr/en/content/core-
computer-science-ib-diploma-program
found = true;
}
}
if (found) {
return middle;
} else {
return -1;
}
}

Again, a similar algorithm was presented in Topic 4.2.1 — Searching, sorting and
other algorithms on arrays in the Core Computer Science for the IB Diploma
Program book®. Since objects cannot be compared in the same manner as primitive
data types, the grade instance variable of the student object is compared to the
grade of the student at the middle position in the array. This comparison is
displayed in red letters.

Bubble sort: Compares every element of the student array to its next. If they are
not in the correct order, they are swapped. This process is called “a pass”. The
algorithm continues until an entire pass is completed without any swaps taking
place. As such, all elements are in the correct order.

public void bubbleSort(int[] students)


{
Student temp;
boolean done;

do {
done = true ;

for (int current=0; current<students.length-1; current=current+l) ({


if(students[current].getGrade()<students[current+1].getGrade()) {
temp = students|[current];
students[current] = students[current+l];
students[current+l] = temp;
done = false;
}
}
} while ('done);
}

Selection sort: Finds the student with the best grade and swaps him/her with the
student at the first position of the array. The student with the second best grade is
then found and is swapped with the student at the second position of the array, and
so on, until there are no more students to be sorted.

public void selectionSort(int[] students)


{
int first, least;
Student temp;

Ees
for(first = 0; first < size; first = first + 1) {
least = first;
for (int current=first+l; current<students.length; current++) {
if (students[cu .getGrade () >students[least
rrent] ] .grade) {
least = current;
}
}
temp = students[least];
students[least] = students[first];
students[first] = temp;

D.4.7 Identify the features of the Abstract Data Type (ADT) list

Exit skills. Students should be able to*:

Understand the nature of an ADT — where no implementation details are known but
the actions/methods are standard.

Abstract Data Types (ADTs) include the phrase data type that has been encountered before.
For example, Java build-in primitive data types, such as int, have already been discussed.
The int data type includes whole-number values between -2,147,483,648 and
2,147,483,647, as well as arithmetic operators +, -, *, /, etc. These arithmetic operators are
an essential part of the int data type, as they describe what operations can be performed
on it.

Through the use of object-orientated programming one may create classes that represent
custom data types. For example, a class that represents time, which includes fields for hours,
minutes and seconds, can be considered a custom data type. This class may be added or
subtracted just like the int data type. However, instead of using operators such as + and -,
one would use methods like add () and subtract ().

Data types may be considered


as any class that consists of data (fields/properties) and
operations on that data (methods/functions).
Useful Information: It is important to understand how objects can be compared
. One
cannot test for equality between two objects by simply using the equality
operator
==). Take into consideration the following object:

public class Person


{
public int idNumber;
public String name;
public int age;

public Student(int idNumber, String name, int age)


{
this.idNumber = idNumber:
this.name = name;
this.age = age;

}
In the following program, two Person objects are created and compared
as follows:
public class ObjectEqualityExample {
public static void main (String[] args) {
Person pl = new Person(318, “Kostas”, 18);
Person p2 = new Person(318, “Kostas”, 18):

if(pl == p2) {
System.out.println(“pl is the same as P2Z)
} else {
System.out.println(“pl is not the same as p27) ;
}

}
Both p1 and p2 refer to Person objects that have an idNumber variable
instantiated
to 318, a name variable instantiated to “Kostas” and an age variable
instantiated to
18. Although these objects are similar, and from the idNumber one could
assume that
they are the same person, they are not the same. They are two differen
t Person
objects. Comparing these two objects using the equality operato
r (==) returns false.
If the ObjectEqualityExample program above is run the output is:

Pl is not the same as p2

A simple way to compare two objects is to compare all their instance


variables or
some specific one that identifies an object beyond any reasonable doubt.
For example,
the idNumber of a Person object can be assumed to be unigue,
and so if two
Person objects have the same idNumber they would be equal. As
such, instead of
comparing pl to p2 by using the equality operator, one could test
the equality of the
idNumber between the two objects as follows:

if(pl.idNumber == p2.idNumber) { .. }
Useful Information: Since one cannot test for equality between two objects by simply

e
using the equality operator (==), but Strings in Java are objects, it is interesting to

EP SR S
look at how one can go about comparing Strings.
The String Java class includes a number of methods that help a developer compare

i
the text of the String object to the text of another String object. The most helpful
method, in our case, for the comparison of two String objects is the .equals()

DN
P
method.

N N N S
For example:

S SN
String sl = “My name is Markos”;
String s2 = “My name is Markos”;

SRR S
System.out.println(“sl is equal to s2:” + sl.equals(s2));

The output of this program snippet would be:

e BRIV
sl is equal to s2: true

NS
Of course, since String objects are used widely and come bundled with Java, they are
sometimes treated in a special manner, which is beyond the scope of this book. Due to

I
that special treatment one may find that under some circumstances the equality

D
operator (==) may be used to effectively compare two String objects. However,
since this is not always the case, it is recommended that the .equals () method is
always used to compare Strings, in order to avoid any unwanted results.

SRR
Abstraction, which was also presented in Topic 4 — Computational Thinking in the Core
Computer Science for the IB Diploma Program book®, relates to the essence of something,
without considering specific or unwanted implementation details. For example, the act of
double-clicking on an application icon and requesting its launch, is an abstraction. The same
action is taken for any application that a user may want to run, but the actual processing
that happens behind the scenes (from the input/output devices to memory allocation and
processing) is abstracted from the user. In a similar manner, in object-oriented
programming, an Abstract Data Type (ADT) is a class that may be used without knowing its
implementation details. The ADT describes the data (fields/properties) and operations that
can be performed on that data (methods/functions), but hides any details as to how the
data is stored and the operations performed. As such, any users that may use the ADT do
not know how exactly the ADT works. They are only aware of the data and operations, as
well as the expected results of the operations on data.

An important ADT that is extensively used in computer science is the ADT list. The ADT list
defines the interface, which means that it defines the methods that a list should encompass
to be called a list. A (linear) list is a group of elements arranged in a linear fashion, one after
the other. Fundamental operations on the elements of the list include the insertion, deletion
and observation of an element, as well as the size of the list. An ADT list may be
implemented in one of two ways; either statically or dynamically. For the static
implementation the one-dimensional array
may be used, while for the dynamic
implementation the single linked list may be used. One-dimensional arrays are linear and
allow for the insertion, deletion and observation of their elements, as well as the array size.
As such, one-dimensional arrays are a specific implementation of the ADT list. Theoretically
an ADT list cannot be filled up. However, arrays, which have to be initialized using a specific
finite, number of elements, can and do indeed become full. There are a number of ways to
work around this issue. On the other hand, single-linked lists allow for the insertion, deletion
and observation of their elements, as well as the list size, and do not fill up. Sections D.4.9
and D.4.10 go into the specifics of static and dynamic ADT list implementations, respectively.

D.4.8 Describe the applications of lists

Exit skills. Students should be able to’:


5

In a list (or a one-dimensional array) any element may be accessed if its index position is
known. However, in both stacks and queues, only one specific element may be read,
inserted or removed at any given time. Stacks and queues are ADTs that are designed
specifically in order to follow these restrictions.

Stacks

Stacks are Last-In-First-Out (LIFO) structures,


meaning that the last element that goes into
a stack is the first element to come out. For
example, in a stack of plates one may add
another plate on top of the stack, but he/she
may remove only the topmost plate, which
also happens to be the last plate added to the
stack. Another example might be a stack of
magazines in a waiting room. The people
waiting may only remove the magazine at the
top of the pile and read it. Anyone finishing
reading their magazine will return the
magazine to the stack and add it to the top of
the pile. As long as no one adds another
magazine to the stack, the returned magazine
will be the one at the top of the pile.

Figure D.3 visually presents how an empty


Image D.2:
A stack of magazines stack may fill with elements. In this specific
example, a magazine is placed on top of the
stack every time. Adding elements on top of a
Magazine #1 Magazine #2 ' Magazine #3 Magazine )

Magazine #4

DAl R Magazinéu#a‘ l
Stack
WV ES - pal gtk Wtrd ) Magazine #2

Magazine #1 (\=lehdlalRa Magazine #1 Magazine #1

Figure D.3: Pushing a magazine to the stack

stack is called pushing.

Figure D.4 visually presents how a stack with elements may become empty. In this specific
example, a magazine is removed from the top of the stack every time. Removing elements
from the top of a stack is called popping.

Magazine #4 W el R Magazine #2 Magazine #1

Magazine #4

‘ ‘Magazine“#?: ‘ Magazine #3
: Stack
W EEepdialch: 2 Magazine #2 Magazine #2

Magazine #1 Magazine #1 Magazine #1 Magazine #1

Figure D.4: Popping a magazine from the stack

ADT lists described in section D.4.7 can be used to to represent a stack. The fundamental
operations of an ADT list upon its elements include the insertion, deletion and observation
of an element, as well as the array size. A stack essentially needs the same operations, but
with some restrictions so that only the top element may be inserted, deleted or observed. If
the stack is empty, an error message should appear if the user tries to delete or observe the
top element of the stack. In order to provide this restriction, a pointer variable needs to be
in place that will always keep the index of the last element that was added to the stack, and
be updated accordingly. This pointer variable will restrict the stack operations to that
element.

The main methods of a stack that may be implemented using ADT lists are the following:

e push(): This method adds an element to the stack as the topmost element.
The element is added according to the list index signified by the pointer variable.
® pop(): This method removes the topmost
element. That is, the last element that
was added to the stack.
The element of the list at the index signified
by the pointer variable is removed and
the pointer variable updated to point to the
second-to-last element of the stack,
which then becomes the last element (top-
most element).
® peek(): This method returns the top-most element, that is, the last element that
was added to the stack, but does not remove
it.
The element of the list at the index signified by
the pointer variable is returned.
® isEmpty (): This method returns whether or
not the stack is empty.
If the pointer variable is equal to -1 then
this method returns true, otherwise false.
® size(): This method returns the size of the stack. That is, how
many elements
there are in the stack.
This method returns the index of the pointer
variable plus one.

Queues

Queues are lines, like the one that is shown in Image


D.3. Queues are First-In-First-Out
(FIFO) structures, meaning that the first eleme
nt that goes into a queue is the first element
to come out. For example, when waiting in
a queue at the supermarket cashier, the first
to
arrive at the cashier will be the first to be serve
d and exit the supermarket. Customers that
join the queue must join at the end, while the
customer that leaves the queue is at the front.

People join at the In computer science, both


People leave from
rear of the queue
the front of the stacks and queues are used in
various cases. For example,
an operating system uses
queues to keep track of
documents to be printed.
Mouse clicks or keyboard
strokes are also put in a
queue so that the computer
system is aware of which
clicks or keyboard strokes
happened and in what order.

Figure D.5 visually presents


Image D.3: A queue (line) of people
how an empty queue may fill
with elements. In this specific
example, is a customer
inserted at the back of the queue every time.
Adding elements to the back of the queue
may
be called inserting, putting, adding or enque
uing.

Figure D.6 visually presents how a queue


with elements may become empty. In this
specific
example, a customer is removed from
the front of the queue every time. Remo
ving
elements from the front ofa queue may be
called deleting, getting or dequeuing.

L]
The front of a queue may also be the head of the queue, while the back may also be the tail.

(@I
ol ag]<l g i ‘ Customer #2 ' Customer #3 el

: i — =
Back ; L ! Customer #4

S Customer #3
Queue Queue
Customer #2 (S olici g 94 @ ESTela ottt )

Customer #1 Customer #1 Customer #1


Front

Figure D.5: Inserting a customer into the queue

Back e

Customer #3 [eliSi TS 2
Queue Queue
Customer #2 W Customer #3 [ NCUSIORmEr
Customer #1 Customer #2 ottt o NG INC E
Front

QU
(o e Customer #2 W Customer #3 el telnt- ot

Figure D.6: Removing a customer from the queue

ADT lists (described in section D.4.7) can be used to to represent a queue. The fundamental
operations of an ADT list on its elements include the insertion, deletion and observation of
an element, as well as the array size. A queue essentially needs the same operations, but
with some restrictions so that an element may only be inserted at the tail of the queue,
while only the element at the head of the queue may be deleted or observed. If the queue is
empty, an error message should appear if the user tries to delete or observe the element at
the head of the queue. In order to provide this restriction, two pointer variables need to be
in place and updated accordingly, that will always keep the index of the head and the tail
elements of the queue.

The main methods of a queue that may be implemented using ADT lists are the following:

e insert(): This method adds an element to the queue as the last element.
The element is added according to the list index signified by the tail pointer variable.
e remove (): This method removes the first element. That is, the first element that
was added to the queue.
The element of the list at the index signified by the head pointer variable is removed
and the pointer variable updated to point to the second element of the queue,
which then becomes the first element.
® peek(): This method returns the first element, but does not remove it. That is, the
first element that was added to the queue.
The element of the list at the index signified by the head pointer variable is
returned.
® isEmpty (): This method returns whether or not the queue is empty.
® size(): This method returns the size of the queue. That is, how many elements
there are in the stack.

D.4.9 Construct algorithms using a static implementation of a list

Exit skills. Students should be able to':


Implement a list using singly linked types. Methods that should be known are add
{head and tail), insert (in order), delete, list, isEmpty, isFull.

As discussed in section D.4.7, an ADT list may be implemented statically using an array.
Static arrays need to have a specific maximum length that cannot be altered at run time.
Items are ordered within the array in such a way that its index represents the position of the
item in the list (remember, the first element of the list will have an index of 0). Two variables
are needed: one to keep the maximum number of elements that may be present in the array
(so, the array length) and one to keep the current number of elements in the array.

A list may be ordered or unordered. Ordered lists contain elements in ascending or


descending order, whereas unordered lists contain elements in no specific order. Adding an
element to an ordered list requires that the element be placed in the correct position so that
the order of the list is maintained. On the other hand, any element can be added to an
unordered list either from the head or the tail of the list.

The following code represents a static implementation of a list using a static array. The
variable MAX LIST holds the number of maximum elements that may be present in the
array, while the variable numItems holds the current number of elements in the array. The
array in this example is named items and holds integers (for the sake of simplicity). It could
have just as easily held some other primitive type or user-defined object.

public class ADTListStatic


{
private final int MAX LIST = 50;
private int numItems;
private int items[];

public static void main(String[] args) {


System.out.println("");
System.out.println("Unordered list");
System.out.println("");

ADTListStatic unorderedlist = new ADTListStatic() ;


//Adding elements to the head of the list.
unorderedlist.addHead(3) ;
unorderedlist.addHead
(4) ;
unorderedlist.addHead
(5) ;
unorderedlist.addHead
(2) ;
unorderedlist.addHead
(6) ;
unorderedlist.present();

//Removing element from the middle of the list.


unorderedlist.remove
(4) ;
unorderedlist.present();

//Adding elements to the tail of the list.


unorderedlist.addTail(1) ;
unorderedlist.present();

System.out.println("");
System.out.println("Ordered list");
System.out.println("");

ADTListStatic orderedlist = new ADTListStatic();

//2dding elements to the list.


orderedlist.insert(3);
orderedlist.insert(4);
orderedlist.insert(5);
orderedlist.insert(2);
orderedlist.insert(6);
orderedlist.present();

//Removing element from the middle of the list.


orderedlist.remove(4) ;
orderedlist.present();

//Adding elements to the tail of the list.


orderedlist.insert(15);
orderedlist.present();
}
public ADTListStatic() {
items = new int[MAX LIST];
numIitems = 0;
}
public boolean isEmpty() {
return numItems == 0;
}
public boolean isFull() {
return numlItems == MAX LIST;
}
public int size() {
return numItems;
}
public int peek(int index) {
if (index >= 0 && index < numItems) {
return items[index];
}
System.out.println("out of range: 0 - " + (numItems-1));
return -1;
}
/*
* Method for adding an element to the head of an
unordered list.
* Before adding the element, all the elements to the right
* of the head are shifted to the right to make way
for the
* new element.
R
public void addHead (int item) {
if (isFull()) {
System.out.println("List is Eudiy =
} else {

int index = 0;
for (int pos = numItems; pos >= index; pos--) {
items[pos+l] = items[pos];
}
items[index] = item;
numItems++;
}
}
/*
* Method for adding an element to the tail of an unordered list.
* No shifting is necessary in this case.
*/
public void addTail (int item) {
if (isFull()) {
System.out.println("List is full.");
} else {

int index = numItems;


items[index] = item;
numItems++;

* Method for adding an element to a specific index.


* Before adding the element, all the elements to the right
* of the specific index are shifted to the
right to make
* way for the new element.
7
public void add(int index, int item) {
if (isFull()) {
System.out.println("List is full.") ;
} else {
if (index >= 0 && index <= numItems) {
for (int pos = numItems; Pos >= index; pos--) {
items [pos+l] = items[pos] ;
}
items[index] = item;
numItems++;

} else {
System.out.println
("out of range: 0 - " + (numItems-1);
}
}
}
// Method for adding an element to an ordered list.
public void insert(int item) {
if (isFull()) {
System.out.println("List is full.");
} else {
if (isEmpty
() {
add (0, item);
} else {
int index = 0;

for (int pos = 0; pos < numItems; pos++) {


index = pos;

index = pos;
break;
} else {
index = pos+l;
}
}
add (index, item);
}
}
}

* Method for removing an element from a specific index.


* The element is removed by shifting all the elements to
* the right of the specific index towards the left, to take up
* the space created by the removed element.
x7
public void remove (int index) {
if (index >=0 && index < numItems) {
for (int pos=index+l; pos<=size(); pos++) {
items[pos-1] = items[pos];
}
numItems--;
} else {
System.out.println("out of range: 0 - " + (numItems-1));
}
1

public void present() {

System.out.println("List elements:");

for (int pos = 0; pos < numItems; pos++) {


System.out.print (items[pos] + " ");
}
System.out.println();
The above static implementation of a list using a static array includes the following methods:

e ADTListStatic(): This method is the constructor. It initializes the array to be


used as the list with MAX LIST positions. It also initializes the variable numItems,
which counts the number of elements in the list, to zero.
e boolean isEmpty (): This method checks whether the list is empty by comparing g
numItems to zero.
e boolean isFull(): This method checks whether the list is full by comparing
numItems to MAX LIST.
e int size (): This method just returns numItems, which holds the number of items
in the list.
e int peek(int index): This method returns the element of the list at the
specified index. If the index provided is outside the bounds of the list then an error
message appears.
e void addHead (int item): This method first checks whether or not the list is full.
Then it shifts all the elements one position to the right and adds the element
provided to the beginning of the list.
e void addTail (int item): This method first checks whether or not the list is full.
It then adds the element provided to the end of the list.
e void insert(Node node) :This method adds the Node provided to the correct
position in the list in order to maintain list order (ascending or descending).
e void add(int index, int item) :This method is a private method that
adds an element to a specific index.
e void remove (int index): This method shifts all the elements to the right of the
specified index one position to the left, so as to take up the space of the element
that needs to be removed.
e void present(): This method just prints out the list, using a £for loop that runs
from zero to one less than numItems.
e void main(String[] args): This method is added for testing purposes. It
creates a new ADTListStatic object and adds numbers 3, 4, 5, 2, 6 to the head of
the list. It then presents the list, which will be the following:

62085843

It then removes the element at index 4 and once again presents the list (remember,
the first element of the list has an index of zero):
6 25 4

Finally the method adds number 1 to the tail of the list and presents the following
output:

6205 451

The main method then creates a new ADTListStatic object (listOrdered) and
adds numbers 3, 4, 5, 2, 6 using the insert method. This way the list remains
ordered. It then presents the list, which will be the following:

25 3FAE5H6
It then removes the element at index 4 and once again presents the ordered list
(remember, the first element of the list has an index of zero):
2345

Finally, the method adds number 15 to the ordered list and presents the following
output:

2 34515

Stacks using a static implementation of a list

Remember, stacks are Last-In-First-Out (LIFO) structures, meaning that the last element that
goes into a stack is the first element to come out. A stack needs the same operations as the
ADT list, but with some restrictions so that just the top element may be altered or examined.

For the sake of simplicity, a stack that may include integers will be presented in this section.
Of course, the algorithms could easily be altered for the stack to include some other
primitive data type or even user-defined objects.

The main methods of a stack that may be implemented using ADT lists are the following:
void push(int item), int pop(), int peek(), boolean isEmpty() and int
size().

The implementation of a stack using static arrays is quite simple:

public class ADTListStaticStack


{
private ADTListStatic list;

public ADTListStaticStack() {
list = new ADTListStatic();
}

public void push(int item) {


list.addHead (item) ;
}

public int pop() {


int item = peek();
list.remove (0) ;
return item;
}
public int peek() {
return list.peek(0);
}
public boolean isEmpty() {
return list.isEmpty();
}

public int size() {


return list.size();
)
}
Pushing an element to the stack involves just adding the
element to the head of the list.
Popping the element from the stack involves peekin
g at the top element of the list, storing it
in a variable, removing the element from the list and
returning the value in the variable. So,
popping an element is different from removing an elemen
t from the stack in that popping
- also returns the value of the element. Peeking at the
element at the head of the stack
involves just peeking at the head of the list. Finding the size
of the stack and whether or not
it’s empty involves simply calling the respective list method
s and returning the results.

The following example could be used to test out the ADTLi


stStaticStack:
public static void main (String[] args) {
ADTListStaticStack stack = new ADTListStaticStack() ;

stack.pus(5)
h ;
stack.push (4) ;
stack.push(3) ;
stack.push(2) ;
stack.push(1);

System.out.println("Top element is: " + stack.peek()) ;


System.out.println ("Popping top element: " + stack.pop()) ;
System.out .println("Top element is now: " + stack.peek()) ;

A new stack is created and the numbers 5, 4, 3, 2,


1 are pushed giving the following stack:

Headl 2 3 4 5Tail

The top element is printed


using the peek () method, then popped, using the
pop ()
method, and then the new top element is printed again,
giving the following output:
Top element is: 1
Popping top element: 1
Top element is now: 2

Queues using a static implementation of a list

Remember, queues are First-In-First-Out (FIFO) structures, meani


ng that the first element
that goes into a queue is the first element to come out.
A queue needs the same operations
as the ADT list, but with some restrictions so that
an element may only be inserted at the tail
of the queue, while only the element at the head of
the queue may be deleted or observed.

For the sake of simplicity,


a queue that may include integers will be presen
ted in this
section. Of course, the algorithms could easily be altere
d for the queue to include some
other primitive data type, or even user-defined objects.

The main methods of a queue that may be implemente


d using ADT lists are the following:
void insert(int item), int remove (), int peek(), boolean isEmpty () and
int size().

The implementation of a queue using static arrays


is quite simple:
public class ADTListStaticQueue
{
private ADTListStatic list;

public ADTListStaticQueue () {
list = new ADTListStatic();
%
public void insert(int item) {
list.addTail (item) ;
}

public int remove() {


int item = peek();
list.remove(0) ;
return item; #
}
public int peek() {
return list.peek(0);
}

public boolean isEmpty() {


return list.isEmpty
()’
}

public int size() {


return list.size():;
}
}

Inserting an element into the queue involves adding the element to the tail of the list.
Removing the first element of the queue involves peeking at the first element of the list,
storing it in a variable, removing the element from the list and returning the value in the

variable. Peeking at the first element of the queue involves just peeking at the first element
of the list. Finding the size of the queue and whether or not it's empty involves simply calling
the respective list methods and returning the results.

The following example could be used to test out the ADTListStaticQueue:

public static void main(Stringl] args) {


ADTListStaticQueue queue = new ADTListStaticQueue();

queue.insert(5);
queue.insert (4) ;
queue.insert(3);
queue.insert(2);
queue.insert(l);

System.out.println("First element is: " + queue.peek()) ;


System.out.println("Removing first element: " + queue.remove());
System.out.println("First element is now: " + queue.peek());

A new queue is created and the numbers 5, 4, 3, 2, 1 are inserted giving the following
queue:
Front5 4 3 2 1Back

The front element is printed using the peek () method, then removed, using the remove ()
method, and then the new front element is printed again, giving the following output:

First element is: 5


Removing first element: 5
First element is now: 4

D.4.10 Construct list algorithms using object references

Exit skills. Students should be able to™:


3’ Implement a list using singly-linked types. Methods that should be known are add
| (head and tail}, insert (in order), delete, list, isEmpty, isFull.

As discussed in section D.4.7, an ADT list may be implemented- dynamically using a linked
list. In section D.4.9 an ADT list was implemented using static arrays. Static arrays need to
have a specific maximum length that may not be altered at run time. That means that
although, in theory, due to array
implementation restrictions, ADT lists do not have a
maximum number of elements that they can hold, they do have a maximum number of
elements that they can hold when implemented in a static manner, using static arrays.
Dynamic implementation of ADT lists overcomes these limitations.

A linked list is made up of two parts: the head (a.k.a. reference variable) and the nodes. The
head includes a variable that points to the first item of the list, as well as, sometimes,
another variable that holds the number of items currently in the list. The nodes are the
elements of the list. They include a data variable (that holds some kind of data, from
primitive types to user defined objects) and another variable that points and links to the
next node in the list.

#of items first item next item next item next

L T J ‘ - T - — ',; P > — '

head nodes

Figure D.7: An example of a linked list with three nodes

Figure D.7 displays an example of a linked list with three nodes that hold integers. The head
of the list holds the number of elements in the list (i.e. three), as well as a link to the first
node of the list. The first node of the list includes some data (i.e. 1), as well as a link to the
next (second) node of the list. The second node of the list includes some data (i.e. 2), as well
as a link to the next (third) node of the list. The third, and last, node of the list includes some
data (i.e. 3), but does not link to another node, since there is no other (fourth) node. As
such, the value of the link is null.

Figure D.8 displays an example of a linked list where the pointer of the head’s first variable is
null. In this case, the head does not point to t of the list, as there is no first

#of items first

head

Figure D.8: An example of an empty linked list

A linked list may be ordered or unordered. Ordered lists contain elements in ascending or
descending order, whereas unordered lists contain elements in no specific order. Adding an
element to an ordered list requires that the element be placed in the correct position so that
the order of the list is maintained. On the other hand, any element can be added to an
unordered list either from the head or the tail of the list.

The code below represents a dynamic implementation of a list using a linked list. Two classes
are needed:

e Node class: Represents a node of the linked list. It includes a data variable named
item (that holds an integer for the sake of simplicity) and another variable, next,
that points and links to the next node in the list.
e ADTListHead class: Represents the head of the linked list. It includes a variable,
numItems, that holds the number of elements in the list, as well as a variable,
first, that links to the first Node object of the list. If there is no first node, the list
is empty and the first variable is null.

public class Node {


private int item;
private Node next;

public Node (int item) {


this.item = item;
}

public void setItem(int item) {


this.item = item;
}

public int getItem() {


return item;
}
public void setNext (Node next) {
this.next = next;
}
Public Node getNext
0 {
return next;
}
}

public class ADTListHead


{
Private Node first;
Private int numItems;

public ADTListHead ( ) {
first = null;
numItems = Q;
}
public Node find(in t index) {
if (index >= 0 s& index < numItems)
{
Node current = first;
for(int i=0; i< index; i++) {
current = cur rent.getNext () ;
}
return current;
}
System.out.printl n("out
of range: 0 - " 4 (numItems—l));
return null;
}
//Methods for addin g elements to an unordered list.
public void addHead (Node node) {
node. setNext (firs
t);
first = node;
numItems++;
}

public void addTail (Node node) {


if (size() == 0) {
node.setNext(fi rst);
first = node;
} else {
Node last = fin, d(size
()-1);
last.setNext(no de);
}
numItems++;
}
// Methods for adding elements to an ordered list.
public void insert (Node node) {
Node current = fi rst;

node.setNext(first);
first = node;

} else {
current = current.getNext();
}
)/
() t
node . setNext (current.getNex
current.setNext (node) ;
}
numItems++;
}
public int peek (int index) {
Node node = find(index);
return node.getItem();
}
public void remove (int index) {
Node nodeT oRemo ve = find (index ) ;

if (index == 0) {
first = nodeToRemove .getNext () ;

} else {
previousNode = find (index-1) ;
Node

if (index == size()-1) {
previousNo de.se tNext (null );
} else {
t());
previousNode.setNext(nodeToRemove.getNex
}
numltems--;

}
public boolean isEmpty() {
return first == null;
}
public int size() {
return numItems;
}
public void present() {
elements:") ;
System.out.println("List

Node current = first;

while (current != null) {


t(cur rent. getItem() e R o
System.out.prin
current = curre nt.ge tNext ():;

}
System.out.println();
}
public static void main(String[] args) {
System.out.println("");
System.out.println("Unordered list");
System.out.println("");

ADTListHead listUnordered = new ADTListHead();

//Adding elements to the head of the list.


listUnordered. addHead (new Node(3));
listUnordered.addHead (new Node(4));
listUnordered.addHead (new Node(5));
listUnordered.addHead (new Node (2)) ;
listUnordered.addHead (new Node (6)) ;
listUnordered.present();

//Removing element from the middle of the list.


System.out.println("Remove element at index 4.");
listUnordered.remove (4) ;
listUnordered.present();

//Adding elements to the tail of the list.


System.out.println("At element 1 at the tail.");
listUnordered.addTail
(new Node(l));
listUnordered.present();

//Peek at the 2nd node's data.


int secondNodeData = listUnordered.peek (1) ;
System.out.println("Second node's data: " + secondNodeData);

System.out.println("");
System.out.println("Ordered list");
System.out.println("");

ADTListHead listOrdered = new ADTListHead();

//Adding elements to the list.


listOrdered. insert (new Node(3));
listOrdered.insert (new Node (4)) ;
listOrdered.insert (new Node (5)) ;
listOrdered.insert
(new Node (2)) ;
listOrdered.insert(new Node (6)) ;
listOrdered.present();

//Removing element from the middle of the list.


System.out.println("Remove element at index 4.");
listOrdered. remove (4) ;
listOrdered.present();

//Adding elements to the tail of the list.


System.out.println("Add element 15.");
listOrdered.insert (new Node (15)) ;
listOrdered.present();

The above dynamic implementation of a list using a linked list includes the following
methods:
zes the variable first to
is the constructor. It initiali
« ADTListHead():This method
counts the number of
variable numItems, which
null and also initializes the
elements in the list, to zero. ty by checking
hod checks whether the list is emp
e boolean isEmpty(): This met
whether £irstisnull.
s the number of items
returns numItems, which hold
e int size():This method just
in the list.
the node at the specified
peek(int ind ex) : This method returns the data of
e int
an error message
inde x prov ided is outs ide the bounds of the list, then
index. If the
appears. to the
adds the Node provided
node): This method
e void addHead (Node
beginning of the list.
Node provided to the end of
e void addTail (Node node): This method adds the
the list.
ided to the correct
ins ert (No de nod e) .Thi s method adds the Node prov
e void ending).
tain list order (ascending or desc
position in the list in order to main e at the specified
d rem ove (in t ind ex) : This method removes the Nod
e voi its Next variable
For that to happ en, the prev ious node in the list is found and
inde x.
oved, as shown in
after the one to be rem
that comes
is set to point to the Node
exist:
Figure D.9. Two special cases the
the first node in the list, then
1. If the node to be removed is
that it
tHead object is changed so
£irst variable of the ADTLis
the list.
points to the second node in

next item next


item next item
#of items first

next item next


item next item
#of items first

next item next


#of items first item

: T . -=
fsissara
Y il ——
nodes
head
node
Figure D.9: Deleting a linked list
2. If the node to be removed is the last node in the list, then the next
variable of the second to last node is set to nul1l.
void present (): This method just prints out the list. It uses a while loop until
the null item is found as the next node, meaning that there is no next node and as
such the end of the list has been reached.
void main(String[] args): This method is added for testing purposes. It
creates a new ADTListHead object (1istUnordered) and adds numbers 3, 4, 5525
6 to the head of the unordered list. It then presents the unordered list, which will be
the following:
652554 3

It then removes the element at index 4 and once again presents the unordered list
(remember, the first element of the list has an index of zero):
6 25 4

The method adds number 1 to the tail of the unordered list and presents the
following output:
625141

Finally, the method peeks at the second node’s data and prints it out, as follows:

Second node's data: 2

The main method then creates a new ADTListHead object (1istOrdered) and
adds numbers 3, 4, 5, 2, 6 using the insert method. This way the list remains
ordered. It then presents the list, which will be the following:

23456

It then removes the element at index 4 and once again presents the ordered list
(remember, the first element of the list has an index of zero):
2:3.4.5

Finally, the method adds number 15 to the ordered list and presents the following
output:
2:384:5:15

Stacks using a dynamic implementation of a list

Remember, stacks are Last-In-First-Out (LIFO) structures, meaning that the last element that
goes into a stack is the first element to come out. A stack needs the same operations as the
ADT list, but with some restrictions so that only the top element may be inserted, deleted or
observed.

For the sake of simplicity, a stack that may include integers will be presented in this section.
Of course, the algorithms could easily be altered for the stack to include some other
primitive data type or even user defined objects.
The main methods of a stack that may be implemented using ADT lists are the following:
void push(int item), int pop(), int peek(), boolean isEmpty() and int

size().

The implementation of a stack using linked lists is quite simple:

public class ADTListDynamicStack


d
private ADTListHead list;

public ADTListDynamicStack() {
list = new ADTListHead();
}

public void push(int item) {


list.addHead (new Node (item)) ;
}

public int pop() {


int item = peek();
list.remove (0) ;
return item;
}
public int peek() {
return list.peek(0);
}
public boolean isEmpty() {
return list.isEmpty();
}

public int size() {


return list.size();
}
}

It is easy to notice that the above implementation is very similar to the static version
discussed in section D.4.9. Nothing changes, apart from the fact that when pushing an item
to the stack, a new Node object must be created.

The following example could be used to test out the ADTListDynamicStack:

public static void main(String[] args) {


ADTListDynamicStack stack = new ADTListDynamicStack();

stack.push(5);
stack.push(4) ;
stack.push(3) ;
stack.push(2);
stack.push(1l) ;

System.out.println("Top element is: " + stack.peek());


System.out.println("Popping top element: " + stack.pop());
System.out.println("Top element is now: " + stack.peek());
A new stack is created and the numbers 5, 4, 3, 2, 1 are pushed, giving the following stack:

Headl 2 3 4 5Tail

The top element is printed using the peek () method, then popped, using the pop ()
method. Then the new top element is printed again, giving the following output:

Top element is: 1


Popping top element: 1
Top element is now: 2

Queues using a dynamic implementation of a list

Remember, queues are First-In-First-Out (FIFO) structures, meaning that the first element
that goes into a queue is the first element to come out. A queue needs the same operations
as the ADT list, but with some restrictions so that an element may only be inserted at the tail
of the queue, while only the element at the head of the queue may be deleted or observed.

For the sake of simplicity, a queue that may include integers will be presented in this
section. Of course, the algorithms could easily be altered for the queue to include some
other primitive data type or even user-defined objects.

The main methods of a queue that may be implemented using ADT lists are the following:
void insert(int item), int remove(), int peek (), boolean isEmpty() and
int size().

The implementation of a queue using linked lists is quite simple:

public class ADTListDynamicQueue


{
private ADTListHead list;

public ADTListDynamicQueue () {
list = new ADTListHead();
}

public void insert(int item) {


list.addTail (new Node (item)) ;
}

public int remove() {


int item = peek();
list.remove (0) ;
return item;
)

public int peek() {


return list.peek(0);
}

public boolean isEmpty() {


return list.isEmpty();
)

public int size() {

ot}
return list.size();
}
}

It is easy to notice that the above implementation is very similar to the static version
discussed in section D.4.9. Nothing changes apart from the fact that when inserting an item
to the queue a new Node object must be created.

The following example could be used to test out the ADTListStaticQueue:

public static void main(String[] args) ({


ADTListDynamicQueue queue = new ADTListDynamicQueue
() ;

queue.insert(5);
queue.insert(4);
queue.insert(3);
queue.insert(2);
queue.insert(l) ;

System.out.println("First element is: " + queue.peek());


System.out.println("Removing first element: " + queue.remove());
System.out.println("First element is now: " + queue.peek());

A new queue is created and the numbers 5, 4, 3, 2, 1 are inserted giving the following
queue:

Front5 4 3 2 1Back

The front element is printed using the peek () method, then removed, using the remove ()
method. Then the new front element is printed again, giving the following output:

First element is: 5


Removing first element: 5
First element is now: 4

D.4.11 Construct aigorithms using the standard library coliections included in


JETS
Exit skills. Students should be able to

mplement algorithms using the classes ArrayList and LinkedList. Students shouid have
| a broad understanding of the operation of these lists and their interface {methods)
| but not of the internal structure.

Common programming tasks that will most likely be needed by any kind of project are
usually packed in libraries. These libraries can be loaded by a programmer so that he/she
may take advantage of any programming tasks they include and avoid rewriting them for
his/her project. Libraries allow for various programming tasks to be written once and then
easily reused whenever necessary. Furthermore, bugs are avoided as known working
libraries that have been carefully tested may be used as “black boxes”. Most programming
languages include a standard library, which includes the programming tasks most widely
used. Java’s standard library collection included in JETS encompasses, amongst others,
ArrayList and LinkedList classes.

Classes (a.k.a. package members) from standard


library collections may be imported using
the import statement at the top of the file in which
the classes are to be used, as such:
import java.util -ArrayList;

After that, one


can create ArrayList objects. The following
example creates two
ArrayList objects, 1istl and 1ist2 respectively
, that will hold Integer objects.
//Creates an ArraylList object.
Arraylist<Integer> listl = new Arra
yList<Integer>() ;
//Creates an ArrayList object with an initial capacity
//of 10 elements.
ArrayList<Integer> 1list2 = new ArrayList<Integer>(10) ;

Arraylists may include only objects as elements


and so do not support primitive types. They
can, however, include any number of elemen
ts. Even if an initial capacity has been
determined, it can change during run time
without the programmer noticing. So, compa
red
to static arrays, ArrayLists may include any number
of elements.

Afull list of all the methods included in the Arra


yList class can be found in the official Java
documentation®. However, the most common methods are described below:

® Adding elements to an ArrayList:


O boolean add(Element e): Adds element e to the end of the list.
Element e may be any kind of object, even user
defined objects. It returns
true if the element is added successfully.
O void add(int index, Element e): Adds element e to the list at the
position specified by index. Shifts the element
at the specified index and
all subsequent elements to the right.
® Removing elements from an ArrayList:
O void clear():Removes all the elements from the list.
O E remove(int index):Removes the element at the specif
ied index. All
elements to the right of the index are shifted
to the left, to take up the
space of the removed element. The element remov
ed is returned from this
method. The return type, E, may be any kind
of object, even user defined
objects.
O protected void removeRange (int start, int end) : Removes the
elements between the start (inclusive) and end
(exclusive) indexes. Shifts to
the left any elements to the right of, and including,
the end index.
® Retrieving elements from an ArrayList:

SRR s et
® Class ArrayList. In Java Documentation. Retrie
ved 19:00, July 8, 2016,
https://docs.oracle.com/javase/S/docs/api/jav
a/util/ArrayList.html
© E get(int index): Returns the element at the specified index. The
return type, E, may be any kind of object, even user-defined objects.
o <TI>T[] toArray (T[] a):Populates a static array a with all the elements
in the list in proper sequence.
e Setting an element in an ArrayList:
0 E set(int index, E element): Replaces the element at the specified
index with the specified element E. The element previously occupying the
specific index is returned.
e Searching for an element in an ArrayList:
O boolean contains(Object o): Returns true if the specified object o is
found in the list.
o int indexOf (Object o): Returns the index of the first occurrence of the
specified object o in the list. If o is not in the list, then -1 is returned.
o int lastIndexOf (Object o): Returns the index of the last occurrence
of the specified object o in the list. If o is not in the list, then -1 is returned.
e |terating an ArrayList: :
0 Iterator iterator ():Returns an iterator over the elementsin the list.
O ListIterator listIterator(): Returns a list iterator over the
elements in the list.
e Checking whether an ArrayList is empty:
o boolean isEmpty ():Returns whether the list is empty or not.
e Getting the size of an ArrayList:
o int size():Returns the number of elements in the list.

Useful Information: Iterators are the easiest way one can cycle through the elements 1
1
of a collection, including ArrayList and LinkedList. There exist two types of i
1
iterators: 1
1
1
e Iterator: allows programmers to cycle through a collection, as well as remove 1
i
any elements they may want. 1
i
o An iterator, initialized to the beginning of the collection, is obtained 1
1
1
by calling the collection’s i terator () method. 1
i
o Iterator methods: I
!
®= boolean hasNext(): Returns true if there are more i
1
1
elements in the collection. 1
1
= Object next():Returnsthe next element. 1
1
= void remove (): Removesthe current element. 1
1
e Listlterator: extends the Iterator to allow bidirectional traversal of a 1
1
1
collection, as well as additional modification to its structure and elements, 1
1
including addition of objects to the collection. 1
1
o A list iterator, initialized to the beginning of the collection, is 1
1
1
obtained by calling the collection’s 1istIterator() or i
1
listIterator (int index) methods. 1
1
o List iterator methods: i
1
1
= boolean hasNext(): Returns true if there are more 1
1
elements in the collection. 1
I
= boolean hasPrevious: Returns true if there is a previous 1
1
element. i
1
1
= Object next():Returns the next element. 1
i
= Object previous ():Returns the previous element. 1
i
® int nextIndex(): Returns the index of the next element. 1
1
1
If there is not a next element, it returns the size of the list. 1
1
= int previousIndex
(): Returns the index of the previous 1
I
element. If there is not a previous element, it returns -1. I
I
1
= yoid remove ():Removes the current element. I
1
= void set(Object o): Assigns o to the current element, 1
1
which is the element returned by a call to either next () or 1
1
I
previous (). 1
1
Both Iterator and ListIterator classes are part of the java.util standard 1
1
library collection. As such, in order to use ArrayList, Iterator and 1
1
ListIterator for our example, the following import statements need to be present 1
1
1
at the top of the file: i
1
1
1
import java.util.Iterator; I
1
import java.util.ListIterator; i
1
import java.util.ArrayList; 1
1
1
1
1
!
Useful Information cont.: In order to avoid writing many import statements at the \

1
1 top of each file, one may use the asterisk (*) symbol to import all package members
1
i as follows:
1
i
1
I import java.util.*;
1
1
I
t
1 All package members under the java.util,
including Tterator, ListIterator
I
I and ArrayList are imported using a single statement.
i
1
1
i
I The following example illustrates how an Iterator may be used to cycle through all
t
1 the elements of a collection. Furthermore, it depicts how a ListIterator may be
1
1 used to modify an object of a collection, as well as how it can be used to cycle
1
i
I through all the elements backwards.
1
I
1
i import java.util.*;
1
1
1 public class IteratorExample {
1
1 public static void main(String[] args) {
1
1 ArrayList<Integer> list = new ArrayList<Integer>() ;
1 Integer one = new Integer(l);
I
i Integer two = new Integer(2);
1
1 Integexr three = new Integer(3);
I list.add(one);
I
i list.add(two);
I
I list.add(three);
1
i
i //Iterator example.
1
1 Iterator<Integer> iterator = list.iterator();
T
i
while (iterator.hasNext()) {
I System.out.print(iterator.next() + “ ),
i
i }
1
i
System.out.println();
1
I
1 //List iterator example.
I
I
ListIterator<Integer> literator = list.listIterator();
1 while (literator.hasNext()) ({
i
1 Integer e = literator.next();
i
I literator.set (e.intValue ()+10) ;
1
I
}
I
1
1 while (literator.hasPrevious()) {
1
1
System.out.print (literator.previous() + “ “);
! }
1
i System.out.println() ;
i
1
i
1
i
t
I
1
The output of the above program is the following:
I
i
i 123
1
i g alz il
1
t
1
The LinkedList class from standard library collections may be imported using the import
statement at the top of the file in which the class is to be used, as such:

import java.util.LinkedList;

After that, one can create LinkedList objects. The following example creates a
LinkedList object, 1ist, that will hold Integer objects.

//Creates a LinkedList object.


LinkedList<Integer> list = new LinkedList<Integer>();

LinkedLists may include only objects as elements and do not support primitive types. They
can, however, include any number of elements. Compared to static arrays, LinkedLists may
include any number of elements, just like ArrayLists.

A full list of all the methods included in the LinkedList class can be found in the official
Java documentation®. However, the most common methods are described below:

e Adding elements to a LinkedList:


0 boolean add(Element e): Adds element e to the end of the list.
Element e may be any kind of object, even user defined objects.
0 void add(int index, Element e): Adds element e to the list at the
position specified by index. Shifts the element at the specified index and
all subsequent elements to the right.
o void push(Element e):Pushes (adds) element e to the beginning (head)
of the list.
e Removing elements from a LinkedList:
o wvoid clear():Removes all the elements from the list.
o E remove (int index):Removes the element at the specified index. All
elements to the right of the index are shifted to the left, to take up the
space of the removed element. The element removed is returned from this
method. The return type, E, may be any kind of object, even user defined
objects.
o E pop(): Pops (removes) the first (head) element from the list and returns
it.
e Retrieving elements from a LinkedList:
o E peek (): Returns the first (head) element of the list.
o E get(int index): Returns the element at the specified index. The
return type, E, may be any kind of object, even user defined objects.
o <T>T[] toArray (T[] a):Populates a static array a with all the elements
in the list in proper sequence.
e Setting an element in a LinkedList:
o E set(int index, E element): Replaces the element at the specified
index with the specified element E. The element previously occupying the
specific index is returned.

® Class LinkedList. In Java Documentation. Retrieved 19:00, July 8, 2016,


https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html
e Searching for an element in a LinkedList:
O boolean contains(Object o): Returns true if the specified object o is
found in the list.
O int indexOf (Object o):Returns the index of the first occurrence of the
specified object o in the list. If o is not in the list, then -1 is returned.
O int lastIndexOf (Object o): Returns the index of the last occurrence
of the specified object o in the list. If o is not in the list, then -1 is returned.
e lterating the LinkedList:
O Iterator descendingIterator(): Returns an iterator over the
elements in the list from last (tail) to first (head).
O ListIterator listIterator(): Returns a list iterator over the
elements in the list.
e Checking whether a LinkedList is empty:
O boolean isEmpty (): Returns whether the list is empty or not.
e Getting the size of a LinkedList:
o int size():Returnsthe number of elementin
s the list.

As it is easily apparent, both ArrayList and LinkedList classes have great similaritie
s.
Both are used to implement list structures, and both may be used in real world applications
without the programmer having to think about what is happening in the internal structure
of
the classes (“under-the-hood”). Furthermore, both have more or less the same methods.
Small differences exist, such as the fact that the E get (int index) method is
faster in
the ArrayList class, whereas the void add(int index, Element e) is faster in the
LinkedList class. These small differences are negligible and beyond the scope of this
book.

Useful Information: Two small programs are included in Appendix A, that present how
stacks and queues may be implemented using the ArrayList class. These programs
also include a text user interface.

D.4.12 Trace algorithms using the implementations described in assessment


statements D.4.9-D.4.11
Exit skills. Students should be able to™:
| Trace algorithms. In examination questions, definitions of Arraylist and LinkedList
methods will be given when necessary.

The algorithms described and implemented in section D.4.9 used a static implemen
tation of
a list. The following two main methods are traced, which are similar to those of section
D.4.9, and make use of ADTListStaticStack and ADTListStaticQueue objects
respectively.
public static void main(String[] args) {
ADTListStaticStack stack = new ADTListStaticStack();

for (int i=5; i>0; i--) {


stack.push(i);
}

System.out.println("Top element is: " + stack.peek()):


System.out.println("Popping top element: " + stack.pop());
System.out.println("Top element is now: " + stack.peek());
}

i>0 stack output


W LG
RN
O

5
_ Popping top element: 1
_Top element is now: o
Table D.2: Trace table for static stack example

public static void main(String[] args) ({


ADTListStaticQueue queue = new ADTListStaticQueue
() ;

for (int i=5; i>0; i--) {


queue.insert
(i) ;
}

System.out.println("First element is: " + queue.peek());


System.out.println("Removing first element: " + queue.remove());
System.out.println("First element is now: " + queue.peek());
}

15,4,3,2]

| First element is: 5


"mfRem né first element:
5
First element is now: 4
Table D.3: Trace table for static queue example

The algorithms described and implemented in section D.4.10 used object references for the
implementation of a list. The following two main methods are traced, which are similar to
those of section D.4.10, and make use of ADTListDynamicStack and
ADTListDynamicQueue objects respectively.

public static void main(String[] args) {


ADTListDynamicStack stack = new ADTListDynamicStack();

for(int i=5; i>0; i--) {


stack.push
(i) ;
}
System.out.println("Top element is: " + stack.peek());
System.out.println("Popping top element: " + stack.pop());
System.out.println("Top element is now: " + stack.peek())

| Top element is: 1


: | Popping top element: 1
De O I
~ Table D.4: Trace table for dynamic stack example

public static void main(String[] args) {


ADTListDynamicQueue queue = new ADTListDynamicQueue
() ;

for(int i=5; i>0; i--) {


queue.insert
(i) ;
}

System.out.println("First element is: " + queue.peek());


System.out.println ("Removing first element: " + queue.remove());
System.out.println("First element is now: " + queue.peek());
}

5
5 true 5]
4 true 5,4
3 true 5,4,3
2 true 5,4,3,2
1
e | true 5,8,8,2,1
L LIS I
T First element is: 5
Removing
first element: 5
| First element is no
Table DE’TTra;:eitabI;Erdyniamlc queue example

Trace Tables D.2 and D.4 are exactly the same, as are Tables D.3 and D.5. Stacks and queues
can be implemented either statically or dynamically, without any apparent differences in the
trace tables. The main difference between static or dynamic implementations of lists, that
could play a role, is the fact that static implementations need to have the size of the list
defined before run time. As such, they can reach a limit where no other elements may be
inserted into the list. This is not the case with dynamic implementations of lists, since in that
case, the lists may expand at run time to take any number of elements.

Section D.4.11 dealt with algorithms that used the standard library collections included in
JETS. The following two main methods are traced, which are similar to those of section
D.4.11, and make use of ArrayList and LinkedList objects respectively.
public static void main(String[] args) {
ArrayList<Integer> list = new Arraylist<Integer>();

for(int i=1; i<4; i++) {


list.add (new Integer(i));
X

//Iterator example.
Iterator<Integer> it = list.iterator();
while (it.hasNext()) {
System.out.print(it.next() + ™ “);
}
System.out.println();

//List iterator example.


ListIterator<Integer> lit = list.listIterator();
while (1it.hasNext()) {
Integer e = lit.next();
lit.set(e.intValue()+10);
}

while (lit.hasPrevious()) {
System.out.print(lit.previous() + ™ “);
}
System.out.println();

~ Table D.6: Trace table for Arraylist example

public static void main(String[] args) {


LinkedList<Integer> list = new LinkedList<Integer>();

for(int i=1; i<4; i++) {


list.add(new Integer(i));
}

//Iterator example.
Iterator<Integer> it = list.iterator();

while (it.hasNext()) {
System.out.print(it.next() + " ");
}
System.out.println();

//List iterator example.


ListIterator<Integer> lit = list.listIterator();

while(lit.hasNext()) {
Integer e = lit.next();
1lit.set(e.intValue() + 10);
}

while (lit.hasPrevious()) {
System.out.print(lit.previous() + " ");
}
System.out.println();

S o Bt (e} biet
BRSNSS A BRI G A P hasPrevious ()

ce table for LinkedList example

Trace Tables D.7 are exactly the same. ArrayLists and LinkedLists can be used
D.6 and
interchangeably, without any apparent differences in the trace tables. Both may hold any
number of elements.

D.4.13 Explain the advantages of using library collections


Exit skills. Students should be able to*

Understand that libraries provide convenient and reliable implementations of


common programming tasks.

Anybody implementing a project of any kind does not want to “reinvent the wheel” and do
extra unnecessary work. This is the case in computer programming as well. For example, if
one has written a sorting algorithm for integer arrays for a previous project, one wants to
avoid having to rewrite it for another project that may need it. Ideally, pre-written code,
tried and tested under scrutiny, does not need to be rewritten but may be used as it is. This
code may be used as a “black box” in that the programmer does not need to know the
internal workings of it, but rather only the input required, as well as the output to be
delivered. For example, in a theoretical sorting algorithm for integer arrays, a programmer
may call the function sort with an integer
array as an argument in this way:
sort (integerArray). The programmer only needs to be aware of the existe
nce of the
sort function, its arguments, if any, as well as the fact that it is going to sort
the elements
of integerArray array in ascending order.

Since searching and sorting, as well as a number


of other programming tasks (ex. accessing a
file, sending data over a network, etc.) are commo
n, most programming languages, Java
included, come with a number of “program sets” that
allow for the easy completion of these
programming tasks. These “program sets” are also
widely known as libraries or library
collections.

As was previously seen in section D.4.11, classes (a.k.a.


package members) from standard
library collections may be imported using the import statement at the top of the file in
which the classes are to be used, as such:

import java.util. ArrayList;

This import statement allows a programmer to access


all the functionalities provided by the
ArrayList. In a similar manner the following import
statement at the top of a file allows
the sort (int[]) function described before to be used:

import java.util -Array.sort(int[] N

In order to avoid writing lots of import statements


at the top of each file, one may use the
asterisk (*) symbol to import all package members
as follows:

import java.util.*;

All package members under the java.util, including Iterator, ListIterator and
ArrayList are imported using a single statement.

Libraries provide convenient and reliable implementations of common programming tasks


since:
e Code in libraries can be written and tested independently of any specific
applications.
® Code in libraries may be used as a “black box” since
it is known to be working. If a
bug is present in the application, it exists in the applic
ation and not in the library,
reducing testing and debugging time.
e Code in libraries may be used in a number of applic
ations and programmers do not
need to “reinvent the wheel”.
e Code in libraries reduces the size of the applic
ation files. Programmers can call
library code and avoid writing it as application
code, which would make the
application files long and cumbersome.
D 4.14 Outline the features of ADT’s stack, queue and binary iree
{701 811118 Students should be able to':

example, they
| Provide diagrams, apphcatlons anddescnptrons of these ADTs. For
and retrieve unique
| should know that a binary tree can be used to efficiently store
keys.
|

d in detail both in
The features of ADT’s stack, queue and binary tree have been discusse
list of these features is
Chapter 1 (Topic 5), as well as in the current chapter (Topic D). A
briefly provided below:

e Features of Stack ADT:


o Stacks are made of a "chain" of data.
o Elements can be "pushed" onto the top of the stack.
o Elements can "popped" from the top of the stack.
o Elements follow the LIFO approach.
be
o Trying to access an element from an empty stack causes error and should
avoided.
o Features of Queue ADT:
o Queues are made of a "chain" of data.
Elements can be "enqueued" at the back of the queue.
o Elements can be "dequeued" from the front of the queue.
o Elements follow the FIFO approach.
o Trying to access an element from an empty queue causes error and should
be avoided.
e Features of Binary Tree ADT:
o Trees are made of nodes which have two pointers. One pointing to the left
of the node to elements smaller than itself, and one pointing to the right of
the node to elements greater than itself.
Trees assemble themselves from the root node.
In case of a balanced tree, the root node contains the middle value of the

whole set.
They are naturally sorted.
Searching can be done in a binary manner.
O

D.4.15 Explain the importance of style and naming conventions in code


Exit skills. Students sh uld beable to':

sty
Understand L1 meamngful |dent|f1ers, T e I mdentatson LT adequate
in
all improve the readability of code for humans and save money, time and effort
programming teams.
across
INT, AIM 5 The need to develop a common “language” to enable collaboration
international frontiers when resolving problems.
Standards and conventions are established to make life easier. They allow people to function
and collaborate at an international level without difficulty. For example, the traffic light
convention dictates that a vehicle must stop if there is a red light, pass if there is a green
light and be cautious at an amber light. This international convention allows people to drive
in any part of the world without any problems. On the other hand, height measurements do
not follow a single international convention. Some people, in some countries, use the metric
system and measure height in meters and centimeters, while in other countries they
measure height in feet and inches. There are a number of situations that do not follow a
single international convention. This leads to difficulties in understanding and
communication between people using different conventions for the same thing. Of course, a
lot of these conventions go a long way back in human history, before globalization, and have
been embedded so deeply in local cultures that they are difficult to change. For example,
while in most of the world people drive on the right-hand side of the road, there are some
countries where people drive on the left-hand side. This difference leads to drivers having
difficulties switching between the two conventions, as well as increased economic costs for
the car industry as a whole, since two types of cars (i.e. some with the steering wheel on the
left-hand and some on the right-hand) need to be created for every car. As such,
international conventions are important and allow for a common “language” that enables
easier communication and collaboration between individuals across the globe.

Programming has its own conventions to allow people from around the world to easily
exchange code and be able to work around the same projects. The reduction of cost,
especially during the maintenance phase, is also a key reason for following coding
conventions. Since most of the cost of a piece of software is taken up with the maintenance
phase7 and because the maintenance is almost always performed by someone other than
the original author, code conventions are necessary to improve readability and allow for any
engineer to understand previously written code quickly and fully. Code that is “clean” and
follows the internationally established conventions is easier for another programmer to
understand and alter, and is therefore easier and less costly to maintain.

The most common coding conventions include the following:

e Language conventions: All programming languages (except from some educational


programming languages) use the English language, so as to remove a language
barrier.
e Comment conventions: Comments can either be “block” (a.k.a. prologue) or “line”
(a.k.a. inline) comments.
o Block comments in Java need to be delimited by /* and */ and may span
multiple lines.
Line comments in Java need to be delimited by //.
The best use of comments is subject to dispute, but overall they are used to
summarize code.

7 Robert L. Glass. Facts and Fallacies of Software Engineering, Addison Wesley (2003)
o Block comments can be used before every class or method to provide a
general description. Line comments can be used on top or next to a line of
code whose workings may not be apparent. An example is shown below:

/’*

The main method loops through numbers 1 to 10


and outputs whether the number is even or odd.
4
public static void main(String[] args) {
int a = 0;

//Loops through numbers 0 to 9.


for(int i=0; i<10; i++) {

//a is incremented in every loop.


a = a+l;

//Checks if a is even or odd and outputs


//the result.
if(a%2 == 0) {
System.out.println(a + “ is even.”);
} else {
System.out.println(a + “ is odd.”);
}
}
}

o Comments should be simple and to the point. The need for a lot of
comments may signify complex code that may need to be rewritten. The
code on its own, using sensible naming conventions, should not need
extensive commentary to be understood.
e Indent style conventions: Although in most programming languages it can be
omitted, indentation of programming blocks conveys the program’s structure and
makes the code easier to read. There are a number of indent style conventions
available®, but all use spaces to signify that code is contained inside some other
code, as can be seen by the following example:

public static void main(String[] args) {


int a = 0;

for (int i=0; i<10; i++) {


a = a+l;
System.out.println(a) ;
}
}

The code inside the main method is indented two white spaces to the right. The
code inside the for loop is indented two further spaces to the right, signifying that
it is both inside the main method and the for loop construct.
e Line length conventions: These refer to the maximum number of characters that
may appear on a single line. Although these conventions probably originated due to

& Indent style. (16, July 2016). In Wikipedia, The Free Encyclopedia. Retrieved 15:05, July 20, 2016,
from https://en.wikipedia.org/wiki/Indent_style
older technical limitations, such as various punch cards that could only consist of 80
characters in one line, they still play a role in modern programming. Screen sizes and
r resolutions have increased, allowing for a larger number of characters to be easily
presented in one line without having to wrap around to a second. Most
programming style guides define a desirable number for characters per line to be in
the range of 72 to 100°. Having to read code that spans more than one line is hard
and should be avoided when possible.
® Naming conventions: A set of rules for naming identifiers. Identifiers can be of any
type of entities, such as variables, method and classes. Giving sensible names that
follow specific conventions, to variables, methods and classes reduces the time and
effort needed to read and understand code. It can also provide additional
information for the identifier. For example, classes may always start with a capital
letter, whereas object instantiations of classes may always start with a lower case
letter. Naming conventions lead to consistency between individuals working on the
same code, enhance clarity and reduce ambiguity. They also help avoid “naming
collisions” between identifiers, leading to two identifiers with the same name.
Overall, following naming conventions and using sensible names for identifiers, that
describe the specific use of the identifiers, leads to better understanding of the code
after a long interval of time and as such, to easier and less costly maintenance.

—_— e

° Characters per line. (7, July 2016). In Wikipedia, The Free Encyclopedia.
Retrieved 15:10, July 20,
2016, from https://en.wikipedia.org/wiki/Characters_per_line
End of chapter example questions with answers

Exercise 1: Consider the following method, method, where a is a non-negative number and
bisa String.

public static String method (int a, String b) {


if (a == 1)
return b;
} else {
return b + " " + method(a-1, b);
1
}

Define recursion.
Trace the call to method (5, "hi"), showing all steps and the final output.
Using method method, construct a method with the following signature:

String method2 (int a, String b, int c, String d)

that obeys the following specification:

e ifa > c then it first prints String b c times, then prints String d, and
finally prints String b a-ctimes.
e ifa <= cthenitprints”a must be greater than c".

For example, the a call tomethod2 (5, "hi", 3, "hello") will output:

hi hi hi hello hi hi

Answer to Exercise 1:

1. Recursion is a programming technique where a method calls itself.


2.

method (5, "hi")


hi + " " + method(4, "hi")
hi + " " + hi + " " + method(3, "hi")
hi + " " + hi + " " + hi + " " + method(2, "hi")
hi + " " +hi +" "+ hi + " " + hi + " " + method(l, "hi")
hi +" " +hi +" " +hi+ " " +hi+""+hi
Outputis:hi hi hi hi hi
3k

public static String method2(int a, String b, int c, String d) {


if (a > c) {
return method(c, b) + " " + d + " " + method(a-c, b);
} else {
return "a must be greater than c";
)
}
Exercise 2: Taking into account ADTListDynamicQueue from D.4.10, trace the following
code below.

public static void main(String[] args) {


ADTListDynamicQueue queue = new ADTListDynamicQueue
() ;

for(int i=5; i>0; i--) {


queue.insert
(i) ;
}

System.out.println("Elements in queue:");

for(int i=0; i<queue.size(); i++) {


System.out.println (queue.remove()) ;
}
}
}

Answer to Exercise 2: A new ADTListDynamicQueue object is created named queue. The


first for loop populates the queue, adding the elements 5, 4, 3, 2 and 1. As such, the
elements in the queue after the first for loop are:

front-5 4 3 2 1-Dback

In the second for loop i begins from 0 to one less than the queue size. However, during
every loop an element is removed from the queue. As such, after every loop, i increases by
one, but queue. size () decreases by one as well.

The trace table is the following:

fo VRS i<gueue.size () ocutput


> ©
5
5 4 3
4 3
1

3
u

4
4 32
oo

Elements in queue
3 2
2
Nwes

S 4
1

Exercise 3: Construct a program that checks whether a given email address is valid. An email
address is valid if it adheres to the following rules:

The @ character is included once.


A period is included once after the @.
At least 2 characters are included after the period.
There are at least 2 characters between @ and the period.
There are at least 3 chars before the @ character.
Answer to Exercise 3:

public class email validation


{
public static void main(String [largs)
{
String email = "kdimitriou@haef.gr";
int length = email.length();
boolean correct = false;
int counter = 0;
int c_counter = 0;

for (int i=0;i<=length-1;i++) {


if (email.charAt(i) == '@')
{
counter= counter + 1;
}
}

if (counter==1) {
System.out.println("The Q@ character is included once");
c_counter = c_counter + e
}
int at_index = email.indexOf('@");
String a = email.substring(at_index+l,length);
int counter_2 = 0;

for(int i = 0;i<a.length() ;it++) {


if(a.charAt(i) == ('.")) {
counter 2= counter_2 +1;
}
}
if (counter==1) {
System.out.println("A period is included once after the Q") ;
c_counter = c_counter + 1;
}
int index_period = a.indexOf('."');
int lengtha = a.length();
int distance (length_a—l) - index period;
1

if (distance>=2) {
System.out.println("At least 2 characters are included after
the period");
c_counter = c_counter + 1;
}
if (index period>2) {
System.out.println("There are at least 2 characters between Q
and the period");
c_counter = c_counter + 1;
}
if (at_index>3) {
System.out.println("There are at least 3 chars before the @
character");
c_counter = c_counter + s
}
if (c_counter != 5) {
System.out.println("Email is incorrect") ;
} else {
System.out.println("Ok");
}

Exercise 4:

Consider the following problem:


Mr. Joe Doe is a high-school teacher in Athens, Greece. He teaches all school grades and is
also responsible for all the computers in the school. The school started a school bookstore
around ten years ago, where schools could buy and sell second hand books and magazines,
to keep the prices low. Since it began as a side project and was initially small, there was no
need for keeping a digital record of the books and magazines.

Currently, all reading material (books and magazines) are allocated a unique identification
number and a paper card is created for each one of them that includes all their details.
Whenever a student buys a book or magazine, the paper card is removed. When a student
brings a book or magazine for sale, a paper card is created.

The school bookstore has grown a lot since the economic crisis hit Greece in 2010. Each year
more and more students prefer to sell their books from the previous year and buy used
books, for their new school year, at a lower rate. The school bookstore has grown so much
and so much paper card housekeeping needs to be managed by Mr. Joe Doe alone that he is
having a hard time keeping up with it. Although the school bookstore is a vital part of the
school, Mr. Joe Doe cannot be offered any help, since the school is a public one and there
are no funds available to recruit a full-time employee. As such, the current system, under
the current circumstances is inadequate. The new application should be maintainable and
there should be a way to back up all the data. The new application would need to handle all
the aspects of the bookstore in a digital manner so as for Mr. Joe Doe to remove the paper
cards currently in place and limit the time spent in housekeeping. The computer available for
the school bookstore is an old one and running Windows XP. It has Java installed.

Develop a Java program that will correspond to the above scenario. The program should
fulfil the following citeria:

A friendly command line interface that allows for easy use of the application.
N e

A list of all the reading material in the bookstore.


©eONOUr®

Alist of all the reading material of some specific publisher.


A list of all the publishers of the books or magazines in the bookstore.
A data entry form to allow the addition of a publisher to the bookstore.
The ability to remove a publisher from the bookstore.
A data entry form to allow the addition of a reading material to the bookstore.
The ability to remove a reading material from the bookstore.
The ability to sort the reading material in the bookstore, according to price.
10. The ability to search for a reading material, using its ID or title.
Answer to Exercise 4:

ReadingMaterialFile
LinearSearch

5 =e
s LR
;
Ees L5 3 SEES SR
<<abstract>>
ReadingMaterial

Magazine

1 t
I
I
Ee=c e
Book
Lt

ReadingMaterialFileRAF
CEosmmeen
PublisherFileRAF

Figure D.10: Bookstore classes

ReadingMaterial, Book, Magazine and Publisher classes


The main data structures surrounding the bookstore can be the ReadingMaterial, an
abstract class, that just describes the basic information related to anything that may be part
of the bookstore. Since it is an abstract data structure, more concrete data structures need
to be created that can be used to create actual data objects in the bookstore. These
concrete data structures are the Book and the Magazine. Since they extend the capabilities
of the abstract class ReadingMaterial, both will have all the variables and methods
included in this class. As such, both will have an id, title, pages, price and a
publisher, as well as the getter and
setter methods for these variables. A book will also
include chapters and a list of authors, while a magazine includes a list of additional resources
it may come with (ex. a cd, recipe guide, etc.).

IO class
In order to describe a publisher, one will need more than just a primitive data variable, such
asan int or a String. So, a Publisher data structure will be needed. It will include the id,
name, address, telephone number and website of the publisher. Every Book or Magazine
will have a single Publisher.
In order for the product to communicate with the user through a command line interface it
will need a way to output and input data:
e The output is easy, it's a single standard command provided by the Java
environment: System.out.print
() and System.out.println(). The later will
terminate the current line with a newline character. Any String that appears
between the parenthesis of those commands will be printed to the terminal.
e The input is a bit more complicated. For that a public I0 class will be created that
will include a static method named input. That method will receive a String that
will be shown as a prompt to the user (ex. “Please enter the title of the
book:”).

ReadingMaterialFile and PublisherFile classes


The product will hold information regarding books, magazines and publishers. In order to do
so, all this information will need to be stored in files so that they may be retrieved and
persist after the application quits.
There are two classes that will be responsible for the reading and writing of all this
information to specific files:
e ReadingMaterialFile will write/read and output all the information regarding
the reading material (books and magazines). The information will be placed in two
separate files, one for the books and one for the magazines, respectively.
e PublisherFile will write/read and output all the information regarding the
publishers.

LinearSearch and SelectionSort classes


In order to be able to search through or sort any kind of data some kind of algorithm is
needed:
e The LinearSearch class will encompass different static methods that will allow the
user to search through a number of arrays holding different kinds of data, such as
Publisher, Book or Magazine objects.
e The SelectionSort class will encompass different static methods that will allow
the user to sort a number of arrays holding different kinds of data, such as Book or
Magazine objects.

Queue class
In order to be able to read the bookstore information from the files, one needs a data
structure that may handle any number of elements and not just a static array that may hold
a predefined number. Since the number of elements that will be read will be unknown the
Queue class will play that role. It will provide a simple implementation of a Queue data
structure.

InputTerminal class
This will be the class that will handle the communication of the user with the product while
creating new Book, Magazine or Publisher entries. It will be comprised of static methods
that will be called from the Bookstore class, where the main method of the application will
reside.

Bookstore class
Will be the entry point of the application. It will hold the main method and will be
responsible for most of the communication between the user and the product. It will
present the main menu, read in the user selections and orchestrate the correct functioning
of the application.

ReadingMaterialFileRAF and PublisherFileRAF classes


These two classes will have the same functionality as ReadingMaterialFile and
PublisherFile, respectively, but will use RandomAccessFile.
Using the RandomAccessFile is not necessary and is not used by default. It can be turned
off/fon by making withRandomAccessFile, in Bookstore and InputTerminal,
false/true, respectively. The RandomAccessFile functionality is included just to present
the different ways one may read/write to a file.

The code solution for this question, provided below, can also be digitally found online at:

http://www.expresspublishing.co.uk/ibadvancedcomputerscience

This code is copyrighted and should not be copied and pasted as part of any assessment, but
may only be used as a guide.

The code solution, provided below, may be improved in a variety of ways that are beyond
the scope of this book. However, some improvements are considered below:

e Additional input validation and error handling: At the moment, the product only
performs a small amount of input validations. For example, if the user does not
input anything for the title of a book it will request the title again. However, there
are a number of occurrences where input validation and error handling could be
better. For example, when the user inputs text instead of an integer when the
program is expecting the latter, or when the user inputs a decimal point number
instead of an integer. The application should be able to handle such input and
output a useful error message.
e Addition of a graphical user interface (GUI) instead of command line interface
(CLI): Visual interactive elements such as buttons, lists, menus would make the use
of the application a lot easier.
e Introduction of some sort of encryption/decryption algorithm that would allow
the bookstore data to be stored even more securely.
e Ability to make automatic backups: At the moment backups can be performed
manually by copying the three data files that have to do with books, magazines and
publishers. This could be done automatically by the application to make life easier
for the user. For example, it could create a copy of the files on the desktop.
e Publisher removal if no reading material links to it.
e Publisher removal disallowance if there are reading materials that include it.

Another aspect that could be improved, although it would be transparent to the users,
would be the actual code of the product. There is some duplicate (identical) code in various
classes (especially ~ ReadingMaterialFile, ReadingMaterialFileRAF and
InputTerminal) that could be combined and simplified.
TerxeieRbuTpESY SUL IO PT BUR DT wexedy o
*
pouzsu IO3EINH x
%/
{ !pT uanysx }
()pI3eb jur or1qnd
/%
TetIsaeRbUTPRSY SY3 FO PT U3 UINIBIF «
#
POYIOW IOSSVOOY x
xx/
{
tzoystTqnd = zoystrand-sTyl
!ootad = sotad sTyl
!sebed = ssbed-styj
{9T3T3 = STITH" sTu3
pPT = PT STU3
}
(zoyst1qnd xoysTtTgng ‘ootad jur ‘sebed jur ‘o73T3 buralzs ‘PT JuT) TeTISIERBUTPESYN
\*
y
Terassenbuipes oyyy o xeystiand sy3 ssystiqnd wezedy
es
Tetassepbutp syl go eotad syu3l eotad wexedy o
esy
TeTIojenbutp 9ya yo sebed yo xequnu 8yl sebed wexedy i
Y
TeTIoleRbUTPES Syl 3O ST3TI SUI 21313 wezedy .
Y
TeTILlRROUTPRe oYyl JO PT Byl pT wexedy
¥
D
AOJONIZSUC ¢
%/
‘xoystTgnd asystTgng o3eatad
Code of the product

!ootad jut ojeatad


!sabed jur =3eatad
{97313 butazs ozeatad
!pT 3ur ojeatad
}
TeTao3eROUTPESY SSeTD® 3oeajzsqe oTTand
sse1o TeIIolERbuTpRSu//
Teraelew bBurpesy syz jo sotad syl uaniery »
%
POyl W IOSSVOOY
x/
{ !{sobed = sebed’'sTtyz }
(sebed jut)sebegies proa OoTTAnd
I
Tetaejerburpesy oyj Jo s=bed o xequnu Lyl sebed wexedp y
¥
POYISW IOFBINN x
wx/
{ !{sebed uanzox }
() ssbegasb jur orTgqnd
/x
Tetaolerbutpesy sy3 zo sebed o zsqumu syl uInISIAY 4
*
POYRBU TOSSVOOY x
%/
{gf®TaT —ieTaTINSTUL |}
(313713 bButais)sr3iTiies proa orTqnd
/x
terasjegbutpesy eyl Jo STITI oyl 873713 wexedy x
%
poylew I03eINH
wx/
{ /®13T3 uanyex }
()®1311396 Butazs orignd
/%
TetxeleNbuTPESY Syl FJO °TITI Oyl uanlexy »
*
poyl el IOSSVDDY
xx/
{ !PT = PT'STUY} }
(pT 3uT)pI3Ss pros oTTand
/%
j00q Sy3 3O STITI euys or3r3 wexedy i
jooq eyl Fo PT Su3 Pr wexedy
¥*
I030RIJSUOD x
xx/
!saoyane []butazs s3eatad
f‘sao3deyo jut s3zeatad
}
TetzejegbuTpesy spusixe joodg sseTo oTTqnd
sseTo ood//
{
{ tzeystiqnd = asystrqnd sTy3 }
(zoysTTand I9YSTTNd) IBYSTTGNE3®s PTOA OTTqnd
Tetxsjepburpesy syl Jo xoystIgnd Sy3 zoystrgqnd wexedp
poyrsw I03BINW x
wx/
{ ‘zsystrgnd uanzex }
() aoysTTang3eb zeystIqnd oTTqnd
/%
Terxejeu Dutpesy oyz o zeysTignd oy3 uINIDIAP
*
POy BW IOSSVOOY ¥
wx/
{ ‘eotad = sotad-'styl }
(eoTad 3utr)o0TId3os proa oTIqnd
/%
Terxsiepburpesy oy3 jo sotxd 8yl sotxd wexedpy
¥
poyjsw I0JBINW
wx/
{ !ootad uangzex }
()®o12g39b juT OTTqnd
/%
poyjew Fo3eIng 4
xx/
{ !szoygne uanzax }
()saoyznyysb []Butxzs orTgnd
/%
H904q eyl o saoyine eyl II® JO ISIT uInyeay .
¥
PoOYLSW IOSSIOOY x
sx/
{ ‘/sasadeyo = sxszdeyo sTyz }
(sas3deyo 3ut)sasideypiss proa otTqnd
/%
joog sy3 ut sxsadeyo yo zsquUnu BYJ szendeys wexedp x
%
POYLSW IOJRINNW x
xx/
{ !szoadeyo uangzax }
() saoadeypasb zur ortand
/%
joog 8yl ur sxejzdeyd FO ISQUU BYJ uInlexy x
POYIBW IOSSODDY H
xx/
d:
!saoyane = saoyane'sTY3
/szo3deyo = szoizdeyo- sTY3
! (zoystTqnd ‘eotad ‘sebed ‘sT3T3 ‘pT)aadns
‘zoonazsuon TeTILIERBUTPESY °Ul STTRD//
}
(zoysTTqnd aeystIgnd ‘saoyzne []Butalzs ‘saejzdeys jur ‘=sotad jur ‘sebed jur ‘°T3TI BuTazs ‘prT jurt)yoog oriqnd
/%
jooq oyz yo aeystiand oyy zeystrand wexedp x
}oog Syl Jo saoyzne oyl TIEB IO ISTT ® saoyzne uexedp
joog oYy ur saejdeyo yo Iequnu ayz szeadeyo wexedy

Kk
jooq ey3z go 9otad syl sotad wexedy

®
yooq @2uy3z go s=bed go Fsqunu Y3z sobed wexedp

®
{ !s9DaInosSSYTRUOTITPPE uUINlax }
() sepanosayTRUOTATPPYISD []bPutazs ortgnd
/%
sutzebew syjz JO SVDINOSVI DYJ TR FO ISTT UINISIP x
*
Poy3om I0SSIDDY x
xx/
/SODINOSOYTRUOTITPPE STUF
= SOOINOSSYTBRUOTITPPE
! (zoystiand ‘eootad ‘sebed ‘sT3T3 ‘pT)Iadns
‘x1030NIZSUCD TRTIOIERDUTPESY 3yl STITED//
) }
(zoystTaqnd I9ysTIOng ‘seoanoseyreuocT3TPPE []Burids ‘eotad jur ‘sebed jur ‘°T3T3 DBuralds ‘PT Jut)ourzeben otTand
/4
surzebew oyz yo xoystrand syy xoystrand wezedy x
{‘o3e ‘eumgxed Trews ‘eptndb odrosx ‘spTnb AL " %9) *
surzebew oyz yo 3aed se pepniout oq Kew jeym X
S9DINOSDI BAJXD Aue JO JSTT B SOOINOSOYTRUOTITPPR wexedy g
yooq ayy yo sorxd sya aotad wexedy x
jooq ayz yo sebed yo zoqunu Y3 sebed weaedp s
}0Oq By} FO OTITR SR or3t3 uwexedy x
}0oq By} 3O PT BuI pr weaedy x
%
Z03DNILSUOCD
xxf
IPPE
!seooanossyTeuoT3 []butails ojeatad
}
e Tetaojeburpesay spuojxs aurzebey sserd orrand
sseyn 2utzebey//
{
{ !{szoyazne = sioyjzne'styl }
(szoyane []HButalg)saoyjnylss proa orTqnd
/x
jooq 9yl Fo saoyine 8yl TTE JO ISTI sxoyne wexedy x
*
*
POY3SW IOSSS0OY 4
wx/
{
{93TSgaM = 93 TSSM STY3Z
‘suoydsTey = suoydeTo - sTU
lZ
/{SS9Ippe = SS9IPpE’STY3
!oureu = Sweu -’ sTYl
!PT = PT STU3}
}
(o3Tsqem mnfiuum,\wnosmwflcu 3uT ‘ssezppe burtals ‘sueu buray S ‘PT 3uT)aoysTIang orTand
/%
zeystiqnd By3 yo e3rsqem |y o31sgen weaedp
asystrand o2yl yo suoydeyen oy3 ouoydeTen wexedp x
zeyusTTgqnd Syl Jo ssaappe au3 ssaappe wexedp y
oysTIgnd 2yl JO Suweu sy3 suweu wexedp i
zeystignd ey3 yo pr Y3 pr uwexedy x
*
Z0JONIAJSUCY x
xx/
!93Tsqem butazs sjeartad
‘suoydsTe] 3utr =3eatad
!sseappe burtazs sjeatad
foureu buta3zs sjeatad
!PT jut °j3eatad
}
IoysTIqnd ssero ortand
SseTo ILySTTARd//
{ !s®dInossyTEUOTI}ITIPPE = S90INOSSYTRUOTITPPR "STY3 }
(seoanosex []BuTtals)Se0INOSEYTRUOTITPPYISS prToa otiqnd
/%
sutzebew Yl FO SYDINOSSI VY3 TTe IO ISTT B 308 sooanosex wezedp i
*
POYISW I0FTINR
*x/
*
PoY3sW I0IBINK £
%/
{ !sseoappe uiniax }
() sseappyasb bButazs orTand
/%
zeystIqnd Syl JO SSBIPPR OYI uInNIeAP ¥
x
poyjeul IOSSBODY x
xx/
{ !sweu = sureu'sTyl }
(sweu BuTalg)sweN3Ss pToA ot1qnd
/%
aoystrand Sy3z Fo sweu ay3l oueu wexedp x
*
poyjsw I03eINK x
wx/
{ ¢{ouwreu uan3ysx }
()oweN3sb butazs oriqnd
/%
aeystTand eyl Fo SurRu Iy} uINISIAY »
*
POy BW IOSEDOOY
xx/
{ !PT = PT"STU3 }
(PT 3uT)pIies proa otrignd
/%
zoystignd 8y3z o PT Byl pr wexedp x
*
poyjsw I03eINK x
**\
{ !pt uanjex }
()p13eb qur or1and
L /*
asystTqnd sy3 3Jo PT U3 uan3exy x
{ ‘®3Tsgem = °3TSgem STUZ }
(°3Tsqem Butalg)e3TsqeMiss proa orrand
/x
asystignd syl Jo s3TEges DYJ s3tsgen wexedy 4
x
poujsul I03e30H x
N*\
{ ‘s3Tsgem uanjzsx }
()®31sgemaeb Butazs orrand
/*
aeystiqud 8yl JoO 3TEgEM PUJ UIANYDIAP «
¥
poulsW IOSSIIOY x
xx/
{ !suoyderel = suoydeTol STyl }
(suoydsTa3 jut)suoydeaTaries proa ortqnd
/%
aaystiqnd sy3y yo suoyderen oyl sssappe wuexedy x
¥
poujsw IOJeINH »
xx/
{ !suoydsre3 uanjysx }
()suoydatrsgiab jur orrqnd
/x
zsystygnd sy3 yo suoydeTs] syl uaInyeAy #
%
poylBUW IOSEBODY «
2x/
{ !ssoappe = sseippe 'sIyz }
(ssoxppe bButa3sg)ssoappyiss proa orrqnd
/%
aoystTgnd ®Yy3 JO SSLIAPPR SUJ ssoappe uwexedy x
i i eS e
}
(yeTtaxoogpesz []3oog oT3eas orrdnd
/%
"S°F)
(ex095%00q SU3 UT SY0OQ eBUF TTEUINI SIH
sTTAOOq BYF FO SIuSIUOR SUF TTF yatm Leaz
¥
TT® spesz - STTAACCEPEIRI 4
SY3 FO SOTIRUS HOoq SUI
sz035300q ¥¥\
- gpoussu peleTea oog//
futzyg TRUTIF DTIERS
! oTTasuTZRbRY, = mSflZmAHh|HZHmKw¢S
Hutazs TeUTF OTIEAS
:,oTTdy00d, = EWYNETII YOOH }
orTaTRTIOIEROUTPESY SSBTD ottand
“umumwmwfiflm.Ofi.m>mfi qxodut
uumvm0MUmumwusm.0fl.m>mn axodut
Numufluzuuaum.OH.m>mn qxodut
ssen BTTATRTISRERbUTPES//
{
{9uUTT uIN3ex
{
fun = SUTT
} (e uoradedoxd) Yo3IED {
Mau) = SUTT
fl anvvammmvmumuwflm.Ofl.mbmfl
vHwfimmemwuumunmnH.Ofl.m>m } &x3
wAvw:flqvmwu.AAAcfi.Ewpmhm
NAmwmwmmEvunflum.uso.Ewumhm
{4u = OUTT butils
}
putays)andur Sutailzg DTIEIS
(obessau
}
OI SS®eId ottand
SSBTD ot//
!/ ()onend MBU = 3STTIOYINE =nond
! ((usyogaxeu ‘T+usyol)burazsqns ourr)juresaed-asbejur = grasysriTqnd 3uT
! (T+usyoy ’ 1) FOXSPUT 'BUTT = ueyOL3IXBU
{UjyOL3XSU = USHOJ
! ((ueyoraxsu ‘T+ueyol)burtazsqns sury)juresaed aebejur = saezdeyo jut
{(T+usyoy ’ ' SUTT = USHOLIKSU
4) JOXOPUT
{ueOoI3IXOU = uSyOo3
! ((usyor3yxeu zebejur
‘T+usyol)butaasqns-ourT)3ursszed = sortad jur
{(T+uUe¥03 ‘. :.) FOXOPUT SUTT = USHOIIXSU
!{uaorlx¥ou = udO
! ((ueog3ixau ‘T+usyol)buraisqns sury)jurssaed asbejur = sebed jur

I
{(T4u®303 ' SUTT
‘,:,)FJOXSPUT = USYOLIXSU
{U9yOI3IXBU = USHOI
{ (ueogaxau LUl
‘ T+usyol)butazsqns = o9T3T3 HButals
! ((usxo3 ‘g)burazsqns sutT)juresaed-aebejul = PT FUT
£ (T4U9x03 ’,1,) FJOXSPUT SUTT = USHOLIXSU JUT
! (41 4)JOXSPUT SUTT = USYO3F JUT
{1 + yabust = yzbust
} (TTnu =; (()surTPesz yooginduT = SUTT))STTUM
‘0 = yabusr ur
!eutT butaas
! (eTTaYo0ogeY3) TopEaYpaIeFIng MU = YooginduT ispesypeioiyng
MOOSH) I9PesdeTTd
¢ (EWYNEIIA MdU = STTIH0Ogey3 ISpeayusTTd
} &3
/{11nu = syooggoleaxe []3jood
!{()onand mMsu = sjyooq onand
£ (uu)uTautad- 3no-we3sis
Butjesad ‘3STX® jJOuU SSOP ISTTF H00q wnH=v=Hu:flNm.uno.Ewum>m
Ly Tmou 3T
! (un)ut3zurad-3no-we3sis
{()Butazsoze = Ix° Burais
‘pejeeId ©g 30U UBD IO ISTXS J0U SI0P sTTAN00q//
} (o uotadeoxm) uyojed {
{
onandwoxgiooq = [T]syoogzoleaae
= onandwoxilooq ood
“Avmflwnwwv.mxooafixoomv
} (44T {y3busT>T ‘0=T 3IUT)IOF
! [yzbuat]oog MU = syoogzokeaxe
{
1 (Azaue) snenbua * s300q
‘sebed ‘®T3T3 ‘PT)300H MOU = Kxjue 3joog
! (zaystIgnd ‘saoyine rsxoqdeyo ‘eotad
oy sT
TMISYS TA
TIARGP )
STTIISYSTIAN
EST nd = zeysTTand IOUSTIANA
/ (grxAIYA
{
uAvmswnwwv.umflanonusmAwflflnumv = [T]saoyane
} (++T ‘y3bueT-szoyine > T {0 = T IUT) I03
u—Avmuflm.UmHAuonuamHmnfluuw mou = saoyzne []Butais
{
{(T+ueyol ' SUTT
. i.) JOXOPUT = USYOLIXSU
{usyog3IXdU = uUSYO3
“Anonpswvwswswflw.umfiqncnufim
¢ (uoyogaxeu ‘T+usyol) buraysqns SUTT = Ioyine Butays
} ( T- =i uejol3x¥su )STTUM
£ (T4+US303 ‘. :.)FOXSPUT SUTT = USYOIF¥SU
ueyoLIXdU = USAOJF
} &x3
{1Tnu = 3nd3lno I9ITAMIUTIA
}
(s300q []%00H) STTANOOHOLSHOOHSI
TIM PTOA DTIEds orTand
/%
sjooq Fo Avxze ue syooq. weaedy y
3 ¥
‘97Tz A00q BY3 03 SHoOq FO KeITe UR SBYTIM - BTTANCOHOLSHOOHSITIM x
xx/
{
¢ (3(00EPAPPYYI
TMSH00]) STTINOOHOLSHOOHDF TIM
‘q = [0]300HPoPPYYUITMSIOO]
{[1]300g MSU = }OOHPSPPVUITMSHOOQ
} esto {
{q = [1-Y3BUST * JOOHPSPPYUF TMSHOOA] JOOTPOPPYUR TMSHOOq
{
{[T]sj00q = [T]3COHPEPPYUITMSIOO]
} (+4T ‘yabusT-syo0q > T Q=T 3UT)I03
¢ [T+y3busT s300q]300H MU = JOOHPSPPVUITMSIOO]
} (TTnu =i syooq)zFt
{}00gpPIPPYUI TMSH0oq []3o0d
{()eTTayo0gpeEax = sjyooq []3joog
(9 300g) STTIAOOFOLSITIM PTOA DTIFEIS UMHpaw
Kxjus joog meu B q Emuumwxu
*STTI yooq sy3 03 AIjue OO MSU B SBITIAM - OTTIHOOHOLSITIM H
5/
{
!syjoogFoAraze uanjzsx
o s + [[lsaoyane)3jurad-3ndino
asT®
w + [Llszoyane)urjurad andano
(T-y3abueT
' saoyane == {)3T
} (+4C ‘yabuet-saoyane>l (o=C jur)aoz
/() szoyanyaeb-duey = sazoyzne []HButaizs
{(uiu + ()p139b-a9ystrand)3jurad:andino
!(uiu + saozdeyo)jurtad-andano
!(uiu + ®0o1ad)3utad:andano
'y + sobed)jurad-zndano
+ ©13713)3urad-3ndino
+ pt)3utad-3ndino
*®TTF STTAH0Oq 3y3zo3 weya pusdde//
dwey
‘() asysTTqngieb = xsystiqnd IBYSTIIANg
! () saoadeypisb-dwey = sxesjdeyo jut
!()ootag3eb duey = sotad jur
! () sebegyeb-duey = sebed jur
{()®13T1396 dwey = o13713 Buraas
{()pI3eb-duey = pT 3uT
![T]syooq = dwejz xoog
} (++T {y3busT-sxooq > T Q=T JUT)I03
} (0 =i y3busT'sjooq 33 TTAU =] SY00q)3IT
! (wu)uT3utad- 3no-ue3sis
(. 'Mou 3T BuTle9ID ‘3STXD 30U SSOP OTTIF YOOq 9YL,)uT3zutad-zno- wejlsis
‘(
yutjutad-3no- welsis
! ()butaysols = zxs Butals
‘pelesad 8q 10u uBD IO JISTX® J0U S80p sTTaY00q//
} (@ uotadeoxm) yozeo {
! (EWYNZTIA
MOOH) I93TIMIUTI M8U = 3ndino
! (sebed + , :sE9V4.)uTIuTI d
N0 WS3SAS
{(®T3T3 + . :FIIIL.)uTIuTad3no welsis
{(PT + :QI,)uT3iutad 3no-we3sig
. - ue3ysis
===,) ur3utad-3no
yurjutad-3no-weasis
dwey
¢ ()aeysTIqng3leb = zeystIqnd IBYSTTANG
! ()saozdeypisb-dusy = saozdeyo 3ut
! ()ooTag39b6' duey = soTad jutr
! ()sobegyeb duey = sabed jut
{()°T3TI396 dwey = 73713 butaas
{()p139b6-dwsl = pT 3uUT
! [T]s3yooq = dwe] xoog
} (++T {yzbusT'sjyooq > T !{0=T 3JUT ) x03
¢ {wu)uT3utad-jno-weasis
(. Aadue st °I03s300q OYL,)uT3utad 3no-we3sis
¢ (wu)ur3autad-3no-welsis
} (0 == yabuoT-syoo q) T
} (TTRu = s300q)
IT
¢ () oTTdYOOEPEST = sj00q
{TInu = S$3}00 q []sood
}
() TRUTWaDTOLSHooHTTYIndaNO PTOA DT3e3s oriqnd
/4
BUTIZOS JHOYGTM TEUTWIOY SYL 01 SIOISHOOY oY3 uT syooq eyr T1e sandino - feuTHxSLOLsNoOUTIvVIndInG «
4%/
{
! ()esoT 0 *and3ano
" mou
i(,° 3T Burjesado ‘3STX® 30U S9OP OTTF }ooq 9YL,)3utad:3n diano
} es1e {
} este {
! (yu)uT3utrad-3no
- welsisg
-K3dwe sT ®31035300q 9YL,)uT3utrad 3no-welsis
¢ (wu)uT3utad-gno-we3sks
} (0 == uy3abuesT'sy00q)IT
} (TTnu = s3o0q)3IT
! ()eTTayoogpeax = S3ooq
!TTnu = sjyooq []3joog
}
() TRUTWISLOLSOTA TISAISNoogTTYINdIno pPToa oT3e3s oTTqnd
/%
*
HUTET0E GNOYITH TRUTWLXSY SY3 07 DAOJEHOOY 8YF UT »
S9T3T3 pue SAI ,S¥00q oYy TTe sindino - TRUTUIDLOLSOTI TLSALSHOOHT TYANdING
%/
{
! 3no we3sis
(yu)uTautrad:
! (,"9103S300q SY3 UT SIOOQ Ou BIB ®x9Yg, ) uT3uTad 3no ‘we3lsis
welsis
3no ad-
! {wu)uTdut
} este {
! (wu)uT3autad-3no-welsis
{ (y==== w)uTautad-ano - wa3sig
£ (()sweN3ob aoysTIqnd + , WEHSITENG.)uT3utad
-jno we3sis
{([C]szoyane + ,: (S)MOHINY.)UT3 we3sis
3no uTad
be"
(Jutx3 - [[]sIoyane)
(((uu)sTEN ) FT
} (++C ‘y3bueT saoyane>l !o=( jut)zoz
! () szoyanyarsh-dwey = saoyane []Butaas
¢ (saeadeyo + ,:SYALAVHD.)uT3utad -3no-welsis
‘(eotad + ,:($) EOI¥d.)uT3utad 3no uwelsis
! ()eTTay00gPEST = S3j00q
{ITTnuU = sjooq []yoog
(39b7e3 3uT)TAYSTIqRIFOTPUTWISTOLSHoOTTYINdINO PTOos DoT3e3s orTand
butlzos JnoylTM TRUTWASI SY3 03 ‘IeysTTAnd UTEIASD ® JO 4
‘®2038300q SY3 UT $Y00q oyl TTe 53ndIN0C - ISYSTTIANGIOTEUTWASLOLSHOOETTYINdINO «
! {uwu)utzutad-3no-we3sis
! (,"®038300q SY3 UT S)00q Ou oIE ®x9Yyr, ) uTautad - ano - wej sis
{{uu)uT3urad: 3no-we3sis
} esto {
! (wu) uT3uTId 3N0 ‘W3 SAS
a w)ur3urad-3no-we3sis
{(9T37T3 + . WIIIL u + PT + ,:QI,)uT3urad-jno-we3sis
! () xoystigng3eb -dwel = xeystiqnd zoYsTIANg
! () sao3ydeypzeh - dues = szezdeyo jur
{()ooTagysh dwey = sotxd jur
{ () sebegysbh-duey = sebed jutr
{()e13TI3°6 dwey = 973713 HButaas
{()pr3sb-dwel = pt 3uT
![T]syooq = dueg 3yoog
} (++7 {yabust-'sjooq > T 0=t 3uT)I0z
o ===,) uT3uT we3sis
3no ad
‘8}00q eTgerTeAy,)ur3zurid-jno-wsysis
! {uwu)utzutad-3no-we3sis
! ([C]sxoyane + welsis
,:(S)HUOHIAY,)uT3utad-3no
b®"
()wrxy - [[]saoy3ne)
(((uu)sTEn )3T
} (++C ‘y3buet saoyzne>[ !o=[ jut)zoz
! ()saoyanyzsb-dwey = saoyzne []Butaas
! (saeadeyo + , :SYEIAYHO,)uT welsds
3uTad
jno
‘(eotad + ,:(4) @OI¥A.)ur3utad 3no-welsis
! (sebed + ,:sEOVJ.)uT3 3no uTad
- wa3sig
£ (9T3T3 + . :FILIL,)uT3u tad
3no - we3sis
£ (PT + 4:QI)uTautad 3no-uelsis
lllll o) urautad-qno -we3sis
! (uu)urautrad-3no-we3sis
{1 4+ PUNOgsS}00q = PUNoIsYooq
} (()p13eb-aeystrand == 39bae3)sT
! ()xoysTTand3sb-dwey = zaystTqnd I8ysSTIAnd
! ()sxeoadeypisb-duwey = sxszdeys jut
{()eoTag3eb-dwey = sotad jutr
! () sebegyeb-duey = ssbed jut
¢ ()oT3TI3eb duwey = °1313 butraas
!()pr3eb-duwey = pT 3uT
!{[T]syooq = dwej joog
} (++T ‘uy3zbusT s3y00q > T !Q=T JUT)IOF
{0 = punogsyooq 3uT
} esT8 {
! (wu)uT3utad-3no - wo3sis
! (."&K3dws sT @x03s300q 8YyL,)uriutad-ino-welsis
! (wu)urzutad-3no-wa3sis
} (0 == y3abusT syooq)3IT
} (110w =; sjooq)FT
Rulle L RE St BT
‘0 = yabust jqut
!outT butazsg
uAmflfihmflfiummmzmsuvumvmmemumm
usm Mou = surzebeyandur IspesypaiezIng
! (AWYNTTIA ENIZVOVR) ZopesysTTs Mou = STTasutzebeyeys zepesysTrg
} &x3
‘ITnu = ssurzebenzolezze [1surzebey
{()onend Meu = ssutzebew anengd
() oTTasuTzebeypess }
[1sutzebey o13eas oTTqnd
(ea0383%00q BYl /%
uT seuyzebew syy Tre ey i
PTTASUTZELRU 6U3 FO 53UL3UOD eUR TTR uzTh Aexue uIng eIy 4
SIOABACOY BYR FO sOTIIUS duTzEbEN *
Byl TTE SpEex - BTTgsuTZRSEHpRSx ,
k*\
‘Bpoulew pejeres surzeben//
{
! {uwu)utau
3no-tad
weysk
-s
! («"®3038300q BYR UT s)jo0q ou axe ®I8Yy, ) uT3utad- 3no weysis
{(wu) UTAU
300
TIWe3s
dhs
} este {
! (u29ystrand sTy3 WOIF punozy {
sjooq oz:vcfiu:fium.uno.EOumhm
} (0 == punogsyooq)
51
‘(uu) uT3UN0 TId
WO3SKg
u u) UT3utad 3no weysig
(()sweN3eh
- zoysTTqnd + u {¥EHSITENG, ) uT3uTad " 3no ‘wegsis
} (++T ‘yabuer- seoanossa > T (g = T UTL) IOF
[ ()ozTs '3stISsoanossx]butals Mau = ssoanosax []Hurtaas
{
£ (T+usy03 ‘,:,)JOXOPUT SUTT = USYOLIXSU
{uejyoL3xXau = usyO
! (e0anosax)ononbus *3STIS9OINOSST
{ (uayoraxeu ‘T+usyol)buraisqns surT = soanossx burils
} (T~ =i ueyoz3xeu )eTTum
{(T+usyo3 ‘,:,)JOXSPUT 'SUTT = USYOIIXBU
{USYOIIXIU = USY03
! ()onand MaU = 3STTSODINOSII aInanyd
! ((ueyogaxau ‘I+usyol)bur
- surT)3urssaed-
taysqns asbejur = grasystignd Jut
£ (T+u®30] ‘,:,) JOXOPUT SUTT = USHOIIXIU
{u93OoL3XoU = U0}
! ((ueyogaxau ’T+usyol)burtaisqns surT)jurssaed-azsbejur = o9oTad jutr
£ (T+usyox ’ 1) JOXSPUT 'SUTT = USYOLIXDU
{USOL3XRSU = usy O3
! ((uejogaxsu ‘T+usyol)burtazsqns -surT)jurssaed-azebejur = sebed jut
{(T+usyox ! \) FJOXOPUT *SUTT = USYOLIXDU
{usyoIlxXau = usyol
! (usyogaxsu ‘T+usyol)burtizsqns-surl = 971313 buraas
! ((usyo3 ‘p)burazsqns-surr)ijurssaed-xsbequr = PT JuTr
! (T+ueyoy 4) FOXSPUT
' SUTT = USHOLIXDU JUT
{(u:u)FOXOPUT 'SUTT = USYO3 3JFUT
!T + yabuest = yzbust
} (TTnu =j (()surpesa surzebeyindut = SUTT))STTUM
} (TInu =i ssurzebew)sT
!sutzebeRpoppyyl tMsautzebeu []aurtzebey
! ()oTTdsuTZebEeNpeax = sautzebew []ourzebey
}
(u autzebey)sTTIsuTZERORHOLO3TIA PTOA DT3e3s OoTTgnd
Kxjue surzebew msu ® w wezedp x
‘o113 surzebew ay3 o3 Axjue surzebew MBU B SIYTIM - STTISUTZRBRHOLSITIM o
*x/
{
!seutzebeyyolezze uinjyax
{(wu)uTaurad - gno-weysis
A mou 3T burjesao ‘3sTX® 30U Ssop STTF Surzebew ayg,)urjurad-jno-welsis
! (wu)urtaurad- 3no-uwe3sis
! ()butazsol-s = zx> HButijs
‘pPe3eeaD ©q 30U URD IO 3STXKO J0U SO0p STTIdurzebeu//
} (® uoradeoxm) yojeo {
!ononpuwoxgautzebeu = [1]saurzebenyoleaze
! ()enenbep- ssutzebew (surzebey) = snanfwoxgsurzebew sutzebey
} (++T ‘y3abusT>T ‘=T 3uT)I0F
! [yabusT]lauTzebey Mou = ssurzebeyyolerze
! (Axaus)snsnbus- ssutzebew
! (zoystTgnd ‘sopanosax ‘sotad ‘sebed ‘eT3T3 ‘pT)surzeben mou = Axzjus surzebey
¢ (qrroys TTqnd) AIY3 TMISYSTIGNIPROT
" STTAIBYSTIGNd = IOYSTTAnd ISYSTIAnd
{ ()ononbsp -3sTIseoanosax (butals) = [T]seoanosax
{()praeb-dwey = pT 3JUT
![t]soutzebew = dwey surzeben
} (++T {y3abuet- sourzebew > T Q=T 3JUT)IOZF
} (0 =i yabueT soutzebeuw 33 TTnuU = ssurzebew)sT
{
3no wel sAs
! (yu)uTauTad
<--mou 3T Burje®ad ‘3STX® 30U S9OP STTF ano welsig
Surzebew ayL, ) urtjurad'
3no - we3sis
! (yu)uTautad:
! ()buraasoze = xx9 Hutaisg
‘pejEOID ©q 30U UEBD IO JSTXO 30U $90p SyTasurzedbeu//
} (o uotadeoxy) yo3zed {
{ (AWYNTTIA ENIZYOVWW) I93TIMIUTI Mou = 3ndino
} Ax3
/7Tnu = 3nd3ano IS} TIMAUTIJ
(seoutzebew []surzeben)oTTdsutzebSeHOLSoUTZRORRSITIM PTOA DTiElS UMHADM
soutzebew o Aeaxe ue sautzebeu Emumm®\H
‘o1tz outzebew syz 03 seurzebew yo Aexxe ue S93TIM - OTTISUTZEDERNOLSSUTZEOERS3ITIA H
xx/
{
TMsouTZebeu) aTTisuTzebeosauTzebeHal TIM
! (sutzebeNPePPYY3
{
‘w = [g]surzebeRpeppyulTMsauTzebeu
{[1]sutzebey mou = suTzebeHPOPPYUITMSSuTzZEbEW
} esTo {
wo= Hfilnamcwfl.mcflummmzvmfifimnuflsmw:fiummmEumcfiummmfluwvvdnuflzmonflflmmmfi
{
/[1]soutrzebew = [T]ourzebeRpoppYylTMSauUTZEbRW
} (++T ‘y3buet-seutrzebew > T !0=T JUT)IOF
usT
- soutzebew]
! [1+y3b sutzebey mou = sutzebeypeppyyl TMSauTZebeu
} (1Tnu = sourzebew)zT
{()oTTas uTzebepe ss = ssutzebew
/TInu = sautzebew []autzebey
() TeutwrsgorseutzebenTTyandano proa oTje3s oriqnd
Butazos 4nouy3Ta TRUTWZD] B3 03 4
paO3EY0CY BY3 UT seurzebew ouiy 1T® sandino - TeuTWISOLSBUTZRBENTTYINdINO
! ()esot1o 3ndano
{(u
" mou 3T Burjesad ‘3STX® 30U seop o113 surtzebew syg,)3urad-jndano
!{u:u + [L]seoanosax)jurad-jndano
osT®
uw + [[]seoanossx)urjurtad-3andano
(t-y3- seoznose
buetx == [)3T
} (++€ ‘y3buet- seoanosea>l !p=[ jur)zoz
! () seoanoseyT
TPPY3SH
RUOTI "dwsy = seoanossx [1Butazs
fluta + Avaumm zayst1and) jutad- 3ndano
. + ®otad)jurtxd:3ndano
+ sobed)jutad-:3ndano
+ ®73713)3utadandino
u + PT)autad-jndino
BTTF sfifi&mnfiunmms ®yy 03 weysy pusdde//
! () zoysTIqngleb-duey = xsystiqnd zoysTTQng
‘()ootag3eb duey = eotad jur
! ()sebeg3ysh-duey = sebed jur
{()eT13TL396 dwes = o7313 butaas
! (wu)uTautad- 3no-we3sis
! (,'®z038y00q °y3 ut ssurzebew ou axe oa9yg, ) urautad 3no we3sAs
W ut3zutad-ano-weysis
} est1e {
adg
3no - welsi
! (4u)uT3uT
===,) UT3uTad 3no-we3sis
Al welsi
InoUTI ds
£ (() oweN3ob-zoystTand + ,:MIHSITEN.)UTI
{
: ([C1seoanosex + uT3utad -3no we3sis
,: (S)HD¥NOSHYE,)
(Jutxy- [[]seoanosax) j) It
(((,u)sTENDbS"
} (++C {yzbue-seoanossa>l !p=[ jut)aox
"dusy
/() sepanossyTRUOT3TPPY3I®b = seoanossx [1Buta3s
f(eotad + ,:(§) EOIWA,)ur3utad jno-uelsis
¢ (sebed + ,:sEOVA,)uTIutad 3no-ue3sis
{(9T3TI + u!EILIL.)uT3uTId 3no welsis
{(PT + ,:QI.,)uT3utad 3no-welsis
{(a —===, ) uT3utad 3no uwe3sis
¢ (wu)uTaut 3no we3sis
ad
h
- dwel
¢ ()zoysTIqng3o = zoystTqnd ISYSTIANd
{()eo1xg39 b
- dwey = ootad jutr
! () sebegyab-duey = sabed jur
{()o13TI3oh dwey = °13T13 Butaas
{()pI3eb-duey = pT 3JuUT
! [t]soutzebew = duoy surzebey
} (++T ‘yjbuet seurzebew > T {Q=T 3IUT)IOF
{
- 3no-we3sis
! (wu)uTautad
i (,-Kk3dwe st °x03SN0Oq BYIL,)uT3utad-3no-welsis
{(,u)ut3utrad-3no-welsis
} (0 == uy3abueT sourzebew)IT
(uu)urjurad-gno- walsis
e w)ur3jutad-3no- wo3zsis
{(STAT3 + W ETIIL u + PT + .:QI.)uT3no
3utawe3sis
d
() zaysTIang3‘dusy
1sh = asystiqnd asystIgng
{()ooTag3eb dwey = sotad jur
! () sebegisb duey = sebed jur
{()eT3TIAe6 dwes = eT3T3 Butasg
{()p1asb-dwey = pr jur
‘[r]lssutzebew = dwey surzebey
} (++T !y3busT'ssutzebew > T /0=T 3UT)I03F
il J)utautad-jno: wej3sisg
! (ussutzebew aTqeTTRAY,)UT3UTId300" wa3sis
{(wu)uT3zutad-3no- we3sig
} ®sto {
! (wu)ut3zutad-3no- ue3sig
! (u A3dwe sT @x03s300q BYT,)urzutad 3nO" walsis
! (uu)urtaurad-qno- wo3sig
} (0 =
y3bueT ‘- soutzebeu) 31
} (TTnu = ssurzebew)3T
! ()eTTdsuTZRb PRSI
RR = ssurzebew
{TINU = sautzebew []surzebey
fivHmflflfiumaoamwfluflanHmeflNmmmEHflmusmuflo
PToA Ot3e3s orignd
Butazos 3noyzts TeuTWISY SYy O3 9I038Y00q BYJ UT
S9T3T3 pue sqI ,ssurzebew syy tTe sandqno - TeUTUI 11 TISqIs
BL ouTzeb
OL enT S8
Tvandano 4
{1 + punogssurzebew = punogssurzebew
} (()p13sb-asystignd == 39bae3) 3T
-dwey
! () xoysTIqndaeb = zsystTqnd I9YsSTTAnd
! ()sotagaeb dusy = sotad jut
! () sebegyeb dusy = sebed jur
‘()eT3T13°6 dwey = =13T13 Butazs
{()pr3eb-duwel = pT JuUT
! [1]soutzebeu = dusy surzebey
} (++1 ‘y3bueT-seurzebew > T /=T 3UT)I0F
!0 = punogssutzebew jur
} estTe {
! (wu)uT3utad 3no-we3sis
(4 A3dwe ST Sx035¥00q °YL,)uT3uTad 3no-we3sis
3no we3sis
! (wu)uT3urad
} (0 == yzbuet-seurzebeu)zT
} (TTnu =i seutrzebew)IT
! ()oTTasuTzZEbEKpPESI = Ssurzebeu
!TTnu = sautzebew []surzebey
}
(39613 3UT) IPYSTTANAFOTRUTWISLOLSOuTZebeNTTYandIno pToa oT13e3s orTand
/%
HUT3IOS INOYJFTM TRUTWIDY oYyl 03 ‘Ioystrgnd uTe3ISD B JO 4
‘sxzogsxooq ay3 ur saurzebew syz TIe sandyno - IBYSTIYNIFOTRUTWISIOLSSuTzEebeNTTVandino x
*x/
! (wu)uTauTad
- 3no -wa3sis
! (,-@x0383y00q By} UT ssurzebew ou sae °8I9YL,)ur3rurad-ino-weisis
! (wu)uT3uTtxd 3no-wa3sis
} est1e {
}
STTLISYSTTANG Ssero otrqnd
!zopeeysTTd
' OT ‘eael jxodut
! zepesypaasgIn
ot 'eael
g jzodwut
{293 TIM3UTI
"oT "eAaR[ jaodut
S8RTD oTTgILYSTIUNG//
{
! (wuw)ut3dutad-3no-we3sig
¢ (4 "®x038y00q 9Yy3z uUT seurzebew ou sae 8x8Yyl,)uT zutad
3no weisis
3no ad:
{(wu)uTaur we3sis
} este {
‘zoysTTqnd STY3 WoxF punoy sautzebew op,)uT3zutad-3no-wezsis
} (0 == punocgssutzebeuw)T
! (uu)uT3zutad-3no- wo3sis
/
(u a)uraurad-ano- wejskg
{(()oureN3®b asystTqnd + , :MAHSITENG.)uT3utad 3no-weysis
! ([C]sepanosex + ,: (§)HOWNOSEY,)
uTIuTId 3Nn0 ' We3shs
(((uu)sTeEnb
" ()wtag " [[]seoanosax)S
{)IT
} (++C ‘y3buet-seoanosea>l !p=[ qur)aoz
! () seoanosayTeRUOTITPPYISh
‘dwey = seoanossx []butazs
{(ootad + ,:($) =OI¥WA,)uT3utad-3no- waysis
¢ (sebed + ,:s@ADVA,)uT3utad-ano’ wa3sks
£(®T3T3 + . TILIL.)uT3utad-jno- wa3sis
{(PT + w:QI.)ur3jutad-ano: wo3sis
s
(u ‘wogsig
‘we3sis
T mEmEm om m E E IR —
{UDOIIXDU = UIYO3
! ((uoor3ixou ’T+us3ol) asbejur
butaisqns-sutT)juresaed- = suoydsTey 3uT
{(T+#uD303 ‘,1,)FOXSPUT SUTT = USHOLIXDU
!{usioL3Xou = U9 O}
!/ (uoor3xou - SUTT
‘T+usyol)buTazsgns = Ssoappe Durtazg
{(T+usyol ‘,:,)IOXSPUT SUTIT = USYOLIXdU
{u9yoI3XoU = uaYo3
! (ueyogaxeu ‘T+usxol)burazsqns-sutr = sweu burtalg
! ((usxol asbejul
‘@)burazsgns-sutry)jurssae d = PT JUT
¢ (T+us3ol 4) JOXSPUT' SUTT = USOLIXSU JUT
(4} u)FOXSPUT SUTT = USX03 JUT
{1 + yabus1 = yabuer
} (TTnu =i (()surIpesa a9ysTTqndlIndut = SUTT))STTUM
!0 = yabuet 3ur
!{sutT bButaas
Y?
) ISpROYpPaISIIng
! (T TATIBYSTTANAD MU = IoysTTqngindut Iopesypeisiyng
! (AWYNETIA WEHSITHENd) I9PeSySTTd MOU = STTITISYSTTIANISYF ISPEaUSTTd
} &xq
{1Inu = sasysTiqndyoAeaze []lzsysTTand
! ()onend mMau = szoystiqnd snend
}
()oTTaIoysTIqngpeax []xoystrand Ot3e3s oTTqnd
/%
srrgreystrand sy3 Fo S3USIUCD SYY TTE UK Avase UINJOI] 4
¥
seTIjUs H@&&.flfig& BYUYY TTIE SpESH -~ SYTATISUBTTUNIPESIT 4
s/
{,oTTaToysTTand, = EWYNATIA WEHSITANd BuTals TeUuTF OT3e3s
(d T9YSTTANg) STTIIBSYSTIINIOLOITIM PToA DT3els oTIqnd
/x
Azque zsystigqnd Mou ® d ureaxedp s
*
‘oT1T3 zoystiand oyl o3 Axjus zoystTqnd MU B SSITIM - STTAASYSIINJOLOITIM
xx/
!sI9YsSTTONdF0oAeIIe UIN3OI
{ (wu)uT3rurad-jno we3sis
! ()butaasols = zas Butraag
‘PO3ESID 9¢ JOUURD IO ISTXS JOouU S0P STTIIdUsTTand//
} (® uotadeoxm) yojzeo {
! (931sgem ‘suoydeTel ‘ssoappe ‘sweu ‘pI)ILYsTTAng MU = [T]sasystiqndzolexae
! ()o3Tsgsmaobh ononpwoagrsystTand = 93Tsgem butajs
! () suoyde 113 o6 - enenfwoagzeystTaqnd = suoydeTel FUT
! () ssaappyaab snenguoxgaaystiand = ssaappe burtais
! () swreN3ob snsngwozgxsystignd = sweu butajls
! ()p13ob-enenpuworgrsystiqnd = PT JUT
! ()ononbep-sasystiqnd (zsysTIqnd) = onsndworgasystiqnd IoysTTqnd
} (441 ‘yabusT>T !Q=T 3uT)I03
! [yabusT] x9ySTIONg MSuU = sasysTTqngzokexxe
! (KAz3ue) ensnbue - sxsystTand
! (@31sgem ‘suoydsto] ‘sSsaippe ‘sueu ‘pr)IsysTIqnd Meu = Axjus rsysTIqnd
! (ueyoraxsu ’T+usyol)burayrsqns
SUIT = 93TSgeOM DuTtals
{(T+USy03 ‘, 1, ) JOXOPUT BUTT = USYOLIXOU
TMSIDYSTTANd) STTAISUST TANAOLS IOUS TTANGSF TIM4
¢ (I9YSTTANGPoPPYY3
‘d = [p]a®ysTTANaPePPYY3 TMSI=YsTTand
{[T]I9YSTIAN MOU = ISYSTTANIPSPPYYUI TMSIYSTTANd
} est1e {
!d = [1-y3bueT’ I9YSTTANAPSPPYYI IMSISYSTTqnd] 28Ys TTANIPepPPYY3 TMsIaysTTqnd
{[T]1saoysTTand = [T]I9USTIANAPSPPYUI TMSISYSTTARd
} (++7 ‘uy3bust-sasystrand > T [0=T IUT)I0F
¢ [T+y3bueT
- s70ysTTANd] IBYSTIANd MSU = ISUSTTANAPSPPYYI TMSISYSTTAnd
} (TTnu = sasystTqnd)IT
{29YSTTANAPOPPYY3 TMSIoYsTIand []aoysTIdna
¢ ()eTTazoysTIqngpeaa = sasystrqnd [lasustrand
)autad-andano
} estTa {
+ 93Tsqgem)utjurtad-jndinc
. + suoydetej)autad:andino
+ ssoappe)3jutad-andano
+ sureu)jutad-andano
2 . + PT)3utad-3andano
*®TT3 orTaxeystignd Sy3z o3 weyaz pusdde//
! ()oatsgqeMasb dwey = o3Tsgsm butaas
! (yosuoydeTarysbh-dwey = suoydsysy jutr
! ()ssoappyaob-dwey = sseappe bButails
! ()sweN3ab' dwey = sweu butazg
{()p13eb-duey = pt 3ur
![T]sasysTtTand = dwey IaYSTTANg
} (++T ‘yabusT- sasysTtTand > T Q=T 3uT)I0F
} (0 =i u3bust'sasystTand 33 TINU =| sasystIqnd)IT
! (wu)uTaurad: 3no we3sis
{(, po3esad oq jouued oTTI zoystrqnd oYL, )urjutad- 3no-welsis
! (wan)ur3autad-ano wajlsis
{()butaasols = zao Butaas
‘Pe3E8AD SO JIOU UBD IO JSTXS 30U S0P STTIxDYSTIgnd//
} (® uoradeoxm) yozeo {
! (EWUNTTIZ WEHSITENG) I9ITIMIUTII Mou = 3nd3no
} &x3
{TTnu = 3ndjno x93 TIMIUTI]
}
(sasystrqnd []I9YSTTqnd)®TTIISYSTTANIOLSISYSTTANGSITIM PTOA DT3e3s oTrqnd
sasystTqnd yo Aeaze ue saaystigqnd uexedy »
-orTy xoystignd Syl o3 saosystiqnd Fo Aezze UR SOATIM - OSTTAISYSTTANJOLSIDUSTIGNADITIM
xx/
! (uu)uraurad-3no-we3shs
! (, saoystraqnd ou axe ayg,)uriutrad-ino welsig
! (wu)ur3urad-3ano-weasis
} (0 == yabue'sasystrand)IT
} (TTnu =i sasysTTand)IT
{()eTTATIOYSTIANdPE®T = sasysTTqnd
{TTnu = sasystIqnd []aeysTIand
}
() TRUTWISIOLSIOYSTIANdTTYIndano proa or3e3s oriqnd
/*
Huraxos 3noylTA TeUTUID] 2Yyj3 03 sasystrand oyl TIR S3ndano - TRUTWISIOLSISYSTTANGTTIvIndanc
sx/
{
{TTnu uanisx
{
{
![t]saoysTTand = aaysTTqnd uInN3lox
} (pT == ()p13eb’ [T]sasystrand)sT
} (++T ‘yabust'sasystTqnd>T {Q=T 3JUT)I0F
‘zeystrqnd a9YSTIANG
{()oTTaaoysTIgngpesx = sasystiqnd []aeysTidnd
}
(PT 3UT) QIYITMISYSTTANGPESI ISYSTIAnd dT3e3s orTqnd

pt asystrand sy3 pr weaedp 4
*
‘pt orgToeds ® uylTe FousTTAnd SU} SUINIBI - AIUF THASUSTIANIPESI i
*x/
! (y@so1o-3ndano
It
} (TTnu =i sasystrand)
! ()oTTdIvYSTTANdPeST = sasystTand
{rrou = sasystiand [laeysTIqnd
}
() TRUTWISLOL SOWRNSQISISYSTTANd TTY3Ind3no proa ot3e3s orrqnd
/%
*
HuTlaIOS JNOYJTH TRUTWI®Y} Y3} O3 x
seweu pue (I ,sxsystiqnd sy3 Tre s3ndino - TRUTWISLOLSSWENSJISISYSTTANATI¥IndInoe »
xx/
{
{(uu)utzurad: ano-we3sis
rsazoystTqnd ou =1e BI9YL,)ur3zurtad’ 3no-we3sis
{(un)utaurad: qno-we3sis
} esTo {
! (ww)uT3zutad-3no ‘wo3sks
fa w)uTzutad ano- we3sis
{(93TSq9M + ,:93TSqeM,)uT3utad
3no’ wo3sks
! (ouoydaTo3 + 3no -weg3sks
,:duoydeTalL,)uraurad
! (ssaappe + ,:SS8IPPY,)uriurad-3no- we3sAs
! (eweu + ,:euweN,)urjurxd-ano- we3sks
‘(PT + .:QIs)uT3durad-3no- we3sis
il ===, ) ur3utTad 3no: waysis
g Jurjurad-ano: wo3sis
dwey
! ()o3TsgeM3sb = 93TSUeM Butaas
! ()suoydetsrieb dwey = suoydsToy Jutr
! () sseappyasb -dwey = ssaappe Butazs
! ()oweN3ob-dwey = sweu Bbutaas
¢ ()pI3eb-duey = PT 3uT
![t]lsaeystTand = dwey I9YSTITANg
} (++T ‘y3buer sasystiqnd > T Q=T 3UT)IOF
rzeystrand otzroads B I0JI SPIODSI ISBYSTIANG FO ABIIR UR SOUDIRSS - UOIRDSIBOUTT x
»x/
}
yoxesgaesut] ssero orTqnd
SSRTD UYDIBSSIRDUTT//
{
{
{
ano welsis
! (wn)uTaurad:
! (, saoysTtrand ou °9xe 3no welsis
9I9YJ,)uTIuTid’
! (wu) uT3utad 3no-uelsis
} esT® {
{
{ (wu)uTdurad-qno uelsis
=== w)ur3utad-3ano weasis
{
{(oweu 4+ ,IEWYN ‘. + PT + ,:QI,)ur3utad-3no-ueisis
! ()o3Tsqem3sb dwey = S3Tsqem bButais
! () suoydetarieb dwel = suoydsTel JFuT
/() sseappyasb-dwey = sssappe Dburais
! ()ouren3yob
- duey = sweu Butiizs
{()praeb-duey = pT 3UT
![t]sasystrqnd = dwey aoYSTIqNg
} (++T {y3buetr-sasystignd > T Q=T 3IUT)IOF
! (y===m=s=sssssmsms=ssmsm——= u)uT3utad-3ano-weysis
{(,:saoysTTand 3no wa3sis
oTqeTTERAY,)uT3uTad
3no we3siks
! (wu)uTautad
} este {
3no wa3sis
! (wu)uTauTtad
{(, saoystTand ou axe jno welsis
oyrmL,)ur3zutad
! (wu)uTaurad-qno-we3sis
} (0 == yabueT' sasystiqnd)3IT
{()p13ob- [epeTd]sasystiqnd = putgol 3ut
}
(punogzi 33 ®z1s > ooefd) STTUM
{0 = @oerd jut
!8sTeJ = punoj uesTooq
{yabusat-sasysTtrgnd = °zTS 3UT
}
(sxoystTand []aoysTIAnd ‘396783 JUT)UDIESSIESUTT JUT OT3ILIS OTTqnd
/%
rAexxe oYy UT SOPISSI JUSWSTD INO SIVYM XSPUT BYJ SSTS PUNOIF J0U JUSWSTS FT - uInNADAP »
PouDIESsS °g 03 SPIODBI IVYSIIAng IO Avaze syl saeystrand wexedp
punoz 8q 03 PT BY3 aobaey wexedy x
x
rzeystiqnd oTgToads B Z0J SPIOODX IDYSTIQnd FO AvIxie Ue SOYDIAVDS - YOABISIVOUTT »
xx/
4
{ {1- uangex }
osT®
{ ‘ooerd uanjyax }
(punoz) 3T
{
{ {1 4+ soerd = soe1d }
osTe
{ ‘ena3 = punoz }
y) 3T
((wtagputgos) syenbe-3abae
{()WeTa3N uUTI
"p3 o O]b= WIILPUTIol Butas
Tand
! ()ou r
- [e oeTd]lsasyst = putgol butajs
}
(punoz 3% °zTs > ooeld) STTUM
!0 = soerd jutr
/9STey = punoy uesTooq
stiqnd
!yzbuet-sasy = 9ZTS JUT
}
sgaesurT
(sxeystrqnd []asysTTqngd ‘3°bxe3z HBura3g)yoze 3uT OoT13exs oTTgnd
/%
rAexae 9yl UT SOPTISOI JUSWOTS JINO DIDYM XSPUT SY3 OSTS ’‘puUnog jou juswerd IT T- uInNIDIP «
PoYoIRSS 9 O3 SPAOVVIT IVYSTIGNG JO ABaae 9Y3 sasystiond weaedp

* ok
punoy 8q 03 SWeu 8y3 q9baey wexedp
{ {1- uanzex }
osT9
{ !ooerd uanjzex }
(punoz) 3T
{
{ {1 + ooerd = soe1d }
asTe®
{ ‘ona3 = punoz }
((wtazpuTgol)stenbe 3abzel) 3T
{()wta3 puUTIO} = WTIIPuTIOl ButIls
! ()e131I3e6" [oorTd]S300q = PuTgol buriis
}
(punoz; 33 °zTs > @oerd) aTTUM
{0 = @oerd 3jut
!9sTeI = PUNOF ueS8TOOq
!{y3zbueT" sjooq = SZTS JUT
}
(syooq []jocog ‘3ebae; HuTals)yoaeoSIESUTT JUT OTIE3S OTTqnd
/=
-Aexie ey3 UT SSPISOI JUSWSTS INOC DISYM XOPUT Y3 OSTD ‘PuUnoy JOU JUSWILS IT T~ UINIBIP x
poypIeas 8q 01 SsYooq FO Aexxe oyl syooq wexedy x
punoil g 03 Y0oq Y3 IO STITI Bud qebrey wexedy
x
*o7213 OryToeds ® x03 S}0OQ IO ARITe uUe SBUYDIBLDS - YOIEISIBSUTT *
xx/
{
{ {1- uanzsx }
ssT®
{ ‘ooperd uanizex }
(punoz) 3IT
{ /1 4+ ooe1d = soerd }
(punozi)
3T
{ !onx3 = punojy }
(putgo3 == 39bae3) IT
{0 = ooerd jur
/9sTez = punog uesTooq
{yab
- ssurzebe
uet w = 82TS JuUT
(seutzebew
}
[]surzebey ‘3ebrey Butays)yoaesgzesutt jur or3e3ls orrqnd
‘Aezae oyl uT SOPISRZ JUBWSTS Ino SIABYM XBPUT BYJ BSTS ‘puncy Jou JUSWSTD /%
FT - UINIDIH 4
peybaees oq o3 ssurzebew go Aexxe oyy soutzeben wexedy
punoy sq o3 surzebew syj Jo STITI OYI 38bxey weaedy o
*
y ‘ar orgToeds ® 203 syooq yo Aexxe ue soyozess - YDIARDGARDULT x
sx/
{
{ {1~ uangysx }
asT®
{ !eoerd uanjax }
(punoz) 3T
{
{ {1 + ooe1d = ooerd }
asTe
{ ‘ena3 = punoz }
(Putgo3 == 3e@bae3) 3t
‘()p13eb- [soerd]sjooq = purgol 3ut
}
(punozi 33 °zTs > ooerd) STTYM
{0 = soerd jut
mmm.flmm = punoy ueaTooq
!{y3busT
- syooq = °zTS JuT
}
(syooq []yoog ‘3ebiey 3uT)YOIBRSSIBSUTT JUT OTIE]S orTand
‘Aexae oy3 UT SeprSex JuUSWSTS INC /%
eaBYM ¥SPUT DY} SSTD ‘puUnog 30U JUSWSTS IT T~ urnlexy 4
peyoxess 8q 03 sjcoq yo Aevaxe syjl sjooq uwexedp 4
PUnOT q 03 jooq dY3l JO I YR 3ebaey wexedp i
*
‘ar oigroeds ® a0y sjooq yo Keaxe ue seyoxess - YDIBSSIRDUTT x
xx/
asTe
{ !ooerd uanjzex }
(punoz) 3T
{ ‘{1 + ooerd = soefd }
asTo
{ !{®nx3 = punozy }
(putrgo3l == 3ebxey) It
- [eoerd] ssurzebew
! ()pr3esb = PUTIO3 JUT
}
(punozj 3% °9zTs > 9oed) STTUM
{0 = ooe1d juT
!9sTEF = punoy uesTooq
‘' soutzebew
!{yzbusT = 32TS JUT
}
(seutzebew []outzeben ‘39b61e3 3UT)YOIESSIESUTT JUT OT3e3s dTTqnd
/%
+ARIi® 9Uy3 UT SOPISOI JUSWOTS JANO BIBYM XSPUT 9Y} 9ST2 'PUROIF 30U JUBUSTS IFT T~ uInIeIH
poyoaees og o3 sautzebew yo Kexxe ayj sourzebew wexsdy o
punoz oq o3 surzebew syl FO I SU3 qebaey wexedp ¥
A
‘qr otgtoeds ® I03 $300q JO ARITR UR SOUDIROS - UDIBSHIVBUTT x
wx/
¥
{
{ !T- uanzex }
osT®
{ !eoperd uanjsx }
(punoz) 3T
{
{ {1 + soe1d = ooe1d }
asT®
{ ‘enay = punoz }
((utarputdol) syenbs-3sbae3) 3T
{ ()WTaI3 "pPUTIO} = WIIIPUTIO} Butazs
" [eoeTd]ssutzebew
{()oTaTI3°b = purgol burazs
}
(punoz 33 °zTs > ooeld) STTUM
!sj00q uanlex
! dwoy [3sxT3]s)ooq
‘[3saTz]syooq = [3sesT]syooq
!{[3sear]syooq = duej
4
{ {3uexzano = 3sesT }
(()ooTag3eh- [3sesat]syooq > ()90Tag3aeb’ [juexano]siooq) IT
} sst1o {
{ {3uszano = 3sesT }
(()ooTa33eb [qsesr]syooq < -’ [3uszano]siooq) 3T
()®0Tag3eb
} (Butpusose)zt
}
(T + 3uexand = jusxano !YIBueT SY0OQ > FUSIAIND !T+3SITI = JUSIIND) I0F
!38ITI = 3sesT
}
(I + 3saTF = 3ISITI ‘y3bueT s3j00q > ISITF /0 = 3ISITI)I0F
{dwey 3yoog
{3sesT ‘jusaano ‘3SITI JUT
}
(butpusose uesTooq ‘sS}0oq []joog)3jaosuorioaTes []yoog oT3zezs oriqnd
e
Butpusosep Io Burpusose sq prnoys Burjzos zsuyzsys Durjeotput °nyea uesyooq ' Burpusose wexedy «
pe3zos ag o1 sicoq aya DBururejuon Aexae uw syooq weaedy
*
aotxd Aq ©x103SHOOG BYI UT SYOOY JYJ SIIOS -~ 1IOSUOTANITAS y
xx/
:
3I0SUOT309T98 sseTd orrqnd
SSBID 3I0§ UOTIVVTSS//
{
{ ‘1T- uanzex }
} ()eneny otqnd
‘enenb <3o8lqo>3sTTdeaay o3eaTad
} onenp ssero orTand
TTan ARl
{astThexay jxo0duT
ssero snond//
{
!seutzebew uinjzex
!duey [3sxT3]ssutzebew
![3sat3]seurzebew = [3sesT]ssurzebeu
! [3sesaT]soutzebew = dusj
{
{ !{3uexano = 3seeT }
(()®oTxg3eh’ [asesar]sautzebew > ()°90Tag39b° [3usaano]ssutzebew) IT
} ss19 {
{ ‘qusaano = 3sesT }
(()ooT2g306" [3sesT]soutzebew < ' [3usaano]ssurzebew)
()®oTag3eb IT
} 3T
(Butpusose)
}
(I + 3usxand = jusxano ‘yjbusr ssurzebew > Juazand !T+3SITF = JUSIIND) 10T
118ITI = 3ISBST
}
(I + 3sat3 = 3saTy ‘yazbueT ssurzebew > 3SITF Q0 = ISATF)IOF
!dweq autzebel
{3seeT ‘juaxand ‘3sITF JUT
}
(Butpusose uesTooq ‘soutzebew []surzebey)izzosucrioeTss []surzebey orjeis orrqnd
/x
Butpusosep o burpusose sg pinoys Hurizos zsyzeuym Hurilestpur snjea uesyooq e Hurpusose wexedy
pejxos sq 03 ssurzebew oy3 Hutureiuod Aezxe ue ssurzebew wexedy x
*
ootad Ag sxolsiyooq syj uT ssuTzebew BY3 SIIOS - JIOSUOTIDI[BE
xx/
¥ 03 PSdU OSTE® TTTM JVHSTTIADUSTTUNG ® ‘OI0OWIBYIINT

ok X ok ok
‘yooq Y3 ur zejdeyd STYZ FO SVSTDIDRS

KX
sya yo 3aed se pejerdwod ST sseyd STYL 'pPasTdwed °q 3snW SSRTO
AVYSTTITRTIONENBUTPESY OY3 BNI3 = STTASSODOYWOPURNUITA BYJ UYITA
A13pexxod uotiony o3 wexboxd syz X0y IOPAO UT HNINIYM
£

N
}
Teutuxerindur ssero oTTqnd
ssero Teutwisgandur //
{
{()oz1s enenb uinjsx
} ()ezts 3ut otrrqnd
{Zequmu uIN3OI
{(1 - ()®zTs snsnb)sacws
snanb
z
{
! ((1+7)396 'snenb ‘T)3ss onsnb
} (++4T T - ()e°zTs'enenb > T /(0 = T 3JUI) IOF
£(0)39b snsnb (308lqp) = zoqumu 309Lqo
} estT® {
{TTnu uaniax
!(w"A3dws st snenb :xoxxm,)urzutad-3no-weysisg
} (() Zadugst-snanb) IT
} ()enenbep 308lqo oTTgnd
{
! (o) ppe - snanb
} (o 3pelqp)esnenbue prtoa oTTqnd
()<3oelqo>3stideaay Mau = snenb
‘(. Ol
:oureu,)3ndut = Sweu
{(,a9doxzdut sem paxsjus nok sweu °yg :z02a%,) uT3utad - 3no - wejsis
} (0 == ()wTay - suwreu)oTTYM
()u3busT’
! (, :oueu,)3indut-QI = Sweu
£ ()enTea3ut’ (()wraz® (, :PT,.)3ndur OI)FoenTea aeberul = PT
! (,7oqumu pt zodoad B jou SBM POIL3U® Nok PT SYL :I0xIW,)uriutad-ino-welsis
} (0 ==PpT || 0> PT)oTTUM
{()enTeA3ut (()wrx3: (, :PT.)3ndut-0I)joenrea asbejul = PT
! 3no ‘uejlsis
(wuw)uTautad:
fgmmmmmmm e W) uTautad-3no we3sis
{(uSTTE3I®P I9USTTAnd,)uT3utad: 3no-weisis
yutautad-3no ‘welsis
! (wu)uTrutad:3no ‘we3sis
! (wu)utautad-3no we3sis
! (y=============—==c== uT3utad 3no ‘we3sisg
c==,)
! (,Az3ue @a03s0Oq MON, )uT3zutad 3no welsig
! (,================ ===,)
uT3uTtad 3no ‘we3isig
! (wu)uTzurad: 3no we3shs
! (wu)ut3zutad-3no we3sks
‘suoydaTal ‘pPT 3JUT
/23TSsqem ‘ssaappe ‘sweu butils
() £xjugasystiand I9YSTTANd OTIEIS Uflfln:w
-@x038)00q By3 ut Axjus zeystTgnd meou e zoy jndur assn Hurzash zogy maflflmucmnwm\“
poyzew Axjugzeystignd “
%*\
!osTEI = OSTTISSOOOYWOPURYYITM UEBDTOOJ TBUTI OTJIE3S
/x
-Krngsseoons poloTdwod USDYG SARY SOSTOIDAKS
oyl usym ATuo SnI) = STTISSOODYWOPUBRYYITM I¥=wl ‘yons sy

k%
“jooq eyz ut zeadeyn STy} JO S9STOISX® 9Y3z Fo jxed

Kk
se peysrdwon ‘urebe eouo ‘ST SSBIO STYL "OTTF Axeurq e o3
u®33TIA puB pesx oq o3 sisysTrgnd Byl I0F ISPIO UT pIreTdwod

X
!o1313 bButazs
}
() Axjumyooq joog or3e3s orTqnd
/=
‘®x038300q BY3 uT Axjus jyooq meu v zoy 3ndur aesn Huriyzebh zoz sigrsucdssy .
*
poyzsu Az3umiooq x
x5/
{
/9T TASSOOOYUOPURYYITM UINJDI
}
()poyzeroI3zeb ueerooq oT3e3s orrqnd

‘andano pue andut 103 sseoDe TeTjuenbeg 70 BITASsEOOywopury Hursn SR BM IByUILUM UINYDIH 4
*
poylsw poulsHoIInh
x/
{
!d uangex
{(®3Tsqem ‘suoydeTe] ‘sseappe ‘sweu ‘pr)asysTtiqnd Meu = d I9YSTTIRd
{(4 93Tsqem,)3ndut
0I = SsSeIppe
! (,7odoxdut sem persjud nok 93TSgeM YL :I0Ixd,)uTiutad’3no
welsis
} (0 == ()wra3 - o3TSqOM)STTUM
()uy3abusT'
! (., :°3TSqeM,)3nduT
QI = S3TSqeM
f()entearur”
( ()wral ' (, :asqunu suoydstel,)3ndur-QI JoonTeas xsbequr
) = suoydetel
! (yxoqumu suoydsTel zodoxd ® jou sem paIdjus nol zsqunu suoydsTel BYL :Ioxad,)uriurtad:ino welsis
} (0 =PT || 0> pPT)oTTUM
f()enTeA3uT” (()wtay - (, :Ixoqunu suoydsTel,)3ndu
- OI)JoonTea'zsbejur
t = suoydsTel
{(., :ssoappe,)3andut
0l = ssoappe
! (,xodoadwt sem poaxejue nok ssaappe oYL :xoxay,)urjurad-ino-weisis
} (0 == ()wray ' sseappe)STTUM
()uyzbueT’
! (. :ssoappe,)3nduTr
OI = SS3Ippe
} (0 == saoadeyo || ¢ > sxozdeyd)oTTyM
‘()enTeA3UT" (()wraa® (, :sxezdeyo,)3ndut OI)Fosnieaidbajur = sas3zdeyo
{
‘()enTeazut” ((Ywrtaa - (, :($) asbezul
oo1xd,)3ndur-OI)gFoenies = sotad
! (,zoqumu @aT3Tsod ® 30U Sem paxajus nok 9otad Syl :I0xxW,)uTiurad-ino’uelsis
} (0 == ®otad || o > soTad)eTTym
s ()enTeA3UT (()wraz (, :(¢) adba3ul
oo1ad,)3ndut-OI)3Foontes = sotad
{
7 ()enTeaszut’ (()wra3- (, :sabed,)andur 01)3oentea’aebojur = sebed
! (,a9qunu oaT3Tsod ® jou sem peaisjue nok sobed sy :I0xxdy,)uriurid-jno welsis
} (0 == sobed || o > sobed)sTTUum
" (()wray: (,
s ()enTeazut :ssbed,)andut 0I)3Foentea asbejur = sabed
{
‘(s OI = ST3ITI
1913T3,)3nduT
! (,sa930RIRYD Gz UBY3} SIow sey Io Ajdwe sem paxsjus no&k 713713 9yl 3no welsis
:x0x1xd,)uriuTid-
} (§z < (Yuabuet (Jwraz o13t3 || 0 == ()wra3 STITI)STTUM
()yabusT’
(u 01 = OT3T3
:913T3,)30ndut
¢ ()entea3ut: (()wta3 - (, :PT,)3andut 0I)zoenTeA’I9b93uUL = PT
! (yaoqumu pT zodoad e j0u sem paxsjus nok pPT SYL 110233, ) uT3uTad 3no we3sis
} (0 ==pT || 0> PT)aTTUM
¢ ()enteAluT (()wWrx3d: (4, PT.)3ndut OI)gOenTeA I9693UI = PT
ano ‘we3lsis
! (4u)uT3dutad-
ano ‘weasAs
L (pmmmmmm w)uT3zutad-
{(,STTE3®P 3Yood,)ur3urad-3no wslsis
! (wn)uTautad-ano ‘we3sis
! (wu)uTautad: ano ‘we3sis
yuT3utad: 3no ‘we3sis
«)uT3uTad 3no ‘we3sis
! (WKajus sx03sH0Oq MON, ) uTiuTad 3Ino welsis
! ( ================= uT3uTtad 3n0
==,)wWe3lsig
‘ (uu)uTautad-qno welsis
! (un)uTautad-ano ‘welsis
‘aoystTand IOYSTIANg
!saoqdeyo ‘sotad ‘sebed ‘prt juT
/%
‘@1038300q BY3 Ut Azjus 0oq meu B Fo szoyjne eyi zoy 3ndut ssn Buryieb zoz erqisucdsey x
#
poyjew Axjugroyjne .
wx/
{
/q uan3ex
! (z9ysTrqnd ‘Aeaayaoyzne ‘sasjdeyo ‘eorad ‘sebed ‘ST3T3 ‘PT) oo MOU = q jyoog
! () Azqugzoyzne = Kexxyzoyzne []Butazs
¢ (pras
AIY3 TMISYSTTANIPEST
ysTTa ' AVMSTTAIOYSTIANd
nd) = IoysTTqnd
¢ ()enteajut- ((Jwrxa: (., :PT xoystTand,)3ndut OI)JoenTea aebezur = prasystrand
!{(,aoqumu pT x9doad B j0U SeM paILsUD NOA PT oyj :x0xxd, ) urdutad 3no - we3sis
} (TTnu == zsystiand || 0 == ®otad || ¢ > ®oTad)oTTUm
¢ (p1r9 QIY3I TMISYSTTANIPLSI
YsTIq ' IYYSTTITSYSTIANG
nd) = Foystrand
‘(yenteA3uT” ((Jwrad - (, :PT aoystrand,)3ndur-OI)Fosnte xebejur
a = prasystiqnd 3ut
¢ () TRUTUISLOL SSWENSQISISYST TTY3NdIN0 - IYISTTATSYSTTANG
TARd
S8ODDE wopuRI//
} este {
¢ (P1a9 AIYI ysTTA
TMISYSTTINIPESI ' STTAISYSTIANG
Nd) = IoysTIgnd
‘()enTepjuT” (()wray - (, :PT x9ysTTqnd,)3ndut-0I)3oenTe a = pIrasystIqnd
asbejul
! (yzoqumu pT x9doad ® j0u SeM peasjus nok PT oYL :I0xx™,)uTiutid-ino wegsis
} (11U == zoystiand || 0 == ®o1ad || o > ®oTad)eTTym
¢ (Prxoys TTqnd) QIY3I TMISUSTTNAPESa
" STTATSYSTTIANG = xoystrqnd
‘()entep3utr” ((Jwraz® (, :PT IoysT
)3ndut Tqnd,
OI)oentea xebequl = prasystrand uUT
¢ () TRUTWISLOLSOUWENSQISISYS
TTYFNd3IN0 ST TIISYSTTANG
TTANG
Atrerjuenbes//
} (()pouzsnora=bi)st
! (wu)uT3utad-3ano -wejsis
! ()enteaz - (()wraz
ut - (, :sxeozdeyo,)andur’o1)FoenTes
1obo3ur = saoqdeyo
! (wToqumu 2AT3TSOd ® j0U Sem peasjus nok saejdeyo oyg ixoxxy,)urjurad’ 3no - we3sis
%
poyzaw Axjugautzebew
**\
{
!Kexayaoyane uxnisax
- sazoyjne (butais)
! ()enenbep = [T]Aexayaoyzne
} (++T ‘yzbust:Aezayaoyne > T (0 = T JUT) IOF
[ ()ozTs ‘saoyjne]butazs meu = Kexayaoyine []Butias
{(,N, =i saoyanysIow 3% ,U, =] SIOYIONYSIOW 3F ,X, =] SIoyjznygaxow 33 &, =j szoyjznyszow)dTTys {
(,
(0)a¥xeyo-" é(u) oN o (K) ssx ‘Ioyzne ISYjOUR DIBYIF ST -0I
u)3ndut = sxoyznyeoaow
} op
} ssT®
f,u, = saoyjnydIow (y < UMNIOYINE)IT
TsSIOYaN® § UBY3 D2I0W DABY J0U UBD Yooq B//
! T+unNIoyane = umNIoyjne
! (zoyane) snsnbus * sxoyane
(s 'y + unNzOY3NE + OI
, I0Y3Ne,)3nduT = IOY3NE
! (,SI930BIRYD Gz uey] Sx0ow sey Io Ajdws sem parsjus nok sureu Ioyine SYJ :1z0xx%, )uT3autad 3no-wejlsis
} (sz < ()y3bust- ()wral - zoyane || == () wra3 I0oU3INE)STTYM
()yabueT-
{(4 i + wunNIoyane Ol = Ioyzne
+ , Ioyane,)3ndut
} (,&, == sazoyanyszow || K, == saoyznyazow)STTIUM
!1 = umNIOoyjne 3ut
! K, = szoyznysaow xeyd
!{aoyane bButajs
! ()enend Mou = sIoyjzne snany
}
() £z3ugzoyane []Butazs or3eds orrqnd
{()enteA3uT” (()wraz - (, :(¢) eotad,)3ndut 0I)3Fo°nTEA a8bojur = ootad
! (,7oqumu aaT3Tsod ® jou sem pexojud nok eotad syy :xoxxd,)urizutad-ino-welsis
(0 == ®oT1ad || 0 > ® oTad) oTTYM }
¢ ()enTeAduT’ ((Jwra3d® (, :(¢) 9otad,)3ndut oI)Fosnrea’xsbey
ur = sotad
‘£ ()enteAlut” (()uwraz - (, :ssbed,)3andur 0I)Foentea asbejur = sebed
! (,x9qumu @aT3Tsod B jou sem pazsjus nok sebed oyl :xoxxd,)urjurtad-ino-weisis
} (0 ==sebed || 0 > s sbed)sTTym
{()sntearut: ((Jwraz - (, :sobed,)3ndut 0I)I0oSnTeA 19693 ur = sabed
{(u OI
:®T3T34)3nduT = sT3T3
! (,sa930®BaRYD GZ ueyl Sxow sey o Ajdws sem persjud nok OT3ITI oYL :I0xay,)uTzutad-3no welsis
} (sz < (Qyabuer: (Jwraz 13ty || 0 == ()y3zbuer’ (juraz-s TIT3) STTUM
{(u :9T373,)3nduT" oI = ST313
{()enTeAjuT’ (()wra3 - (, :PT,)3Indut OI)3Foeniea’asbeju I =pT
! ( xoqumu pt xadoxd B j0u seM paxsjus nok pT 8yl :xoxxd,)urjurad-3no-welsis
} (0 =pT |l O > PT)STTUM
{()enTeAzut” (()wray ' (, IS Bo3ur
:PT.)3ndur-OI)zFoonTERA" = PT
{ (wu)utaurad: ano "we3sig
*3no -wej3sis
*3no ‘wa3sis
Jurgutad: 3no ‘we3sis
yurjutad- 3no ‘we3sis
yurautad- 3no ‘uwe3sis
w)ut3urad: 3no "we3sis
"3no -wajsisg
*3n0 "wa3sis
! (uwu)uTauTtad:3no we3sis
! (wu)urautad-ano ‘we3sig
‘zeystTqnd IOUSTIANd
!ootad ‘sebed ‘prt 3juUT
!e13T13 butazs
}
() Axqugsutzebew surzebey orjzeazs orrand
-sxoysyooq oy3 ut Axjus sutzebew mau e oy andur xesn Buryzeb zoz sygrsuodssy
() Az3ugeoanossx []butazs or3ezs orrqnd
/%
‘ax03sy00q ®Y3l uT Arjus sutzebew meu B FO ssonossa syl xoz andur xssn Burizazeh xoy srqrsuodsey i
*
poyjzem AIjugesInossx
xx/
fur urnjex
! (roystTand ‘seoinosax ‘eotad ‘sebed ‘S73T3 ‘pPT)surzebe Mou = u sutzebeR
¢ () Kzjugeoanosax = seoanosax []butaas
{
{
¢ (p1aoysTTANd)
AIYF TMISYSTTANdPESI " JYYSTTIIOYSTIANG = IoysTTand
f()enteAjut’ ((Jwrxy - (, :PT xsbajur
Fdystiqnd,)3ndut-OI)3zooniea = prasystiqnd
! (,aoqumu pT xadoaxd ® j0u sem paxsjue nok pT oYL :I0xx¥,)urzurad-ino-wa3zsis
} (11nu == asystiqnd || 0 == ®oTad || 0 > sorad)STTUM
¢ (p1aoysTI9nd)
4IU3 TMISYSTTANIPESI " AVYSTTIISYSTIANG = Ioystignd
f()enteA3uT ((Jwray® (, :PT avystiand,)3ndut 01)zoentea xebequl = prasystrqnd Jur
* AVYSTTIISYSTTANG
£ () TRUTWISLOLSSWRNSAISIBYSTTANATTYINdINO
s5e00R wopuex//
} este {
AIYI TMISYSTTANIPeST * 9TTIISYSTIANd = T9ysTIgqnd
¢ (p1x9YsTTAnd)
f()enteAjuT” (()wrxy - (, :PT FoystIqnd,)3ndut-QI)zoonTeas a9b23uI = prasystiqnd
! (,asqunu pT xodoad ® j0u ses paxejus nok pPT SYIL :I0xxF,)urTiutid-jno-wslsis
} (1Inu == asystiand || 0 == ®otad || o > @oTad)sTTUm
¢ (p1aoys TTand) QIYA TMISYSTIANIP®OIT
' STTAISYSTIANd = IoYstTIgqnd
{()enteazutr: ((Jwraz: (, :PT I9ystTIand,)3ndut OI)Foentea aebejur = prasystiqnd 3Jut
TTY3nd3no o7 TIIvYSTTINd
¢ () TRUTWISLOLSOWRNSAISISYSTTANd
ATTerjusnbes//
} ((pouasworasbi)3t
¢ (wau)utautad:3no we3sis
sx03sjoog sserd orTand
sseIp dxojsxood//
! Kexaygeoanosax uaniax
- seoanosex (butayg) =
! ()enenbep [T]4eazaysoanossx
} (++T ‘yabuet Aexayeoanossx > T /0 = T JUT) IOF
/[ ()ozTs ' seoanosex]butalzs mou = KAeaxaysoanosex []Butazs
{
{
33 ,U, = SOOINOSSOYLIOW 3¥ ,X, =| SedInoseyexow 33 A, =] sedanoseYSIOW)STTUM {
SN =j seoinossyeiow
(,
(0)3gxeyo- ¢&(u) OoN I0 (K) seox ‘ooanossa IdYjoUER BIBYIF ST 4)3ndut -0I = Seoanosay¥sIoW
} op
} osT1®
{,u, = SoDINOSSYsIoW (j < WNNSDINOSSI)IT
‘SODINOSOI p UBYJ OIOW DARY jou ued surzebeuw ev//
/ THUNNSOINOSSOT = WNNSOINOSSI
! (90anosex) snanbus ' SEDINOSSIT
{
(4 . + unNeOINOS®I + , QI
90INOSDI,)3nduT = SOINOSLI
{(,sT930eIRYD Gz uEy} oFow sey xo Ajdwe Sem POISIUS 9OINOSSI OYL :IOIIH,)uT3uTad-ino-welsis
} (g2 < ()yabust' ()wrtx3 soanosax || == ()WTI3 9DINOSDI)DTTUM
()y3zbueT’
(, . + UMN®DINOS®I + , QI
©0INOSSI,)3ndur = SOINOSSIX
} (,X, == ssoanossoysaow || ,&, == seoanossyszou)dTTYM
{1 = WNN®DINOSSI JUT
! K, = sepanosoysIow IBYD
!ooanosax butals
!/ ()onend meuU = S9OINOSBI SNdBNY
Teutux®l °Y3} IESID O3 pesn//
opop orzioeds ponTd sxx//
}
()nuskmoys proa orrand
/%
¥
SYI sAetdsTp - POYISW DUDHMOUS x
- peuTwzey 9Y3 UT nuSW IS
xx/
{
1 () nusMoys
}
() ®@a03s3o0d ottqnd
7
SseTO O s308[ge IOF FO3ONIFSUCD x
oz038300g
k.x.\
{
! ()®a03sy00g MdU
}
(sbxe []HButals)uTreu PTOA ot3eas orrand
/%
poy3ew UTeH x
xx/
= STTISSOOOYWOPUR¥UITM UBSTOOQ TBUTZ otje3s
iosTes
/%
-Krngsseoons peieTduoo useq 84BU SOSTOIDKS

*
SY
oy usym ATuo onal = STTISSODOYWOPURNUITA oyew ‘yons

X
K
oy3 yo aed
-s00q sy3 uT ze3deyd STYR FO SOSTRISAD

X
STUL ~o7TF AxeuTlq B O3
se pegerduwoo ‘utebe ®ouO ‘ST SSBTD

X ok ok
2y3 I0F I9PIO UT poajeTduon
u233TIMA pue peSa oq O3 sxoystrand
® { pxOWIDYIANI
oq 03 peou OSTR TTTM AVISTTIISUSTIANG %
‘yooq eoyz ut zojdeyp STUF JO SISTDIDKS
SSETD


syy go gaed se pejerdwoo ST SSBTR STUL -pogetdwoo oq S
SUI PN} T
= STTASSSOOVUOPURNUI ou3 UITH
IPMOTTATRTISITROUTPESY

X oK
O3 wezbozd Byl I0F ISPIO UT DNINIYM
A730®II00 UOTAONF
*

~
x
{yesaq
{ () zoysSTTANIAG TR TISIBHOUTPESUISTT , osed
{yesxq
{() TeTao3eNOUTPESYTTYISTT : ,P, ©SED
{yesaq
! ()aoysTIqngSAOWSIT osed
Iyesaq
! ()xsysTTONgPPE : ,q, 9SBD
!yes1q
{()sa9YSTTIANATIYISTT : ,®, Ssed
} (uot3osres) yo3Tms
' {(,L, =i uoT3OST®S 3% ,T, =| UOTIOSTOS 3%
\4, =i uot3oeTes 3% ,b, = uoT3OeTSS 33 ,F, =] UOTIDSTSS 3% ,®, =] UOTIDSTSS 3%
,P, =i UOT3D9[dS ¥% ,D, =| UOTIDSTSS 33 ,J, = UOTIDS[SS I3 ,®, =] UOTIDD[SS)STTUM {
(,
f(0)3¢xeyo cuxogaed o3 juem nok op uorioe QI
UYSTUM,)3InduT = UOTIOSTSS
} op
/{uoT309T3s IByYD
‘welsis
utad-
! (wu)uTa3no
! (uwu)uTautad:
3no we3sis
f(43txE (L,)ur3urad-jno uwelsis
/(. (®T3T3 70 QI) TETao3zew Hutpesax I07 yoxess (T,)ur3zutad-yno weisis
# (., (butpusosep 1o bBurpueose) osotad Aq sTerasizew Hurpesa 3x08 (Y,)urrutad-ino weisig
! (,@x0353)00q 9Y3 woxy Terisjew Hurpesx e ssowey (6,)urjutad-ino-weisig
! (,®3038300q 8yl 03 TeTIojEwW Burpesx ® pPpY (3,)uriutad-ino-welsiAg
! (,aoystTgnd oTzToeds o sTeraojzew Hurpeex 9y3 TTE ISTT (°,)urizutad-ino weisis
! (,®1038}00q @Yz uT sTerasjrew Hurpess Syl ITe ISTT (P.)ur3zutad-ino weisis
! (,39ysTTqnd ® SA0wRy (0,)urzuTtad’3no-wslisis
! (uxoystrqnd ® PPY (g,)uTrjutad-ino-uweysis
{(,saoystrand Sy3z TTe 3ISTT (®.)uT3uTad 3no welsis
{(,:suor3oe BUTMOTTOF ©Y3 IO duo 309798, )uT3uTtad’ 3no welsis
‘we3sis
utad-
! (ww)uTr3no
! ( ===================== ===,)
UT3uTad" 3no ‘we3sis
! (,9x035300g 9Yy3 03 SWODTSM,)uT3iutad- 3no
welsis
! (==================== ====,,)
uT3uTad " 3N0 'WS3SAS
spoo otyroeds ConTg xxx//
£{,3\)utjurad-3no ‘weisis
SIUSWUOITAUD ISYIC UT POSN JT N0 PIJjUSWWOD 8¢ prnoys//
xx/
{
! ()snutjuoporssaad
{
{ () TRUTWISLOLSIBYSTTANATTYINdINO0 AVHSTTAISYSTTANG
ss9dDe wopuex//
} este {
{ () TRUTWISLOLSIOYSTTANG
T TYINdINO * ST TIABYSTTANG
Atrerjuenbes//
} (()pourswoIasbi)3T
}
() SI9YSTIGNATIVISTT PTOoA oTTqnd
\*
‘Teutwzel syl o3 saeystrand Syl TT® SISTT - POYISW SAOOHTTVISTT «
xx/
{
!OTTISSSOOYWOPURYYITM UINFDI
}
()poursnoIazeb uesyooq or3e3ds orrqnd
/x
‘andano pue jndut 03 ssoooe ferjusnbsg I0 STTJIssooOywopury HuTsSn SaR OM I9Yloyum uUINIDIP o
*
PoY3Su POYISHOIIeh 4
xx/
fyesxq
: 3Tnegyep
!yesaq
!(0)3Ttxo-we3sks : ,[, sseo
{yesaq
4() TeTIo3eWOUTPERSYPUTT : ,T, OseDd
{yesaq
! ()eotaghgTerasjenburpesyiios : ,y, osed
{jesxq
! () Tetasjzewbutpesysaocwax : ,H, sseo
!yesaq
! () Tetasjeyburipesyppe : ,J, °oseD
" AVYSTTIISYSTTANG
{ () TRUTWISLOLSPWENSQISISYSTTANATT¥INdINo
sssope wopuex//
} esT® {
£ () 9TTITOYSTIINGPESI
" STTATOYSTIANG = sasysTTand
¢ () TRUTWISLOT SOWENSQISISYSTTANATTYFndIno
8T T4ISYSTIAN
Kirerauenbes//
} (()pouasworasbi)zt
{1Tnu = sasystrand []asysTrand
(.9, =j UOT3}DOTSS B3 ,B, =] UOTIDSTIS)STTuM {
£(0)3vxeyo
" (, é¢mxogxad o3z juem nok op uoT3dE YOTYM,)InduTr
QI = UOTIDSTSS
} op
{uoT3oeTes IRYD
! (uwu)ut3utad-3no we3sis
! (,oureN - we3sis
(q,)ur3utad-3no
{(.a1 (e,)ut3zurad-jno welsis
! (4 :Rq @aowex o3 xaysTtIgnd ® I0F Yoxess,)urijurad-ino welsis
no -we3sig
! (wu)uTrutad:
}
() z9ysTTqngssocwsx proa oTTqnd
/*
TeuTwx®) 8yl ybnoxyy xoysTtignd B SACWSI O] ISSN BY] SMOTIE - POYISW ISYSTTGNIDAOUSIT
xx/
{
¢ ()snutjuoporsseoad
{
OLOF
{(d) ®oTTAIOYST ' IONI
TAM TA T TATISYSTTANG
sseooR wopuex//
} st {
LOF
! (d) ®TTAISYSTT ST AO
TNIN TAISYSTIAN
AfTerjusnbes//
;)FT
} (()pouasnorash-sxogsiood
st Ig nd
! () Kxqumasy
- Teutwi sri ndur = d a9ysTIqnd
}
() x9ysTTangpPPe PToA OTTAnd
/%
Teutuzsl sy3 ybnoayz zsystiqnd B ppe 03 I9sSn 9Y3 SMOTTE - POYISW ISYSITANAPPR »
‘9 = € 3qur
ab
- sxsys
/ [T-y ue
tTand T
]zoys TTnd Mou = dwel []avysTIARd
} (., == uot3oeres || &, == uOTIOST®S)JIT
3% ,X, =j UOT3DST9S 3% K, =j uotaoeres)aTTum {
{(,N, =j UOT3IOST®S 3% ,U, = UOTIDITSS
(.
£ (0)3gTeuR”
IYF SAouLT 03 auem noXk sans nok OI
21y,)3nduT = UOTIDSTSS
&¢(u) oN zo (K) sex ‘Axzjus 3}ooq SA0qe
} op
¢ (yu)uTdurad 3no-we3sis
! ( ================================= W) utautad- ano we3sis
{(93TSQPA 3UTI
+ . :EIISEEM,)uTN0 d
uS3sis
! (ouoydeTe3 + . :ENOHAETEL,)uT3uTad 3no-weisis
! (ss9appe + =”mmmmanfl=vGfluflflnm.ufio.fimumhm
! (sureu + :“HZ«Z:v:Huaflnm.uno.Ewumhm
{(owreu + ,:QI,)uT3utad-3no-welsis
ano
) ut3utad:- uaysks
f
yutjutad-3no we3sis
NfivmuflmAmBumm.m0>oEmmouHmu0£mflHn¢m = @3Tsgem butais
uAvmnoflmmfiwaumm.Hm>oEwm0uumumnmflHnfim = suoydaT®3 3UT
uAummwuuvmuom.Hw>oEwmouumumnmflHA=m = ssaappe butaas
NnvwEMZumm.Hw>oEmMOuumnmanHnum = sureu HBuTI3s
p13
- [eaouwsy
:() eb
oz]sasys trand = PT 3UT
} ostT®
! (, xoystrqnd yons ou ST sxoyg, ) uTautad 3no - weisis
(T- == °2a0wayol)IT
! (sasystTand / 157 9UrRIRIUOIRDS) UDILSSIRDUTT " YOIBSSILSUTT = SAOUSYOR
/(,:yoaess o3 suweN,)3ndur’ QI = I9IBWEIRIUDIELSS butaas
} estT® {
" YOIBSSIBOUTT
‘I93SWRIRIYDIESS)UOIESSI BSUTT = [A0USYOR
¢ (szoystiand
QH:qumflfl.OHvMowun>.nwmmunH = I9j9WRIBgUOIRSS JUT
f()enteazuT” ((Jwraly - (, :yoIedsS 03
} (,®, == UOT3DOT®S)IT
{1- = sAowsyo3 3UT
ANAP
* ATHOTTAT
¢ ()oTTaToUSTT ESTG
ISYSTIAN = sIoystand
A1TeT3USnbes /7
} (()pouasworazeh;st
)
} (,®. == uotzoeres)zt
(.9, =i uotz oeTes 3% 1By =j UOT3DaT®S)aTTym
‘(0)3vreyo-
(, ¢wrozred 03 juem noi op uorjoe UPTUM,) 3Indu {
T 01 = uorjoeTes
} op
{uot3oeTes zeyo
{ (wu) uTdu3n0
Tad-‘we3sis
! (usouTZRbEYR AA_.vfl.nufl.._..um.uao.Emumhm
! (., s3oog Am:vu._uun..num.u:o.swumhw
‘{u:odk3 3o sTeTIEREW Butpesa TTR® ISTT,) uT3utad- 3no ‘we3sis
A ) uT3uTa d
3no ‘weysis
}
() TeTTo3eRbUTPROYTTYISTT PTOA otTqnd
TTRUTWID] SY3 UT 9I03SY0Oq Y3 FO TeTao3eun Burpesxz ey TTe SASTT - poyzswm /%
TRTISIeRBUTPRSNTTVISTT «
*x/
{
! () enutjuopogrssazd
! (u'Po3oTSpP Axa3us ISYSTIANG, ) uT3uTad 3no weysis
uAmEouvwaflhnwgmfiflnumoawufluzmg.mgmwflwmnm:
mflflnsm
S$S90D® wopurz//
uAmEmuvmafimuonmflflnumosmumnmflflnnmwuflu } este {
s.mflfihuwamflflnsm
hflfimfiucwzwwm\\
} (()poursoraehi)
3t
‘140 = €
‘[T] saey stig nd = [[]dmeq
} (T =i saoweyos)zt
} (++T ‘yabuet-sazoystrandsT {0=T 3uT)I03z
IO STETISIEW putpesx TT® 35TI.)andut Or)FoenTea Iebsjul = PT
s (yenTeA3uT (()wraa- (, &(QI) xoysTrAnd YDTUM
® jou SeM paxdAUS nok prt °yIL :x01x9, ) uT3utad 3no weisis
f (,3oqumu pt 1odoad
} (0 ==7PpT |l 0>PpPT)eTTUn
STETISIEW Hutpeex TTE 3STT.)3ndur OI)FoenTes I0bs3UI = PT IUT
s (yenTeazuT (()wrx3- (, &(ar) xeusTrand YDTUM FO
Ta
# (un) uTau3no d-
‘we3sis
{
" IYHSTTITIYSTTIAN
! () TRUTWISLOLSOWENSAISISYSTTARATTYANdINO0
sseode wopuel//
} osT® {
STTIISYSTTAN
£ () TRUTWISIOLSOWENSAISISYSTTANGTTYINdIN0
Kyterausnbss//
} 3T
(()pourewoiasbi)
Id
300 ‘WO3SAS
{ (uu)uTauT
}
() zoysTTanakareTxerepbutpesydsTT PToa oTTand
/x
* TRUTWIS] SYI UT Bx031SHOOq JYF FO ‘zoysTtTand »
SISTT -~ pPoyisuw nwnmflHnnmhmflMflumumzmnflvaM#MAfi %
uTe3I80 B JO ‘IETISIRW Butpeex 8y3 TT®
*k.\
{
() enuTjuopogssead
{
{
KfivHmcaEuchBmwaflNmmmSHamufimuzo.mmMmAMwflMflnwumzwnfinmwm
sse9Doe wopuea//
} esta {
NAuHmcHEMwaoamWQHNmmmzflflmunmuso.waamamaumumflmflfivmwm
Atterajusnbas//
} It
(()pouaenoIa=bi)
} osto {
{
SIO
! () TRUTWITYANAINO LSY
" ITIST OOH
TITETISF T Y
BROUTPES
ssoooe wopuex//
} esT® {
BRBUTPRRY
STTATR TSNdn0
/() TeuTwIS FOISYooa"TTYa
! (wu)utaurad-ano ‘we3sks
¢ (,outzebeny (qg,)urjutad-ino’ we3sks
! (u¥oog (e,)ur3zurad-3no -ue3sis
! (u:ppe 03 Tetaejeuw Buripesx yo adh3 jeyM,)urjutad-3no ‘ue3shs
! (uu)ut3utad-3no ‘we3sis
}
() TetaezeRbutpeSyppe pPTOA oTIgnd
Teutwial °y3z ybnoayy fetxsiew burpesz e Ppe 03 I9sSn SY3 SMOTTR - POYIsW TeTISIeHOUTPePPEe
xx/
! ()snutjuoporssaad
! (PT) I9YS TTANdIOTRUTWISI
TYINd3Nno
OLSOUTZeSeNT
" AVNST TATe TI93eRbuTPpRSY
ssa0oe wopuex//
} osTo {
{ (PT) I9YSTTANAFOTRUTWISLOLSSuTZRBbeNTTY3nd3no
*STTATe TIoFeRbUTPRSY
ATrerjusnbes//
} st
(()pouzsnorashi)
w)ur3utad-3no- wa3sis
! (yseutzebeR,) ututad-3no- wa3sks
! (yu)utzutad-ano- we3sks
! (PT) I9YSTTINGIOTRUTWISLOLSHOOFTTY
* AYYS T TATR TIO3BHOUTPESY
INdINO
ss900® wopuex//
} asT1o {
{ (PT) 2I9YS TTANdFOTRUTUIDLOL
oI TYINd3N0 T TATR TIOIRHOUTPRSY
S
A1TeT3USnbASs//
} (()pouasrora=sbj)st
u)uT3uTad:
gno ‘weasis
! (usy00g,
) uT3utad- 3no ‘we3sis
{(uwu)uT3utad-3no- weglsis
! (,outzeben (q,)ur3iurad-jno welsis
{(u3oog (e,)ur3rutad-3no ue3sis
! (,:oa0wez o3 TETIojRWw burtpesa yo odhk3 jeuM,)uriutad-ino welsis
¢ (wu)utaurad-3no weasis
)
() TeTaorebuTpesysscwax proa oTTqnd
/%
TeutwIo) oy3 ybnoayz JOOJ B DAOWSI O3 IDST DYJ SMOTTR - Poylsw TerrsjejbuTpeogoAcuRx
xx/
{
! (yenutjuopogssaad
TIM * IVUSTTA
¢ (u) ©TTAPUTZRH TR TAS3 eROUTPRSY
RHOLOF
ssspoR wopuex//
} esta {
OLO]
TaIM " STTITRTISIBROUTPRSY
! (u) oY TIoUTZEBER
Attertausnbas//
} (()pourswoIl=b sxo3syoodi) 3T
! () Azquzgsutzebew Teutursrindul = w sutzeber
} esTe {
{
¢ (q) ©TTANOOHOL O TIM IVUSTTATE TI23 BHOUTPERDY
$s9DDE® wopuex//
} st {
TIM ‘DT TATR TS} BNOUTPRSY
¢ (q) ®TTANOOHOLPI
Artetauenbes//
} - ex03sjood|) FT
(()poyasRoIaLb
! () Kxaumgyooq- Teutwragindul = q joog
} (,®, == uoT3DOTIS)IT
{(,q, =i UOT3DSTSS 3% ,B, =| UOT3IDIT3s)STTUm {
- (,
1(0)3¥xeyo cwxogxad o3 juem QI = UOCT3IOSTSS
nok op uor3ide YoTyM,)3Indur
} op
/{UoOT309T9S IBYD
! (wu)urTaurad-3no-we3sis
{u== w)uT3uTad- 3no-uelsis
¢/ (()suwreN3o
- xoystTand
b + , 1WEHSITENG.)UTIUTId
3n0 weisis
{([F]saoyane + ,:(S)WOHINY.)UTIuTad 300 We3sis
(((uu)stenbs-
(Jurtay - [[]saoyane) )3T
} (++L ‘yabust-szoyane>l ‘o=[ 3urt)zoz
! () saoyany3ab- [saocwsyol]siyooq = sxoyane []bButaas
! (sae3deyo + ,:SYAIAVHO.)U3no TIuTId
welsis
{(ooTad + ,:($) FOI¥A.)uTzutad-3no-weisis
{(sebed + ,:sHA9VE.)uTi
3no uTad
weysis
S(9T3T3 + . ETLIL.)uT3u
3no Tad
wejsis
{(PT + u:QI.)uT3ut
-3no welsis
ad
2 ) urT3utad-3no-wegsis
! (wu)ur3zurad-3no-wegsiks
! ()aoysTTangl
- [eaocwsyol]syooq
eb = zaystiaqnd ISYSTIQNg
! ()sas3ydeypi- [sacwsyol] eb
s)yooq = szojzdeyo jut
! ()o01Ig396"° [9A0wey0o]]sooq = sotad jur
! () sebegyesb- [sacwsyolzlsyooq = sabed jutr
£ ()oT3TL3®6
" [eaocweyol] syooq = o3ty bBuraas
! ()p13eb’ [@acweyoz]sjooq = PT JuUT
} esTe
{{,"®I03S}00Q BY3 UT OOQ YONS OU ST BIdYL,)uT3urtad 3no-uweisis
(I~ == Saowsyol)IT
! (ena3 ‘s3j00q) TRTISIEROUTPEOYIOIYOILSS = SAOUSHOF JUT
¢ () syoogpeoT = syooq []3joog
} (e, == uot309T8s)IT
(.9, =i UOT3}DS[®S 33 ,®, =| UOTJODTOS)STTUM {
(0)3vaeyo’
(, ¢wrogzed o3 juem nok op uor3loe YOTUM,)3ndur
QI = UOT3OSTSS
} op
{uoT3oeTes IBYOD
! (wu)uTautad-3no ‘uejsis
“Avuonmflflnsmuwm.Hw>oEwmovumm=fiNmmmE = zoystTand aoysTTAnd
!/ ()eo1agaeh' [esoweyoy]ssurzebew = @otad Jut
! () sebegyeb’ [aaoweyoy] ssurzebeu = sobed jur
:()oT3T1396" [0Acumyol] sourzebew = 971313 butazs
! ()pI13°b ' [9AcuwEyo]] seutzebew = pT JuT
} os1®
£ (,-@3035300q 9y3 uT Surzebew yons ou ST sa9yg, ) uTrutad - 3no welsis
(1- == ®A0WS¥O3)IT
! (enay ‘sputzebeu) TRTIS}EROUTPRSYIOIYDILDS = SAOWSYOZF JUT
/() seutzebeypeoT = seutzebew []aurzebeq
} os1e {
{
{(,po3eTep Aajue oog,)ur3jurad-3ino-welsis
{
* VIS T TATRTIOFBHOUTPESY
! (dwe3) O TTANOOHOLOITIMGI
sseoDe wopuex//
} esTo {
TIM DT TITRTIOIBROUTPESY
! (duwe3) ®TTIHOOFOLSHOOHGSF
ArTerausnbes//
} (()poyzswora=bi)3t
{
‘140 = €
‘[t]syooq = [[]due3y
} (T =i ®Aowe¥ol)3T
} (++T {u3bueT sy0oq>T {0=T JUT)IOF
‘0 = [ 3ur
- syooq]ocg
! [1-y3bueT mou = dwez []oodg
} (,&x, == uot3oeres || ,&, == uOT3OSTSS)IT
=j UOT3DST®S %% ,U, =j UOTIDSTSS 33 ,X, =i UOTIOSTSS 3I¥ K, =j uotyoeres)oTTyM {
{(,N,
oN xo (K) sex ‘Kzque JOoOq SAOQe SU3} SAOWSI 03 JUeM nok aans nok 0l
eay,)3andut = UOT3OSTSS
(.
s (0)awaeyo- &(u)
} op
“AmEmugmflflhmcflummmSOHmuflnzwu.hflMWHfihHMflumumEmnflummm
sseode wopuex//
} ost1e {
NAmeuvwHflhw: flummmz oamoafl Nmmmzm uanz.W AfihHMH nwumzmcflvmwm
Airerausnbes//
} (()poursnoriaebi)
st
{
{
‘140 = C
!{[tT]soutzebew = [{]dwsg
} (T =i saowsyol)zt
} (+4T ‘y3buesT ssurzebew>T !(g=T 3uT) x03
‘0 = € qur
! [T--y3b
seutzebew]surz
usT ebey mou = dwey []eutzeber
} (LXK, == uot3oeres || ,&, == uotjoeTes)zT
(\N, =i UOT3DST®S 3% ,U, = UOTIOSTSS 3% (X, =i UoT3oaTSs 33 ,&, = uorjoaTes)°TTUM {
£(0)3¢aeyD"
(, ¢(u) oN xo0 (&) sex ‘Kajus sutzebew saoqe Y3 saowdx o3 juem nok aans nok say,)3ndur-or = UOT309T9S
} op
! (wu)uT3zurad-3no-we3sis
o ===,) uTautad-3no-we3sig
¢ (()sweN3sb-xousTTIand + , IWAHSITENG.)uT3uta 3n0- wegsis
d
{([Clseoanossx + ,: (S)ED¥NO
uT3uTad
SHY,
3no woysisg
)
(((uu)
()wray
sTe- [[]seoan
nbaosax) "
i) FT
} (+4C ‘y3buet-sedanosea>l o=C 3ut) I03
uAvm@UHflOm@fiHflflOfluflUU4pwm.hmboEmmouumwnflummmE = sadanossx []butazs
{(®0t1ad + ,:($) EOTWA.)ur3utad 3no’ueisks
!(sebed + ,: EOYd . ) UT3uTad 3no we3sis
(97373 + , 1WILIL.)uTdurad-3no weasis
‘(PT + .:QI.)uT3utad 3no-we3sis
e — == ‘we3sig
‘uwe3sig
1 () sjjoogpeoT = s)ooq []3jood
} (i, == uOT30OTaS)IT
f(,q, =j 2dA13x0s 3% e, = =dArizos)erTum {
(,
i (0)ayxeyo- éwxogzzad o3 juem oI = adir3zos
nok op uor3zoe YoTyM,)3ndur
} op
!ed&13a0s xeyd
3no ‘we3sis
! (wau)uT3utad-
! (,Butpusoseqg (q,)ur3urad-3no welsis
! (,butpusosy (e,)ur3zutad-3no welsis
! (,:but3zzos go adh3 jeym,)urzutad-ino-ws3sisg
! (wu)uT3utad-ano ‘ue3siAs
/(,9, =j UOT3IDSTSS 3% ,®B, =| UOTIDSDTSS)STTUA {
- (,
‘(0)3¢xeyo cwrogzxed o3 juem nok op uorioe YOTYM,)3Indur OI = UOTIOSTSS
} op
{uoT309T9s IBYD
! (wu)utdutad-3no ‘we3sis
! (,outzeber (q.)ur3zurad-3no welsis
{(,qo0g (e,)urautad jno-welsis
¢ (,:901ad &q 3x0s o3 TeTxsjew Burpesxz o =odA3 jeuym,)ur3zurad-ino-uelsis
! (wu)uT3utad 3no ‘we3sis
}
COOHMm\nMHm.flNWUMEUG.«.UMOMU.HOM pPTOA U._.u._nnfl_nm
/%
¥*
ootad Aq pe3xos Tetyojew Surpeex oyl sieTdsTa - poylsw S0TagAQTRTIISIBHOUIPESYIIOS «
xx/
! ()snutjuoporssaad
! (, pe3oTop Axjus ino welsis
surzebey,)uriutad-
o W) uT3autad-ano wolsis
! (()suweN3eb zoysTTand + , IWAHSITENG,)uTIuTad
3no we3sis
{([C]szoyane + 3no we3sis
,: (S)YOHIAY.)UT3IuTad
(((uu)sTenbs"
(Jutag- [[]szoyane) ;)3T
} (++C ‘y3busT-saoyane>l ‘=L jut)zoz
! ()saoyanyayeb- [T]syooq = sxoyzne []Butazs
! (saezdeyd + ) uT3utad ano-welsis
:SYELAYHD.
f(eotad + ,:($) EDI¥A.)uT3urad-3no- ws3zsis
{(sebed + ,:5EHVd.)uT3uTad 3no we3sis
{(9T3T3 +
FILIL.)uT3utad 3no welsis
{(PT + .:QI.)ur3durad
3no welsig
‘u J)urtautad:
3no - weisis
JJur3utad-ano-we3sis
{()aeysTIqng3=b- [T]syooq = aeystiqnd IBYSTIGNd
! ()szeqdeypysb- [T]lsyooq = sazejdeyo jut
! ()@oTxa39b" [T]Sjooq = @otad juT
! ()sobegzeb’ [T]syooq = sabed jut
" [T]sj00q = ®T3T3 Burazs
{()eT3TI386
£()p13eb- [T]syooq = PT 3uT
} (-~T {0=<T !T-y3bueT s3y00g=T JuT)IOF
d
3N0 wexsis
u) UT3UTI
! (. : (butpusosep) ootad Aq sjyooq peo3zIo; yuT3ut 3no we3sis
ad
)utjutad-3no welsis
! (9sTe3 ’‘S300q)31IOSUOTIOSTOS "JIOSUOTIOSTIS = SHOOq
} osTe {
s)ur3autad-3no-we3ysis
)yurjutad-3no-wo3sis
! (9na3 ‘s)00Q)3IIOSUOTFOSTSS "JIOSUOTIOSTSS = SY0oq
} (.®, == adAz3zos)3T
} estTo {
,*3IO0S O3 ©I03SOOQ dY3 UT SYOOQ OU SIe dIdYL,)ur3zutad 3no-welsis
} (0 == uy3bust-syooq || TTAU == s300q)FT
! ([C]seoanosex + 3no ws3sis
,: (S)HOYNOSHI,)uT3uTad
(Jwtay - [(]sedanosax) "
(((uu)sTENDb® {)IT
} (+4C !yabuet-'seoanosaa>l {o=L jur)axoz
" [T] sourzebew
! () sooanossy¥TeUCTITPPYISh = sodanossa []Butajs
! (eoTad + ,:(§) FOI¥4.)uriurad-jno-we3sis
! (sobed + ,:sE9Vd,)ur3zutad-3ino-ueisis
{(9T3T3 + o ETLIL.)uT3uTad-3no we3sis
{(PT 4 u:dIu)uT3uTxd 3no-welsis
(0 w)uT3utad-3no we3sAs
! (wu)urT3utad-3no-wa3sis
{() zoysTTqndaob-’ [T]ssutzebew = xaystTqnd ISYSTIANd
! ()o0Tag39b " [T]soutzebew = sotad jut
! () sobegaeb [T]souTzebew = sobed jut
{()a131I396" [T]ssutzebeu = o73713 butals
{()pr3sb- [T]seutzeben = pT JuT
} (--T !{0=<T ‘T-u3zbusat- ssurzebew=T juT)IO3F
! (wu)ut3utad-3no welsis
! (,: (Bbutpusosep) ootad Aq ssutzebew welsis
pej3xos,)ur3zutad-ino
! (wu)utdurad-jno welsis
! (osTeg ‘sourzebew)3I0SUOTIOOTOS JIOSUOTIOSTOS = sSsutzebew
} est® {
! (wn)ur3zutad-3no-welsis
!(.: (Bbutpusose) ootad Aq ssutzebew ps3zos,)uriutad-ino wslsAs
! (wu)uTautad-- 3no-welsis
! (ena3 JIOSUOTIOSTIS = Ssutzebew
‘ssurTzebewr)3I0SUOTIOSTSS
} (., == adAz3zos)3T
} este {
!(, 3I0s 03 2I03S300q 9Y3 UT sourTzebew ou oI SI9YL,)UT3uTId 3no- welsis
} (0 == yabust- seurzebew || TTnuU == saurzebeu)zT
! () seutzebeypeoT = ssutzebeuw []surzebey
} sste {
{
ad
3no -welsis
! (wu)uT3ut
£ () x9ysTT
- [sacws
ang yo3]sy
3eb ooq = xsystrqnd IoysTIand
“Avmnmummnuumm.Hw>osmmouumxoon = szojdeyo
jut
uAVWUHHmuwm,HmboEwMOuHmMoon = ®ot1ad jut
¢ () seb'eg3[saocusyoy]syo
eboq = sebed quT
£ ()°T3T
" [eaowey
L3° o3 ] sjooq
6 = oT3T3 buTaas
{()p138b- [er0owayo3]Sj00q = PT 3uT
} ostTe
TSI03S300Q SY3 UT YOOq Yons ou ST ®a9Yy, ) ur3urad-3no - we3zsis
(I- == saAoweyol)zT
! (snx3 \mMooAVHMfikumSmaflumwmu0hnuum0m = SAOWSYO3 JUT

i
! () syoogpeoT sjooq []xoog
} (ie, == uot3oeTes)zT
(.9, =i uotr3joeTaSs 3% 1B, =j UOTIDSTSS)STTUM
{(0)3¢aeyo- {
(, cwxogzaad o3 juem nok Op uoT3d®e yosTyM,)3ndur
QI = uor3zoeTes
} op
{uor3joeTes xeYD
! {uu) uTauta
3no ‘weysis
d-
! (uSuTzEbeR (q,)ut3zutad:3no-weqsis
¢ (u3oog (e,)uriutad gno-weisis
(4 :PUTF 03 Teraegzew Butpesx o =diz 3eYM, ) uT3utad- 3no ‘we3sis
! (uu)uT3uT 3no we3sisg
ad
}
() Tetzs3enburpesyputs proa orrqnd
Tetxonew Burpesx e spurg
/%
- Poylew yerislebutpesuputy
xx/
! ()enutjuoporssexd
! (wu)uT3urad-3no
- weasisg
Hil{r— )uT3utad- 3no-we3sis
{(()sueN3eh-zoysTTqnd + , ‘NEHSITEAG.)uT3utad
3no wessis
! () so0INOS9YTRUOTI
TPPYISD ' [sAoweyoq ] souTzebew = ssoanossx []Butazs
{(eotad + ,:(¢$) 3no uwelsis
FDOI¥d.)urzurad
{(ssbed + ,:5m9¥d.)ur3iurad-3no welsis
(97373 + 4 EILIL.)uT3uTad 3no wo3ysis
{(PT + u:QI.)urjurad-3no we3sis
o ===,) ur3utad 3no-we3sisg
! (wu)urautad ano-wa3sis
! () aoysTIqng3eb
- [sacwsyoi]saurzebew = geystTqnd I9YSTTANd
! ()ooTag3ob’ [eacwsyo3] ssuTtzebeuwr sotad jut
! () sebegaeb - [eaocwsyol]ssuTzebew sabed jqut
! ()o13TI3ob" [oaocmeyo]]sautzebew = oT3T3 Butaag
! ()pI3eb- [sacweyol]sautzeh RW = PT 3ut
} este
{(,"27035300q 9Yy3 UT SutzZebew yons ou ST dxdYL,)urjurad" 3no- w3 siks
(1- == SAOWSYO3)IT
¢ (enag ‘ssutzebeu)
TeTI93 BHOUTPROYIOIYDILDSS = SACWSYO] JUT
! ()soutzebepypeoT = soautzebew []surzebey
} esTs {
{
£ (wu)uTaurad-3no-we3sis
u 3no
- ws3sisg
===, ) uT3utad-
- zoysTTb
¢ (() sweN3s and + , 1MEHSITENG.)UTIU TId
300 wo3sis
{([C]szoyane + ,:(S)¥WOHLAV.)uT3autad jno-we3sis
(((uu)sTenba"(Juraa - [C]szoyane) ) IT
} (++C ‘yabust-saoyane>l (0=C jur)aoz
! () szoyanyaob- [ssowsyo3z]syooq = sxoyane []Butaas
¢ (sze3deyo + , :SYAIAVHO.)uTIuTId" ano- wo3sis
{(ooTad + ,:($) HOI¥d.,)ur3urad: 3no -wa3sis
¢! (sobed + ,:sEOVd.)uT3uTad" 3no* wo3sis
£(®13T3 uEIIIL.)uT3uTad" 3no- w3 sig
+
+ w:QI.)uT3utad: 3no -we3sis
{(PT
(=== w)ur3zutad-ano- wo3sis
{ (uwn)urdurad: ano ‘uelsks
J IT
(syoogrTvAeTdsTP)
! (Jut3zutad-
3no ‘we3sig
{1- = SAOWSYO] JUT
!(,q, =i UOT3OOTOS 33 B, =i uoT3osTIs)STTYM {
f(0)ayaeyo-
(,, cwroyxed o3 juem nok op uor3zoe YSTYM,)3nduT
QI = UOT3IOSTSS
} op
{uoT3lD8TSsS IRYD
! (un)uTautad-3no: we3sis
{(,®T3TL (qu)uT3zurad 3no- we3sks
{(aa1x (e,)urzutad-3no ‘uwe3sis
! (.:&q saocwex 03 jooq ® I0F yoxessg,)uriurtad-3zno ‘uwe3skg
wegysis
! (wu)urautad-ano:
} (syoodrTvAeT1dsTp uesTOoOq ‘syooq []yood) TerIiojerburpesyIogyoreds jur o3eatad
/%
‘punojy }ooq ou ST T~ °AeIIe S$YOOY SYJ UT IOF POYDIBRSS OOg Oyl JO ¥°9puT oy3 HBurhAryTubrs asbejur ue uanjlaxp x

¥
eTgqeTTRAR Sjooq TTe AerdsTp 03 jou o xauyjzsym HutdyTubrs uesrooq ® syoogTTvAeTdsTp wexedy

X
sjooq STgeiTRAR JO ARixR UR syjooq wexedp

* ok ok ok
‘Teutwady oyz ybnoayz
300G B IOF YDIESS O3 ISSn Y3 SMOTTE - POYISW TeTIel eHbuTpeeyIofyoIess
xx/
! ()onutjuopogssaad
{ (wu)UuTaUT ad - 3no
- we3sisg
A w)ur3utad-ano-we3sis
¢ (()suwreN3®b
- azoysTTand + , :MEHSITENd.)uT3utad
ano welsis
! ([L]lseoanosex + ,:(S)EDYNOSHY,)uTautad
jno -welsis
(((uu)sTenba-
(Juray- [(]sedanosaa) ) 3IT
} (++C !‘yabusT'ssoanosaa>l ¢0=C 3jut)aoz
{uoT3oeTe9s IBYD
3no we3sis
! (wu)uTaurad
! (4w®T3TL (9.)utrutad: 3no-uwelsig
{(.dI (®.)ur3zutad'3no wezsis
!(,:&q saowsa o3 sutrzebew ® I03 yoxess,)urijurtad-ino-welsis
! (wu)ur3urad-3no-we3sis
} (ssutzebeniTvAeTdsTp uesTooq ‘ssutzebew []surzebey) retaiozenburpesyiogyoress juTt o3eatad
/x
‘punog jooq Ou ST T- x
- Keaze sourzebew oyjl ur I03I poyoxees osutzebew syj 3o xopur oyl Durtdyrubrs zebejur ue wUINIDIAP i
Aerdstp
¥
eTqeTTRAR soutzebew TTe Aerdsip 03 jou 1o xeylsym HBurtAyTubrs uesTooq ® sourzebeqrrv wexedpy i
soutzebew aTqeTTEAR JO Aeaae ue ssutzebew wexedp x
%
‘TeutwI®e] oylOIUY aySl
noBS
ybDI
YI
surzebew e I0F YOIBSS O} ISSND BY] SMOTTR - POUlSW TeTISIeHBUTPRS
%%/
{
!sAcwSY¥oO3 uInlox
TT
LOS)YDILSSIBOU {
! (syo0q ‘IS]OWRIBRJYOI "YOIBSSIBOUTT = SAOWSYOF
ndur ess
! (,:yoaess 03 ST3ITL,)3I QI = I93sWeaegyoa butalys
} este {
UOIRSS) DUTT BOUTT
! (sjooq ‘I93°8WRIBRJ YOIBSSIB r 'YOIBSSI = SAOWSYO]
andu IBSS
{()onTeA3uT” (()wta3 -’ (, :‘yoxess o3 gI,)
' oI)gosniea xsbsjul = I93SWRILUO JUT
} (i, == uoT30919S)IT
" aVySTTATR TI83 ndINo
! () TRUTWISLOLSOTITISAISYOOHdTTYI eRbUTPRSY
Ss900® wopuex//
} est® {
ST TATRTIS3 RO INo
¢ () TRUTWIBIOLSSTITISAISHOoATTYINd3 UTPRSY
Atterausnbes//
} (()PoyasWOII=bi)IT
Krtetauenbes//
} (()pouasworaebi)zt
!ITnu = syooq []3joog
} ()syoodgpeor []3oog sjeatad
/*
-sjooq o Aexie ue uanldIP x
¥
“STTI 9Y3 WOXI SHOOQ SPROT - POUISU SHOCHPROT »
%x/
{
{sA0cWSYO] UIN}DI
{
! (ssuTzebew ‘I9]0WRIRIUDIELSS)YOILSSIRSOUTT ‘'YOILSSIBSUTT = SAOWSYO]
! (4:ydaees 03 OI
ST3ITL,)3ndut = I9jzswexregyoress burilsg
} est8 {
! (ssuTzebew ‘I9]°WERIBRJYOIELOS)YOIROSIBOUTT ‘YOILSSIBOUTT = SACWDYOF
! ()enTeA3zuT" (()wra3 " (, :ydaess o3 [I,)3ndut 0I)FoenTea I9HSjUI = I93SWRIRJUDIESS JUT
} (e, == uoT3o9TSs)3IT
{
{
' VYR TTATE TI93 BRBUTPRSY
/() TRUTWISLOLSSTAITLISAISOUTZRERRTTYINdRNO
sseoo® wopurRi//
} st {
{ () TRUTWIDLOLSOTITISAISOUTZRbRRTTYINd3no
"I TATe TI9]) BRBbUTPESY
Arterausnbes//
} (()pou3zsworasbi)zt
} (seutzebewriyAerdstTp)3IT
! (Yutautad-3ano -we3lsis
{1~ = SAOWRYO] IJUT
(.9, =j UOT3DO[®S 33 ,B, =| UOTIDD[SS)STTYM {
{(0)3yaeyo-
(, cwzogzaed o3 juem nok op uoTIO® YOTYM,)3ndur
OI = UOTIOSTSS
} op
! () nuspMoys
! () uTau3no we3sis
Tad-
03 NOLLOH OI
ANY S59d,)3ndut
1 (, onuT3uod
! (wu)uTautad-3no welsis
} Avmflaflunoooammwnm proa sjeatad
*
pue obesseu sAeydsTp - PoulSwW wscflvGOUOEmmwum\*
-nusw o3 senuTjucd
wx/
{
!goutzebew uaniex
{
mhvwaa&waflnmmmzvmou.h@dflfiflhdflfluwumzmnflvmmm = seutzebew
$S200R WOPURI//
} este {
bew
uAvwflflhwnfiummmzvmwu.mflflhHMfiuwvamcflfimmm = soutze
KtTerauenbss//
} st
(()pouzeworaebi)
{7Tnu = seutzebeu []surzeben
} ()ssutzebewpeol [1outzebeny ozeatad
/%
-goutzebeuw Jo Aeaze ue uINIBIY x
*
woxy ssurzebew speoy - poylsW souTzebeHPEROT »
‘o713 °y3
*x/
/§}00q UINISI
{
uAw0flflh&oomvmwu.hm&mflflwflmflumumzmcflnmwm = s3jo0q
Sse0DR WOpuURI//
} este {
NAvmflflhxoomvmmu‘NAAMHMflkumEmnfivmmm = sjooq
(pT aaystiond ‘eotad ‘sebed ‘pT) SIUT b o«
*
1o dn
spew ST Ing SEIAE QYOO MOOH O3 IRTTWES ST SHEIAY QUOOEM ENIZVSVH x
x/
/GxSEIAE ONINIS + G+SAIAE INI = SHIXE QUODEM MOOH IUT TBRUTI OT3E3S
/%
‘jooq Aue xoz juessid 8q UED SIOYINE® INOF JO WNWTXEBUW B JBYJ POUNSST ST 3T x

*
$034q GpT = GBI + 9T = GxGZ + Gxb

Kk
%k
:dr 93e3 PTNOM BTTJ UT POI01S PIODBI HOOQ UdED

kK
X
(y zoyzne ‘g zoy3ane ‘g xoyjne ‘T Foyzme ‘®©1313) sburiys g

X
(pT asystiqnd ‘saeideyo ‘eotad ‘ssbed ‘pr) squr g

Kk
X
:30 dn spew ST PIODBI YOO B SOUTS

K
‘®TTF ® UT POI03S piodex jooq e sjussexdex SAIAY (QHOIMY MOOH

~X
x
!y = SELXE INI 3UT TEUTF OTIe3s
‘se1Ty 3ndano oyl UT JUT UB BIOIS 03 pspesu serhg sy3 sjueseadsa SEIAE INI//
!GZ = SHIAY ONIMIS IUT TeUTI OT3Ie3S
/*
‘asqunu Aur useq sary PTnod 31 ‘xsumeiboxd syz Aq pepIoSp ST STYUL x
*seTTy 3ndano ay3z ur se3hq gz dn eyes TTTm wexboxd STY3 UT pesn BQ x
TTT# 3eyy HBurxls Axzsao ‘Kem STYJL 'UDED SISIDRIBYD GZ x
Fo umuTxew e 2avy Aew ‘(°D3® ‘sIoyine ‘sSOT3T] ‘'X9) STTLIOP SNOTIRA 4
@x03s 03 ‘weaboxd sTyz ut pesn sburals syl eyl uesw so3hg Gz x
.mmuhncfi‘unmafimcflnum»qmmon»mamfimsumucmmmummummaum|Wszam«
*\
}
AvgeTTATeTIS}eHPbUTPR™®Y sserd ot1Tqnd
{uot3deooxgOI
‘o1 'eARL jx0durt
!TTdsseooyuwopuey
‘ot ‘eael jzodurt
AvYeTTATeTI93eRbuTPERY//
! (peoyoLAIjus)proDaySTTANOOgPE®I = [T]SeTI3UE}00q
{SELAE QYODEY MOOHxT = pesyoriijue 3ut
} (+4T !SOTIIUFFOISQUNMUST {(Q=T JUT)IOF
oTTye3ep °y3 ybnoayy door//
}Ka3
! [seTajugIorsqunu]yood MSU = SOTIFUAN00q []3ood
{SHIAY QUODMY MOOH / 9ZTSOTTIN00q = SOTIFJUHIOISCUNU
{ (Jyabust-STTANO0ESYI (IUT) = SZTSITTIN0OQ JUT
{(uMT, ‘ENYNITIA MOOH) STTISSSOOVWOPURY MSU = STTJY00HSUR
}&x3
{0 = S9TIFUFIOISqUNU JUT
{oTTAy00gSY] STTISSSDOYWOpURY
()eoTTayoogpeax []joog oT3e3S oafinnw
STTANCOQ 9Y3 JO S3USIUCD SY3 TR yata Aexae chsumnw\”
DIOJSHOOG BYJ WOIAF SOTIJUD OO TI® SPEIX - BTTIHOOHPERII H
k.&.\
- spoylew pejlerea HOoH//
{LAvgeTTIsuTZRbRW, = deZEAthmZHmflwflz butazs TeUuTy OT3E}S
{ W AYMOTTIN00q, = FWUNITII MOO" BuTtazs Teurz or3e3s
!GxSALXE ONINLIS + pxSHEIAE INI = SHIAE QMODTY ENIZVOWW JUT TRBUTF OTIE3s
/%
-sutrzebew Aue x0T «
quessxd 8 uUBD SVDINOSSI TRUOTITPPR INOJ JO WNBWIXRW © 3BY3 POUMSSE ST 3T *
*
s934&q T§T = GxGZ + bxb *
*
:dn 93] PINOoM BTTI UT PHIOJS PICOSI WEHNNUME yoes
*
(p ®oanosex ‘g Loxnosex ‘z soanosea ‘] eoanosex ‘eara) sburals g *
{()3uipe
- eTTayoogoyl
sx = sabed jut
! (s®3AgeT1313) butays meu = o731y Burazs
_ (s°34geT373) ATTnIpEeI STTANOOHSYSF
! [sELAE ONI¥WLS]e3Aq meu = soihgeT3ty []eadq
! ()3uIpesa OTTAN00ESYI = PT 3JUT
! (peeyoLA
yoes zjus)
oTTINOOGSYF
{SAIXE QUOOEY MOOH / SZTSSTTIAOOQ = SOTIIUFFOIOqUAU
{ (JyabusT oTTaYOOgOYF (IUT) = SZTSSTTANOOG IUT
{(uMZ, EWYNETIA MOOH) ®TTISSOOOYWOPURY MU = STTIN0OHSY3
}&ag
{0 = SSTIJUFFOISqUMU FUT
/{eTTAd00gaY] OTTJSSeDOTWOpURY
uoT3deoXdOI SMOIY3 (PesyolAIjue JUT)pPIODSYSTTINOOGPESI YOOg OTIEBIS ofiflnsw
STTaAcOq oy3 woxy peex o3 Arjue jo zequmu pesgorhizue Emnmmw\w
®2038300q BY3 woay AIjUS YOOQ B SPESI - PIOOSUSTTIHOOHPESIT H
xx/
{
/TTnU uxnysx
) {
u"®TT3 9x03s5%00q °yj3 usdo o3 Hutkiz xoxxm,)ur3zurzd-ano wsysis
} (ot uot3deoxmoI) yozeo {
!{$9TI3UENOOq UINJDI
! (uu)uT3utad-3no-we3sis
{ (., 'P®3EOID ©Q 30U UBD IO 3ISTXD 30U S0P STTF FOOq 8yl ,) urTautad 3no - wa3lsis
! (wu)urzurad-yno we3sis
{()butrazsoze = zae HButazsg
‘Pe3ESIDd Bq 30U UBD IO ISTXD J0U SI0P STTIY0Oq//
} (® uotadeoxm)yojeo {
!eTTaN0OgeY3 STTISSS0OyWopuRy
}
(Az3us TIM uesToog
300g) ST TINOOHOLSI oT3e3s oTTqnd
/x
INFSSSOONS SeM DITIM DYJ IDYIDYM uInNIVdAY x
STTANOOT Byl 031 93TIM 03 Azjus Axyus wexedp y
*
ITIM
2x038x00q 2Yy3 03 AIJULD YOO B SOITIM - DTTAYOCOHOLD x
*x/
/7TNU uIn3eax
/(. 9TT3 @x038y00oq oay3 uado o3 butdxy zozag,)urzurad-3no-welsis
} (ot uoradeoxzmoIr) uyozeo {
{(xoystTand ‘szoyzne ‘saszdeyo ‘ooTad ‘sebed ‘97313 ‘PT)YOOH MOU uUANIDI
AIY3 TMISYS TTANGPEST " nd)
¢ (arasystra STTAISYSTIInd = Ioystiqnd I9YsTIANd
/{ paoyazne ‘gaoyzne ‘zaoyine ‘Taoyzne } = saoyzne []Burtazs
! (seakgpaoyane) butazs msu = proyane HButils
! (se3dgpaoyane) ATTnapesx STTIHOOISY
! [sSELAY ONINIS]®3&q meu = sejhgpaoyane []e3hq
! (se3hggaoyane) butals meu = gaoyane DButalsg
! (se3hggaoyane) ATTnIpeSI STTIH00EIYT
!/ [sEIAD ONI¥IS]®3&q meu = sejhggaoysne []o3hq
! (so3hgzaoyane) butails msu = gioyane Butajs
! (se3hgzaoysne) ATTNIPEDI STTINOCHSYT
/[sELXE ONIMIS]®3&q meu = sejiggaoyane []e3hq
! (so3hgraoyane) butals mau = TIoyzne HBurtaas
! (se3hgraoyzne) ATTNIPeSI STTIHOOHSYS
! [SHILAE ONI¥IS]1®3&q msu = sojhgrroyine []e3iq
! ()3urpesa oTTaYoodeys = gIrxeystiqnd Jut
! ()3urpesax-oTTadyoogsys = saazdeyd jut
{()3uIpeax-STTaNoogsyz = 9oTad Jut
{SEIXE QIODMI MOOH / SZTSSTTIAOOQ = SOTIFUFIOISqUNU
¢ (JyabusT oTTANCOCESYI (IUT) = SZTSSTTINOO] FUT
{(WMZ, HWYNETIA MOOH) 9TTISSeDdywopuey Meu = oTTIoogeyl
}Aag
!0 = S9TIJUAIOISqUNU JUT
/BTTIN00gSIY3 ST TISSI0OOyUwopury
}
(ssTajus []3joog)STTAN0OgOLoITIMSI ueaTood oT3els orrqnd
/*
INISSE00NS Ses DITIN SUJ ISYIOYA uIniexy i
STTIN0OQ BY3 03 SITIA 03 SOTIJUD setajue uexedy i
x
870383000 SY3 03 SOTIFUS JOOU SOITAH-BX - STTANOOFOLOITIMOT
xx/
{TTnu uinjex
{
! (4"®TTF ®x03sy00q 8y3z usdo o3 bButhijy zoxadm,)urzutad:jno-wsisiks
} (ot uoradeoxmor) yozeo {
{
/9STeI uInNlex
] ., '9703s)00q 9Yy3 03 HBUT3TIM STTYM I0xad,)uT3zutad-ino-wsisisg
} (ot uotadeoxmoI) yo3zed {
/enx3 uanisx
{T+S®TIJUIFOISqUOU = SSTIFJUHFOISQUNU
! (Az3ue ‘83TIMOLAI3US) PIODSYSTTINOOHSFTIM
{SHEIAE QUODHEY MOOHxSSTIFUIIOIOMU = 93 TIMOLAIFUS FUT
1} &a3
{SHEIAE QUODEY MOOH / ©ZTSOTTINOOQ = SOTIFIUTFOISqUAU
{ (JyabusT-STTIYOOHSOYI (JUT) = SZTSSTTANOOQ JUT
f (M2, EWYNITIZ YOOH)®TTISSOOOYWOPURY MSU = STTIYOOHSUS
}Ax3
{0 = SOTIZUIFOISqUNOU JUT
! ()p1r3eb-Lijus = pt JuUT
!SEIAE QUOOTd MOOH / ©ZTSOTTANOOq = SOTIFUFFOISqUNU
¢ ()y3busT STTAYOOHSYI (IUT) = OZTSSTTIYOOQ 3JUT
¢ (uMZ, ‘HAUNITIA MOOH) STTISSSOOVUOpURY MSU = STTJIioogsyl
}Ax3
{0 = S9TIZUFFOIDqUINU JUT
!9TTdYoogsyl OTTISSeDDYFWopURY
}
uot3deoxmoIl smoayz (Axjue yoog ‘©3TIMOLAIIUS JUT)PIOOSYSTTINOOHSITIM PTOa DT3ie3ds oriqnd
/%
STTANOOQ Yl 03 «3Tam 03 Axjus Azjue wexedp x
BTTINOOG oYz 03 3Tam 03 Axjus yo Iaqumu o3TaMorAajue wexedy x
x
BI03SHOOG BYJF 03 AIJUS OO B SOITIM - PIOOSYSTTIAOOHDITIM
xx/
{1Tnu uanzox
*®TT3 ®@x03sjooq =y3 usdo o3 HButday zoxxm,)uTiutad-ino welsis
} (ot uot3deoxmOI) uyd3ed {
{
{9s8TR3F UIN3SI
! (,®@x038y00q OYy3 03 HBuTlTIM STTYM 3no welsis
I0I1xH,)uT3utrad
} (ot uor3zdeoxmOI) yozeo {
/ena3 uanisa
{
! ([T]seTa3us ‘93 TIMOLAIFIUS) PIOOSYSTTINOOHSITIN
{SEIXE QYODEI MOO€xT = ®3TaMoriziue 3ut
} (++T ‘yzbuer-seTIzUS>T {0=T JUT)IOF
!{yzbust seTIIUS = SSTIFUFFOIS2qUNU
ST TANOOHSYZ
{ (0) yabusaes
} &x3
! (u u)pusdde-eqs
} (SEIxg ONI¥IS > ()uzbust eqs)errym
! (uu)I0F3ngPUTIIS MOU = QS a9FINgGDOUTIIS
} (+4T {p>T ‘yzbueT’ saoyzne=T 3UT) I0F
s
- eqs) senkgeatam’ oTTAYoOHEIYT
£ (()Butayso
(. u)pusdde-eqs
} (SEIxg ONIMIS > ()uyabuer eqgs)oTTUM
! ([t]saoyane) zozyngbuTils MU = egs I9FIngbuTtiIzs
} (++T ‘uy3zbusT‘'saoyiane>T {Q=T 3JUT)I03F
! ()saoyanyarsb-Kkijue = saoyzne []Butazs
¢ (aTaoysTTqnd)
JUISI TIM STTIHOOHIYI
! (szo3deys)
quIsl TIM STTINOOHSY]
! (eot1ad)qure3Tas STTINo0ogSYUS
ST TANOCOHOYS
! (sebed) qurelTam
o3 T3) @3 Tam ST TINCCESYD
£ (()se3hg3eb
{ (PT) JUISITIM STTINOOHSYI
! (@3 TaMozLa3us) 39S ST TANOOHSY
() asystTqngdieb -Kajue = grasystiqnd
{()prasb’ 3utr
! ()sasadeyniyeb- Lxqus = saesadeyd jut
! ()ooTag39b6 A3jqus = sotad jur
! () sobegysb-Aijqus = sebed jur
¢ ()butrazsoz-3ags = ST3IT3
{
‘(s u)pusdde-3qgs
} (SEIXE ONI¥LIS > ()y3busT 3qs)sTTym
! (®T13713) a9zgngbutazs meu = 3qs aegyngbutazs
{()°13TI396" Aaque = °13T3 butias
! () szoyanyaab-duey = sxoyzne []bBurazs
! (szogdeyo + , :SYAIIVHO,)uT3utad 3ano-welsis
‘(eot1ad + ,:($) FOI¥A.)uTzutad 3no-welsis
¢ (sebed + ,:5EOVd,)uTruTad-3no-welsis
{(8T3TI + 4 FILIL.)uT3uTad 3no we3sis
{(PT + ,:QI.)urjurad-3no wolsis
a W) urzutad-ano welsis
! (wu)utautad-ano-we3sis
¢ () xoysT1qng3asb-dwey = zaystiqnd x9YSTIANg
! ()sae3zdeypiab-duey = saxejdeyo jut
! ()oo1ag39b dwey = sotad jutr

1
! () sebegyab-dwey = sebed jur
{()oT3TI396 dwey = 1373 bButaas
{()p13eb-dwey = pT 3uUT
! [t]syooq = dwe3 joog
} (++T ‘yabusT-'sjyooq > T Q=T JuT)IOF
} (TInu =i s3jooq)3zT
! ()eTTaYoOogpeSI = S3}00q
!{TTnu = sjooq []soog
}
() TRUTWIDLOLSYOOHTTYaINd3INO PTOA DOT3®3S OTTqnd
/%
*
BuTiaos 3NOYlTM TBRUTWISY SY3 O3 9I0YSHOO] 9y} UT syooq oyl TTe sindino - TeuTWIDLOLSHoogTTyandino x
»x/
{
{
!(,"9TT3 ox03syooq =y3z uado o3 HButdzj zno welsis
zozad,)uTjzutid
} (ot uoradeoxzoI) yozeo {
{
' eqgs) sejhgelTam ST TANOCOTSYT
£ (()Butazsos
} (++7 ‘y3buey-sjyooq > T {0=T 3IUT)I0ZF
lelele «) uT3u
3no
Tad
we3sis
{ (. S300q STQeTTRAVY,)uT3uTid 3no-we3sis
! (,u)uT3uta
- 3no - we3sis
d
} st {
! (wu)ur3zutad-ano weysis
*Aadwe st ®x03sj00q I9YJ,)urzurad-ino-we3lsis
! {wu)ur3zutad-qno-we3sis
} (0 == yabus1-sjyooq)FT
} (TTnu =j s3ooq)3FT
! ()eTTdyoodgpeax = syjyooq
!1Tnu = sjooq []s3joog
}
() TeuTWaaLOLSOTI TISAISHoogTTYIndIno proa or3e3s or1qnd
/+
*
Butjaos 3nOY3TM TRUTWIS] BYJ O3 SI0ISHOOH BYJ UT
S9T3T3 pue 6QI ,5300q ®Y3 TTe s3ndlno - TRUTWIDLOLSSTITLSAISHOOHTTYINAINO 4
xx/
{
! (yu)utautad-
3no we3sis
! (, ®7015j00q OY3 UT SY0Oq OuU BIR BIYL,)uTautad:3nowe3sis
w)uT3iutad-ano-wegsis
} esT® {
! (wu)ut3jutad-gno-wa3sis
! (y========= w)uT3utad-3no-weysis
{(()sweN3ob-aoystTqnd + , :YEHSITENG,)uT3uTad 3no-wejsis
{([C]szoyane + ,: (S)™UOHIAY,)UTIuTad
3no welsis
(((uu)sTenba"
(Jutay - [[]szoyane) ) FT
} (++C ‘yabust-saoyzne>l !o=L jut)aoz
} este {
! (uu)urT3urad- 3no-welsis
! (. K3adwe st ®z03Sjy0OQ BYL,)uT3utad-3no uwe3sis
¢ (wu)uT3aurad-3no-we3sis
} (0 == yabueT sx00q)IT
} (TTnu = sjooq)3zT
! ()eTTdyoogpPEDX = S)0Oq
{TTnu = syooq []sjoog
}
(3°2bae3 3UT) IBYSTIANIFOTRUTWISLOLSHOOETTYINdIno pToa oT3e3s orTqnd
/%
Butyzos T
jnoyl TRUTWIDI dyj o3 ‘zoysTrand UTe3ISO B JO
132038300¢ Y3 UT SY0oq Y3 TTe s3ndino - ISYSTTUNIFOTBRUTUIDLOLSHOOHTTYINdANO
#x/
{
{
- welsis
! (wu)utdurad-ano
! (, ©I03S3¥00q SY] UT SYOOq Ou SIB 9ISYL,)ur3utad-ino- wsisisg
¢ (wu)utaurad-3no-we3sis
} est1e {
! (wu)urautad-3no -uwe3sis
) uT3uTad - 3no-welsis
£(2T3T3 + 4 iFIIIT » + PT + jno welsis
,:QI,)ur3urad
! ()xoystTandasb -dwey = xaysTtrqnd zoysTIqnd
! ()saoadeyp3sb-duwey = sasizdeyd 3ut
! ()ooTag3eb-dwey = sotad jur
! () sebegieb-dwey = sebed jur
{()o131I396 dwey = 13713 Butazs
{()p13sb-dwey = PT 3UT
!{[T]s3yooq = dwe3 3yoog
(- aeysTTqnd STY3 WOIF PUNOI SY0oq ON,)ur3iurtad-3no welsis
} (0 == punogs3jooq)FT
¢ (4u) uTautad-3no-weysis
A w) uT3uTad-gno woe3sis
! (()suweN3ob zoysTiand + 3no walsis
, WAHSITEAG.)uT3utad
{([Clsaoyane + 3no we3sis
,:(S)YOHIAV,)uT3uTad
(Juray-' [C]saoysne) )3T
(((uu)sTEnbe"
} (++C ‘y3bueT-saoyzne>l !g=C 3jut)zoz
! ()sxoyanyazesb-dusy = szoyane []Burtass
{(saeadeyo + , :SWAIAYHD,)uTrzutad: ano-wejlsis
{(ootad + ,:(¢) =OI¥4E.)ur3lurad- gno ‘wej3sis
{(sebed + ,: FOVd . ) uT3utad
3no welsig
{(9T3T3 + ., FILIL.)uTIuTId3no - weisis
{(PT + .:QI,)uT3utad 3no-welsis
A J)ur3dutad-ano-wejzsis
! (wu)ur3utad-3no-we3ysis
/1 + punogsjooq = PUNOISHOO]
} (()p13eb-asystriand == 39bae])IT
! ()aoysTTandieb -dwey = aoystTand IoYsTTANg
! () szo3deypysb-dwey = szozdeys 3ut
! ()@oTIg39b " duren eotad jut
! () sebegyeb- dusy seobed jut
{()®T3TI396 dwey = ®13713 butaas
{()p13sb-duwey = pT 3UT
![T]syooq = dwe3 3oog
} (++T ‘yabusT-sjyooq > T {0=T JUT)IOF
{0 = punogsjyooq 3ut
! (wu)uTaurad-3no-we3sis
{()butaasols = zas Butajs
‘peje@ID 99 30U URD IO ISTXO 30U S0P SyTASuTzEbew//
} (® uotrideoxm)yolzeo {
{
! (pesyorirjus) proosysTTgouTtzebeypesa = [T]serajugsurzebew
{SHIAE QUODAM ENIZYOVHxT = Pesyoriijus jut
} (44T !seTajuEFoISqUMUST Q=T JUT)IOF
oTTFeRIRp Oyl ybnoayy doot//
}&a3
! [seTajumForoqunu]autzebey Msu = ssTijumgsurzebew []surzeben
ENIZYOUW
QYOO AE
!SEL / ©2TSeTTdourzebew = SOTIJURFOISqUMU
“Avnuwmwa.maflhwcflummmzwnu (3uT) = ®zTgoTTIouTzebeW JUT
{(uM3, 'EAYNITIZ ENIZVOYW) OTTISSS00yuopuey Msu = SoTisutzebensys
}&a3
/{0 = soTIjU¥FoISqUNU JUT
!oTTgouTZzEbEROY] OTTISSoOOYwopuey
}
() oTTasuTzebeypeax []surzebey o13els oTTqnd
/*
*
©I038Y00q DY3 WOIF SSTIJUS duTzebew TR SPESI - OTTIOUTZRDERPESX y
xx/
‘osTDION® se pojordwoo 9q of - ‘Spoylsw psyeyax surzeben//
! (wu)uT3utad-ano we3sis
! (, ®71035300q 9Y3 UT SY0OJ OuU 81 3no welsig
BI9YJ,)uTjutad’
! (wa)uT3utad-ano we3sis
} est8 {
! [sHIAE ONTHMIS]®1Aq Mou = saojkgreoanossx []e3&q
{()3uipesa eTTgoutzebeyeys = grasystrgnd jut
{()3urpesax’ sTTdouTzeRbEReY3 = °0Tad JuTt
{()3urpeax’ aTTdouTZRbRRAYS sebed jut
! (so3AgeT313) butazs meu = °7373 HBuraas
! (se3Ago13T3 )
ATTnapesa ST TJoUTZRERKOY3
{[s=LXd ONI¥LS]1®3&q meu = se3iger3Ta []o3dq
{()3uIpesa oTTdouTzebENoUl = PT 3JUT
yo9s
! (peogorAaj us)
9T TISUTZRERRAYY
ENIZVOVW
QYOO AE
{SEI / ©zZTSoTTJouTzebew = SOTIJUFFOISqUOU
! ()yabueT -oTTasuTzebeRsys (3ur) = ozTgeTTIourzEbEW juUT
{ (.M, ‘ENYNITIA ENIZVOYW) ®TTISSe0Oyuwopury Meu = olTisutzebensyi
YKa3
{0 = soTAZUFFOISUMU JUT
!oTTdouTzRbRReY] OTTISSoDOywopuey
}
uoT3deoXHOT smoxyy (peewogAijue juT)paoosysTTdsurzebeypesx surtzebel oT3ie3ls orignd
/x
eTTgouTzebeu oy3 woxy pesax 03 Azqus JO Iaqumu peayorizjus wexedpy s
x
ox018)00q Y3 wozy AIajue surzebew B SpPESX - PIODSYSTTISUTZEOENPEDI i«
xx/
{TInuU uanlex
/(. ®TT3 2x038y00q 2y3z uedo o3 Buthiz zoaag,)urrurad-3no-welsis
} (ot uoTadeoxmOI) yo3led {
!seTajugsutTzebew uInjlex
! (wu)ur3urad-ano we3sis
/(, Po93®2ID ®Q 30U UBD IO JSTXD JOU SSOP STTF durzebew oyr,)urjurid-3no welsis
¢ ()uabuet - eTTISUTZEOENAYY (3ur) = eztgerrgsutzebeu jut
/(2MT, ‘EWYNETII ENIZVOVW) ©TTASSOOOWWOpURY meu = STTgeurzebensul
Y&a3
{0 = sOTIjUFFOISqUAU JUT
!oTTioUTZRbRRSY] STTISSeDOYWOPURY
}
(Kx3ue sutzebeR) oTTIOUTZEOERHOLOF TIM UBSTOOH OTIEIS orTand
/%
TnFSSeDOONs Sesm 93TIM BY} IBYIdYM uInNIDIY x
oyTgautzebew oyl 03 °3TIM 03 Kzaus Kxaue wexed) x
*
oz038%00q Byl 03 SuUTzEHEW ¥0OQ B SOITIM - VTTISUTZEORHOLIITIA »
%/
{
/TTnu uIN3SIT
! (4" 9TT3 °30385100q SY3 uedo 03 bBbuthiz z0zxF, ) urjutad-3no we3sis
} (oT uot3deoxd0I) uoIEd {
‘sedanossa ‘ootad ‘sebed ‘oT3T3 ‘PT)ouTzRbEW MSU uInlex
! (zaystIgnd
sTT
AIY3 TMISYS
¢ (arxey )
' STTITIBYS
qnd
TTANAPESI TIANd = zsystiand xeysTIANd
’‘gedanosax ’ze9oanossx /190IN0S3I } = S$92IN0SSI [1butazs
{{ peoanossx
! (so3Agpooanosax) Sutals MOU = yODINOSSI Butaas
NAmwuhmqwousommuvmaau&fimou.wfiflhmnflummmzwnn
! [smIxg ONTHIS1®3hq meu = sordgpeoanosax []o3Aq
! (seyhggooanosex) butals MU = £OOINOSSI butaas
NAmwummmwouaomwuvhfiflshummn.wflflhmnflummmzwnu
! [sEIAg ONI¥IS]®3hq meu = ss3kggeoanosex []e34q
! (se3hggeoanosex) butals mou = g®OInossa butaas
uAmmuhmmmou50mwuvhflflflhvmou.mfiflhwcflnmwmzwnu
! [SELAE ONINIS]o3Aq meu = sojiggeoanossx [1934q
! (soqAgreoanosax) butals MOU = [9DINOSSI butaas
NAmoummflmuHsOmOhvhaanhvmmu.aflflhwnflnmwmzmnu
/yabusT seTIjUS = SOTIFUIIOISqUAU
! (0) yabuerryes
‘a1 TaoUTZRORRAYY
} Ax3
{SHIAE QUODEM ANIZVOYH / ®zTgeTTdsuTzEbRW = S®TIJUFFOIIqUMU
! ()yabuet -eTTAsUTZRBENSY] (3UT) = SzTSSTTISuTzZEbPW JUT
{(uMI, ‘IWYNTTII ENIZUOVK) OTTISSOOOYWOPURY MSU = ST TJoutzebersya
}Axy
{0 = S9TIJUFFOISQUNU JUT
!oTTaouTZRbRROY] OTTJISSeDOYUOpURY
}
(seTajus TIMSI
[]surzebey)oTTIouTzebEROL93 uESTOoOg OT3iels or1Tqnd
1
TNISSODONS SEBM SJTIM Y3 ISUISYM uInNBIP »
aTTgoutzebew syl 03 SITIMA O] SITIJUS sotxue wexedy x
x*
21038300 SY} 03 SOTIZUS ouTzebew SOITIA-8X - STTISUTZRHEHOLSITIMSI
xx/
{
{TInu uInyex
! (,"®T13 °x03s)y00oq oYz uado o3 HButhay zoxxg,)urzutad-3no wslsis
} (ot uot3deoxmOoI) uyo3eo {
{
{9sTRI uINl°IT
! (, ®310353)00q @Yl 03 HUTITIM STTYM I0xxd™,)uTizurid
3no wslsAhs
} (ot uot3deoxmOI) yojeo {
/onx3 uaniex
{1+S9TIQUIIOIBQUNU = SSTIFUFIOISqUINU
! (Azque ‘e3TaMorLAijus)proosysTTIsuUTZebRHe3
TIM
{SEIXE QUODEI HENIZVOVWxSOTIJUZIOISQUNU = 93TIMOLAIIUS JuUT
} &x3
{SEILAE QUODTI ANIZYOVW / ®zTISoTTdourzebeu = seTajugzorsqumu
= ! (4 u)pusdde-3qgs
} (SHLAE ONINILS > ()u3abusT aqs)sTTym
! (973 T3) 297IngbuTals MeU = 3qs ao7IngbuTIis
{()oT3TL3eb Aajue = °13T3 BuTIas
/()p1rasb-Axjus = pPT 3JUT
QYOO
!SE ENIZYOVW
IAE / ©zTSeTTdsurzebew = se9TIjugyoIoqumu
2 ()yabusT ‘oTTI2UTZRORNRY (3UT) = ozTgoTTgauTZzebew JuUT
£ (.M, ‘EWUNITIZ INIZYOVH) OTTASS90OYWOpuRy MOU = STTIsuTzebensus
}&a3
{0 = SOTIIUFFOISqUNU JUT
!aTTasuTzEbEReY] STTISSoDDYWopURY
}
uotadeoxmOI smoxyl (Axjus surzeben ‘S3Tamoriijus TIM
3uT) proDSYSTTdouUTZREbRRO3 PTOA DT3e3s OTTqnd

orTgoutzebew syz o3 S3TIM 03 Arjud Kaque wezedp »
orTgeuTzRbEW DYz 03 93TIM 03 AIjus FO ISQqUNU o3 TaMorAaqus wexedy i
ZROHENORITIM
¥
@103853%00q 2y3 03 Axjue SurzRbEW B SOQTIM - PIOOYSTTISUT x
xx/
{TTnU uIN3SI
1 (, 9TTF °7038300q 8y3 uedo o3 Butdkail zozam,)ur3rurad-ano-uelsis
} (ot uor3deoxmOI) yo3IEd {
{
/9sTez uIniex
! (, @z035)00q 9y3 03 bur3aTIM STTUM z0xad, ) ur3autad 3no waisis
} (or uotadeoxmOI) yo3ed {
/ena3 uanjax
{
! ([T]seTazus ‘g3TIMoTAI3us) prODSYS TTISUTZRbRHeI TIM
{SELAE QUOOTY HENIZVOWWxT = 93TIMOLAIZUS 3ut
} (++T ‘y3buer-seTIUS>T {0=T JUT)I0F
{
{(u"®TTF ®a03sy00q sy3z usdo o3 Hurtha3z zozxm,)uTzutad-3no wezsis
} (ot uor3deoxmoI) uojeo {
{
! (()Bbutazsol ‘eqs) senhgeatam sTTIoUTZROEROY]
{
“(u u)pusdde-eqgs
} (sELxg ONI¥IS > ()yabuer'eqgs)eTTum
! (un)x93Fngbutrads meu = eqs zezgngburaas
} (++T {p>T ‘yzbueT’'ssoanossa=T 3uT)a03F
¢ (() Buta3soy ‘eqs) se3hge3Tam o1 TasuTZRORROYT
{
{(u uw)puadde-eqs
} (SEIXE ONINIS > ()u3bust eqs)eTTym
!([t]sooanosaa) ze33ngbutazs meu = egs I83FngbuTIyS
} (++T ‘y3busT‘seoanossa>T !(Q=T 3Jut)I03F
! () seoanoseuTRUOTITPPY3
" A1jus
I®h = seoanosex []Burtaysg
! (grxsjure3Tam
yst1q ' sTTAouUTZEEENOY
nd) T
! (eo1ad) j3ure3TaM o TIoUTZRERRAY]
! (sobed) qurey
o] TaouTZEbEROY]
Tam
{(()s
o713e34g3
13) 93 TaM ST TASUTZREEHOYT
reb
{ (PT)3uI
T TISUTZROERSYY
e3TIM
! (®3Tamyoos
oriaju
o TIouTZRbRKOY
e)
{1 ()p13
() 79ysTIgngleb
96° -Kajus = grasystrgnd jut
! ()eoTag3sb-Azqus = sotad jut
! () sebegaeb-Kxqus = sebed jur
{()bura3soz-3qs = 91313
() Ta
3no
uTau ds
we3si
} este {
¢ (wu)uTautad-3no welsis
—=,) urjutad-3no-welsis
! y====
¢ (()ouren3ob- zousTIand + W :gEHSITENd,) uT3utad 3no we3isis
{
{([C]so0anossx + .1 () E0¥NOSEY, ) uT3uTad 3no we3sAs
()wrxa - [[]seoanosaa) i) IT
(((uwu)sTenbe"
b} o(++C ‘yabueT ' seoanosaa>L ‘o=C 3ut)zoz
= seoanoseax []Butaas
uAvmmuusommmHNGOflufinvfluwm.mEmu
{(eotad + ,: (%) NUHmmzvcfluuflum.pso.fimumhm
! (sebed + , :SEOVA.)uTFu we3sis
3no Tad
(97373 + \ {ETLIL,)uTauTad 3no we3sis
/(PT + .:QI.)ur3urad-3noueisis
mm
e ——==m==—s============= :vufluuflum.uno.Emum
4 :vnfluaflum‘ufio.fiw»mhm
¢ () zoystTangash-dwe3 = oysTTInd ISYSTTAN
: ()ooTxgaeh dwel = sotad jut
/() sebegaeb-duey = sobed jut
{()eTaTIaeh dwey = oT3T3 Buriis
! ()praeb-dwea = PT 3IUT
:[t]ssutzebew = dwel sutzeber
} (++T ‘uyabue-seutzebew > T {0=T IUT)IOZF
} (TInUu =i soutzebeuw)IT
/() oTTaouTZRbERPEST = seutzebeu
{{Tnu = soutzebeuw [1sutzeber
}
pTOA DT3E3S ottand
AuHmdflEumBOwacfiNmmmsfiflmunmuuo
/%
HUTITOS INOYIFTM TRUTWISI SYF OF
- HmafliuwhoawmuwNmmmzflfidusmuso ®
2I0QSYOOY BYF UT ssutzebew a2yl 11 sandano
‘n
(9T3T3 + L EIIIL . + PT + uiQIs)uTjutad-3no we3sig
‘() ousTIana3eh-duwe = zeystrqnd sysTrqng
¢ ()®oTxg306 dwey = soTad Jut
! () sebegyeb duey = sobed Jut
‘()eT3TI396 dwey = e7371q Butazg
‘()p13sb-dwey = pt jur
![1] ssutzebeu = duey sutzebey
} (++T ‘y3busT- ssurzebeu > T !0=T 3uTt)aogz
fa u)uT3uTad 3no weysis
¢ (u " soutzebeu STARTIT®AY, ) uT3utad ' 3no weysis
! {uu)uT3autad-3no-we3sks
} esTa {
! (uu)uT3u qno Ta
- weys
d is
{(yKadwe st sx03s3j00q ®Uil,) uT3utrad - 3no we3sis
! (wu)UTru N0 Ta
WO3SdAS
} (0 == y3ibu st - ssutzebew) 71
} (TTNU =; ssutzebew) g1
! () oTTasuTzZR bERpP EST = sautzebew
{TTnu = ssurzebeur [1sutzebey
AvHmufisumaoamwfiuflamnHmmqflummmEAHflusm }
uno PToa d13e3Ss OTTQnd
/x
but3xos 3noyztm TBUTWIS] 9yl 03
¥
SST31T3 pue sqrl ,ssurzebew ©I03S}00Q BY3 UT
8yl TT1® s3andano - HmafiEuwHoamm.fluflanHmwnflummmzflfifin
mpflo x
xx/
! (wu) UT3UTI 300 we3ds&s
‘(4 ®20353%00q By3 uT SOOq OU BIE ®asyy, ) uT3utad - 3no-weysis
{(PT + u:QI.)ur3utad-3no-we3sis
o 4)uTautad-3no-we3sisg
! (uwu)uT3urad-3no-wejsis
/1 + punogseurzebew = punogssutrzebeur
} (()pr3sb-asystrand == 3ebie3) 3T
! (yzouystTiqndasb
-dwsy = zoystTqnd aoysTIqnd
! ()ootagiseb-dwey = eoTad jut
! () sobegisb-dwey = sebed jut
{()o13TI396 dwey = °13713 Burals
{()p13eb-dwey = pPT 3uT
![T]soutzebew = duey surzeben
} (++T ‘y3bue7-seurzebew > T {Q=T 3UT)I0F
{0 = punogssurzebew juT
} esT® {
! (wu)ur3durad-3no-we3sis
f(, &3dwe sT @x03SYOOQ SYL,)ur3zutad 3no-uwelsis
! (uu)urautad-3no-welsis
} (0 == yabust ssurzebeuw)zT
} (1Inu = ssurzebew)IT
! ()oTTaouTZRbRRpPESx = sourzebeu
!{1TTnu = soutzebew []surtzebey
}
(39bae3 jut)adysTIqndzoTRUTWISTOLSSUTZRORNTTYINd3NO PTOA DT3e3s DTTqnd
/%
bButizos jnoylzTM TRUTWIS] 9y3x 03 ‘Ioystiqnd uTelISO B JO 4«
‘szogsyoog oYz ur ssurzebew dyjz Tre s3indync - xSysTIqnIIOTRUTWILLOILSSuTzZRDERTTYandino x
xx/
! (wu)ut3zutad: 3no-we3sks
! (,"®a03s)y00q 9y3 utr ssurzebew ou axe sx9YL,)uTiurad-jno-welsig
! (ww)uT3urad- ano-we3sks
} sstT8 {
TTTH 22yl Butaas Lzoae ‘Kem sTYL "yoes SI930BIBUD GZ »
3o unutxew ® saey Lew ‘('D38 ‘SSSIpPpR ‘SWRU X9) STTRISP SNOTIEA x
®x03s 03 ‘wexzboxd sTyy ur pesn sBurals oyl eyl uwsw solAE GZ x
se34q ut ‘andur Butazs Aue yo yzbust oy3 sjusssadex SEIAY ONTULS »
*\
}
AVIOTTIIOYSTTANg ssero oriqnd
/a7 Tdsseooyuopury
o1 'eael jxodwt
{uoT3ded‘o1
xgOI
"earl jx0dut
AVISTTAXBYSTIANA//
{
! {ww)ut3zutad qno-weysis
! (,"®1038300q SY3 UT SO0 Ou DIV ®I9YL, ) uTautad 3no ‘w3 sis
{ (un)uTdurad 3no-wezsis
} sste {
{
{(u-79ystiqnd STY3 woxy punoy seurtzebew oN,)uTzutad-qno-wezsig
} (0 == punogssutzebeu)gT
! (uu)uTautad-ano-uwejsis
! (y==== ==, ) uT3uT 3no Id
ws3sis
Y (()owe- asysTIqnd
N3eb + , i¥AHSITENG.)uT3utad-3no
wesis
{([C]sedanossx + ,: (S)@ADYNO
) uTautad SEY,
3no wejsis
(({un)s
" (Juwtay- [(]seoanosea)
TENDS {) 3T
} (++C ‘y3buet-seoanosaa>l ‘o= jur)zoz
! () seoanossyTRUOT
TPPYIaL "dusy
} = ssoanosex []butays
{(®otad + ,:($) EOING.)uTautad jno-weaskg
{(sebed + ,:5@A9VA.)uT3uTId 3n0 weysis
{(9T3T3 + ., !FTLIL.) UTIUTId 300 we3sis
}Aa3
! [seTa3ugzoIoquUMuU] ISYSTTqng MOU = soTIjumaaystrand []aysTTand
{SHIAE QODEY / SZTSSTTAISYSTTAnd = SSTI3UuFFOISquNU
{()y3busT STTITSYSTIANASOYF (JUT) = 92ZTSOTTIILYSTIAnd FuT
f(uMZ, ENUYNETIA YAHSITENG) OTT.ISSOOOYWOPURY MBU = STTAISYSTTANdSY3
}Kag
/0 = SOTI3UIIOISqUAU JUT
{9TT4I0YSTIANGOYF STTASSSOOYWOpUERY
}
()eTTaasysTIqnapeax []zdysTIqngd oT3e3ds orTqnd
/x
aTTaxeystTIand ®Yy3 IO S3juULUO0D BYR TT® YITM Avxae uINIBIAY x
*
sotajue zoystiqnd Oyl TTE SPESI - STTAILUSTTANIDPEOX 4
wx/
! IV¥OTTaTBYSTTANd,, = EWYNEIIA WAHSITEnd butazs teurs oT3e]}Ss
{€xSULAE ONIMIS + ZxSHIAL INI = SHIAE QUODEY IUT TRUTF oT3e3s
/x
s934q €8 = GL + 8 = €252 + Ta¥ »
*
:dn ®ye3 pPTROM STTF UT POI0IS PIODBIT oOoq yoes *
.1
(231sgen ‘ssoappe ‘sweu) sburils € x
(ouoydeten ‘PT) SAUT ¥ x
*
:3o dn spew ST pxodax eystrand ® ODUTS *
"OTTF ® UT pexols paoosx axoystiand ® sjusssadex SELAY QOO ¥

~
*
!y = SELAE INI 3UT TRUTI DT3e3s
*oTT3 Indano oY3l UT JUT UR BI03S 03 pepesu seldg oy3 sjussexdex SEIAY INI//
‘Gz = SEIAE ONI¥LS IUT TeuTy OI3E3s
/x
rasqumu Aue useq saey pTnoo 31 -oumexboxd oy3z Aq peproep ST STUL x
‘113 3ndano syl ur s834q gz dn eyey TTIm wexboad sTY3 UT pPesn Bq x
! [SEIAE ONINIS]®3&q mou = seikgesueu []e3dq
{() 3UIPES " OTTITISYSTIANASYI = PT IUT
! (Peoy¥o 3OS rAa3us)
ST TIISYSTTANASYF
{SEIAE qQIODT / ®zTSOTTAxsystTqnd = SoTIzUFOISQUNU
{()yabusT-oTTITPYSTTANG®Y3 (3UT) = SzTsOTTarsysTIqnd JuT
£ (uMT, ' EWYNITIE 9EHSITENG) STTASSSOOWWODURY MOU = STTAISYSTIqnASU3
}&a3
{0 = SOTIFUHFOISqUNU JUT
{9TTIIBYSTTANISY3 ST TISSOOOYUOpURY
uoT3deoxXHEOI sMoIyl (PeSYorAIjus JUT)pPIOOSYSTTIIISYSTTANIPesI ISUSITAngd OTIB3S ofifinaw
oTTdroysTIqnd ®Yy3 woxy pesx o3 Aijus Fo Ioqumu peaygoriijus Emummm\fl
@x038)00q oYz woxy Axjus aeysTIgnd B SpESl - PIOODYSTTIISYSTTINIPERSI H
. xx/
{TTNU uIn3lax
{
{(4'®TT3 IoystTand oy3 usdo 03 ButdAzy zoxay,)urjurad-3no-wes3sis
} (o1 uor3adeoxmOI) yo3zed {
!soTajugasysTTqnd urnisx
! (wu)uraurad-jno-welsis
{ (4, POjeaID ©q 30U UBD IO ISTX® JOU S90p OTTI aoystrqnd oYy, )urzutad-3no-weisis
! (wu)uTzutad3no - we3sis
!()butaasol-s = zx9 Burajzs
‘pe3esI0 o 30U UBD IO ISTXS J0U S20p ITTIISYSTIOnd//
} (® uotraydeoxm)yojeo {
{
! (pe2YOoLAI3US) PIOOSYSTTIIYSTTANdPEDT = [T]sotazugasystignd
!SHIXE QYODMIxT = pesyoriijus 3ut
} (++T !sSTajugzoasquMu>T Q=T JUT)IOJF
sTTye3Ep °y3 ybnoayy doot//
!ona3 uanisx
! T+SSTIFUFFOISqUNAU = SSTIJUFFOISqUNU
{(d ‘93TaIMOLAI3Ud) PIODSYST TIIDYSTTANIDOFTIM
{SHIAE QUODTIxSOTIIUIIOISqUOU = S3TIMOLAIFUS JUT
1} &x3
{SEIXE QMOOMY / ezTSeTTdaeysTIgnd = SOTIJUFFQISqUNU
! (Jyabuet-oTTaTEYSTIANGSY3 (IUT) = 92ZTSSTTIxSYsTIAnd JuT
{ (W43, ‘EWUNTTII YEHSITHAJ)OTTISSOOOYWOPURY MOU = OTTJIISYSTIANdsyus
1&g
{0 = soTIjUAFOISqUMU JUT
{9TTAISYSTTANASYF ST TASSOOOYWopURy
(d FoYSTIANd) ®TTAISYSTTARGOLSFTIM UEBSTOOE OT3IBIS oflansw
Kxque zeoystrand meu ® d Emnmmw\H
‘o117 aeystraqnd syl o3 Axjue xeysTTqnd MeU B SOYTIM - BTTIISYSTTONIOLOITIA H
xx/
{
/{TInu uanyex
! (9173 aoystIqnd oy3z uedo o3 Butkiy zoxam,)urzurad-3no welzsis
} (ot uotadeoxm0I) yojeo {
! (o31sgqom ‘suoydeTe] ‘sSsaippe ‘sweu ’‘pr)IsYsSTIqnd MU UINIDI
! (se3hge3Tsgem) butals msu = 93Tsqgem butias
¢ (se3hge3Tsqen)
ATTnIpeea ‘T TIISYSTTANISYSF
! [sEIxg ONI¥IS]®34&q mau = sejzigeztsgem []93hq
{()3urpesa SoTTIISYSTIANgaY3 = suoydeTs3 JuT
! (se3Agssoappe) butals msu = ssazppe Hutajzs
! (seahgssoappe)
ATTnIpeea ' OTTIISYSTIANASYTF
{ [SEIAE ONI¥LS]®3&q msu = se3hgsseappe []e3iq
! (se3hgsweu) butails meu = sweu BuTtazs
! (se3Agoureu)AT TnIpesa ' ST TIISYSTTANIDUD
} (ot uor3deoxmOI) yo3zed {
!8nI] uInlsx
{
‘([T]seta3us ‘°3TIMOLAIIUS)PIOODYSTTITIYSTIANISI
TIM
{SELAE QUODTY»T = 93TIMOLAIIUD JuT
} (++T ‘yabueT’serajue>T /(=T 3IUT)IOF
' seTIjUL
!{yabueT = SOTIJUIFOISqUOU
£ (0) yabusT3es OTTATIBYSTIANADUF
} &x3
{SEIXE QUODEM / 9zTSOTTIIoUsTIqnd = SOTIFUFFOISQUNU
£ ()yabueT OTTAISYSTTIANISU3 (IUT) = SzTSeTTdIdysTIqnd JuT
! (uMZ, ‘FWYNTTII YEHSITENG)OTTISSSOOYWOPURY MOU = STTIISYSTTANILU3
}Ax3
{0 = SOTIUIIOISqUNU JUT
{eTTaIOYSTINdOY] OTTASSSOOYWOPUERY
}
(seTajue []a9YSTIANd) OTTAIOYSTIINIOISITIMSI UBRSTOOH OT3e3s OTTand
/%
TNISSDODNS SeM BYTIM BYJ ISYIOYM uInisxp x
oTTaxaystTTand By3l 03 SITIM O3 SOTIJUS satajus wexedp i
*
°x038300q @Yy 03 SVTIUS IoYSTTARd SOITIM-BI - SITIISYSTIANIOLSITIMDI x
*x/
{
{ITNU uIN3yLOI
! (,o1T3 xoystTqnd °yz usdo o3 Butdkiz zozxm,)urzutad-ino-welsis
} (ot uot3zdeoxmOI) yo3zeo {
{
/9sTeF uIN3aI
{(,oTTF aoystIqnd ®y3 o3 Duritam oTTym x0xad,)urizurad-3no-uelsis
} (ot uor3adeoxmOI) yojed {
! (ssaappe) 293IngbuTIIS MOU = SSOIPPYIQS aozIngbuTrizs
! () sseappyaeb-L1jus = sseappe bButaas
! ()butaysol -sureN3qs = sureu
{
S {(u u)puadde-sueN3igs
} (sEIx€ ONTHIS > () u3buet-swrenaqs)eTTym
! (sureu) zezyngbutals mou = sweNlqs zezFngbutiis
! () swreN3®b
- Azqus = sweu butajs
! ()p13®b-Lajus = pt jJuT
{SALAE QODEY / ©zTSSTTAIousTTAnd = SOTIIUEIOISqUAU
£ ()y3bUST STTAISYSTIANASY (IUT) = ozTgOTTAToYsTIqnd JuUT
f(WnT, EWYNITIS YHHSITENG) ©TTISSOODYWOPURY MSU = STTITISYSTTANISU3
}&aq
{0 = S9®TIUIOISqUNU JUT
{STTIIYSTTANGSY] STTISSOOOYWopURy
}
uot3dedxmOI smoayl (Azjus zeysTTqng ‘e3Tamorirjus JUT) PIODSYSTTIISYSTTANISITIM PTOA DT3E3s OTTqnd
/%
arTazsystiand eyl o3 83rtam o3 Axjue Kajue wexedp
orrgIaysTIand sy3 o3 ®3Tam o3 Axjus o zequmu e3Tamorlijus wexedy
*
21038300q oYy 03 Azjus avysTTAnd B SOITIM - PIODSUSTTAIBYUSTTNISITIM 4
**\
{
{TInu uxnjex
{
{(u'o1TF aoystTqnd °y3z usdo o3 Burthaz zozxx,)urzutad-zno-wezsis
} (ot uot3deoxmoI) yozeEo {
{
!{®sTeI uIn3laIx
*oTT3F z9ystIand oy3 o3 BuriTam STTYM x0xxd™,)urjutad
3no weisig
} (+47 ‘yabuer'saeystTand>T !0=T 3UT)IOF
{11nu = d asysTIqnd
! ()oTTATBUSTIONgPEDT = saaysTIand
{rrnu = saeystiand []asysTIqnd
}
(PT 3UT) IY3ITMISYSTTINpPe®T ISYSTTAnd OTIB3Is OTTqnd
/x
pt aoustrand syz pr weaedy i
»
*pt oryToeds ' yats aeyustrqud 9yl sUANISIT - AIYI TMISUSTIADIPEST 4
2x/
{
/(. o113 Feystiand oy3z uedo o3 Butkxjy xo0xxd,)uTzutad- 3no-welsis
} (ot uot3adeoxmOI) yo3zeo {
{(()so @3 TaM " ST TIISYSTTANGOYF
@3 TSgeM) 3Ag3eb
! (euoyde JUISF TIM STTe3)TIISYSTTANISYF
! ( () se3Ag3eb’ ssoappR) 83 TIM ST TIISYSTTANdSY3
£ (() se3hgyeb sureu) 93 TaM STTIISYSTTANGSYT
ITIM
" STTIISYSTTANISYF
{(PT)3UIS
YOO " OTTIIDYSTTANGSUF
! (93 TIMOLAT IUS)
- e3TSgeMIAs
! ()butazsol = S3TSASM
{
0 !(n u)pusdde-o3lTsgeMiqs
} (SEIXE DNI¥IS > ()yabueT e3Tsgemaqs)oTTuM
! (93 Tsqem) 2973ngbuUTI3S MOU = 93TSqeOM3ds IoFgyngbutays
{()o3Tsgesm3ieb-Axjus = o3Tsqgem Butazs
! ()suoydetTarieb-Aazus = suoydersl jur
" SSOIPPYIJS
! ()Puta3503 = SSIIPPER
He (. u)pusdde-sseappyids
} (SEIxg ONINLIS > ()y3zbueT ssoippyaqs)STTus
g )JuTjutad-3no-we3lsis
! (u================ w)uT3utad-3no-we3sis
/(93 TSgeM + ,:93TsgeM,)uTiutad 3no ws3lsis
! (suoydst193 + ,:vuoydeter,)uriutad:ino-weisis
! (ssoappe + ,:SS°IpPpPV¥,)uriutad-ino-wa3sis
! (sureu 4 , :swepN,)ur3zutad-3no-we3lsis
{(PT + .:aI.)ur3rutad 3no-we3sis
Gl ===, ) UT3uTad
3no - wa3lsis
! (uu)urzurad-ano
- we3sis
! ()o3TsgomMasb-dwey = 93TsgaM Butaas
! ()suoydsTar3ab-duey = suoydets3 jur
! () ssoappvyaeb -dwsl = ssaippe butizs
! () sureN3ob dwey = sweu bButazs
{()pryeb-dwey = pt 3uT
![1]lsasystignd = dwey x9ysSTIANg
} (++T ‘y3buer- sazsystiqnd > T /Q=T 3UT)I0F
} (TTnu = sasystrand)IT
{()°TTaI9YSTIANgpPeax = sasystrqnd
{TInu = sasystidand [laeystIqng
}
() TRUTWISLOLSISYSTTAN TT¥Ind3no pToa doT13®3s OTTqnd
/%
*
HUTIXOS JNOYJITM TRUTWIDY x
ey3 o3 sasystiqnd oyz TTe sandine - TRUTWISDIOLSISYSTTANITIVINdINO &
xx/
{
!d uanzex
![t]saoystiand = d uxngysx
} (PT == ()pI3eh’ [T]sasysTTqnd) IT
! (wu)urT3ut ad
3no - we3sis
! (ym=====m====—c——c==sse— 1) uT3uTa d
qno weasis
{
{(oweu + ,IEAWN ‘u + PT + ,:QI,)ur3utid-jno-we3sis
{()®o3rsqemareb-dwey = e3Tsqgem Butags
! ()ouoydeToriob -dwey = suoydeTelz jut
! () sseappyasb-dwey = sseappe Hutalg
! ()suweN3ob dwey = sweu HBurazsg
! ()pr3eb-duey = pT FUT
![T]sasysTtTqnd = dwey asysTTAnNg
} (44T ‘yabusT'saeystrand > T /=T IJUT)I0F
£ w)uT3uTad-3no-weysis
! (u:szoysTIqnd STqeTTRAY,)Uu3n0T3uTad
welsis
! (wu)utjutad-3no we3sis
} ®ste {
{ (wu)uT3zutad-3no we3shs
! (- sasystTqnd ou oxe °YL,)urjutrad-jno wsisis
! (wu)urzurad-3no-we3sis
} (0 == y3buet-sasystrqnd)3IT
} (T1nu =i sasystignd)zT
{()eTTaTvYSTIINIPEDI = savystTand
‘110U = sxeystiqnd []roysTIqng
}
() TeUTWISLOLSOWENSQISIDYSTTINATTYINdINo proa ot3e3s orrqnd
/%
*
HuTlaI0S INOYITM TRUTWID] DY OF
ssueu pur g ,sasysttand °8y3 TR sindjno - TeUTWISLOLSOWRNSQISIDYSTTANITIYIndano
e/
{
d-
3no - we3sis
! (wn)uT3uTa
(47970353009 SY3 UT SO0 Ou BAB N0 wEIsAs
VIVYT, ) UTIUTIA
! (wu)uT3urad- 3no-weisis
} este {
e £ (wu)ut3autad-3no-we3sis
(,"®1035300q Y3 UT SY00q OU BIB BI9YL,)ur3urad-3Ino wezsis
! (wu)uTautad- 3no-wezsis
} ss1® {
Chapter References

1. International Baccalaureate Organization. (2012). IBDP Computer Science Guide.


Recursion (computer science). (27, May 2016). In Wikipedia, The Free Encyclopedia.
Retrieved 13:39, June 3, 2016,
https://en.wikipedia.org/wiki/Recursion_(computer_science)
3. Peter Smith. An iterative solution to Towers of Hanoi. Course Comp 151, California
State University Northridge, September 2002. Retrieved 22:20, June 5, 2016,
http://www.csun.edu/~psmith/151handouts/hanoi3out.pdf
4. Dimitriou K. Hatzitaskos M. (2015). Core Computer Science for the IB Diploma
Program. Athens: Express Publishing. More information at:
https://www.expresspublishing.co.uk/gr/en/content/core-computer-science-ib-
diploma-program
5. Class ArrayList. In Java Documentation. Retrieved 19:00, July 8, 2016,
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html
6. Class LinkedList. In Java Documentation. Retrieved 19:00, July 8, 2016,
https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html
7. Robert L. Glass. Facts and Fallacies of Software Engineering, Addison Wesley (2003)
8. Indent style. (16, July 2016). In Wikipedia, The Free Encyclopedia. Retrieved 15:05,
July 20, 2016, from https://en.wikipedia.org/wiki/Indent_style
9. Characters per line. (7, July 2016). In Wikipedia, The Free Encyclopedia. Retrieved
15:10, July 20, 2016, from https://en.wikipedia.org/wiki/Characters_per_line
piisy
:g osed
Appendix A

{yesaq
! ()dod 3pe3s
1Z oseo
{yesaq
! (qusweTa) ysnd-jyoe3s
f()3urzxsu-3ndur = JUSWSTS JUT
{(, :3jusweT® xojud,)3utxd ino- welsis
:T oseo
} (uoT3o®TSs) UOITMS
! (yurautad-ano welsis
! ()3uraxsu-3andut = UOTIPDTSS JUT
4]
(70}
{(, tuotzoeTes aesn,)3utad-3no-welsis
= {(,3TXE - p,)uT3utad-3no we3sis
v {Y3 FO sSjuswWST® ISY3J JUTIg .m=vnflu=fium.u=o.50uwhm
-
! (,30oe3S
! (,yoe3s woxy jusweTe® dod *zu)urautad-3jno - we3sisg
o] ! (,:suotado
:(,joe3s 03 juswele ysng ‘T,)uriurad-3no wslsis
ButmoTToF 9yl Jo Suo 3097198, ) uT3utad 3no we3sisg
)
Appendix A — Stacks & Queues

} (esTR3F == 3TX9) STTYM


~v ¢ (ywezboad uvorzerndruew jno- welsis
yoe3s,)urzurid
I
o
{ (ut we3skg) asuuedg msu = jndut ISUUEDS
7
L
/()yoe3s MBU = 3OBRS YOe3§
!@sTe = 3ITX9 ueLT00q
|
} []Butazs)urtew proa or3e3s oITqnd
(sbae
-¢ }
s utey ssefo orrqnd
(@] eAaRl
T30ns
!zouue jz0dWT
P STTF IsATI//
LLl
o
2 ssep 3 strAexay oy Sursn uonejuswayduwy yoeis Ty
=8
! (z9qunu + , :psasowsx JusweTH, ) ur3urad-no ‘wegsks
(T - ()®zTs yoe3g) dAcwex - yoeas
‘(T - ()ezTs'3yoe3s)3sh yoezg = aequmu
JuT
} este {
! (u &3dws st 3oE3S ®YL,)ur3utrad-3no - we3sig
b (() A3dwmst-3oe3s) 3T
} ()dod ptoa or1qnd
{
! (z9quinu)
ppe * yoe3s
} (zoqumu jut)ysnd proa otTgnd
{
‘()3asT1dRIaY MU = 3jDE3g
} ()xoe3s orignd
{yoe3s <aebeojurdjsriiessy o3eatad
} 3oe3s ssero orrgnd
{3sTTheaay TT3n eARL Jaxodurt
STT3 puodesg//
{
{
! ()ut3utad-3no-weysis
{
!{yesaq
{ena3 = 3TxX®
iy oseo
‘yesaq
! () sausweTmiuta yoeqs
d:
{(, iuotjzoeres aesn,)3urtad-3no weysisg
{(w3TXE "p,)ur3urad-3no-welsig
! (,y0e3s °y3z FO SJULWST® °Y3 JUTII °€,)uTizutxd-ino welzsis
! (,oe3s woxz jusuere dog ‘g,)uriurad-ino-weilsis
{(,30oe3Ss 03 jJusWSTS ysnd °T.,)urautad-ino-wsysis
! (,:suotgdo BUTMOTTOF ®Yyj JO suo 309198S,)ur3zutad-3no-welsis
} (®sTeF == 3TX°) STTYM
! (,wexboxd uotjerndruew yoe3s,)uriutad-3ino welsis
! (ut ‘we3sAg) aIouuens mou = 3nduTl IBUURDS
! ()3oe3s mMau = 3ydOe3ls yoelzs
!asTe = 3TXS uESTOOq
} (sbae []Butazs)urew proa oT3e3s oTIqnd
}
utel ssero orrqnd
!z9uueng
' TT3n BARL jxOodWT
oTT3 3saTa//
sse[d 3sTIhAeaxy oy} Suisn uoneluswajdwi anand z'v
d
3no - weisis
! ((1)395 yoe3s)urjuta
} (--T {0 =< T {1 - ()®zTs'3Pe3S = T JuT) I0F
} es1° {
! (. &K3due sT 3pe3Ss °8YyL,)ur3zurad-ino-welsks
} - 3yoe3s)
(()A3durgsT 3IT
} ()s3uswermiurad proa orTqnd
ppe * joe3s
{ (zequmu)
} (asqumnu 3ut)ysnd ptoa ortTqnd
{()3asTtIARIIY MSU = 3}OEB3S
} ()yoeas oriqnd
!yoe3s <aebejur>3ystrleaay ojeatad
} 3oe3s sseo orrand
1130 BARL 310dWIT
‘{ast7heaay
@TTF puodeg//
! ()ur3utad-3no-we3sig
!yesaq
!ena3 = 3TX®
iy osed
{yesaq
! () sjusweTmautad-yoe3s
1g osen
!yesxq
! ()dod
- 3yoeas
1z oseo
!yesaq
! (3uswaTa)
ysnd - jyoe3s
{()3ur3xsu-jndur = JuUsSWSS JUT
{(, :3jusweT® x93ug,)3utad-3no-uwelsksg
11 osed
} (uoT3oSTSs) uyo3TAS
! (Yurautad-3no wa3sis
! ()3ur3zxeou- 3nduTr = UOT3OSTOS JUT
uwe3sis
£ ((1)3°6 yoe3s) uTautad-3no
} (=T {0 =< T ‘T - ()°zTs'30®3S = T 3JUT) IOF
} es1® {
:(, Kydue st doe3s oym,)uriutad:3no-welsis
} (()A3dwgst-yoe3s) IT
} () sjuswsTmiutad proa o1Tqnd
{
{ (zoqumu + 4, "vw>oEwu«unmEmHm=v:auaflum.uso.fiwumhw
(T - ()°ozTs ' 3joe]ls)SAoWSI
}YOels
‘(T - yoels
()ozTs'3yoe3ig)3eb = Isqumu JUT
} es1° {
:(,-K3dws sT yoe3s eyL,)uriurad-3no welsis
} (()A3dugst yoelis) 3IT
} ()dod ptoa oTTqnd
{

You might also like