You are on page 1of 56

Centre for Computer Technology

ICT114 Mathematics for Computing


Week 5

Queueing Theory Algorithms and Flowcharts

Objectives
Review Week4 Queueing Process Queue Characteristics Kendalls Notation Erlang Distribution Algorithms Flowcharts

March 20, 2012

Discrete Probability Distribution


f(x) is a probability function if
1.

f(x) 0 f(x) = 1
x

2.

sum is taken over all possible values of x


March 20, 2012

Distribution function for a Discrete Random Variable


The distribution function for X can be obtained from the probability function for all x in (-, ), 0 -<x<x1 f(x1) x1<x<x2 F(x) = f(x1)+f(x2) x2<x<x3 . . f(x1)+.+f(xn) xnx<
March 20, 2012

Continuous Random Variables


The function f(x) has the properties 1. f(x) 0

2. f(x)dx = 1
-

March 20, 2012

Binomial Distribution
let p = probability that an event will happen q = 1-p, probability that the event will fail

The probability that the event will happen exactly x times in n trials

f(x) = P(X=x) = nCx px q(n-x)


March 20, 2012

Properties of a Binomial Distribution


Mean, = np Variance, 2 = np(1-p) = npq Standard Deviation, = (npq)

March 20, 2012

Normal Distribution
Any variable X following normal distribution with mean and standard deviation can be linearly transformed to the standard normal distribution by subtracting mean and dividing by standard deviation. Z be the standard variable corresponding to X X Z = --------------
March 20, 2012

Normal approximation to Binomial


(X np)

Z = --------------- (np(1-p)) will approximately follow standard normal distribution


March 20, 2012

Poisson Distribution
The probability distribution of the Poisson random variable X, in a given time interval is given by e-t (t)x P(x:t) = ------------------- x= 0, 1, 2,. x! where is the average number of outcomes per unit time
March 20, 2012

Centre for Computer Technology

Queueing Theory

Introduction
Queueing Process consists of
Customers arriving at a service facility Then waiting in a line (queue) if all servers are busy Eventually receiving service Finally departing from the service

March 20, 2012

Introduction
Queueing system is a
Set

of customers Set of servers An order where customers arrive and are processed

March 20, 2012

Introduction
It is a birth-death process with a population consists of customers either waiting for service or currently in service Birth occurs when a customer arrives at the service facility Death occurs when a customer departs from the facility State of the system is the number of customers in the facility.

March 20, 2012

Queue Characteristics
Queueing systems are characterized by five components
Arrival pattern of customers Service pattern Number of servers The capacity of the facility to hold customers The order in which customers are served

March 20, 2012

Arrival Patterns

Arrival of a customer is usually specified by interarrival time, the time between successive customer arrivals Arrival patterns may be Deterministic (exactly known) Random (known probability distributions) Depends on the number of customers already in the system or may be state-independent

March 20, 2012

Arrival Patterns

Customers arrive singly or in batches

Balking, occurs when a customer refuses to enter the service facility because the queue is too long
Reneging, occurs when a customer already in queue leaves the facility because the queue is too long

March 20, 2012

Service Patterns

It is specified by service time, the time required by one server to serve a customer Service time may be
Deterministic Random variable

March 20, 2012

Service Patterns

Depend on the number of customers already in the system or may be stateindependent A customer may be served
By a single server A sequence of servers

March 20, 2012

System Capacity

It is the maximum number of customers, permitted in the service facility at the same time
In the service In the queue

When a customer arrives at a facility that is full, the customer is denied entrance

March 20, 2012

System Capacity
The customer who is denied entrance is not allowed to wait outside the facility. The customer is forced to leave without receiving service Why ???????

A system with no limit has infinite capacity A system with a limit has finite capacity

March 20, 2012

Queue disciplines
Queue discipline is the order in which customers are served
FIFO (first in first out) LIFO (last in first out) Random basis Priority basis

March 20, 2012

Queueing systems - Types


Some important queueing systems are
Single queue, single server Single queue, multiple servers in parallel Multiple queues, multiple servers in parallel Single queue, multiple servers in series

March 20, 2012

March 20, 2012

Kendalls notation
Kendalls notation for specifying a queue characteristics is v/ w/ x/ y/ z v indicates arrival pattern w denotes service pattern x denotes the number of servers y represents system capacity (number of customers) z designates queue discipline
March 20, 2012

Some notations for v/ w/ z


Queue characteristic Symbol
D M Ek (k = 1, 2, 3..) G FIFO LIFO SIRO PRI GD

Meaning
Deterministic Exponentially distributed Erlang type distributed Any other distribution First in first out Last in first out Service in random order Priority ordering Any other ordering

Interarrival time
or

Service time

Queue discipline

March 20, 2012

Erlang distribution

It is a continuous probability distribution. Developed by A. K. Erlang, to examine the of telephone calls which might be made at the same time to the operators of the switching stations. This distribution, measures the time between incoming calls, is used in conjunction with the expected duration of incoming calls to produce information about the traffic load. It is used for traffic modelling (traffic engineering) for applications such as the design of call centres.

March 20, 2012

March 20, 2012

Please Note
If y or z are not specified it is taken to be (infinity) or FIFO respectively y is assumed as (infinity) z is taken as FIFO

March 20, 2012

Example
A D/ D/ 1 has
Deterministic values for Interarrival times Deterministic values for Service times Only one server

The variables y or z are not specified, so the

System capacity (customers) is

Queue discipline is FIFO

March 20, 2012

Centre for Computer Technology

Algorithms and Flowcharts

Programming Task - Phases


A typical programming task can be divided into two phases: Problem solving phase

produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm implement the program in some programming language
(Algorithms and Flowcharts)

Implementation phase

March 20, 2012

Steps in Problem Solving

First produce a general step by step process (pseudocode) Refine the step by step process successively to get a detailed algorithm that is very close to a computer language. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English.
(Algorithms and Flowcharts)

March 20, 2012

Example
Write an algorithm to determine a students final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

(Algorithms and Flowcharts)

March 20, 2012

Example - Pseudocode
Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print FAIL else Print PASS
(Algorithms and Flowcharts)
March 20, 2012

Example - Algorithm
Step 1: Step 2: Step 3: Input M1,M2,M3,M4 GRADE (M1+M2+M3+M4)/4 if (GRADE < 50) then Print FAIL else Print PASS endif
(Algorithms and Flowcharts)

March 20, 2012

Flowchart
A Flowchart
shows logic of an algorithm emphasizes individual steps and their interconnections They allow a process to be described in a step-by-step manner e.g. control flow from one action to the next

(Developing Flowcharts, Putting Algorithms to work)


March 20, 2012

Terminators
Start

Oval Shape One line in or out Used to indicate the beginning and end of a process

Stop

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Data Boxes
Input

Parallelogram shaped One line in, One line out Used to indicate the input or output of data from the system.

Output
(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Process Boxes
Rectangle shaped One line in, One line out Used to indicate a process step

Process

(Developing Flowcharts, Putting Algorithms to work)


March 20, 2012

Decision Boxes
Diamond shaped One line in, two lines out Must contain a binary question (Yes/No, True/False, 0/1, etc) Used to branch a program dependent upon a condition being met

(Developing Flowcharts, Putting Algorithms to work)


March 20, 2012

Yes/No Question

Basic Flowchart Symbols


Name Symbol Use in Flowchart Oval Denotes the beginning or end of the program

Parallelogram

Denotes an input operation

Rectangle

Denotes a process to be carried out e.g. addition, subtraction, division etc.

Diamond

Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE)

Hybrid

Denotes an output operation

Flow line

Denotes the direction of logic flow in the program

March 20, 2012

Simple Flowchart

This chart indicates a typical example of Input, Process, Output

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Flowchart - Example
START Input M1,M2,M3,M4

GRADE(M1+M2+M3+M4)/4

Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print FAIL else Print PASS endif
Y (Algorithms and Flowcharts)

IS GRADE<5 0

PRINT PASS

PRINT FAIL

STOP
March 20, 2012

Three basic structures

All flowcharts are composed of three basic control structures


Sequence Decision Repetition

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Sequence
Events happen one after the other, with no branching Flow is directly from top to bottom

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Decision
Uses a decision box to branch to one of two options Flow is downwards Lines rejoin the flow at lines, NOT boxes.

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Repetition
Used to repeat a process, or wait until a condition is met before proceeding. Flow is upwards. Lines join at lines, NOT boxes.

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Flowchart to find the sum of first 50 natural numbers


(Computer Fundamentals, Prof. B. I. Khodanpur)

March 20, 2012

Flow Chart to find largest of two numbers


(Computer Fundamentals, Prof. B. I. Khodanpur)

Start

Read A, B

Yes Print A

Is A > B

No Print B

End
March 20, 2012

Flowchart to find the largest of three numbers A,B, and C


(Computer Fundamentals, Prof. B. I. Khodanpur)

NO

March 20, 2012

Bad design
What is wrong with this chart? The box has two lines in, one line out Lines must join other lines, never boxes!

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Bad design
What is wrong with this flowchart? Never use curved lines. Always straight Always vertical or horizontal.

(Developing Flowcharts, Putting Algorithms to work)

March 20, 2012

Summary

Queueing systems are characterized by five components


Arrival pattern of customers, Service pattern, Number of servers, The capacity of the facility to hold customers and The order in which customers are served

Kendalls notation for specifying a queue characteristics is v/ w/ x/ y/ z


v (arrival pattern), w (service pattern), x (number of servers), y (system capacity) and z (queue discipline).

March 20, 2012

Summary
A typical programming task can be divided into two phases : Problem solving phase and Implementation phase Pseudocode is a general step by step process An Algorithm is a refined Pseudocode All flowcharts are composed of three basic control structures : Sequence, Decision and Repetition

March 20, 2012

Reference

R Bronson : Theory and Problems of Operations Research, Schaum's Outline series, McGraw Hill Computer Fundamentals, Prof. B. I. Khodanpur, R. V. College of Engineering. Developing Flowcharts, Putting Algorithms to work.

March 20, 2012

You might also like