0% found this document useful (0 votes)
42 views69 pages

A Level Computer Science 1 1

Uploaded by

Cynthia Boli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views69 pages

A Level Computer Science 1 1

Uploaded by

Cynthia Boli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Bilingual Grammar School Advanced Level Computer Science

CHAPTER 1: COMPUTER ORGANISATION AND ARCHITECTURE  Function keys, labeled F1-F12, perform specific functions based on the software used. F1 for
example is used in most software to display help.
Introduction  Alphabetical keys
The term computer is derived from the word “compute” which means “to calculate.” This simply  Numerical keys
means that the computer is a calculating machine. Every thousandth of a second or so, a computer  Navigation keys also called direction keys are used to navigate through documents and
performs thousands, millions, or even billions of simple arithmetic operations in order to carry out websites. Examples of navigation keys are the up, down, left and right arrows.
its tasks.  Action keys
Formally, a computer is defined as an electronic device that can accept, store and process data to
produce information. It can also be defined as a machine that can accept instructions and perform The way keys are arranged on a keyboard is known as the layout of the keyboard. There are
computations based on those instructions. different keyboard layouts but the best known are QWERTY mainly used by English speakers and
The term computer organization refers to the physical organization of the components in a AZERTY used by French speakers. Another keyboard layout modified greatly from a standard layout
computer system, and to the characteristics of those components. It includes the high-level aspects is DVORAK, devised to increase typing speed by placing frequently used keys more naturally.
of a computer’s design, such as the memory system, the memory interconnect, and the design of the A keyboard connects to the computer through cable PS/2 cable, USB cable or wireless (cordless).
internal processor or CPU.
1.1.2. Mouse
1. Hardware A mouse is a handheld device which is moved across a flat surface to control the movement of a
Hardware refers to the physical and tangible components of the computer like the keyboard, mouse, cursor or pointer on the computer screen. It is a pointing device. A standard mouse has two buttons,
monitor and internal circuits. Computer hardware components can be grouped into five functionally the right and the left buttons, which are pressed to enter commands into the computer.
independent main units: input, control, arithmetic and logic, memory and output units. Different actions that can be performed with a mouse are:
The input unit accepts coded information from human operators using devices such as keyboards,  Click: Pressing the left mouse button. This action can be used to select objects (files, folders,
or from other computers over digital communication lines. The information received is stored in the commands) or options in a menu.
computer’s memory, either for later use or to be processed immediately by the arithmetic and logic  Double-click: Pressing the left button two times in quick succession. It can be used to open
unit. The processing steps are specified by a program that is also stored in the memory. Finally, the a file, folder or program.
results are sent back to the outside world through the output unit. All of these actions are  Right-click: Pressing the right mouse button. A right-click opens a context menu from
coordinated by the control unit. which options like cut, copy and paste can be selected.
 Drag and drop: Pressing the left mouse button and moving the mouse while holding, is a
Processing Unit drag while releasing the left mouse button after a drag is a drop. Drag and drop can be used
to move files or documents from one place to another, and to select text.
Control Unit
Input Unit Output Unit A mouse connects to a computer through PS/2 cable (PS/2 mouse), USB cable (USB mouse), or
wireless (optical mouse).
Arithmetic
Logic Unit
1.1.3. Scanner
A scanner is a device that is used to input printed images such as photographs or pages of text
Memory Unit directly into the computer. It converts hardcopy information into electronic form (softcopy) for
storage in the computer. A scanner works by shining a light at the image being scanned and
Functional Units of a Computer measuring how much light is reflected back using an optical sensor. The amount of light
that is reflected back tells the computer how light or dark the image is at each point.
Common scanner devices are the flatbed scanner, optical mark reader, optical character reader,
1.1. Input Unit
barcode reader and magnetic ink character reader.
The input unit consists of hardware components that allow the computer user to enter data and
commands into the computer. These components are called input devices. Examples of input
a. Flatbed Scanner
devices are keyboard, mouse, scanner, joystick, light pen, touchpad, tracker ball and microphone.
A flatbed scanner is a scanner in which the object to be scanned is placed flat against a piece of glass.
When the object is placed, the scanner moves the light and sensor itself and scans the whole
1.1.1. Keyboard
The keyboard is the standard input device attached to computers. It is a device with keys that are image automatically. Most flatbed scanners are A4 size
pressed to enter data and commands into the computer. These keys represent letters, numbers,
symbols and control characters. When a key is pressed, a number (code) representing each b. Optical Mark Reader (OMR)
c. Optical Character Reader (OCR)
character, is sent to the computer to tell it which key has been pressed. The keyboard has a
d. Barcode Reader
total of 101-104 keys divided into different groups or keypads.

© 2014- BGS Molyko 1


Bilingual Grammar School Advanced Level Computer Science

e. Magnetic Ink Character Recognition (MICR)


1.3. The Processing Unit
1.2. Output Unit The processing unit, also called central processing unit (CPU), is an integrated circuit or “chip”
The output unit consists of devices that allow the user to retrieve information from the computer. which processes instructions and data. It is the part of the computer that interprets and executes
Output devices provide the results of computations to the person using the computer, in a way they program instructions. It also controls the other components of the system. The CPU is made up of
can understand. Examples are monitor, printer, speaker and projector. three main components: the arithmetic-logic unit (ALU), the control unit (CU) and registers.
Examples of CPUs are Intel Pentium II, III, IV, Pentium Celeron, and AMD Athlon.
1.2.1. Monitor
Also referred to as VDU (Visual Display Unit), the monitor is the most popular output device. It 1.3.1. Control Unit
displays information generated by a computer on a screen. Such output is known as softcopy output. The control unit acts like supervisor seeing that things are done as they ought to. It locates and
Monitors are characterized by the technology they use, their resolution and their size. retrieves program instructions from memory, interprets them and ensures that they are executed in
proper sequence. It also ensures that data is selected from memory as necessary and information is
 By the technology used, monitors are of two main types: Cathode Ray Tube (CRT)
stored correctly as well.
monitors and Flat Panel Display.
o CRT monitors are similar to a television set.
1.3.2. Arithmetic-Logic Unit
o Flat panel display monitors are of different types: Liquid Crystal Display (LCD),
The arithmetic-logic unit (ALU) performs arithmetic and logic operations. It contains arithmetic
Electroluminescent Display (ELD), Gas Plasma (GP) and Thin Film Transistor (TFT)
circuits that perform arithmetic operations like addition, subtraction, multiplication and division,
monitors.
and logic circuits that perform comparisons like equal to, less than, greater than, greater than or
equal to and less than or equal to.
Question: What are the advantages of flat panel monitors over CRT?
1.3.3. Registers
 Monitor resolution refers to the number of dots (pixels – picture elements) on the screen.
Registers are special storage locations within the CPU that offer an advantage of speed. They work
It is expressed as a pair of numbers that give the number of dots on a row and the
under the direction of the control unit to accept and hold data that is being processed. Since the CPU
number of rows. A variety of different resolutions are available. For example, VGA is 640
uses registers for the processing of data, the number of registers in a CPU and the size of each
x 480. This means that there are 640 pixels in each row across the screen and 480 pixels
register affect the power and speed of the CPU.
in each column up and down the screen. SVGA is 800x600.
Registers are grouped into two: special purpose registers and general purpose registers.
640 pixels
 Special purpose registers are dedicated to specific tasks like:
640 VGA o the accumulator which collects the result of computations,
pixels Screen o the memory address register (MAR) which keeps track of where a given instruction or
piece of data is stored in memory uses also the base and limit register
o the memory data register (MDR)which holds data values.
The size of a pixel is known as dot pitch. The smaller the dot pitch, the higher the number of dots
o the program counter (PC) which holds the address of the next instruction to be executed.
the screen has. Displays with lots of pixels are called high resolution while those with fewer
o The current instruction register (CIR) which holds the instruction being executed.
pixels are called low resolution. The higher the resolution, the clearer and sharper the image will
appear on the monitor. Most monitors come with a .28 dot pitch.
 General purpose registers on the other hand have no specific function; they are used
according to the need of the program being executed.
 The size of a monitor refers to how big the monitor is. It is measured in inches along the
diagonal from the bottom left hand corner to the top right hand corner of the screen.
Question: How would you define processing?
Typical sizes are 10" or 12" for LCDs and 14", 15" or 21" for desktop monitors.
1.3.4. The Instruction Cycle
1.2.2. Printer
The instruction cycle describes how program instructions are repeatedly fetched, decoded and
A printer is a device that produces computer-generated information on paper. Such output is
executed, one instruction at a time, until an instruction to HALT is encountered. Before an
referred to as printout or hardcopy. Based on the technology used, printers can be classified into
instruction can be fetched, it must be placed into memory as well as related data, from an input or
impact and non-impact printers.
secondary storage device. Once the necessary data and instructions are in memory, the central
 Impact printers have mechanical contact between paper and printing head (e.g. daisy wheel,
processing unit performs the following four steps for each instruction:
dot matrix and line printers).
1. The control unit fetches (gets) data and instructions from memory.
 Non-impact printers have no mechanical contact between paper and printing head (e.g. ink-
2. The control unit decodes the instructions i.e. determines what they mean, and directs that the
jet, desk- jet, laser printers).
necessary data be moved to the arithmetic-logic unit.

Question: What are the advantages and disadvantages of impact and non-impact printers?
© 2014- BGS Molyko 2
Bilingual Grammar School Advanced Level Computer Science

3. The arithmetic-logic unit then executes the instruction on the data. That is, the ALU is given meaning that everything held in it is lost when power is switched off. Two types of RAM exist: Static
control and performs the actual operation on the data. RAM and dynamic RAM.
4. The arithmetic-logic unit stores the result of this operation in memory or in a register.
 Dynamic RAM (DRAM) consists of capacitors that slowly leak their charge over time. Thus,
they must be refreshed every few milliseconds to prevent data loss. DRAM is cheap memory
owing to its simple design.

 Static RAM (SRAM) consists of circuits that retain their charge over time. SRAM is faster and
more expensive than dynamic RAM, and does not need to be refreshed as DRAM does. Due to
The Instruction Cycle its cost it is not used as main memory but rather to build cache memory. also used in registers

Steps 1 and 2 together are called instruction time or I-time and steps 3 and 4 together are called b. Read Only Memory
execution time or E-time. The combination of I-time and E-time is called the machine or instruction Read only memory (ROM) is a kind of memory whose contents can only be read by the computer.
cycle or the fetch-decode-execute cycle. The length of time taken to fetch, decode and execute an Data found in ROM is written by the manufacturer and cannot be modified by the user. ROM is
instruction is measured in clock cycles. useful for holding data that never changes like the “boot” or start-up program which is run when the
computer is switched on.ROM is non-volatile meaning that its content is preserved even without
1.3.5. System Clock power. There are four types of ROM:
The CPU has a small quartz crystal circuit called the system clock that controls the timing of all
computer operations. The system clock generates regular electronic pulses, or ticks, that set the  Masked ROM is ROM programmed with its data when the chip is fabricated.
operating pace of components of the system unit. Each tick is known as clock cycle and the pace of  Programmable ROM (PROM) is ROM that can be programmed once but not reprogrammed.
the system clock is called clock speed. Clock speed is measured in megahertz (Mhz) or gigahertz  Erasable Programmable ROM (EPROM) is ROM that can be erased by strong ultraviolet light
(Ghz) and refers to the number of clock cycles per second that the CPU runs at. Mega and giga stand and new data burnt into it. To do this the chip has to be removed from the machine and put
for million and billion respectively while hertz means cycles per second. Thus, 1Ghz means one back after the changes have been made.
billion cycles per second. A computer that operates at 3 Ghz has 3 billion (giga) clock cycles in one  Electrically Erasable Programmable ROM (EEPROM) is ROM whose content can be erased
second (hertz). electrically. In this case, the chip need not be removed from the machine. The programming is
The faster the clock speed, the more instructions the processor can execute per second. The speed done using special software.
of the system clock has no effect on devices such as a printer or disk drive. The speed of the system
clock is just one factor that influences a computer’s performance. Other factors, such as the type of c. Cache Memory
processor chip, amount of cache, memory access time, bus width, and bus clock speed. Cache memory is a smaller and faster memory between the CPU and main memory, which stores
copies of data from the most frequently accessed memory locations. The purpose of cache memory
1.4. Memory Unit is to speed up accesses by storing recently used data closer to the CPU, instead of storing it in main
The memory unit, also called storage unit, consists of computer components that hold programs and memory. Cache is static RAM and is usually organized in levels:
data for use in the computer. Memory or storage devices hold programs and data that can be made  Level 1 (L1) cache, Level 2 and Level 3 cache.
available for initial or additional processing when required. A storage device is made of two parts:  Level 1 cache is closest to the CPU or within it.
the storage medium and the device.  L2 and L3 caches are outside it.
 The medium is the surface or substrate that holds actual data
 The device reads information from or stores information onto the medium When the CPU needs to access memory, cache memory is examined first. If the data is found in
cache, it is read from it. Otherwise, main memory is accessed. When the CPU refers to memory and
Computer storage can be classified basically into two: primary storage and secondary storage. finds the data in cache, it is said to be a HIT. Otherwise, it is a MISS.

1.4.1. Primary Memory 1.4.2. Secondary Memory


Primary memory/storage is directly accessible to the CPU. It holds programs and data that the CPU Secondary memory is not directly accessible to the CPU. It is used to store programs and data for
is currently working with. Primary memory is also called internal memory, immediate access backup purposes (future use). It could be placed within the computer or connected externally.
memory or primary storage. Primary memory consists of random access memory, read only Programs and data from secondary memory must be transferred to main memory for processing.
memory and cache memory. Secondary memory is also called secondary storage, mass storage, backing storage or external
storage. It can be divided into magnetic storage, optical storage and solid state storage.
a. Random Access Memory
Random access memory (RAM) also called “main memory” is the temporary storage space into a. Magnetic Storage
which a computer loads programs and user data when it is running. It is the computer’s working Magnetic storage devices store data as electromagnetic charges on the magnetic surfaces of the
space. It is read/write meaning that data can be read from and written onto it. RAM is also volatile storage units. Examples are floppy disks, hard disks and magnetic tape.

© 2014- BGS Molyko 3


Bilingual Grammar School Advanced Level Computer Science

 Floppy Disk o CD-R stands for compact disc recordable. It is a type of CD that can be recorded by the
A floppy disk consists of a round flexible plastic disk coated with a magnetic substance and user. Once the user records on the CD, the content is set and cannot be changed. CD-R can
protected by a plastic cover lined with a soft material that wipes the disk clean as it spins. The disk be read by CD-ROM drives but to write on them, you need a CD-R drive.
is made of two recordable surfaces which are divided into a number of circular paths called tracks. o CD-RW stands for compact disc rewritable. It is a type of CD that can be recorded, erased
The number of tracks per surface varies with the particular type of disk. Each track is in turn and reused by the user. CD-RW cannot be read by a CD-ROM and CD-R drives. CD-RW
divided into a number of smaller units called sectors. A sector is the basic unit of storage on the disk drives are required to read and write on them.
and has a capacity of 512 bytes.
 Digital Versatile Disc (DVD)
 Hard Disk A DVD is similar to a CD in size and thickness but has a higher storage capacity than the CD. DVDs
A hard disk consists of several metallic platters which store data. Each platter has two sides and is use a laser beam of wavelength shorter than used by CDs. This allows for smaller indentations and
divided into a number of rings called tracks. Tracks on a platter are numbered 0 from the outside increased storage capacity. Just like the CD, different ions of the DVD exist: DVD-ROM, DVD-R and
and usually go up to 1023. Each track is divided into sectors. A sector is the basic unit of storage on DVD-RW. A DVD can store up to 17GB of data. Common DVD storage capacities are:
the disk and has a capacity of 512 bytes. Sectors are grouped together to form clusters. A cluster is
the smallest logical amount of disk space that can be allocated to hold a file. A cylinder is a sum set Types Characteristics Capacity
of all the tracks on all the platters that have the same track value. DVD-5 Single-sided, Single-layer 4.7GB
Factors that determine the performance of hard disks are, seek time and drive rotational speed. DVD-9 Single-side, Dual-layer 8.5GB
o Seek time is the time taken to move the read/write head over the right track and sector. DVD-10 Double-side, Single-layer 9.4GB
o Drive rotational speed is the total number of revolutions the disk platters make per DVD-18 Double-side, Dual-layer 17.1GB
minute. Higher rotational speed leads to higher transfer rate.
 Blu-Ray Disc
A Blu-ray disc is an optical disc similar to a DVD and of same size, but read and written with a blue
or violet laser, whose shorter wavelength makes a higher data density possible. Blu-ray discs can
hold 25 GB for single layer or 50 GB for double layer.

c. Solid State Storage


The term solid-state essentially means no moving parts. Solid-state storage devices are based on
electronic circuits with no moving parts (no reels, no spinning disks). They store data using a special
type of memory called flash memory. Flash memory is a type of EEPROM that can only be erased in
blocks; it cannot be erased one byte at a time. In this regard it resembles a disk that is divided into
sectors. Flash memory is usually used for storing larger amounts of data while EEPROM is used for
 Magnetic Tape small amounts of data, such as machine configuration. Examples of solid state devices are USB
A magnetic tape consists of a magnetically coated stripe on which data is stored. Data is stored on memory sticks, memory cards and secure digital cards.
the magnetic tape in chronological order or sequentially. This means that any piece of data is always
stored in the next available space on the tape. To access data, the tape drive has to move through all  USB Flash Drive
the preceding data before it can access the desired data. This mode of access is known as sequential A flash drive is a small, keychain-sized flash memory device with a USB interface, treated by the
access. Less susceptible to environment, they are suitable for long-term storage and backup. computer as if it were a disk drive. A flash drive is also called thumb drive, jump drive or memory
stick.USB flash drives have practically replaced diskettes as a handy way to transport data. They can
b. Optical Storage be carried in one’s pocket and plugged into any computer for immediate access.
Optical storage devices store data as microscopic light and dark spots on the disk surface. Examples
are Compact discs, digital versatile discs and Blu-ray discs. They are less susceptible to  Secure Digital Cards
environmental damage. A secure digital (SD) card is a type of flash-memory card that incorporates a cryptographic security
system to prevent copyright violations, often used in digital music players and digital cameras.
 Compact Disc (CD)
A CD is a round disk coated with a metallic surface on which data can be stored and accessed via 1.4.3. Characteristics of Storage Devices
laser technology. To store or access data on a CD, the CD drive focuses a laser beam on the disc Five important characteristics of storage devices are capacity, access time, access method, volatility
surface. Different variations of CD exist: CD-ROM, CD-R and CD-RW. A CD can store 650MB to and mutability.
700MB of data.
o CD-ROM stands for compact disc read only memory. CD-ROMs can only be read but not a. Capacity
recorded on by the user’s computer. Their content is set during manufacture.

© 2014- BGS Molyko 4


Bilingual Grammar School Advanced Level Computer Science

The capacity of a storage device is the maximum amount of data that can be stored on the device’s Examples are RAM, Flash memory, CD-RW, DVD-RW. Those that can be accessed only for reading
medium. It is expressed in terms of the number of data bytes the device can hold. This simply means are immutable (read only). Examples are ROM, CD and DVD.
the unit of measurement of storage capacity is byte. Units of storage are summarized as follows:
1.4.4. Memory Hierarchy
1 bit = 0 or 1 Modern computers manage memory by organizing memory into a hierarchy in which large and
4 bits = 1 nibble slower memories feed data into smaller but faster memories for faster processing of data. This
8 bits = 1 byte 1 character organization of computer memory is known as memory hierarchy. At the top of the hierarchy are
1024 bytes = 1 kilobyte (KB) approx. 1/2 page the CPU registers followed by cache memory. The next level in the hierarchy is made up of main
1024 KB = 1 megabyte (MB) approx. 500,000 pages memory, which is followed by magnetic disk.
1024 MB = 1 gigabyte (GB) approx. 5 million pages
1024 GB = 1 terabyte (TB) approx. 5 billion pages Registers

Cache Memory
b. Access time
Access time is the average time taken for a storage device to search and read required data on its Faster and Main Memory
Slower and
medium. In other words, it is how fast data can be read from or written to a memory device’s smaller in size
Magnetic Disk larger in size
medium. It is measured in seconds. Units of time are summarized as follows:
Millisecond (ms) = Optical Disc/Solid State Devices
Microsecond (µs) =
Magnetic Tape
Nanosecond (ns) =
Picoseconds (ps) =
Femtoseconds (fs) = Memory hierarchy

c. Access Method
An access method is the technique used to retrieve information from or store information to a 1.5. The Motherboard
medium. Storage media can be accessed in two ways: sequentially or randomly. The motherboard is the main printed circuit board in the computer which holds the chipset and
other electronic components that give function to the computer. The motherboard is indispensable
 Sequential Access to the computer and provides the main computing capability.
The medium is accessed by proceeding from the beginning of the medium until the designated area
is reached. Any new data is stored in the next available space on the medium. To read any data 1.5.1. Motherboard Form Factor
stored on the medium, the device has to start from the beginning going through each data until the Motherboard types are better described by what we call the motherboard form factor. The form
required data is found. An example of sequential access medium is magnetic tape. factor of a motherboard determines the specifications for its general shape and size. It also specifies
what type of case and power supply will be supported, the placement of mounting holes, and the
 Random Access physical layout and organization of the board. The most common form factors found in modern PCs
Random access means that any location in storage can be accessed at any moment in approximately are:
the same amount of time. Data is accessed in any order, regardless of its location on the medium. To  Advanced Technology (AT)
read any data stored on the medium, the device does not need to go through all preceding data. It is  Advanced Technology Extended (ATX)
also called direct access. Examples of direct access devices are RAM, ROM, CDs, DVDs and magnetic  Low Profile Extension (LPX)
disks.  New Low profile Extended (NLPX)

d. Volatility 1.5.2. The System Bus


Volatility refers to the behavior of the device without power. A device can be volatile or non-volatile. A computer bus is a set of parallel lines that interconnects various components inside the computer,
Volatile means that the device loses its content when power is switched off. Examples of volatile allowing the exchange of data between them. It is the pathway between these components, enabling
devices are Cache and RAM. data to be transferred from one component to another. The width or size of a bus is determined by
Non-volatile means that the device preserves its content even without power. Examples of non- the number of lines it has. The system bus is made up of three different busses: the data bus, the
volatile devices are ROM, magnetic disks, optical discs and solid state devices. address bus and the control bus.

e. Mutability a. The Data Bus


Mutability simple refers to the ability for the device to be accessed for reading and/or writing. The data bus carries data between the CPU and main memory or peripherals. During a write
Storage devices to which data can be written and read from are said to be mutable (read/write). operation, data is carried from the CPU and during a read operation, data is carried into the CPU.

© 2014- BGS Molyko 5


Bilingual Grammar School Advanced Level Computer Science

This means that the data bus is bidirectional. The size of the data us determines how much data can o VESA: Video Electronics Standard Architecture
be transferred in a single operation. o SIMM: Single Inline Memory Module
o DIMM: Dual Inline Memory Module
b. The Address Bus o PCMCIA: Personal Computer Memory Card International Association
The address bus carries address information from the CPU to main memory or peripherals. It is
unidirectional. The CPU uses the address bus to send the address of the memory location to be 2. Computer Architecture
written to or read from. Also, when the CPU reads data from or writes to a port, it sends the port Computer architecture refers to those attributes of a system that have a direct impact on the logical
address out on the address bus. The size of the address bus determines the maximum amount of execution of a program like the instruction set, the number of bits used to represent various data
main memory (RAM) that can be addressed. A computer with a 32 bit bus size can address a types, I/O mechanisms and techniques for addressing memory.
maximum RAM of 232 bits = 4GB.
2.1. The Von Neumann Architecture
c. The Control Bus The term Von Neumann computer in its strictest definition refers to a specific type of computer
The control bus is used by the CPU to send out signals to enable the outputs of addressed memory architecture in which instructions and data are stored together in a common memory. This type of
devices or port devices. Typical control bus signals are memory read, memory write, I/O read and architecture is distinguished from the Harvard architecture in which separate memories are used to
I/O write. store instructions and data. It is a stored-program computer model that was designed by the
Hungarian born Mathematician, John Von Neumann. It is based on three concepts:
When the CPU wants to read data from a memory location, it sends out the memory address of the o Both data and instructions (programs) are stored in a single storage structure called
desired data on the address bus and then sends out a Memory Read signal on the control bus. The memory
memory read signal enables the addressed memory device to output the data onto the data bus. The o The contents of this memory are addressable by location, without regard to the type of
data from the memory travels along the data bus to the CPU. data contained there.
o It has a single processing unit which is. As such, execution occurs in a sequential fashion
1.5.3. Input/Output Interfaces from one instruction to the next.
The CPU communicates with I/O devices through bus interfaces connected to the system bus. These
bus interfaces also called expansion buses are then connected to ports which allow the exchange of Programs being stored in memory ensures that by altering the stored program, the computer can
data and information between the computer and external (peripheral) devices. perform a different task – reason why a computer is called a general purpose machine.
Neumann divided the computer into four functional units: input, processing, storage and output.
a. I/O Ports
A port is a pathway for data and information to go into and out of the computer from external 2.2. Flynn’s Taxonomy of Computer Architecture
devices such as keyboards, monitors and printers. Michael Flynn classified computer architecture into four distinct categories based on the notion of
There are many standard ports as well as custom electronic ports designed for special purposes. stream or flow of information into the CPU. He identified two types of information streams:
Examples of ports are:  The instruction stream which is the flow of instructions into the processing unit
o PS/2 ports for connecting the keyboard and mouse  The data stream which is the flow of the data on which the instructions are performed.
o VGA (Video Graphics Adapter) port for connecting the monitor
o RJ45 port for connection to an Ethernet network 2.2.1. Single Instruction, Single Data Stream
o RJ14 for connection to the Internet via phone line A SISD machine is a uniprocessor machine which receives a single stream of instructions that
o USB port for connecting USB devices like Flash drives, printers, keyboards and mice operate on a single stream of data. At any given moment, a single instruction is being executed on a
o Serial ports for connecting serial devices like PDAs given data set. In SISD machines, instructions are executed sequentially. That is, instructions are
o Parallel port connecting parallel devices like printers executed one after the other, one at a time. Hence these machines are also called sequential or serial
o Firewire is high performance serial bus, for connecting devices to your personal processor machines. They are typical examples of Von Neumann’s computer model.
computer. FireWire provides a single plug-and-socket connection on which up to 63
devices can be attached with data transfer speeds up to 400 mbps.
Control Unit Processor
b. I/O Bus Standards
Instruction Data
Ports follow standards that define their use. Examples of such standards are: stream
Memory stream
o SCSI: Small Computer System Interface
o USB: Universal Serial Bus
SISD Architecture
o IDE: Integrated Device Equipment
o PCI: Peripheral Component Interconnect
o ISA: Industry Standard Architecture
o EISA: Extended ISA

© 2014- BGS Molyko 6


Bilingual Grammar School Advanced Level Computer Science

2.2.2. Single Instruction, Multiple Data Stream


SIMD machines are multiprocessor machines which are capable of executing the same instruction
on all the processors at the same time. They have n identical processors which operate under the
control of a single instruction stream issued by a central control unit on different data sets. At any
given moment, the control unit broadcasts the same instruction to all processors which operate on
different data sets from distinct data streams. SIMD machines are also called array processor
machines. An example is the CRAY’s vector processing machine.

PE 1 DS 1

Control Unit PE 2 DS 2
IS
DS = Data Stream
DSn IS =Instruction Stream Question: SIMD, MISD and MIMD machines are known as parallel processing machines.
PE n PE = Processor Element
Instruction What do you understand by parallel processing?
stream
2.3. Parallelism
Memory
The performance of computers can be increased by making them perform a number of operations in
parallel. This is known as parallelism. Parallelism can be achieved through parallel processing and
SIMD Architecture
pipelining.

2.2.3. Multiple Data, Single Instruction Stream 2.3.1. Parallel Processing


MISD machines are multiprocessor machines capable of executing different instructions on different Parallel processing is the use of multiple (independent) processors simultaneously to execute a
processors, but all of them operating on the same data set. They have n processors, each with its single program or task. The problem is divided into portions so that multiple processors work on
own control unit, that share a common memory. Each processor receives a distinct instruction their assigned portion of the problem at the same time. Parallel processing requires special
stream but all operate on the same data stream. Such machines no longer exist. software that recognizes how to divide the problem and then bring the results back together again.
Some personal computers implement parallel processing with multiprocessors while others have
𝐼𝑆 1 multicore processors.
Control Unit 1 PE 1
a. Multicore Processors
𝐼𝑆 2 Multiple processing units can be fabricated on a single chip. In this case, each of these processors is
Control Unit 2 PE 2
IS = Instruction Stream termed core. The term processor is then used for the complete chip. Hence, we have the terminology
PE = Processor Element dual-core, quad-core, and octo-core processors for chips that have two, four, and eight cores,
𝐼𝑆 𝑛 respectively.
Control Unit n PE𝑛

b. Multiprocessors
Data Computer systems may contain many processors, each possibly containing multiple cores. Such
Memory
Stream systems are called multiprocessors. These systems either execute a number of different application
tasks in parallel, or they execute subtasks of a single large task in parallel. All processors usually
MISD Architecture have access to all of the memory in such systems, and the term shared-memory multiprocessor is
often used to make this clear. The high performance of these systems comes with much higher
complexity and cost, arising from the use of multiple processors and memory units, along with more
2.2.4. Multiple Data, Multiple Instruction Stream complex interconnection networks.
MIMD machines are multiprocessor machines capable of executing multiple instructions on multiple
data sets. They have n processors, n streams of instructions and n streams of data. Each processor 2.3.2. Pipelining
element in this model has a separate instruction stream and data stream hence such machines are The simplest way to execute a sequence of instructions in a processor is to complete all steps of the
well suited for any kind of application. Examples of MIMD machines include multi-core computers current instruction before starting the steps of the next instruction. If we overlap the execution of
like the Blue Gene, Fujitsu K computer and CRAY Jaguar. the steps of successive instructions, total execution time will be reduced.

IS 1 DS1
Control Unit 1 PE 1
© 2014- BGS Molyko 7
IS 2 DS 2
Control Unit 2 PE 2 DS = Data Stream
Bilingual Grammar School Advanced Level Computer Science

For example, the next instruction could be fetched from memory at the same time that an arithmetic
(execute) operation is being performed on the register operands of the current instruction. This An instruction set architecture (ISA) consists of the instruction set together with the resources
form of parallelism is called pipelining. needed for their execution. It provides the interface between the computer's software and hardware
and can be viewed as the programmer's view of the machine. Besides instructions, the ISA defines
Definition: Pipelining is a technique that allows for the simultaneous execution of the parts of an items in the computer that are available to a program - e.g. data types, registers, addressing modes,
instruction. and memory.
There are two types of fundamental CPU architectures based on the notion of instruction set:
Below is an example of a four-stage pipeline with three instructions. The stages are: complex instruction set computers and reduced instruction set computers.
IF: instruction fetch ID: instruction decode EX: execute WB: write back
2.4.1. Complex Instruction Set Computer (CISC)
Instr. 1 IF ID EX WB CISC (pronounced sisk) is a CPU design with a large amount of different and complex instructions. In
CISC processors, the control unit contains a number of micro-electronic circuitry to generate a set of
Instr. 2 IF ID EX WB
control signals and each micro-circuitry is activated by a microcode. Complex instructions are first
Instr. 3 IF ID EX WB decoded and the corresponding microcode routine dispatched to the execution unit.
The standard features of CISC processors are:
Clock Cycle 1 2 3 4 5 6
 a large number of different and complex instructions.
 the use of complex addressing modes.
Cycle 1: Instruction 1 is being fetched from memory.
 execution of different machine programs on a CISC machine.
Instructions 2 and 3 have not entered the pipeline yet
 the use micro-program control unit.
Cycle 2: Instruction 1 is being decoded  limited number of registers.
Instruction 2 is being fetched  variable length instruction encoding
Instruction 3 has not entered the pipeline yet  direct memory access

Cycle 3: Instruction 1 is being executed Examples of CISC processors are: Intel 386, 486, Pentium, Pentium Pro, Pentium II, Pentium III,
Instruction 2 is being decoded Motorola’s 68000, 68020, 68040, etc.
Instruction 3 is being fetched

Cycle 4: Instruction 1’s results are being written back to register or memory 2.4.2. Reduced Instruction Set Computers (RSIC)
Instruction 2 is being executed RISC (pronounced risk) is a CPU design with a small number of basic and simple machine language
Instruction 3 is being decoded instructions, from which more complex instructions can be composed. RISC instructions are
hardwired. That is, they are built into the chip with hardware rather than programming. Hardware
Cycle 4: Instruction 1 is completed implementation of instructions is much faster and uses less silicon than a microcode
Instruction 2’s results are being written back to register or memory implementation.
Instruction 3 is being executed The standard features of RISC processors are:
 a small and limited number of instructions.
Cycle 5: Instruction 1 is completed  the use of hardwired control unit.
Instruction 2 is completed  consumption of less power and high performance
Instruction 3’s results are being written back to register or memory
 instructions are very simple and consistent

Cycle 6: Instruction 1 is completed


 the use of simple addressing modes
Instruction 2 is completed  fixed length instructions (easier to decode)
Instruction 3 is completed  pipelining possible because of fixed length instructions

2.4. Instruction Set Architecture Examples of RISC processors are: IBM RS6000, MC88100
Every CPU has a predefined instruction set which defines the primitive operations that it can DEC’s Alpha 21064, 21164 and 21264 processors, Motorola/IBM PowerPC
perform.
2.4.3. Addressing Modes
Definition: An instruction set is the collection of bit patterns or binary codes for the machine A machine instruction specifies to the CPU what to do, where the data is located, and where the
operations that a processor has been designed to perform. output data (if any) will be put. Every instruction is made up of two parts: Op-code and operand.

© 2014- BGS Molyko 8


Bilingual Grammar School Advanced Level Computer Science

 The Op-code (operation code) denotes the basic machine operation e.g. ADD, STORE,
SHIFT, XOR. e. Indexed Addressing
 The operand (one or more) provides the data which the instruction manipulates. The effective address of the operand is generated by adding a constant value to the contents of a
register.
For example,
ADD A, $0E ADD is the op-code; A and $0E are operands 3. Number Systems and Data Representation
MOV AX, #0 MOV is the op-code; AX and #0 are operands Computers use binary patterns (fixed number of bits) to represent data, which could be numbers,
letters, videos, images or other symbols. It is important to decide on how these patterns will be
Operands can be specified in different ways in an instruction. The way an operand is specified in an interpreted. The interpretation of binary patterns is called data representation or encoding.
instruction is known as an addressing mode. Different representation schemes exist.

Definition: An addressing mode refers to the way in which the processor locates the data (operand) 3.1. Number Systems
associated with an instruction. A number system is a set of symbols and rules used to represent numbers. The number of different
symbols used in a given number system is known as the base or radix of the system. The largest
a. Register Addressing value of a symbol (digit) in a given number system is always one less than the base or radix of that
In register mode, operand is the contents of a processor register; the name of the register system. If the base of a system is represented by“𝑏”, then the largest value a digit in that system can
is given in the instruction. For example: assume is “𝑏 − 1”.
Examples of number systems include the binary, octal, decimal (denary) and hexadecimal systems.
ADD R1, R2, R3
3.1.1. The Decimal System
The above instruction uses three register to hold all operands. Registers R2 and R3 hold the two The decimal system has a base value of 10. Its maximum or largest value of digit is (𝑏 − 1) = 10 −
source operands while register R1 holds the result of the computation. 1 = 9, meaning thatthe decimal system uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent any
quantity.
b. Immediate Addressing
In immediate mode, the operand is given explicitly in the instruction. In other words, the value to be Consider the number 23410
manipulated by the instruction is immediately part of it. There is no need for any additional It can be written as234 = 200 + 30 + 4
information. For example: 234 = (2 × 100) + (3 × 10) + 4
234 = (2 × 102 ) + (3 × 101 ) + (4 × 100 )
ADD R2, R3, #10
This means that there are two one hundreds, three tens and four ones in the number 234.
This instruction adds the number 10 to the content of register R3 and stores the result in register For any n-digit number, the value each digit represents depends on its position in the number.
R2. The operand 10 has been addressed immediately. Decimal positions (place values) are powers of ten as shown below:

c. Direct Addressing Least Significant


Most Significant
10𝑛−1 102 101 100 Digit (LSD)
In this addressing mode, the operand is in a memory location; the address of this location is given Digit (MSD) …
explicitly in the instruction. It is also called absolute addressing. For example:
Decimal positions for an 𝑛-bit number
LOAD R2, $0FF
Where, 100 is the ones place
The above instruction loads the content of the memory location $0FF into register R2. The operand 101 is the ten’s place
$00FF has been addressed directly. 102 is the hundreds place

d. Indirect Addressing The value of any digit in a given n-digit number is obtained by multiplying the digit by its place
Here, the effective address of the operand is the contents of a register that is specified in the value. The value of the number is the sum of the products of the digits and their place values. That is,
instruction. For example: we multiply each digit by its place value, then we add the different products obtained.

ADD R2, R2, #R3 Remark Each digit position in decimal has a weight that is ten times the one to its immediate right.
That is, 102 is ten times greater than 101 which is ten times greater than 100 .
This instruction adds the contents of the memory location held in register R3 to the content of
register R2 and the result of the operation is held in register R2. 3.1.2. The Binary System

© 2014- BGS Molyko 9


Bilingual Grammar School Advanced Level Computer Science

The binary system has a base value of 2. Only two digits 0 and 1, are used to represent any quantity
in binary. These digits are called binary digits or more commonly bits. To express any quantity in b. Binary to Decimal Conversion
binary we use powers much like in the decimal system but this time, the weights are powers of 2 as To convert a binary number to decimal, we proceed as follows:
shown below. Step 1: starting with the 1s place, write the binary place value over each digit in the binary
number to be converted.
Least Significant
Most Significant Step 2: add up all the place values that have a “1” in them
2𝑛−1 22 21 20 Bit (LSB)
Bit (MSB) …
Example 1: Convert 110102 to base 10
Binary positions for an 𝑛-bit number 16 8 4 2 1
1 1 0 1 0
e.g. the binary number 11012 is expressed as11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20
This means that there are 1 ones, 0 twos, 1 fours, and 1 eights in the number 1101. 16 + 8 + 2 = 2610

a. Decimal to Binary Conversion Convert: 11112 (15), 100112 (19), 101012 (21) to base 10.
To convert from decimal to binary we use the repeated division method. The general technique of
this method can be used to convert any decimal number to any other number system. Example 2: Convert 1101.0112 to base 10
Step 1: divide the decimal number you want to convert by 2 in regular long division until you 1101.0112 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 + 0 × 2−1 + 1 × 2−2 + 1 × 2−3
obtain a final remainder = 8 + 4 + 0 + 1 + 0 + 1⁄4 + 1⁄8
Step 2: use the remainder as the least significant bit of the binary number = 13 + 0.25 + 0.125
Step 3: divide the quotient you got from the first division operation by 2 until you obtain a final = 13 + 0.25 + 0.125
remainder = 13.375
Step 4: use the remainder as the next digit of the binary number
Step 5: repeat steps 3 and 4 as many times as necessary until you get a quotient that cannot be Exercise: Convert the following binary numbers to decimal
divided by 2. 1010.1012 (10.625) (ii) 10011.0012 (19.125)
Step 6: use the last remainder (that cannot be divided by 2) as the most significant bit of the
binary number. c. Binary Arithmetic
 Addition
Example 1: Convert 21310to base 2 Rules for addition:
213/2 = 106 remainder 1 LSB 0+0=0; 0+1=1; 1+0=1; 1+1=10; 1+1+1 = (1+1) + 1 = 10+1 = 11
106/2 = 53 remainder 0
53/2 = 26 remainder 1 i. 100 + 01 = 101 ………………………………….(4 + 1 = 5)
26/2 = 13 remainder 0 ii. 1101 + 101 = 10010 …………………………. (13 + 5 = 18)
13/2 = 6 remainder 1 iii. 1111 + 110 = 10101 ………………………….. (15 + 6 = 21)
6/2 = 3 remainder 0
3/2 = 1 remainder 1  Subtraction
1/2 = 0 remainder 1 MSB Rules for subtraction:
0-0 = 0; 1-0 = 1; 0-1 = 0 (we borrow a digit); 1-1 = 0
Therefore, 21310 = 110101012
i. 10101 − 100 = 10001 (21 − 4 = 17)
Example 2: Convert 25.7510 to binary ii. 1010 − 101 = 101 …... we borrow a digit worth 2 to continue with the calculation (10 −
5 = 5)
2510 = 110012 , iii. 1001011 − 110101 = 10110 (75 − 53 = 22)

0.75 × 2 = 1.5 1  Multiplication


0.5 × 2 = 1.0 1 Rules for multiplication:
0.7510 = 112 0 × 0 = 0; 0 × 1 = 0; 1 × 0 = 0; 1 + 1 = 1

⇒ 25.7510 = 11001.112 i. 101 × 10 = 1010 ……………………………….. (5 × 2 = 10)


ii. 111 × 101 = 100011 …………………………. (7 × 5 = 35)
Example 3: Convert: 33.332 to decimal. iii. 11011 × 1101 = 101011111 ……………… (27 × 13 = 351)

© 2014- BGS Molyko 10


Bilingual Grammar School Advanced Level Computer Science

 Division Example: 1. Convert 1001102 to base 8


Rules for division: 1001102 = 100 110
0/1 = 0; 1/1 = 1; 1/0 = undefined. 1002 = 48 , 1102 = 68
∴ 1001102 = 468
i. 1000 ÷ 10 = 100 ………………………. (8 ÷ 2 = 4)
ii. 100001 ÷ 11 = 1011……………………….(33 ÷ 3 = 11) Example 2: Convert 10111012 to base 8
11011 ÷ 101 = 101 𝑟 10 ………………….(27 ÷ 5 = 5 𝑟 2) 10111012 = 001 011 101
0012 = 18 , 0112 = 38 , 1012 = 58

3.1.3. The Octal System ∴ 10111012 = 1358


The octal system has a base value of 8. It uses the digits 0-7 to represent any quantity. Weights in
octal are powers of eight as shown below. b. Octal to Binary Conversion
To convert from octal to binary, we replace every octal digit by its 3-bits binary equivalent.
Least Significant
Most Significant
8𝑛−1 … 82 81 80 Digit (LSD)
Digit (MSD) Example1: Convert 738 to binary
78 = 1112 , 38 = 1012
Octal positions ∴ 738 = 1111012
0
Where 8 is the one’s place
81 is the eights place Example 2: Convert 4508 to binary
82 is the sixty fours place 48 = 1002 , 58 = 1012 , 08 = 0002
∴ 4508 = 1001010002
Example: 3678 = 3 × 82 + 6 × 81 + 7 × 80
(This means that there are 3 sixty fours, 6 eight’s and 7 one’s in 367) 3.1.4. The Hexadecimal System
The prefix “hex” means 6 and “deci” means 10. The hexadecimal number system is thus a base-16
a. Binary to Octal Conversion number system. Each digit position represents a power of 16. The digits used in this system are 1, 2,
Theorem 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F, where𝐴 = 1010 , 𝐵 = 1110 , 𝐶 = 1210 , 𝐷 = 1310 , 𝐸 = 1410 , 𝐹 =
If base R1 is the integer power of another base, R2 (i.e. R1 = R2d), then every group of d digits in R2 is 1510.
equivalent to 1 digit in the R1 base.
For example: Assume that:
Assume that: R1 = 8 (octal) and R2 = 2 (binary) R1 = 16 (hexadecimal)
R2 = 2 (binary)
From the theorem, 8 = 23
Hence, 3 digits in base-2 is equivalent to 1 digit in base-8. From the theorem, 16 = 24
Hence, 4 digits in a binary number is equivalent to 1digit in the hexadecimal number system.
From the stated theorem, the following is a binary-octal conversion table.
The following is the binary-hexadecimal conversion table
Binary Octal Binary Octal
Binary Hexadecimal Binary Hexadecimal
000 0 100 4
0000 0 1000 8
001 1 101 5
0001 1 1001 9
010 2 110 6
0010 2 1010 A
011 3 111 7
0011 3 1011 B
To convert from binary to decimal, proceed as follows 0100 4 1100 C
Step1: make groups of three bits starting from the least significant bit and move towards the most
significant bit. 0101 5 1101 D
Step 2: replace each group of bits by its octal representation. 0110 6 1110 E

© 2014- BGS Molyko 0111 7 1111 F 11


Bilingual Grammar School Advanced Level Computer Science

For example:
o A 4-bit pattern will represent the integers 0 to (24 ) − 1 = 3
o An 8-bit pattern will represent the integers 0 to (28 ) − 1 = 255
 To convert from binary to hexadecimal
Step1: make groups of four bits starting from the least significant bit and move towards the most 3.2.2. Representation of Signed Integers
significant bit. Signed integers can represent zero, positive integers, as well as negative integers. Four
Step 2: replace each group of bits by its hexadecimal value representation. representation schemes are available for signed integers:
1. Sign-Magnitude representation
Example 1: Convert 1001102 to base 16 2. 1's Complement representation
1001102 = 0010 0110 3. 2's Complement representation
00102 = 216 , 01102 = 616 4. Biased representation (Excess-𝑛)

∴ 1001102 = 2616 a. Sign-Magnitude Representation


In sign-magnitude representation, the most significant bit is the sign bit with 0 for positive and 1 for
Example 2: Convert 10111012 to base 16 negative. The remaining (𝑛 − 1) bits represent the absolute value of the integer. The absolute value
10111012 = 0000 0101 1101 of the integer is interpreted as "the magnitude of the (𝑛 − 1)-bit pattern".
00002 = 016 , 01012 = 516 , 11012 = 𝐶16
Example 1: Suppose 𝑛 = 8 and the binary representation 01000001.
∴ 10111012 = 5𝐶16 Sign bit is 0 ⇒number is positive
Absolute value is 1000001 = 65
 To convert from hexadecimal to binary, we carry out the inverse operation. That is, we Hence, the integer is 65.
replace every hexadecimal digit by its 4-bits binary equivalent.
Example 2: Suppose 𝑛 = 8 and the binary representation 10001001.
Example 1: Convert 4508 to binary Sign bit is 1 number is negative
416 = 01002 , 516 = 01012 , 016 = 00002 Absolute value is 0001001 = 9
∴ 45016 = 100010100002 Hence, the integer is −9

Example 2: Convert 6𝐸 to base 2 The drawbacks of sign-magnitude representation are:


6 = 0110, 𝐸 = 1110 o There are two representations (0000 0000 and 1000 0000) for the number zero, which
∴ 6𝐸 = 11011102 could lead to inefficiency and confusion.
o Arithmetic is cumbersome making the design of electronic circuits for this scheme difficult.
Assignment:
1) Convert the following octal numbers to hexadecimal. b. 1’s Complement Representation
i) 658 (ii) 538 In 1's complement representation the most significant bit is still the sign bit. The remaining (𝑛 − 1)
bits represent the magnitude of the integer as follows:
2) Convert the following hexadecimal numbers to octal. o for positive integers, the absolute value of the integer is equal to "the magnitude of the
i) 12B16 (ii) F2E16 (𝑛 − 1)-bit pattern".
o for negative integers, the absolute value of the integer is equal to "the magnitude of the
3.2. Representation of Numbers complement (inverse) of the (𝑛 − 1)-bit pattern".
A number can be a whole number (integer) or a fractional number (real number). It may also be a
positive or a negative number. There are various ways by which numbers are represented using 0s Example 1: Using 1’s complement, represent the following base 10 numbers on 8 bits.
and 1s. i) 2610 = 11010
Number is positive ⇒ sign bit is 0
3.2.1. Representation of Unsigned Integers ⇒2610 = 0 0011010
Unsigned integers can represent zero and all positive integers. The value of an unsigned integer is
interpreted as “the magnitude of its underlying binary pattern”. That is, for an unsigned integer, all ii) −25
the bits in the binary pattern are used to represent the magnitude of the integer. Number is negative ⇒ sign bit is 1
In binary, an n-bit pattern can represent 2n distinct integers. Therefore, an n-bit pattern will 25 = 11001
represent integers from 0 to 2n − 1. Complement of 0011001 is 1100110
⇒−25 = 1 1100110

© 2014- BGS Molyko 12


Bilingual Grammar School Advanced Level Computer Science

Number is negative ⇒ sign bit is 1


Example 2: Give the decimal equivalent of the following 1’s complement binary representations. 24 = 11000 = 0011000
i) 0010 0001. 1’s complement of 24 is 1100111
Sign bit is 0 ⇒ positive 2’s complement of 24 is 1100111 + 1 = 1101000
Absolute value is 010 0001 = 33 ⇒ −24 is represented by 1 1101000
Hence, the integer is +33
ii) −13
ii) 1000 0001 Number is negative ⇒ sign bit is 1
Sign bit is 1 ⇒ negative 13 = 1101 = 0001101
Absolute value is the complement of 000 0001, i.e., 111 1110 = 126 1’s complement of 13 is 1110010
Hence, the integer is −126 2’s complement of 13 is 1110010 + 1 = 1110011
⇒ −13is represented by 1 1110011
The problem with this representation is that there are still two representations for zero (0000 0000
and 1111 1111). Example 2: Give the decimal equivalent of the following 2’s complement binary representations.
i) 01100000
 Addition in 1’s Complement Sign bit is 0 ⇒ positive number
o Add binary representations of the two numbers Absolute value is 110 0000 = 96
o If there is a carry (referred to as end-round carry), add it to the result. Hence, the integer is +96

 Subtraction in 1’s complement ii) 1 001 0001


Subtraction is implemented using addition as follows: Sign bit is 1 ⇒ negative number
o Determine the 1’s complement of the negative number Absolute value is the complement of 001 0001 plus 1, i.e.,110 1110 + 1 = 111
o Add the binary representations of the two numbers Hence, the integer is −111 (−27 + 24 + 20 = −128 + 16 + 1 = −111)
o If there is any carry, add it to the result
Modern computers use 2's complement in representing signed integers. This is because:
Example: subtract 37 from 51 in binary 1. There is only one representation for the number zero unlike in sign-magnitude and 1's
37 = 0100101 ⇒ 37 = 1011010 ⇒ −37 = 1101101in 1’s complement complement representations.
(51) 00110011 2. Positive and negative integers can be treated together in addition and subtraction.
(-37) + 11011010 Subtraction can be carried out using the "addition logic".
--------------
1 00001101  Addition in 2’s Complement
+ 1 o Add binary representations of the two numbers
--------------- o If there is a carry, ignore it
(14) 00001110
 Subtraction in 2’s Complement
c. 2’s Complement Representation Subtraction is implemented as follows:
In 2's complement representation, the remaining (𝑛 − 1) bits represent the magnitude of the o Determine the 2’s complement for the negative number
integer as follows: o Add the binary representations of the two numbers
o for positive integers, the absolute value of the integer is equal to "the magnitude of the o If there is any carry, ignore it
(𝑛 − 1)-bit pattern".
o for negative integers, the absolute value of the integer is equal to "the magnitude of the Example: subtract 37 from 51
complement of the (𝑛 − 1)-bit pattern plus one". That is, we just add one to 1’s 37 = 0100101 ⇒ 37 = 1011010 (1’s C) ⇒ − 37 = 1 1011011 (2’s C)
complement to get 2’s complement. (51) 00110011
(-37) + 11011011
An alternative and simple way of getting 2’s complement is - ------------
o to write the representation of the positive number (14) 1 00001110 discard end-round carry
o starting from the least significant bit, flip all the bits to the left of the first 1.
d. Excess-n Representation
Example 1: Using 2’s complement, store the following base 10 numbers. In excess-n notation, where n is the number of bits used, the value represented is the unsigned value
i) −24 with a fixed value 2n-1 subtracted from it.

© 2014- BGS Molyko 13


Bilingual Grammar School Advanced Level Computer Science

= 0.4 × 2 = 0.8 0
Example 1: Represent the = 0.8 × 2 = 1.6 1
= 0.6 × 2 = 1.2 1
3.2.3. Representation of Real Numbers
Computers represent real numbers in a form similar to that of scientific notation of mantissa (M) So a binary representation of 0.2is given by 0.001100110011
and an exponent (E) of a certain radix (R), in the form of 𝑀 × 𝑅 𝐸 . Both M and E can be positive as 64.2 is 100000.001100110011
well as negative. For example, 1.25 × 10−1 is expressed in scientific notation where 1.25 represents
the mantissa, −1 the exponent and 10, the radix. Step 2: we normalize the binary representation
The IEEE 754 standard for representing floating-point numbers in the computer has two 1000000.001100110011 becomes 1.00000001100110011 × 25
representation schemes: 32-bit single-precision and 64-bit double-precision.
Step 3: 5 is the true exponent.
 In 32-bit single-precision floating-point representation: In excess-16, we have 5 + 16 = 21
 the most significant bit is the sign bit (S), with 0 for negative numbers and 1 for positive 21in 5-bit unsigned representation is 10101
numbers.
Step 4: The mantissa stored is what is on the right side of the radix point of the normal form.
 the following 8 bits represent the exponent (E).
So M is 0000000110011001100110
 the remaining 23 bits represent the mantissa (M) or fraction (F).
Putting all these together we have 64.2 represented as:

0 10101 00000001[10011001100110]

NB: On 8 bits we see that part of the number will be missing. That is why we say the mantissa
determines the precision (exactness) of the number.

 In 64-bit single-precision floating-point representation: b. −15.375


o the most significant bit is the sign bit (S), with 0 for negative numbers and 1 for positive Negative number ⇒ sign bit is 1
numbers. 15 = 1111
o the following 16 bits represent the exponent (E). 0.375 × 2 = 0.75 0 𝑀𝑆𝐵
o the remaining 47 bits represent the mantissa (M) or fraction (F). 0.75 × 2 = 1.5 1
0.5 × 2 = 0.96 0
In floating-point representation, the mantissa and exponent play two important roles. The mantissa 0.5 × 2 = 1.0 1
affects the precision of the number while the exponent affects the range. Precision has to do with
the exactness of a number while range has to do with the set of numbers that can be represented. 0.375 = 0101

For simplicity, we will use a 14-bit pattern for floating point with a 5-bit exponent and an 8-bit 15.375 = 1111.0101
mantissa. In this case, we will use excess-16 representation for the exponent. Normalized we have, 1.1110101 × 23
Examples: 𝐸 = 3 ⇒ 19in excess-16
1. Represent the following numbers as 32-bit single precision floating-point numbers. 𝐸 = 10010
a. 32.2 −15.375is represented as1 10010 11101010
b. −15.37
c. 0.125 c. 0.125
Positive number ⇒Sign bit is 0
Solution: 0 = 0000
a. We convert the number to binary 0.125 × 2 = 0.25 0 𝑀𝑆𝐵
32 = 100000 0.25 × 2 = 0.5 0
0.2 = 0.2 × 2 = 0.4 0 𝑀𝑆𝐵 0.5 × 2 = 1.0 1
= 0.4 × 2 = 0.8 0
= 0.8 × 2 = 1.6 1 0.125 = 0.001
= 0.6 × 2 = 1.2 1 Normalized we have, 1.0 × 2−3
= 0.2 × 2 = 0.4 0 𝐸 = −3 + 16 = 13 = 01101

© 2014- BGS Molyko 14


Bilingual Grammar School Advanced Level Computer Science

like English, German, Italian, Portuguese and Spanish. Latin-1 is backward compatible with the 7-bit
0.125 is represented as 0 01100 00000000 ASCII code. That is, the first 128 characters in Latin-1 (code numbers 0 to 127 (7FH)), is the same as
ASCII. Code numbers 128 (80H) to 159 (9FH) are not assigned. Code numbers 160 (A0H) to 255
2. Suppose the following 14-bit floating-point representation patterns, what decimal numbers do (FFH) represent other special characters like Å, Æ, Ç, ~, £, ¤, ¥, § and ©.
they represent?
3.3.3. Unicode Character Code
a. 01000011000000 Unicode originally uses 16 bits (called UCS-2 or Unicode Character Set - 2 byte), which can
b. 10111010000000 represent up to 65,536 characters. Before Unicode, no single character encoding scheme could
c. 11111000000001 represent characters in all languages. Unicode is backward compatible with the 7-bit ASCII and 8-bit
Latin-1. That is, the first 128 characters are the same as ASCII and the first 256 characters are the
Solutions: same as Latin-1.
The original 16-bit range of U+0000H to U+FFFFH (65536 characters) is known as Basic
a. 010000110 00000 Multilingual Plane (BMP), covering all the major languages in use currently. The characters outside
Sign bit is 𝑆 = 0 ⇒positive number BMP are called Supplementary Characters, which are not frequently-used.
𝐸 = 10000 = 16 (in normalized form) UCS-4 (Universal Character Set - 4 Byte), uses 4 bytes (32 bits), covering BMP and the
Fraction is 1.11 (with an implicit leading 1) = 1 + 1 × 2−1 + 1 × 2−2 = 1.75 supplementary characters.
The number is +1.75 × 2(16−16) = +1.75 × 20 = +1.75
4. Digital Electronics
b. 10111010000000
Sign bit 𝑆 = 1 ⇒ negative number 4.1. Boolean Algebra
𝐸 = 01110 = 13 (in normalized form) Boolean algebra also known as the algebra of logic was developed by an English mathematician
Fraction is 1.1 (with an implicit leading 1) = 1 + 1 × 2−1 = 1.5 called George Boole. It deals with binary variables and logic operators operating on these variables.
The number is −1.5 × 2(13−16) = −1.5 × 2−3 = −1.625 A binary variable has only two possible values 0 or 1. Logic operators operating on these variables
are AND (·), OR (+) and NOT (‘). Operations are defined for the values 0 and 1 as follows:
c. 1 11110 00000001
Sign bit 𝑆 = 1 ⇒ negative number AND
OR
0·0=0 NOT
𝐸 = 11110 = 30 (in normalized form) 0+0 =0
Fraction is 1.00000001 (with an implicit leading 1) = 1 + 2−8 0·1=0 0̅ = 1
0+1 =1
The number is −(1 + 2−8 ) × 2(30−16) 1·0=0 1̅ = 1
1+0 =1
1·1=1
1+1 =1
3.3. Representation of Characters
Characters are represented using a chosen character encoding scheme (character set, charset, 4.1.1. Laws and Theorems of Boolean Algebra
character map, or code page). The most commonly-used character encoding schemes are: ASCII, o Commutative law
Latin-x for western European characters, and Unicode for internationalization. 𝐴 · 𝐵 = 𝐵 · 𝐴|𝐴 + 𝐵 = 𝐵 + 𝐴

o Associative law
3.3.1. ASCII Character Code (𝐴 · 𝐵) · 𝐶 = 𝐴 · (𝐵 · 𝐶)|(𝐴 + 𝐵) + 𝐶 = 𝐴 + (𝐵 + 𝐶)
ASCII stands for American Standard Code for Information Interchange. The ASCII character code is a
7-bit code used to represent numeric, alphabetic, and special printable characters. It also includes o Distributive law
codes for control characters, which are not printed or displayed but specify some control function. A 𝐴(𝐵 + 𝐶) = (𝐴𝐵) + (𝐴𝐶) | 𝐴 + (𝐵𝐶) = (𝐴 + 𝐵)(𝐴 + 𝐶)
7-bit means a total of 27 = 128 characters can be represented.
 Code numbers 0 to 31 and 127 are special control characters, which are non-printable o Identity law
(non-displayable) 𝐴·1 =𝐴 | 𝐴+0= 𝐴
 Code numbers 65 to 90 represent 'A' to 'Z', respectively.
o Redundancy law
 Code numbers 97to 122 represent 'a' to 'z', respectively.
𝐴·0 =0 | 𝐴+1 =1
Code numbers 48 to 57 represent '0' to '9', respectively.

o Complement law
3.3.2. Latin-1
𝐴 ∙ 𝐴̅ = 0 | 𝐴 + 𝐴̅ = 1
Latin alphabet No. 1 or Latin-1 in short, is the most commonly-used encoding scheme for western
European languages. It has 191 printable characters from the Latin script, which covers languages
© 2014- BGS Molyko 15
Bilingual Grammar School Advanced Level Computer Science

o Idempotence law
𝐴·𝐴 =𝐴 | 𝐴+𝐴 =𝐴 4.1.3. Constructing Truth Tables
A truth table shows the output for all possible values of the input variables for a given Boolean
o Absorption law expression. To construct a truth table, we evaluate the Boolean expression for all possible
𝐴(𝐴 + 𝐵) = 𝐴 | 𝐴 + (𝐴𝐵) = 𝐴 combinations of values for the input variables. The number of possible combinations is always equal
to 2𝑛 where 𝑛 is the number of input variables.
𝐴 𝐵 𝐴̅ 𝐴̅𝐵 𝐴 + 𝐴̅𝐵
o Involution law
0 0 1 0 0 Example 1: Construct a truth table for the expression 𝐴 + 𝐴̅𝐵
𝐴̿ = 𝐴
0 1 1 1 1 We have 2 input variables 𝐴 and 𝐵 ⇒ we will have 22 = 4 different combinations.
1 0 0 0 1 o No name
1 1 0 0 1 𝐴 + 𝐴̅𝐵 = 𝐴 + 𝐵 | 𝐴(𝐴̅ + 𝐵) = 𝐴𝐵

𝐴𝐵 + 𝐴𝐵̅ = 𝐴 | (𝐴 + 𝐵)(𝐴 + 𝐵̅ ) = 𝐴

o De Morgan’s Theorems
𝐴 𝐵 𝐶 𝐴𝐶 𝐵 + 𝐴𝐶 ̅̅̅̅ = 𝐴̅ + 𝐵̅ | ̅̅̅̅̅̅̅̅
𝐴𝐵 𝐴 + 𝐵 = 𝐴̅ ∙ 𝐵̅
0 0 0 0 0 Example 2: Construct a truth table for the expression 𝐵 + 𝐴𝐶
0 0 1 0 0 4.1.2. Simplifying Boolean 3 input variables ⇒ 23 = 8 different combinations
Expressions
0 1 0 0 1
Simplifying a Boolean expression consists of using
0 1 1 0 1 the laws of Boolean algebra to write the
1 0 0 0 0 expression in its simplest form.
1 0 1 1 1
Example 1: Simplify the expression 𝐴𝐵 + 𝐴(𝐵 +
1 1 0 0 1
𝐶) + 𝐵(𝐵 + 𝐶)
1 1 1 1 1 Solution:
𝐴𝐵 + 𝐴(𝐵 + 𝐶) + 𝐵(𝐵 + 𝐶) = 𝐴𝐵 + 𝐴𝐵 + 𝐴𝐶 +
𝐵𝐵 + 𝐵𝐶
= 𝐴𝐵 + 𝐴𝐵 + 𝐴𝐶 + 𝐵 + 𝐵𝐶 (𝐵𝐵 = 𝐵)
= 𝐴𝐵 + 𝐴𝐶 + 𝐵 + 𝐵𝐶 (𝐴𝐵 + 𝐴𝐵 = 𝐴𝐵)
= 𝐴𝐵 + 𝐴𝐶 + 𝐵 (𝐵 + 𝐵𝐶 = 𝐵)
= 𝐵 + 𝐴𝐶 (𝐴𝐵 + 𝐵 = 𝐵) Example 3: Construct the truth tables for the following
i) 𝐴̅𝐵 + 𝐴𝐵̅
Example 2: Simplify the expression ii) 𝐴̅𝐵𝐶 + 𝐴𝐵𝐶̅ [𝐵(𝐴 xor C)]
̅̅̅̅̅̅̅̅
𝐴𝐵̅ + 𝐴(𝐵 ̅̅̅̅̅̅̅̅
+ 𝐶 ) + 𝐵(𝐵 + 𝐶 ) = 𝐴𝐵̅ + 𝐴(𝐵̅ 𝐶̅ ) + 𝐵(𝐵̅ 𝐶̅) De Morgan’s iii) 𝐴(𝐴 + 𝐶̅ )(𝐴 + 𝐵)
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 𝐵𝐵̅ 𝐶̅
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 0𝐶̅ (𝐵𝐵̅ = 0) 4.2. Logic Gates and Circuits
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 0 (0𝐶 ′ = 0) Logic gates and circuits are simply ways of representing Boolean functions and expressions
= 𝐴𝐵̅ (1 + 𝐶) (1 + 𝐶’ = 1) electronically.
= 𝐴𝐵̅ ∙ 1 (𝐴𝐵̅ ∙ 1 = 𝐴𝐵̅)
= 𝐴𝐵̅ (𝐴𝐵̅ ∙ 1) 2.1. Logic Gates
A logic gate is an electronic device that implements a simple Boolean function. Logic gates carry out
Example 3: Use De Morgan’s theorems to simplify the following the operations that the microprocessor performs. When a microprocessor is designed, a logic gate
i) (𝐴̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
+ 𝐵𝐶 + 𝐶𝐵 ) cell library (collection of all low level logic functions used to implement the logic) is also deeply
̅̅̅̅̅̅̅̅̅̅̅
̅ + 𝐴𝐶̅ ) planned and developed.
ii) (𝐴𝐵
There are six basic logic gates: AND, OR, NOT, NAND, NOR and XOR.
Example 4: Show that
i) 𝐴 + 𝐴𝐵 = 𝐴 a. AND Gate
ii) (𝐴 ̅̅̅̅̅̅̅̅
+ 𝐵 ) = 𝐵̅ (𝐴̅ + 𝐵)
iii) (𝐴 + 𝐵)(𝐴 + 𝐵̅ ) = 𝐴
© 2014- BGS Molyko 16
Bilingual Grammar School Advanced Level Computer Science

It is a logic gate whose output is “true” only when both inputs are “true”. If neither or only one of the
inputs is “false”, the output is “false”. The following illustration and table show the circuit symbol A B ¬(A+B
and logic combinations for an AND gate.
0 0 0
0 1 1
A B A.B Logic NOR
1 0 1
0 0 0
1 1 1
0 1 0
Logic AND 1 0 0 f. XOR Gate
1 1 1 Exclusive-OR is a logic gate whose output is “true” when one but not both of its inputs is “true”. The
output is "false" if both inputs are "false" or if both inputs are "true." Another way of looking at this
b. OR Gate circuit is to observe that the output is “true” if the inputs are different, but “false” if the inputs are
It is a logic gate whose output is “true” when either or both of the inputs are “true”. If both inputs the same.
are "false," then the output is "false."
A B Output
A B A Or B
0 0 0
0 0 0
0 1 1 Logic XOR
0 1 1
Logic OR 1 0 1
1 0 1
1 1 0
1 1 1
c. NOT Gate 2.2. Logic Circuits
It is a logic gate whose output is “false” if its input is “true” and vice versa. It is called logical inverter, Circuits are made by combining two or more logic gates. Gates are combined into circuits by using
because it reverses the state of its input. A NOT gate accepts one input and produces a single output. the output of one gate as the input for another.
Examples
A Output
0 1
1 0
Logic NOT (inverter)

d. NAND Gate
The NAND gate operates as an AND gate followed by a NOT gate. The output is "false" if both inputs
are "true." Otherwise, the output is "true.

A B ¬(A B)
0 0 0
0 1 1
Exercise 1: Construct logic circuits for the following expressions
Logic NAND
1 0 1 1) 𝐴̅𝐵 + 𝐴𝐵̅
2) (𝐴 + 𝐵)(𝐴 ̅̅̅̅̅̅̅̅
+ 𝐵̅ )
1 1 1
̅ ̅
3) 𝐴(𝐵 + 𝐴)
4) (𝐴̅ + 𝐵)(ABC
̅̅̅̅̅̅)
5) (𝐴 + 𝐵̅ )𝐴𝐶
e. NOR Gate
A NOR gate is equivalent to an OR gate followed by a NOT gate. Its output is "true" if both inputs are Exercise 2: What are the outputs for the following logic circuits
"false." Otherwise, the output is "false."

© 2014- BGS Molyko 17


Bilingual Grammar School Advanced Level Computer Science

© 2014- BGS Molyko 18


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 2: SYSTEM SOFTWARE
b. The Shell
Introduction The shell, command shell or command interpreter, is the part of the operating system that provides
Computer hardware require instructions to perform tasks. These instructions are provided by the an interface between users and operating system of a computer to access the services of the kernel.
programs or software installed in them. Software refers to the collection of computer programs and It understands and executes commands that are entered interactively by a human being or from a
data that run on a computer, and which make the hardware useful. They are the intangible program.
components of the computer system. There are two types of shell:
Computer software has two major categories namely system software and application software. 1. Command-line shell eg. Bash (sh), Command Prompt (cmd), C shell, Bourne shell, Korn
System software control and coordinate computer resources (hardware and operations) so that the shell (ksh) etc..
computer user and applications can smoothly interact. They help the computer carry out its basic 2. GUI-shell eg. Windows Explorer or Windows Shell
operating tasks. System software are designed to perform computer related tasks. They include
operating systems, firmware, utility programs, device drivers, library programs and language A third type of shell is recently developed - a GCLI (Graphical Command Line Interface) shell. A GCLI
translators. shell combines the features of both CLI and GUI shell and provides an interface which is both user-
friendly and powerful.
1. Operating System
The operating system is the essential software that is required for a computer to become When a user logs in, a shell is started up.
operational. It is the software layer that is on top of the hardware to provide functionality to
computer components, manage the hardware and serve as interface between the computer user and c. System Calls
the computer. The interface between the OS and the user program is defined by a set of instructions called system
calls. User programs use system calls to talk with the operating system.
Definition: An operating system is software that manages the computer hardware resources and
provides basic interface for execution of various application software. Definition: System call is the mechanism by which a program requests a service from the operating
system’s kernel.
The operating system is called a virtual machine as it hides the complexity of the hardware and
presents the user with an interface that is easier to understand and work with. When a running program needs a service from the operating system, it calls a system call.
The operating system is stored on disk, but it needs to be loaded into memory (RAM) once the
computer is switched on and before any other program can be run. The term bootstrapping refers to 1.2. Operating System Functions
the process of loading the operating system into a computer’s memory. This process is done by a 1.2.1. Memory Management
program called the bootstrap loader that is stored permanently in the computer’s electronic ROM For a program to be executed, it must be found in main memory (RAM). In a multiprogramming
chip. Examples of operating systems are Windows (95, 98, 2000, XP, Vista, 7 and 8), Macintosh environment in which several programs can reside in memory at the same time, every program and
Operating System (Mac OS), Linux and UNIX. its data must be protected from the actions of other programs. Memory management keeps track of
what programs are in memory and where in memory they reside.
1.1. Operating System Structure Memory allocation determines where a program as well as its related data will be kept in memory
The operating system can be divided into two main components: kernel and command interpreter for execution. Memory needs to be allocated efficiently to pack as many jobs in memory as possible.
(shell). Memory can be subdivided into segments or frames (pages).

a. Segmentation
Segmentation is when memory is divided into variable sized units called segments. When segments
are used, memory allocation can be done in three different ways:
o First fit allocates the first free segment that is large enough for the new process.
o Best fit allocates the smallest block among those that are large enough for the new
process.
o Worst fit allocates the largest block among those that are large enough for the new
process.
OS structure
b. Paging
a. OS Kernel Paging is when memory is divided into fixed-size units called frames. Jobs are broken up into blocks
The kernel is the central part of an operating system that is running at all times on the computer. It of same size as frames called pages which are allocated a number of frames. The OS then uses a page
loads first and remains in memory as long as the computer is on. It consists of utilities (file manager, table to map program pages to memory frames. The pages for each job could be in logical order or
memory manager, device drivers, process manager etc.) that perform basic required functions. In they may be scattered about wherever there is a free frame.
many operating systems, only the kernel can access hardware directly.

© 2014- BGS Molyko 19


Bilingual Grammar School Advanced Level Computer Science
running state, its register values are loaded into the CPU while register values for the currently
c. Virtual Memory running process are stored into its PCB. This exchange of information is called a context switch.
A program may require more memory than it is available. To solve this problem, virtual memory is
used. Virtual memory is part of the hard disk that is used as an extension of RAM. It is slower, but it b. Process Synchronization
is considerably bigger. As execution goes on, data is being swapped between RAM and virtual In a multi-tasking system, processes compete for resources. A resource is anything that is required
memory. by a process to accomplish its task (processor, memory, I/O device, bus, file etc). Some resources
When a program is running, only the pages that contain the necessary data are kept in RAM while can only be used in a non-sharable or exclusive mode. That is, they cannot be used by more than one
those that are not needed are kept on disk. For example, a program that has been minimized for a process at a time. Such resources are known as critical resources. A critical section is a part of a
long time may be transferred to virtual memory so as not to fill up the main memory. program where it has access to a non-sharable (critical) resource. To prevent two or more
Disk thrashing occurs when the OS has to spend a considerable proportion of its time swapping data processes from entering their critical sections over the same resource, processes must be
between virtual and real memory. synchronized.

1.2.2. Process Management Definition: Process synchronization is about getting processes to coordinate together in order to avoid
A process is a program in execution. It consists of the program’s instructions and the resources two or more processes entering into critical section over the same resource.
allocated to it for execution. A program is static while a process is active. The operating system
performs process management to carefully track the progress of a process and all of its intermediate If processes are not synchronized, it leads to deadlock and starvation.
states.
A process changes state as it executes. The different states a process can have are shown in the c. Deadlock
diagram below. Deadlock is a permanent blocking of a set of processes competing for resources. It is a situation in
which each of two processes is waiting for the other to do something; thus, neither one can proceed.
For a deadlock to occur, the following four conditions must hold.
 Mutual Exclusion: At least one resource must be held in a non-sharable way.
 Hold and Wait: A process must be holding a resource and waiting for another.
 No Preemption: No resource can be forcibly removed from a process holding it.
 Circular Wait: A waits for B, B waits for C, C waits for A.

Deadlock can be prevented by ensuring that one of the above conditions does not hold. For example
using pre-emptive scheduling.

d. Starvation
Process states
Starvation is a situation where a task can never finish because it can never get a necessary resource
such as a large block of memory. The operating system should detect such tasks and do its best to
o New - The process is being created.
allocate the resources that they need.
o Ready - Process has all needed resources - waiting for CPU only.
o Running - Instructions are being executed.
1.2.3. CPU Scheduling
o Waiting - Process is waiting for some event to occur (human, hardware or another
CPU scheduling is the act of determining which process in the ready state should be moved to the
process)
running state. It decides which process in memory is to be executed by the CPU at any given
o Terminated - Process has finished execution
moment. Scheduling decisions may take place when a process:
1. Switches from running to waiting state
Definition: The turnaround time for a process is the amount of time between the time the process
2. Switches from running to ready state
arrives the ready state and the time it exits the running state for the last time.
3. Switches from waiting to ready
In other words, it is the length of time it takes to run a process from initialization to termination,
4. Switches from running to terminated
including all the waiting time.
Scheduling can be preemptive or non-preemptive.
Question: What is a scheduler?
 Preemptive scheduling is scheduling in which the currently executing process is forced to
a. Process Control Block give up the CPU. Scheduling under (2) and (3) is preemptive.
The operating system manages a large amount of data about a process like the program counter
(PC), CPU registers, memory management information, I/O status, scheduling data and process  Non preemptive scheduling is scheduling in which the currently executing process gives up
state. This data is stored in a data structure called a process control block (PCB) also called process the CPU voluntarily. Scheduling under (1) and (4) is non-preemptive.
descriptor or state vector. Every process has its PCB and each time a process is moved to the

© 2014- BGS Molyko 20


Bilingual Grammar School Advanced Level Computer Science
There exist different algorithms used for scheduling. Examples are first come, first served, shortest An interrupt is a signal generated by hardware or software that causes the CPU to suspend what it is
job first and round robin algorithms. doing to handle another task of higher priority. Any event that will cause an interrupt is called an
interrupt request (IR). For example, a key pressed on the keyboard. An interrupt handler or
a. First Come, First Served interrupt service routine (ISR) is a program that services an interrupt request. It contains the
First come first served algorithm moves processes to the CPU in the order in which they arrive in actions that will be executed for a given interrupt request.
the ready queue. It is non-preemptive. As such, when a process has the CPU it runs to completion
before giving up the CPU. b. Polling
Consider that the following processes arrive in the order they are given below.
c. Buffering
A buffer is an area of memory used to temporarily store data while it is being moved from one place
Process Service time
to another.
P1 140
1.2.5. File Management
P2 75
The file system is the portion of the operating system that manages how files are stored. Examples
P3 320 of file systems are FAT used in MS DOS, NTFS used in Windows, ext2 used in Linux and HPFS used in
OS/2. The operating system is responsible for the following activities in connection with file
P4 280
management:
P5 125 o File creation and deletion.
o Directory creation and deletion.
o Support of primitives for manipulating files and directories
Using FCFS algorithm to schedule the processes, we get
o Mapping files onto secondary storage.
o File backup on stable (nonvolatile) storage media.

1.2.6. Providing User Interface


Working on a computer, a user has to interact with the computer. A user interface is the means of
b. Shortest Job First communication or interaction between the user and the computer. The operating system provides
Shortest job first (SJF) algorithm looks at all the processes in the ready state and dispatches the one this means that enables an individual to see and work when using a computer.
with the smallest execution time. It is also generally implemented as a non-preemptive algorithm. Different operating systems provide different types of user interfaces.
Using the SJF algorithm, we have
a. Command Line Interface (CLI)
A command line interface allows the user to interact with the computer by typing the commands in
a specified format. It provides a prompt through which the user types the commands. Here the user
mostly makes use of the keyboard.
In this type of interface, the user has to remember the name and format of the commands. Spelling
Disadvantage mistakes and deviations in format lead to errors and the task is not performed. Examples of
 Some jobs may never be executed as they have a high service time (starvation). operating systems that provide a command line interface are MS DOS, early versions of UNIX and
Linux.
c. Round Robin
Round-robin algorithm distributes time equitably among all ready processes by establishing a b. GraphicalUserInterface (GUI)
particular time slice (or time quantum), during which each process executes. At the end of the A graphical user interface allows the user to interact with the computer through graphical items
quantum, the process is preempted. It returns to the ready state to allow another process its turn. such as icons, menus, dialog boxes, etc. Here, the user mostly makes use of the mouse to point and
Using round-robin algorithm with time slice of 50, the above processes will be scheduled as follows: click on these graphical items. GUI is also known as WIMP system where WIMP stands for windows,
icons, menus and pointers.
This type of user interface requires a lot of memory space to store the graphics and can cause
machines with low processing power to be slow. Examples of operating systems with a graphical
user interface are Windows, Macintosh operating systems, some versions of Linux and UNIX.

c. VoiceRecognition Interface
1.2.4. Management of I/O Devices
A speech recognition interface allows the user to give verbal commands to the computer. The user
communicates with the computer through natural language. They are also called natural language
a. Interrupts
interface

© 2014- BGS Molyko 21


Bilingual Grammar School Advanced Level Computer Science

1.2.7. Providing Security 1.3.6. Embedded OS


Security is the most desirable characteristic of any operating system. An operating system should An embedded operating system is an operating system that is used in an embedded system. An
provide a means for safeguarding system resources from unauthorized users and protection of one embedded system is a small computing device that is built into a larger equipment often as a single
user's resources from other users of the system. chip and dedicated to a given task. Embedded systems control many devices in use today such as
Popular operating systems offer security features through incorporation of the following: digital watches, mobile phones, microwave ovens, washing machines, vehicles, photocopiers,
o Login name. cameras and process controllers.
o Login password. Embedded OS are ROM based. That is, they cannot be modified as ROM is read only.
o Read/write access file permissions.
o Encryption of data 1.3.7. Network OS
o Virus protection software layers. A network operating system is an operating system which includes networking features. It contains
special functions, protocols and device drivers that enable the computer to be connected to a
1.3. Types of Operating Systems network.
1.3.1. Single User OS Examples of network operating systems are Windows-NT, Windows-2000 server, Windows server
A single user operating system is an operating system which allows only one user to work on the 3000, Novell Netware and Artisoft LANstatic.
system at a time. No two or multiple users can work on the system simultaneously. Some multi-purpose operating systems like Windows XP, Windows 7 and Mac OS 10, come with
Examples are Control Program for Microcomputers (CP/M) and Microsoft Disk Operating System capabilities that enable them to be described as network operating systems.
(MS DOS).
2. System BIOS
1.3.2. Multi User OS Basic input output system (BIOS) is software that contains hundreds of programs that allow for
A multi-user operating system is an operating system which allows multiple users to work on the communication between the CPU and devices. It is stored on ROM, which is a permanent chip on the
system simultaneously. This type of operating system is larger and more complex than a single user motherboard.
operating system. There are three kinds of BIOS for hardware devices:
Features of multi-user operating systems, which are not provided in single user operating systems,  Permanent never changing BIOS for never changing hardware like the keyboard
are:  BIOS for hardware that changes occasionally. It requires extra volatile information so it is
o Time sharing (CPU devotes time to all the users in round robin fashion). stored on a separate chip called CMOS (Complementary Metal Oxide Semiconductor).
o Tight security features.
o Resource sharing among users. 3. Utility Programs
o System administrator privileges Utility software is used to enhance the operating system, or in some other way improve the
Examples of multi-user operating systems are Linux, Unix and Virtual Machine System (VMS). usefulness of the system. They help analyze, configure, optimize and maintain the computer. Rather
than providing user-oriented or output-oriented functionality, utility software focuses on how the
1.3.3. Single task OS computer infrastructure operates. Most major operating systems come with several pre-installed
A single task operating system allows a user to execute one and only program at a time. The user utilities. Examples of utility software include: disk defragmenters, backup utilities, disk compression
cannot run two or more programs at the same time. It is not possible to be preparing a worksheet utilities, disk cleaners, file managers, disk formatters and virus checkers.
on the computer while printing a report or listening to music. Once a user invokes a program, the  Disk defragmenters detect computer files whose contents are broken across several locations
computer gets dedicated to that task only. on a disk, and move the fragments to one location to increase efficiency.
CP/M and MS-DOS are examples of single user single task operating systems.  Disk cleaners find and delete files that are unnecessary to computer operation, or take up
considerable amounts of space. They help users decide what to delete when their hard disk is
1.3.4. Multiprogramming OS full.
A multi-programming operating system is an operating system that allows multiple programs to be  Backup utilities make copies of all information stored on a disk, and restore either the entire
held in main memory at the same time. The concept of multi-programming is that the operating disk (e.g. in an event of disk failure) or selected files (e.g. in an event of accidental deletion).
system keeps several jobs in memory simultaneously and decides which can be executed at a given  Disk compression utilities reduce the space that a file takes up on disk, increasing the
moment. capacity of the disk.
 File managers provide a convenient method of performing routine data management tasks,
1.3.5. Multitasking OS such as deleting, renaming, moving, copying, merging, generating and modifying files.
A multitasking operating system allows a user to execute more than one program at a time. It allows  Disk partition utilities divide an individual drive into multiple logical drives, each with its
a user to be preparing a worksheet on the computer while printing a report or listening to music. own file system which can be mounted by the operating system and treated as an individual
Multitasking is an extension of multiprogramming as two programs cannot be executed drive.
simultaneously if they are not found in memory at the same time.  Disk formatters
Windows Me, Windows-XP, Macintosh operating system, OS/2 are examples of single user,  Virus checkers prevent, detect, and remove malware.
multitasking operating systems.

© 2014- BGS Molyko 22


Bilingual Grammar School Advanced Level Computer Science
4. Device Drivers
A device driver is software that allows interaction between the operating system and a hardware
device. It is an interface for communicating with the device through the specific computer bus that
the hardware is connected to. Without an appropriate device driver the system cannot
communicate with a device, rendering the device useless. Installation of device drivers usually
happens automatically when hardware is connected (plug n play), or from a CD provided with the
device. Sometimes a device driver needs to be updated to stay functional.

5. Library Programs

6. Language Translators
A language translator is a computer program that translates program instructions from one
programming language to another. There are three types of language translators: compilers,
interpreters and assemblers.
 Compilers translate instructions written in a high-level language into machine language
instructions.
 Interpreters translate instructions written in a high-level language into machine language
instructions and execute them, one line at a time.
 Assemblers translate instructions written in assembly language to machine language
instructions.

© 2014- BGS Molyko 23


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 3: COMMUNICATION SYSTEMS 1.2.1. Network Operating System
A network operating system is an operating system which includes networking features. It contains
1. Computer Networks special functions, protocols and device drivers that enable the computer to be connected to a
A computer network is a collection of computers and other devices that are connected together so network. NOS provide the ability to share resources and the ability to manage a network name
they can communicate and share resources. The smallest network can be as simple as two directory, security, and other housekeeping aspects of a network.
computers linked together. The resources shared include files, folders, printers, disk drives and Examples of network operating systems are Windows-NT, Windows-2000 server, Windows server
anything else that exists on a computer. Any computer or device on a network is called a node. 3000, Novell Netware and Artisoft LANstatic.
Networking is the term that describes the processes involved in designing, implementing, Some multi-purpose operating systems like Windows XP, Windows 7 and Mac OS 10, come with
upgrading, managing and otherwise working with networks and network technologies capabilities that enable them to be described as network operating systems.

1.1. Types of Computer Networks 1.2.2. Network Interface/Adapter Card


Different criteria exist for classifying computer networks. According to geographical area covered, A network interface card (NIC) provides the physical interface (link) between the computer and the
networks can be classified as local area networks, wide area networks, metropolitan area networks, communication medium. A NIC manages the communication and network protocol for the PC.It
personal area networks etc. prepares data, sends data and controls the flow of data. It plugs into the system board and provides
ports for connection to the network. A NIC is also called a LAN card or network adapter card. There
1.1.1. Local Area Network are two kinds of NIC: wired NIC for wired networks and wireless NIC (WNIC) for wireless networks.
A local area network (LAN) is a network that is used for communication among computer devices, A NIC may be designed as an Ethernet card, a Token Ring card, or an FDDI card (but not all three).
usually within an office building or home. It enables the sharing of resources such as files or
hardware devices that may be needed by multiple users in an organization. A LAN is limited in size, 1.2.3. Hub
spanning a few hundred meters, and not more than a mile. It is fast, with speeds from 10 Mbps to 10 A hub is a device that works as central connecting point for multiple computers in a network. It has
Gbps. An example of LAN is the network in the Multimedia Resource Centre. ports to which the computers in the network are connected. Data sent to the hub is broadcasted to
all the ports but, only the destination computer receives it. There are three kinds of hubs:
1.1.2. Metropolitan Area Network  Passive hubs which only split the transmission signal so it can be sent to all the ports
A metropolitan area network (MAN) is a large computer network that usually spans a city or a large  Active hubs (also called Multiport Repeaters) which regenerate data bits to maintain a strong
campus. It is optimized for a larger geographical area than a LAN, ranging from several blocks of signal over extended cable lengths
buildings to entire cities. A MAN typically covers an area of between 5 and 50 km diameter. An  Intelligent hubs (also called Concentrators) usually have their own microprocessor chips and
example of a MAN is a cable TV network. network operating systems. They can be managed remotely on the network.

1.1.3. Wide Area Network 1.2.4. Switch


A wide area network (WAN) covers a large geographic area such as a country, a continent or even A switch is used at the same place as a hub but the difference between the two is that a switch has a
the whole world. It is a distributed collection of LANs. That is, it connects two or more LANs switching table within it. A switching table stores the Media Access Control (MAC) address of every
together. This is done using devices such as bridges, routers or gateways, which enable them to computer connected to the switch and sends the data only to the requested address, unlike the hub
share data. The largest and most well-known example of a WAN is the Internet. which broadcasts the data to all the ports. Switches can therefore be considered as an advanced
form of hubs.
1.1.4. Personal Area Network A MAC address is a built-in number (i.e. set by the manufacturer) consisting of 12 hexadecimal
A personal area network (PAN) is a network that is used for communication among computers and digits that uniquely and permanently identifies the network adapter of a computer. Examples of a
computer devices in close proximity of around a few meters within a room. A PAN usually includes MAC addresses are 00-14-22-DA-67-15 and 00-13-02-31-E8-BA.MAC address is also called the
laptops, mobile phones, personal digital assistants, digital cameras and headsets. It can be used for physical address. Under Windows, the MAC address of a computer can be displayed by typing
communication between the devices themselves, or for connection to a larger network such as the ipconfig/all at a Command prompt.
Internet. The most popular is the Wireless PAN (WPAN), a Bluetooth connection between two
laptop computers or phones. 1.2.5. Repeater
A repeater is a device used to expand the boundaries of a wired or wireless network. With physical
1.2. Computer Network Components media, data transmissions can only span a limited distance before the quality of the signal degrades.
All types of computer networks require special networking software and hardware to allow Repeaters are used to preserve signal integrity and extend the distance over which data can safely
different computers to communicate with each other. The most important software component travel by regenerating the signals they receive. Active hubs are considered as repeaters (multiport
required for a network is the network operating system (NOS) while there are many types of repeaters).
hardware devices which are either installed or connected to the computer terminals in order to
construct a network. 1.2.6. Bridge
A bridge, also called a layer 2 switch, is a device used to create a connection between two separate
computer networks or to divide one network into segments. Creating multiple segments in a local
network reduces the network traffic making the network to be faster and more efficient. A bridge

© 2014- BGS Molyko 24


Bilingual Grammar School Advanced Level Computer Science
performs its segmenting function by examining the data packet and forwarding it to other physical 1.3.1. Bus Topology
segments only if necessary. In bus topology, all computers are connected to a single cable (trunk or backbone) known as bus, by
a transceiver either directly or by using a short drop cable. Bus transmits in both directions such
1.2.7. Router that any transmission can be received by all stations. All ends of the cable must be terminated, that
A router is a device that joins several networks together and is responsible for routing data from is plugged into a device such as a computer or terminator, to avoid signals from bouncing back.
one network to another. It keeps track of the IP addresses of the computers on the networks
connected to its network interface cards and directs data packets appropriately. It is more powerful
than a bridge because instead of just choosing network segments based on previous traffic, a router
can look up the best route for a packet to take. Routers can be computers with operating systems
and special network software, or they can be other dedicated devices built by network
manufacturers. The Internet relies heavily on routers.
Bus topology
a. Advantages
1.2.8. Modem  Easy and inexpensive to set up as little cabling is required
A modem (modulator/demodulator) is a device that encodes data for transmission over a particular  Easy to include additional stations without disrupting the network
medium, such as telephone line, coaxial cable, fiber optics, or microwaves. It converts digital signals  Failure of one node does not affect network
from a computer to analog signals or waveform for transmission over a medium (modulation) and
converts analog signals from the medium to digital signals understandable by the b. Disadvantages
computer(demodulation).  High rate of data collision
Common types of modems are:  Fails if there is any damage to the bus
 Dial-up Modem  Any break in the bus is difficult to identify
 Cable Modem
 DSL Modem 1.3.2. Star Topology
 Sat modem In a star topology, all the computers are connected to a central device which could be a computer, a
hub or a switch. Any communications between computers in this topology must pass through the
1.2.9. Multiplexer central node. As such, the central node controls all the activities of the network.
A multiplexer abbreviated MUX, is a device that takes input signals from different sources and
transmits them over a single transmission line. This process is known as multiplexing. There are
different types of multiplexing:
 Frequency-division multiplexing (FDM), in which the carrier bandwidth is divided into sub
channels of different frequency widths, each carrying a signal at the same time in parallel.
 Time-division multiplexing (TDM), in which the multiple signals are carried over the same
channel in alternating time slots.
 Code-division multiplexing (CDM), in which the multiple signals are carried over the same Star topology
channel but every signal is coded differently. a. Advantages
 Breakdown of a node does not affect the network
1.2.10. Cables  No disruption of the network when connecting or removing devices
Cables are used to link computers in a LAN. There are three types of cables commonly used:  It is easy to detect faults
 Coaxial cable
 Twisted pair cable b. Disadvantage
 Fiber optic cable  Failure of the central node affects the entire network
 It is costly due to the amount of cables required to connect the devices
1.2.11. Gateway
A gateway is a device that connects two dissimilar computer networks using direct and systematic 1.3.3. Ring Topology
translation between protocols. A gateway translates outgoing network traffic to the protocol needed In ring topology, all the nodes are connected in the form of a closed loop such that each node is
by the destination network. The term gateway is also sometimes loosely used to describe any device connected to two others. It uses an empty data packet called a token and a special protocol called
that acts as the entry or exit point for a network. token ring. Packets travel around the ring in a clockwise direction. To transmit, a node requires an
empty token.
1.3. Network Topologies
Network topology is the layout or arrangement of the components of a network. It refers to the way
in which computers and cables are connected together to build a network. Different types of
topologies exist.

© 2014- BGS Molyko 25


Bilingual Grammar School Advanced Level Computer Science
1.4.4. Wireless Network Standards
Wireless networks are established without physical wiring techniques involved. They use radio and
infrared signals and are based around one of these technologies: Bluetooth, Wi-Fi, WiMax,
terrestrial microwaves and satellite.

a. Bluetooth
Bluetooth is a low power, short-range wireless technology largely used to interconnect computing
Ring topology
devices into a personal area network. It is based on IEEE standard 802.15 which gives specifications
a. Advantage for Wireless Personal Area Network (WPAN).
 No collision as a station needs the token to transmit
 Each computer acts like a repeater so signals are not attenuated b. Wi-Fi
Wi-Fi stands for Wireless Fidelity. It is based on a set of wireless networking technologies known as
b. Disadvantage 802.11. These include 802.11b, 802.11a, 802.11g and 802.11n. The range of Wi-Fi network
 If a node in the network fails, the entire network fails transmission is about 30-40m indoors and up to about 100m outdoors.
 Network is disrupted when additional stations are added The table below shows the different 802.11 standards for wireless networking.

1.4. Network Technologies Specification Popular name Frequency Speed Compatible with
802.11a Wireless-A 5 GHz 54 Mbps
1.4.1. Ethernet Network
802.11b Wireless-B 2.4 GHz 11 Mbps Wireless-A
Ethernet (IEEE 802.3 standard) is the most common and widely used technology to establish a local
area network. An Ethernet network is formed by physically connecting the individual computer 802.11g Wireless-G 2.4 GHz 54 Mbps Wireless-B, -G
units to each other in a bus topology or a star topology. Ethernet’s media access policy is CSMA/CD 802.11n Wireless-N 2.4 GHz 100 Mbps Wireless-B, -G, -N
(Carrier Sense Multiple Access with Collision Detection).
 CS: means that a station listens to (senses) the medium and transmits only if medium is idle c. WiMax
 MA: means that any station can use (access) the medium WiMax stands for Worldwide Interoperability for Microwave Access. It is based on IEEE standard
 CD: means that each station stops transmitting immediately it senses a collision 802.16 and facilitates high speed wireless network links to both fixed and mobile devices. The range
of a WiMax wireless connection is around 3-10km.WiMax service providers are now just entering
When a collision is detected, the two stations involved will retransmit after a random time wait the market, offering customers an alternative to a DSL Internet connection.
created by a backoff algorithm.
1.5. Network Architectures
1.4.2. Token Ring Network 1.5.1. Client/Server Architecture
Token ring (IEEE 802.5 standard) is a network technology developed by IBM in which computers Client/server is a network architecture in which a more powerful computer called server is
are connected together in a ring. Token ring’s media-access method is called token passing. A dedicated to serving less powerful computers called clients. Servers hold shared resources like files,
special message, called token, circulates along the ring from one computer to another and each programs and the network operating system. They provide access to network resources to all the
computer can transmit only while it is holding the token. Information flows in one direction along users of the network. There are many different kinds of servers, and one server can provide several
the ring from source to destination and back to source. When a station wishes to transmit, it waits functions. For example, there are file servers, print servers, mail servers, database servers and Web
for the empty token to pass by. It seizes it and inserts data into it and then releases it to the medium. servers. Users run applications on client workstations which rely on servers for resources such as
The token circulates until it gets to the destination computer that picks it and retrieves the data. files, devices and even processing power.
After retrieving the data, it regenerates the token and sends it back to the medium. Internet services are organized according to a client/server architecture. Client programs, such as
Web browsers and file transfer programs create connections to servers, such as Web and FTP
1.4.3. Fiber Distributed Data Interface servers. The clients make requests and the server responds to the requests by providing the
FDDI is a network technology that uses fiber-optic cables in a ring topology with dual rings on which services requested by the client.
information can travel in opposite directions. The media access method for FDDI is token passing.
The primary ring is used for data transmission, and the secondary ring remains idle. Because of this 1.5.2. Peer-to-Peer Architecture
double ring topology, if a station fails or a cable becomes damaged, the dual ring is automatically Peer-to-peer (P2P) is a network configuration in which all the workstations (computers) have equal
wrapped around itself, forming a single ring. This prevents downtime as a result of a failed machine capabilities and responsibilities. Each workstation acts both as a server and a client. This means that
or faulty wiring. any computer on the network can provide services to any other computer. Peer-2-peer is usually
implemented where strict security is not necessary. P2Pnetworks are generally simpler and less
expensive, but they usually do not offer the same performance under heavy loads.

© 2014- BGS Molyko 26


Bilingual Grammar School Advanced Level Computer Science
Remark A hybrid network combines client/server and peer-to-peer architectures. It is the most 2.1.1. Analogue Signals
commonly used network architecture. An analog signal is one in which information is represented as a continuous variation of some
physical property or quantity. Analog signals are continuous waves that carry information by
1.6. Benefits and Limitations Of Computer Networks varying the frequency or amplitude of the wave.
1.6.1. Benefits  When the amplitude of the signal is varied the technique is called amplitude modulation (AM)
 Sharing devices such as printers saves money.  When the frequency of the signals is varied, the technique is called frequency modulation
 Site (software) licenses are likely to be cheaper than buying several standalone licenses. (FM).
Human speech is an example of an analog signal. Telephone lines use analog signals because they
 Files can easily be shared between users.
were originally designed for speech.
 Network users can communicate by email and instant messaging.
 Data is easy to backup as all the data is stored on the file server.
 Organizations can organize videoconferences ( videoconferencing)
 Employees can work from home (telecommuting)

1.6.2. Limitations
 Purchasing the network cabling and file servers can be expensive.
 Managing a large network is complicated. It requires training and a network manager
usually needs to be employed. Analogue signal
 If the file server breaks down the files on the server become inaccessible. Email might still
work if it is on a separate server. The computers can still be used but are isolated. 2.1.2. Digital Signals
 Viruses can easily spread to other computers throughout the network, if one computer is A digital signal is one in which information is represented as a sequence of binary values 0 and
infected.. 1.These two values represent two conditions, on or off, corresponding to two known levels of
 There is a danger of hacking, particularly with wide area networks. Security procedures are voltage or current.
needed to prevent such abuse, eg a firewall. Digital signals do not continuously vary as analogue signals. Signals are transmitted within the
computer as digital signals. Systems that use digital technology are known as baseband systems.
2. Data Communication
Data communication refers to the exchange of data between two devices via some form of
communication channel. In data communication the following basic terms are frequently used:
 Data: a collection of facts in raw form that becomes information after processing.
 Signal: an electric or electromagnetic encoding of data.
 Signaling: propagation of signals across a communication channel.
 Transmission: sending of data from one place to another by means of signals.

There are five basic components in a communication system. Digital signal


 Data Source: creates data for transmission
 Transmitter: encodes data for transmission 2.2. Broadband and Baseband Transmissions
 Communication channel: connecting medium between communicating devices 2.2.1. Baseband System
 Receiver: decodes transmitted signals back to data A baseband system is a single-channel system that supports a single transmission at any given time.
 Destination: the final destination of the transmission In a baseband system, data is sent as a digital signal through the media as a single channel that uses
the entire bandwidth of the media. Baseband communication is bi-directional, which means that the
Example: John calls Peter on phone. same channel can be used to send and receive signals. In Baseband, frequency-division multiplexing
The data source is John, the transmitter is John’s phone, the communication channel is the is not possible.
telephone cable or microwave, the receiver is Peter’s phone and the destination is Peter.
2.2.2. Broadband System
2.1. Analog and Digital Signals A broadband system is a system that supports multiple transmissions via multiple frequency
Data is transmitted from one point to another by means of electrical signals that may be in analogue channels. In a broadband system, data is sent in the form of an analog signal where each
or digital form. transmission is assigned a portion of the bandwidth. Broadband communication is unidirectional, so
in order to send and receive, two pathways are needed. This can be accomplished either by
assigning a frequency for sending and assigning a frequency for receiving along the same cable or by
using two cables, one for sending and one for receiving.

© 2014- BGS Molyko 27


Bilingual Grammar School Advanced Level Computer Science
2.3. Transmission Modes and Techniques channel is therefore used to transfer timing signals to keep the both parties synchronized. Accuracy
Transmission modes simply refer to the direction of flow of information between two is dependent on the receiver keeping an accurate count of the bits as they arrive.
communicating devices. It could be simplex, half duplex or full duplex.
Serial transmission is slower than parallel transmission but it is suited for long distances. It is
2.3.1. Simplex cheaper as only one transmission line is required. Synchronous transmission is faster than
In simplex mode, signals are transmitted in only one direction all the time. The flow of information asynchronous transmission because fewer bits have to be transmitted; only data bits and no extra
is unidirectional from transmitter to receiver always. Examples are television broadcasting, control bits. For this reason it is the choice for network communications links.
computer to the printer connection and CPU to monitor communication.
2.4. Communication Switching Techniques
A B Long distance transmission is done over a network of switched nodes. Data is routed by being
switched from one node to another. Three switching techniques exist: packet switching, circuit
2.3.2. Half Duplex switching and message switching.
In half duplex mode, signals can be transmitted in both directions but only one way at a time. The
flow of information is bidirectional but information can only be sent if it is not being received. It is 2.4.1. Packet Switching
suitable for data transmission between a computer and dumb terminals. An example is the police Packet switching is a switching method in which the message to be transmitted is broken into small
radio (walkie-talkie). data packets and sent over the network. Each packet contains a portion of data and some control
information. The packets may take different routes to arrive their destination and they may arrive in
A B any other. On arrival, they are put back into order and the message is reconstituted. Each packet is
sent with a header address which tells what its destination is. The header address also describes the
2.3.3. Full Duplex sequence for reassembly at the destination. One packet contains information on how many packets
In full duplex mode, signals can be transmitted in both directions simultaneously. The should be arriving. If a packet fails to arrive, the destination computer sends a message to the
communicating devices can transmit at the same time. The flow of information is bidirectional. It is sender’s computer asking it to send the missing packet again. This method is suitable for
suitable for interactive systems. An example is the telephone. transmission of data.

A B 2.4.2. Circuit Switching


Circuit switching is a switching method in which a dedicated communication path in physical form
2.3.4. Parallel Transmission between two stations within a network is established, maintained and terminated for each
Parallel transmission is the method of transferring several bits at the same time over separate communication session. This channel remains open throughout the communication process and
channels. For example, eight separate channels will be required if a block of eight bits is to be cannot be used by anyone else. It has basically three phases: circuit establishment, data transfer and
transmitted in parallel. Parallel transmission is fast but it is suited only for short distances as cabling circuit disconnect. The message is sent without being broken up, so it is received in the order it was
for long distances will be expensive. It is mainly used for connections within the computer and for sent. This method was designed for voice transmissions. Telephone networks use circuit switching
connecting the computer to the printer. for transmission of phone calls.

2.3.5. Serial Transmissions 2.5. Transmission Media


Serial transmission is the method of transferring data one bit at a time through the same channel. If A transmission medium is the physical pathway that connects computers and other devices on a
a block of 8 bits is to be transmitted in series, the bits will be transmitted one after the other on the network. Each transmission medium requires specialized network hardware that is compatible with
same channel. Serial transmission can be asynchronous or synchronous. that medium, and most networks need to use a combination of transmission media types selected
based on the network's needs. There are two categories of transmission media: guided and
a. Asynchronous Serial Transmission unguided media.
Asynchronous transmission describes the process where transmitted data is encoded with start and
stop bits, specifying respectively the beginning and end of each character. Data is sent character by 2.5.1. Guided Media
character with each character preceded by a start bit and a stop bit is added to the end. Other Guided media are the physical links through which signals are confined to narrow path. They are
control bits like the parity bit are added to the group before the stop bit and small gabs are inserted made up of an internal conductor bounded by jacket material. They are also called bounded or
to distinguish each group. conducted media. Three common types of guided media are coaxial cable, twisted pair cable and
fiber optical cable.
b. Synchronous Serial Transmission
Synchronous transmission describes a continuous and consistent timed transfer of data blocks. Data a. Coaxial Cable
is sent as one long bit stream or block of data without start or stop bits and with no gabs. Upon Coaxial cable consists of an inner core and an outer flexible braided shield, both of conductive
reception, the receiver counts the bits and reconstructs bytes. It is essential that the same timing is material separated by an insulator. The braided shield prevents the cable from picking up or
maintained by both sender and receiver as there are no start and stop bits and no gaps. Another emitting electrical noise. There are two types of coaxial cable:
 thinnet and

© 2014- BGS Molyko 28


Bilingual Grammar School Advanced Level Computer Science
 thicknet.

Coaxial cable
To connect coaxial cable to devices, we need coaxial connectors. The most common type of
Optic fiber
connectors used today is the Bayone-Neill-Concelman, or BNC connector.
The light source can be LED (light emitting diode) or LD (laser diode)
b. Twisted Pair Cable
Twisted-pair cable is the most common type of cabling used in LAN networks today. It consists of a 2.5.2. Unguided Media
pair or pairs of insulated wires twisted together. Cable twisting helps reduce noise pickup from Unguided media do not use physical means to define the path to be taken. They provide a means for
outside sources and crosstalk on multi-pair cables. There are two types of twisted pair cables: transmitting electromagnetic waves but do not guide them. They are also called unbounded media.
shielded twisted pairs (STP) and unshielded twisted pairs (UTP). Examples of unguided media are infrared waves, radio waves and microwaves.

Twisted pair cable uses RJ-14 a. Infrared


and RJ-45 connectors Infrared uses transmitters/receivers (transceivers) that modulate non-coherent infrared light.
Infrared signals do not penetrate walls as such transceivers must be within line-of-sight either
directly or via reflection. Line of sight is a type of propagation that can transmit and receive data
only where transmit and receive stations are in view of each other without any sort of an obstacle
Twisted pair cable between them.

 Unshielded Twisted Pair b. Radio waves


UTP cables consist of 2 or 4 pairs of twisted cable. Cable with 2 pair use RJ-11 connector and 4 pair Radio wave systems transmit signals by modulation of electromagnetic waves with frequencies
cable use RJ-45 connector. RJ stands for registered jack. There are five levels of UTP: below that of visible light. Radio waves carry information by systematically changing some property
of the radiated waves such as amplitude (AM radio), frequency (FM radio) and phase. Radio waves
Category 1: These are used in telephone lines and low speed data cable. are omnidirectional. This means that signals spread out in all directions and can be received by
Category 2: These cables can support up to 4 mps implementation. many antennas.
Category 3: These cable supports up to 16 mps and are mostly used in 10 mps.
Category 4: These are used for large distance and high speed. It can support 20mps. c. Microwaves
Category 5: This is the highest rating for UTP cable and can support up to 100mps. Microwaves are electromagnetic radiations beyond the frequency range of radio and television.
There are two types of microwave systems: terrestrial microwave systems and satellite systems.
UTP can be connected as straight through or crossover. A straight-thru cable has identical ends. A
crossover cable has different ends.  Terrestrial microwave systems are land-based. Microwaves being line-of-sight and traveling
in a straight line, the earth’s curvature poses a problem to long distance microwave transmissions.
c. Fiber Optic Cable As such, long distance transmissions require directional antennas (repeaters)to be used at intervals
Fiber optic cables use optical fibers that carry digital data signals in the form of modulated light of 25 to 30 kilometers between the transmitting and receiving end.
pulses. An optic fiber consists of an extremely thin cylinder of glass, called the core, surrounded by a
concentric layer of glass, known as the cladding. Each cable has two fibers - one to transmit and one  Satellite systems use communication satellites to solve the problem posed by the earth’s
to receive. curvature to terrestrial microwave systems. A communication satellite is a microwave relay station
There are two types of optic fibers: placed in outer space. A microwave signal is transmitted from earth to the satellite which amplifies
 A single mode fiber (SMF) uses a single ray of light to carry transmissions over long the signal and sends it back to earth. The earth station transmits the signal to the satellite on an up-
distances. link, on one frequency and the satellite repeats those signals on a down link which is on another
 A multi-mode fiber (MMF) uses multiple rays of light simultaneously with each ray of light frequency.
running at a different reflection angle to carry transmissions over short distances.

© 2014- BGS Molyko 29


Bilingual Grammar School Advanced Level Computer Science
If the checksum obtained matches the one sent, the transmission is considered to be successful and
error-free.

2.6.3. Cyclic Redundancy Check


A CRC is an error-detection code in which each segment of the original message is combined with
additional bits to make a binary number that is divisible by some previously chosen divisor.
 k is the length of the message we want to send, i.e., the number of information bits.
 n is the total length of the message we will end up sending the information bits followed by
the check bits. Peterson and Brown call this a code polynomial.
 n-kis the number of check bits. It is also the degree of the generating polynomial. The basic
 Advantages of microwave systems (mathematical) idea is that we're going to pick the n-k check digits in such a way that the
o No cables needed code polynomial is divisible by the generating polynomial. Then we send the data, and at the
o Multiple channels available other end we look to see whether it's still divisible by the generating polynomial; if it's not
o Wide bandwidth then we know we have an error, if it is, we hope there was no error.

 Disadvantages 2.7. Peripheral Device Control


o Line-of-sight will be disrupted if any obstacle, such as new buildings, are in the way 2.7.1. Buffering
o Signal absorption by the atmosphere. Microwaves suffer from attenuation due to A buffer is an area of memory used to temporarily store data while it is being moved from one place
atmospheric conditions. to another. Buffers are used to compensate for differences in rate of flow of data or time of
occurrence of events, when transferring data from one device to another. Routers use buffers to
o Towers are expensive to build
route data packets on the Internet. When a packet is sent from one router to another via one or
more intermediate routers, the packet is received at each intermediate router in its entirety, stored
2.6. Transmission Checks
there until the required output line is free, then the packet is forwarded.
Network data transmissions often produce errors, such as toggled, missing or duplicated bits. As a
result, the data received might not be identical to the data transmitted, which is obviously a bad
2.7.2. Interrupt
thing. Because of these transmission errors, network protocols very often use error-detection codes.
An interrupt is a signal to the processor emitted by hardware or software indicating an event that
An error detection code is a binary code that detects digital errors during transmissions. The
needs immediate attention. An interrupt alerts the processor of a high-priority condition requiring
detected errors can be corrected, but can prompt the data to be retransmitted. Examples of error-
the interruption of the current task the processor is executing. Interrupts are used to handle such
detection codes include parity checking, checksums and cyclic redundancy checks.
events as data receipt from a modem or network, or a key press or mouse movement.
2.6.1. Parity Checking
2.7.3. Polling
Parity checking refers to the process of using a parity bit to check that data has been transmitted
Polling is the process by which the central computer or communications controller in a network,
accurately. A parity bit is an extra bit transmitted with a data unit that will be used to check its
"polls" or asks each device in the network if it has a message to send and then allows each in turn to
integrity. There are two types of parity: odd parity and even parity.
transmit data. Access and control of star network typically is maintained by a polling system.
 In odd parity, the parity bit is added such that the total number of bits at 1, in the data unit, is
an odd number.
2.7.4. Handshaking
 In even parity, the parity bit is added so that the total number of 1s is an even number.
Handshaking is the process by which two devices initiate communications. It begins when one
device sends a message to another device indicating that it wants to establish a communications
Example: What are the parity bits for the following data units in odd parity?
channel. The two devices then send several messages back and forth that enable them to agree on a
communications protocol.
i) 11101100 ii) 00100101 iii) 11010101

2.8. Communication Protocols


Example 2: What are the parity bits for the following data units in even parity?
For proper communication in a network, different entities must speak the same language. There
must be mutually acceptable conventions and rules about the content, timing and underlying
i) 01101010 ii) 11000101 iii) 10011100
mechanisms. These conventions and associated rules are referred as protocols.

2.6.2. Checksum Definition: A protocol is a set of rules that govern how devices on a network communicate.
A checksum or hash sum is a count of the number of bits in a transmission unit that is included with
the unit for the purpose of detecting errors that may have been introduced during transmission. The Protocols allow different computers from different vendors and with different operating
checksum or hash sum may be computed according to the number of set or unset bits in the characteristics to ‘speak the same language’. They set the message formats and procedures that
message. On reception, the receiver applies the same checksum function/algorithm to the message. allow machines and application programs to exchange information. The same protocols must be

© 2014- BGS Molyko 30


Bilingual Grammar School Advanced Level Computer Science
followed by each machine involved in the communication in order for the receiving host to be able
to understand the message. A protocol may be physical or logical. Layer 4: Transport
It is responsible for end-to-end delivery of entire messages. It allows data to be transferred reliably
2.8.1. Physical Protocols and uses sequencing to guarantee that it will be delivered in the same order it was sent. It also
Physical protocols are concerned with how a device connects to a medium. They ensure that a provides services such as error checking and flow control. Examples of protocols at this layer are:
device connected to a medium can transmit through the medium. They make sure that the layout of TCP, UDP, NETBEUI and SPX.
pins on the connectors is the same and that devices are correctly connected and configured. Few
examples of physical protocols are 802.11 for Wi-Fi connections and DSL for broadband. Layer 3: Network
It is responsible for path determination, routing, and the delivery of packets across internetworks. It
2.8.2. Logical Protocols is also responsible for addressing (also known as logical addressing) for example IP addressing.
Logical protocols are concerned with data handling. They ensure that data are in the right format for Examples of protocols at this layer are: IP, IPX and ICMP.
the application, the bit rates match at both ends, and the same error correction is used. Examples of Examples of devices that operate at this level are Layer-3 switches and routers. WAPs (wireless
logical protocols are TCP/IP, HTTP, POP3, FTP, SMTP and WAP. access points) with built-in routing capabilities also act at this layer.

2.8.3. The OSI Reference Model Layer 2: Data Link


The Open Systems Interconnection (OSI) reference model or more commonly the OSI model is an It is responsible for reassembling bits taken off the wire by the physical layer to frames and makes
ISO standard that defines how network communications take place by providing a framework for sure they are in the correct order and requests retransmission of frames in case an error occurs. It
standardization. The OSI model divides network communications into seven layers. Each layer is provides error checking by adding CRC to the frame. Examples of protocols at this layer are:
responsible for carrying out specific functions when transmitting data on the network. The table Ethernet, Token Ring, PPP and ISDN.
below shows the layered architecture of the OSI reference model. Examples of devices that operate at this layer are: switches, bridges, NICs and WAPs (Wireless
Access Points).
7 Application Layer
Layer 1: Physical
6 Presentation Layer This layer communicates directly with the communication medium. It is responsible for activating,
maintaining and deactivating the physical link. It defines electrical and optical signaling, voltage
5 Session Layer levels, data transmission rates, as well as mechanical specifications such as cable lengths, and
connectors, the amount of pins and their functions. Examples of devices that operate at this layer
4 Transport Layer are: hubs, repeaters, and NICs.

3 Network Layer
These layers can be recalled using the These layers can be recalled using the following mnemonics: All People Seem To Need Data
2 Data Link Layer following mnemonics: All People Seem To Processing. (Layers 7 - 1)
Need Data Processing. (Layers 7 - 1)
1 Physical Layer 3. The Internet
3.1. Brief History
OSI Reference Model Many years ago, the military of the United States of America desired to interconnect or link their
computers in order to better understand and manage information and communication with respect
Layer 7: Application to enemy attacks in times of crisis. In the year 1969 the Department of Defense (DoD) then
It provides network services directly to the user’s applications such as a web browser or e-mail developed an experimental network called the Advanced Research Project Agency Network
client. This layer is said to be “closest to the user”. Examples of protocols that operate at this layer (ARPANet)
are: TELNET, HTTP, FTP, SMTP and POP. In the year 1980, the National Science Foundation of the United States of America then developed
the technology of ARPANet to produce the National Science Foundation Network (NSFNet) which
Layer 6: Presentation now enabled universities and other school establishments in the USA to be interconnected. After a
The Presentation layer represents the data in a particular format to the Application layer. It defines great deal of work, a network which enabled the transfer of large amounts of information at very
encryption, compression, conversion and other coding functions. Examples of specifications defined high speed which is today called the Internet was developed.
at this layer are: GIF, JPEG, MPEG, MIME and ASCII. The Internet can be defined as a worldwide/global system of interconnected computer networks. It
is the network of networks in which users can view information on the World Wide Web, exchange
Layer 5: Session electronic mail, participate in electronic discussion forums (newsgroups), send files from any
It establishes, maintains and terminates end-to-end connections (session) between two applications computer to any other and even use each other’s computers directly if they have appropriate
on two network nodes. It controls the dialogue between the source and destination nodes, which passwords. Another name for the Internet is information superhighway.
node can send when and for how long. Examples of protocols that operate on this layer are: RPC,
NETBIOS and X.225

© 2014- BGS Molyko 31


Bilingual Grammar School Advanced Level Computer Science
3.2. ISP and Internet Access phones and other handhelds with Internet capabilities to access the Internet using existing cell
An Internet service provider (ISP), also sometimes referred to as an Internet access provider (IAP), phone networks.
is a company that offers Internet access to individuals and organizations. The ISP connects to its
customers using a data transmission technology appropriate for delivering Internet Protocol 3.2.5. Internet over Satellite
Paradigm, such as dial-up, digital subscriber line (DSL), cable modem, wireless or dedicated high- Internet over satellite (IoS) allows a user to access the Internet via a satellite that orbits the earth. A
speed interconnects. satellite placed at a static point above the earth's surface, communicates with the ISP’s dish giving
ISPs may provide Internet e-mail accounts to users which allow them to communicate with one the user access to the internet.
another by sending and receiving electronic messages through their ISP's servers. They may also
provide services such as remotely storing data files on behalf of their customers, as well as other 3.3. The TCP/IP Model
services unique to each particular ISP. The Internet uses a collection of protocols known as the TCP/IP protocol suite. It is called TCP/IP
Different methods exist for connection to the Internet. after two of its most prominent protocols, but there are other protocols as well. The TCP/IP model
is based on a four-layer model for networking. The layers from top to bottom are application layer,
3.2.1. Dial-Up Connection transport layer, Internet layer and network access layer. Below is a comparison between the TCP/IP
A dial-up connection is a connection that is established by dialing a telephone number through a model and the OSI model.
modem. A dial-up connection uses a dial-up modem to transmit digital information over the Plain
Old Telephone System (POTS). POTS refers to the standard telephone network designed for analog Application Layer
transmission of voice over copper wire. This type of connection offers relatively slow transfer rates Application Layer HTTP FTP SMTP DNS RIP
and is established on demand. This method has long been the most widely used method to connect Presentation Layer
to the Internet but it has been replaced by high-speed broadband and wireless connections.
Session Layer Transport Layer
TCP UDP
3.2.2. Digital Subscriber Line (Host-to-host)
Transport Layer
DSL uses the standard copper telephone wires, often already installed in homes and offices to
provide a high-speed Internet connection. xDSL means that there are different types of DSL: Internet Layer
Network Layer ARP IP IGMP ICMP
asynchronous DSL (ADSL), synchronous DSL (SDSL), High bit-rate DSL (HDSL), Rate Adaptive DSL
(RADSL) and ISDN DSL (IDSL). Data Link Layer Network Access
 ADSL allows the telephone wires to be used for analog POTS system and digital data transfer Ethernet Token Frame ATM
Layer Ring Relay
simultaneously. The download speed (downstream) for ADSL is faster than the upload speed Physical Layer
(upstream).
 SDSL cannot share the physical medium with standard telephone communications and has a OSI Model TCP/IP Model
download speed equal to the upload speed. TCP/IP Protocol Suite
A DSL connection requires a transceiver (DSL modem) which allows an Ethernet UTP or a USB
connection directly to a PC, or to a hub, router, or switch to provide Internet access to an entire During a transmission, a message travels down all network layers at the source machine. Before
network. The transceiver can be integrated into a router or switch. sending a message to the next layer, each layer places it in an envelope of overhead information
related to that layer. This process is called encapsulation. Encapsulation at each layer produces a
3.2.3. Broadband Cable data unit called protocol data unit (PDU).
TV channels only take up 6MHz of cable bandwidth each, which usually leaves several hundred MHz At the receiving end, the message travels up through the network layers, each layer removing the
available. This additional space on cable is used for high-speed Internet connection. Information envelopes added when the message was sent. So, upon its receipt, the message is in its original state.
from the Internet travels through the cable as a single TV channel. Just as with DSL, cable Internet
requires a special transceiver (cable modem) which allows information to be sent and received on 3.3.1. Network Access Layer
frequencies not used by TV channels. The cable modem provides one or more LAN interfaces, This layer is responsible for sending and receiving TCP/IP packets on the network medium
usually Ethernet or USB which connect directly to a client or a device such as a hub, switch, or (Physical/Data Link). The network Access layer PDU called frame, is obtained by adding a header
wireless router to allow additional clients or entire networks to use the same connection. The cable and a trailer to the PDU from the Internet layer.
modem is also equipped with connections for TV and radio. Applicable LAN technologies: Ethernet, Token Ring, FDDI etc.
Applicable WAN technologies: X.25 (old), Frame Relay, ATM etc.
3.2.4. Wireless Internet Access
Wireless Internet access or wireless broadband is particularly useful for mobile users. With 3.3.2. Internet Layer
handheld devices becoming more advanced and increasingly popular, wireless access is becoming This layer is responsible for packaging, addressing and routing of packets. The PDU at this layer is
one of the major ways of connecting to the Internet. This method provides an “always-on called datagram or packet.
connection” which can be accessed from anywhere as long as you are geographically within network Core Internet layer protocols are: IP, ARP, ICMP and IGMP.
coverage. Wireless Internet access includes deploying Wi-Fi hotspots for accessing the Internet.
Technologies such as GPRS and UMTS (Universal Mobile Telecommunication System) allow Smart

© 2014- BGS Molyko 32


Bilingual Grammar School Advanced Level Computer Science
a. Internet Protocol
Internet Protocol (IP) specifies the format of packets and the addressing scheme. All computer 3.3.4. Application Layer
devices (desktops, laptops, PDAs, phones, tablets) connected to the Internet, have IP addresses by The application layer provides user applications with the ability to access the services of the other
which they are identified. layers. Some protocols of this layer are HTTP, FTP, POP, SMTP, Telnet, IMAP and WAP.

Definition: An IP address is a unique identifying number given to every single computer on a TCP/IP a. Hypertext Transfer Protocol
network. HTTP is a standard method of publishing information as hypertext in HTML format on the Internet.
It provides the ability to supply web pages between a browser and the server. HTTPS is a secure
Two versions of IP addresses are available: IPv4 that uses 32 bits and IPv6 that uses 128 bits. version of HTTP used for accessing secure web servers, whereby all data transferred are encrypted.
 An IPv4 is made up of four sets of numbers separated by dots such as 123.23.168.22. This
notation is known as dotted decimal notation. Each of the four numbers separated by dots b. File Transfer Protocol
can be any number from 0 to 255, making for a total of 4.3 billion potential IPv4 addresses FTP is a standard for transferring files between a server and a client on a TCP/IP network. It
(i.e. 255×255×255×255). provides the ability to upload and download files between hosts on the network.

 An IPv6 has eight sets of numbers separated by colons such as c. Simple Mail Transfer Protocol
3ffe:1900:4545:3:200:f8ff:fe21:67cf. SMTP is used for sending e-mails between servers on the Internet and other TCP/IP networks. It
governs the transmission of mail messages and attachments. SMTP is used in the case of outgoing
IP addresses are assigned manually by an administrator or automatically by DHCP (Dynamic Host messages.
Control Protocol) or APIPA (Automatic Private IP Addressing). An IP address is also known as a
logical address. d. Post Office Protocol
POP is a standard protocol for delivering e-mails to personal computers. There are different
b. Address Resolution Protocol versions of the post office protocol indicated by POPn where n = 1, 2, 3 or4.
ARP resolves IP addresses to MAC addresses. It is used to obtain the MAC address of a node on a
network when its IP address is known. e. Telnet
Telnet is a protocol that allows a computer on the network to be accessed remotely. It provides the
Assignment: Differentiate between an IP address and a MAC address. ability to login into a remote host and administer the machine. Using Telnet a computer can be used
as a terminal on another.
c. Internet Control Message Protocol
ICMP is responsible for diagnostics and error reporting. It is used to send control and error f. Wireless Application Protocol
messages to computers and servers. WAP is a protocol which runs on mobile phones and provides a universal open standard for
bringing Internet content to mobile phones and other wireless devices.
d. Internet Group Management Protocol
IGMP is responsible for management of group multicast. Assignment: Give the full meaning of the following protocols and state their functions.
i) IMAP (ii) RIP (iii) DNS
3.3.3. Transport Layer
The transport layer is responsible for sequencing and transmission of packets, acknowledgment of 3.4. TCP/IP Ports
receipts, recovery of packets and flow control. In essence, it engages in host-to-host transportation A computer has a single physical connection to the network. All data destined for a particular
of data packets and the delivery of them to the application layer. A transport layer PDU is called computer arrives through that connection. However, the data may be intended for different
segment. applications running on the computer. To identify the application for which the data is intended,
Core protocols at this layer are TCP and UDP. TCP requires port numbers on the host and destination for communication.

a. Transmission Control Protocol Definition: A communication port is a number (16-bits) that identifies an application on the Internet
TCP is a connection-oriented reliable protocol used in the accurate transmission of large amounts of or TCP/IP network.
data. Data packets are verified using checksums and retransmitted if they are missing or corrupted.
The application plays no part in validating the transfer. Popular Internet application protocols are associated with well-known ports assigned by the
Internet Assigned Number Authority (IANA). Sample TCP port numbers are:
b. User Datagram Protocol
UDP is a connectionless unreliable protocol used for the transmission of small amounts of data. Data
packets are sent without testing to verify whether they actually arrive at the destination, nor
whether they were corrupted in transit. It is up to the application to determine these factors and
request retransmissions. UDP is faster compared to TCP.

© 2014- BGS Molyko 33


Bilingual Grammar School Advanced Level Computer Science
A search engine is a computer program that searches for specific words on the World Wide Web and
Port number Protocol returns a list of documents in which they were found. Examples of search engines include Google
and yahoo.
20 FTP data channel

21 FTP control channel 3.5.2. Electronic Mail


Electronic mail or e-mail (email) is a means of sending messages, text, and computer files between
23 Telnet computers via the Internet. To send and receive e-mails, you need an Internet connection and an e-
mail account which can be created within a webmail service such as Yahoo, Hotmail or Gmail. When
25 SMTP you create an e-mail account, you are given a unique email address that gives you access to your
80 HTTP mail box. An email address is made up of two parts separated by the symbol @ pronounced “at”. For
example [email protected].
110 POP In the above address,
 bgsmolyko is the user ID, user name or login
Ports are usually combined with IP addresses to form a socket. For example 127.102.10.0:80.  yahoo.com is the domain name. The domain specifies the mail server (computer) on
which the mail box is located.
3.5. Internet Services
3.5.1. The World Wide Web The part of the domain name after the dot is called top-level domain, and specifies the type of
The World Wide Web (WWW) is a system of interconnected hypertext documents that can be organization or the country the host server is located. Some common top-level domains are:
accessed via the Internet. Documents are connected to other documents by hypertext links, enabling o .com - for commercial enterprises
the user to search for information by moving from one document to another. It consists of a large o .edu - for educational institutions and universities
number of web servers that host websites. A website consists of a number of web pages connected o .gov - for United States government agencies
by hypertext links. A web page is a text file that contains information stored using a structured o .net - for organizations such as Internet Service Providers
language called HTML (Hypertext Markup Language). o .org - for non-commercial organizations
A website can be accessed by typing its address or URL (Uniform/Universal Resource Locator) into
the address bar of a web browser. An example of a URL is http://www.crtv.cmwhere http is the 3.5.3. Instant Messaging
protocol used and www.crtv.cm, the domain name (address) of the site. Instant messaging is a live (or real time) communication which occurs when brief text messages are
exchanged instantly over the Internet. Instant Messaging requires that both users be on-line at the
Example 1: http://www.bgsmolyko.edu/Ls3,4/ict796/intenet.pdf same time. Common IM applications are AOL Instant Messenger, Yahoo Messenger and Microsoft
 http is the protocol used (hypertext transfer protocol) MSN messaging.
 www.bgsmolyko.edu is the domain name (the machine at BGS Molyko that hosts the website)
 Ls3,4/ict796/internet.pdf is the path of the document (resource) on the host computer. Ls3,4 3.5.4. Internet Telephony
is the folder, ict796 is the subfolder and internet.pdf is the file(resource). Internet telephony or voice over IP (VoIP) is the transmission of voice telephone conversations
through the Internet or IP networks. It allows users to have voice-talk with others through the
Example 2: www.minsup.gov.cm Internet. The telephone calls are digitized and transmitted through the Internet. Internet telephone
 gov is the top level domain which specifies that the URL is for a government institution. services can be mainly categorized into net-to-net and net-to-phone telephony.
 cm specifies the country in which the URL is hosted or the country in which the institution is In net-to-net telephony, both caller and receiver must be online. When both are online, one dials the
found. other person’s phone number. If they accept the call, then voice communication is established.
In net-to-phone, only one person has to be online. This person dials the other person’s phone
Assignment: What is a home page? number and the latter receives a ring on their phone. Yahoo messenger and Skype provide services
for both types.
a. Domain Name System
A domain name system (DNS) is a service which performs the function of turning human- 3.5.5. Interpersonal Computing
understandable domain names into IP addresses. Interpersonal computing refers to person-to-person interactions facilitated by websites that enable
collaborative content creation, sharing and manipulation. Interpersonal computing involves: blogs,
b. Web Browser social networks, wikis and viral video sites.
A web browser (or simply browser) is a computer program that enables a user to read hypertext in
files or on the World Wide Web. Popular browsers include Mozilla Firefox, Microsoft Internet a. Blogs
Explorer, Opera Mini and Netscape. A blog (web log) is a chronological, journal-style website which its author (or "blogger") maintains
like an online diary, with regular entries of commentary, descriptions of events, or other material
c. Search Engine such as graphics or video. Many blogs provide commentary or news on a particular subject; others

© 2014- BGS Molyko 34


Bilingual Grammar School Advanced Level Computer Science
function as more personal online diaries. They also provide the readers with the ability to leave o It is accessible 24 hours each day.
comments in an interactive format. o It needs a small number of staff to run.
o It does not need huge office space.
b. Social Networking Sites o Products can be sold at cheap prices
Social networking sites are websites that allow user to build personalized communities to socialize
with. Common features include a customizable profile, the ability to add other users as friends, the  Some disadvantages of e-commerce are:
ease of sharing pictures, music, text, and links, and built-in chat and mail features. Examples of o Credit card fraud - hackers are able to steal credit card numbers on computers.
social networking sites are Facebook, Twitter and Instagram. o Certain websites spy or track the buying habits of their customers.
o Some goods do not arrive after they are paid for.
c. Wikis o It lacks human interaction as one only sees pictures and some text descriptions.
Wikis are websites that allow visitors to easily add, remove and edit content, hence enabling the
collaborative authorship of comprehensive documents. The best example of a wiki is the multi- 3.5.7. Online Banking
lingual, web-based encyclopedia Wikipedia, and which currently includes over two million articles. Online banking (Internet banking) is simply the use of the Internet to perform banking operations
like opening an account, accessing account information, transferring funds, getting a bank statement
d. Viral Video Sites etc. In an Internet banking system, the bank has a centralized database that is web-enabled. All the
A viral video is a video that is distributed by sharing. Viral video sites are websites that allow services that the bank has permitted on the Internet are displayed in a menu. Any service can be
anybody to post videos online. Whilst it is now not difficult to put a video on any website, the selected and further interaction is dictated by the nature of service.
significance of viral video sites is that they provide somewhere to put videos where it is likely that
at least some other people will actually find them. Examples are YouTube and Kaltura. 3.6. Intranet and Extranet
An intranet is a private network that is set up using the same technology and protocols as the
3.5.6. Electronic Commerce Internet but is restricted to users inside an organization. It provides similar services within an
E-commerce refers to the buying and selling on the Internet. Different models of e-commerce exists: organization to those provided by the Internet without necessarily being connected to the Internet.
business-to-business, business-to-consumer, business-to-government and m-commerce An intranet can be seen as a private version of the Internet. To access an intranet, some form of user
authentication is usually required. External access to an intranet is not always provided.
a. Business-to-Consumer An extranet is an interconnection of two or more intranets. It allows an organization to share
B2C model sells goods or services to the consumer, generally using online catalog and shopping information with other organizations using Internet standards but with security features preventing
cart transaction systems. For example, an online pharmacy giving free medical consultation and access to others.
selling medicines to patients is following a B2C model. Amazon is an example of one of the first and
still one of the most successful B2C e-commerce companies.

b. Business-to-Business
B2B describes commerce transactions between businesses, such as between a manufacturer and a
wholesaler, or between a wholesaler and a retailer. In this form, the buyers and sellers are both
business entities and do not involve an individual consumer.

c. Business-to-Government
B2G is a derivative of B2B marketing. B2G sites provide a platform for businesses to bid on
government opportunities which are presented as solicitations requests for proposal (RFPs) to
tender.

d. M-Commerce
M-commerce refers to the use of mobile devices for conducting transactions. The mobile device
holders can contact each other and can conduct the business. Even the web design and development
companies optimize the websites to be viewed correctly on mobile devices.

Some e-commerce websites are: www.bruneiair.com for airline ticket bookings, www.amazon.com
for sales of books and magazines, www.brumedia.com/shop for sales of computers, shirts, and
cameras

 Some advantages of setting up an e-commerce website are:


o Products can be sold to local customers and those from abroad.

© 2014- BGS Molyko 35


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 4: INFORMATION SYSTEMS 1.2. Characteristics of Information
Good information is that which is used and which creates value. Experience and research show that
Introduction good information has numerous qualities.
A system is an integrated set of regularly interacting or interdependent components created to
accomplish a defined objective, with defined and maintained relationships among its components. a. Timeliness
Basically, there are three major units in every system namely input, processing and output. The Delay destroys the value of information. For effective decision making, information must reach the
objective of a system demands that some output be produced as a result of processing the suitable decision-maker at the right time. Timeliness means that information must reach its recipients within
inputs. the prescribed timeframes.
An information system can therefore be seen as a set of interrelated components that collect data,
process the data to produce information. b. Accuracy
Wrong information given to decision-makers would result in wrong decisions. Accuracy means that
1. Data and Information information should be free from mistakes and errors.
Data are raw facts and figures that have no context or purposeful meaning. In computing, data is
simply any number, letter or symbol that can be entered into a computer system. When data has been c. Current
processed it gives information. For the characteristic of timeliness to be effective, information should be current or up-to-date.
Information is data that has been processed. The processing gives it meaning and a context. Information must be current as a fact of yesterday may not be a fact of today.
Information can also be defined as the useful knowledge derived from facts placed in the right context
with the purpose of reducing uncertainty. d. Completeness
For example, the number 12.5 is data because we do not know why or in what context it is being used. Information should have every necessary part or everything that is wanted. If information is not
However, if the number appears on a student’s report card to show that they have an average of 12.5, complete, it may lead to wrong decisions being made as only half of an entirety of the information is
then this data has changed into information, because it has acquired a context (it’s an average) and known.
meaning.
Also, the binary patterns that describe an icon on your desktop are data. They become information e. Explicitness
after the operating system software has processed them, because then they become meaningful to you Good information should not require further analysis for decision making. It should be clear and
as the icons representative of your hard disk or Internet explorer. obvious, leaving no doubts as to its intended meaning.
In summary,
𝐼𝑛𝑓𝑜𝑟𝑚𝑎𝑡𝑖𝑜𝑛 = 𝐷𝑎𝑡𝑎 + 𝐶𝑜𝑛𝑡𝑒𝑥𝑡 1.3. Data Collection
All computer systems need to have data input into them otherwise they have nothing to process.
1.1. Sources of Data Getting the data for the computer to process is known as data collection. Data collection can be manual
a. Questionnaire or automatic.
A questionnaire is a set of questions used for collecting data from people. A questionnaire may be in
paper format or online. 1.3.1. Manual Data Collection
Manual data collection uses forms and questionnaires. Data collected through this method has to be
b. Interview entered into the computer by typing and clicking.
An interview is a meeting during which somebody is asked questions. Interviews allow you to collect a Many different errors can occur when entering data into a system. To try and reduce the amount of
greater depth of data and understanding from people than is possible by just using a questionnaire. input errors, a system designer can build in validation and verification checks into the software that
the data is entered into.
c. Observation
In observation, the data gatherer observes what is happening during a process or event and produces a. Data Verification
some kind of data file as a result Verification means checking the input data to make sure it has been entered correctly. Verification
tries to ensure there have been no transcription errors. It is a check on accuracy. Two methods of data
d. Data logging verification are double entry and proofreading.
Data logging is an automated method of gathering data by using sensors.
 Double Entry
e. Document review Double entry consists of entering the data twice. The two entries are then compared against each other
Document review is getting relevant data from a document, an article or a book. and a warning given if they do not match. For example, a new password is always entered twice.

f. Data mining  Proof Reading


Data mining is the exploration of databases to collect data. Proofreading consists of reading the data entered either on screen or printout, to be sure that it
matches the data source. It is also known as visual check.

© 2014- BGS Molyko 36


Bilingual Grammar School Advanced Level Computer Science
b. Data Validation o Input the number including the check digit.
Validation is a check on input data to ensure that the data is sensible or reasonable. It compares the o Weight each digit by its position in the string and add up the results.
input with a set of rules that the computer has been told the data must follow. If the data does not
match up with the rules then there must be an error. Validation only checks that the data is valid. The
data may be valid but not correct. Five types of validation checks are: Position 10 9 8 7 6 5 4 3 2 1

 Type/Format check Digit 1 8 5 8 1 3 4 1 5 3


A type check is used to ensure that data entered in a field fits the required data type. For example, a
Weightings 10 72 40 56 6 15 16 3 10 3
person’s name will consist of letters of the alphabet and sometimes hyphens and apostrophe. Any
name that contains numbers will be rejected as invalid. Total = 10+72+40+56+6+15+16+3+10+3 = 231

 Length check o Divide the total by 11. If the remainder is 0, then the number has passed the validation
A length check ensures that an entered value is no longer than a certain number of characters. For check and so it is likely that it has been inputted correctly.
example, a phone number has 8 digits. Entering fewer or more digits makes a number invalid. 231 / 11 = 21 remainder 0

 Range check Exercise:


A range check is used to ensure that the data entered falls between a specified minimum and i) Dates are read into a computer in the following format: DDMMMYY e.g. 15DEC92. The
maximum values. For example, a mark in an exam is between 0 and 20. Any mark below 0 or above 20 following dates were rejected by a validation program: 3JAN71, AUG2166, 31SEP72. State the
is rejected as invalid. validation check used to discover each error.

 Presence check ii) Calculate the check digits to complete the ISBNs: 019276150-1 and 995640216-8.
A presence check ensures that an entry has been made in a particular field. If it has not, the system will
not allow the record to be saved or any entries to be made in later fields. Such fields called mandatory iii) Set up a spreadsheet which will calculate and check the validity of Modulo-11 weighted check
fields are indicated on some systems by the used of an asterisk. digits for any given ISBN.

 Check digits 1.3.2. Automatic Data Collection


A check digit is a digit attached to the end of a string of digits that can be used to check that the string Automatic data collection is a form of data input in which there is no data entry. It uses sensors and
is correct. It is calculated from the other digits in the string. One example where a check digit is used is specialized input devices to collect data that is directly entered into the computer without any human
in the 10 digit ISBN number which uniquely identifies books. The last number of the ISBN is actually involvement. It is also called data capture. Different automatic data collection methods are:
the check digit for the other numbers. For example, in the ISBN 1858134153, the 3 at the end of the
number is the check digit. a. Optical Mark Recognition (OMR)
The check digit for ISBNs is obtained using a calculation method known as the Modulus-11 weighted OMR uses a device called an optical mark reader to read marks made with prescribed pens, pencils or
check digit calculation. special writing material on OMR forms, and convert them into information in the computer. This
system is good for multiple choice examination questions.
o Start with original number i.e. 185813415
o Weight each digit by its position in the string and add up the results. b. Optical Character Recognition (OCR)
This method uses a device called an optical character reader to read characters from printed or
Position 10 9 8 7 6 5 4 3 2 1 handwritten text and transmit them to the computer as if they were typed from the keyboard. This
method is suitable for capturing data from airline tickets; reading postal codes; capturing data from
Digit 1 8 5 8 1 3 4 1 5 telephone and electric bills.
Weightings 10 72 40 56 6 15 16 3 10
c. Magnetic Ink Character Recognition (MICR)
Total = 10+72+40+56+6+15+16+3+10= 228 The device used is a magnetic ink character reader that reads characters written in magnetic ink, using
magnetic stripe readers or card swipe machines that capture the information on the magnetic card.
o Divide the total by 11 and then subtract the remainder from 11. The check digit is the result These are seen on the back of credit cards and bank cards.
of this operation.
228 / 11 = 20 remainder 8 => Check digit is 11-8 = 3. d. Barcode Reading
o Add the check digit to the end of the original number to get the complete product number. An optical device called barcode reader is used to read the barcode on products and convert them into
i.e. 1858134153. a form that can be processed by the computer. A bar code is a sequence of vertical lines and numbers
that identify a product. They are used in libraries, supermarkets and retail shops.
To check whether the ISBN is correct,

© 2014- BGS Molyko 37


Bilingual Grammar School Advanced Level Computer Science
e. Voice Recognition
This method converts speech into text or a sequence of computer commands. It is most common for  At the operation level, employees with operational roles need information to help them carry
data entry and word processing environments. out their duties. Results of operational work are passed upwards to let the tactical planners
evaluate their plans.
2. Information System Components
There are five basic components in an information system: hardware, software, procedures, data and In order to meet with the information needs of the organization, different types of information systems
people. exist which can be grouped into two: operations support systems and management support systems.

 Hardware 3.1. Operations Support Systems


Hardware refers to the physical devices that make up the system. They are the whole set of equipment Operation support systems process data generated by business operations. They act at the operational
used for input, processing, storage and communication of data. level of the organization. Major categories of OSS are transaction processing systems, office
automation systems and process control systems.
 Software
Software is the collection of computer programs used in the system. They provide the instructions that 3.1.1. Transaction Processing Systems
tell the computer what to do. A transaction is any event of interest to an organization. It may be a business activity such as a
payment, a deposit, a customer’s order, a reservation or a student’s registration. Transaction
 Data processing systems capture and process data generated during an organization’s day-to-day
Data are raw, unorganized, potentially useful facts and figures that are processed to produce transactions and maintain records about the transactions. They are vital for any organization or
information. business as they gather all the input necessary for other types of systems. TPS are also called Data
Processing Systems.
 People
People are the main actors of the system. They are the users of the information system. They input There are two types of TPS: batch processing and online processing systems.
data into the computer, give some direction to the computer to perform tasks and review information
on the computer for output. a. Batch Processing
With batch processing, transaction data is collected over a period of time and all processing is done as
 Procedures a group. Batch processing is ideal in situations where large amounts of data requiring similar
Procedures are the series of documented actions taken to achieve a particular goal. A procedure is processing are to be processed. Examples are:
more than a single simple task. It can be complex and involved, such as reinstalling software,  Payroll systems for calculating employee salaries
performing a backup etc.  Billing systems for calculating consumer bills.

3. Organizational Information Systems b. Online Transaction Processing


There are three levels at which information can be used in an organisation: strategic, tactical and With online transaction processing (OLTP) the computer processes transactions as they are entered.
operational levels. This can be represented using the pyramid below. Such systems are ideal for situations where the master file needs to be updated each time a transaction
is made. Examples are:
 Stock control systems which reduce automatically the number of items in stock once an item
has been bought
 Reservation systems which reduce automatically the number of seats available on a flight or bus
Strategic Executives once a seat has been booked.
Level
3.1.2. Office Automation Systems
Tactical Managers Office automation systems automate office procedures and enhance office communication and
Level
productivity. They support a wide range of office activities such as creating and distributing
Operational documents, sending messages and scheduling. The software an OAS uses to support these activities
Workers
Level include word processing, spreadsheets, databases, presentation, graphics, e-mail, Web browsers,
personal information management, and groupware. They use communication technologies such as
 At the strategic level, information is needed by senior managers (executives) to help them with voice mail, facsimile (fax), videoconferencing, and electronic data interchange (EDI) for the electronic
their business plans. Information at this level is used for making long term decisions. exchange of text, graphics, audio, and video. OAS are also called Office Information Systems (OIS).

 At the tactical level, information is needed by middle managers to help them monitor and
control business activities. Tactical planning and decision-making takes place within the
guidelines set by the strategic plan.

© 2014- BGS Molyko 38


Bilingual Grammar School Advanced Level Computer Science
3.2. Management Support Systems 3.2.3. Executive Information Systems
Management support systems provide information and support needed for effective decision making Executive information systems (EIS) are designed to support the information needs of executive
by managers. They act at the tactical and strategic levels of the organization. Major categories of MSS management. Their purpose is to analyse, compare and identify trends to help the strategic direction
are management information systems, decision support systems and executive information systems. of the organisation. Information in an EIS is presented in charts and tables that show trends, ratios,
and other managerial statistics. Because executives usually focus on strategic issues, EISs rely on
3.2.1. Management Information systems external data sources that can provide current information on interest rates, commodity prices, and
Management information systems generate accurate, timely and organized information needed by other leading economic indicators.
middle managers to take decisions, solve problems, supervise activities, and track progress. They To store all the necessary decision-making data, DSSs or EISs often use extremely large databases,
provide routine information for routine tasks. The source of data for an MIS usually comes from called data warehouses.
numerous databases. These databases are usually the data storage for Transaction Processing Systems.
MIS take information from TPS and summarize them into a series of management reports. As such, MIS 4. Other Information Systems
are sometimes called Management Reporting Systems (MRS). 4.1. Expert Systems
MIS generate three basic types of information or reports: detailed, summary and exception. An expert system is a computer program that tries to emulate the decision making of a human expert.
 Detailed reports confirm transaction processing activities. A detailed order report is an It does this by combining the knowledge of human experts and then, following a set of rules, it draws
example of a detail report. inferences. An expert system is made up of three parts: a knowledge base, an inference engine and a
user interface.
 Summary reports consolidate data into a format that an individual can review quickly and  The knowledge base stores all of the facts, rules and information needed to represent the
easily. To help synopsize information, a summary report typically contains totals, tables, or knowledge of the expert.
graphs. An inventory summary report is an example of a summary report.  The inference engine is the part of the system that interprets the rules and facts using
backward and forward chaining to find solutions to user queries.
 Exception reports report information that is outside of a normal condition. These conditions  The user interface allows the user to enter new knowledge and query the system.
called the exception criteria, define the range of what is considered normal activity or status. An
example of an exception report is an inventory exception report that notifies the purchasing Expert systems are one part of an exciting branch of computer science called artificial intelligence (AI).
department of items it needs to reorder. Exception reports help managers save time because AI is the science and engineering of making intelligent machines which are able to simulate human
they do not have to search through a detailed report for exceptions. Instead, an exception behavior. AI technology can sense your actions and, based on logical assumptions and prior
report brings exceptions to the manager’s attention in an easily identifiable form. Exception experience, will take the appropriate action to complete the task. AI has a variety of capabilities,
reports thus help them focus on situations that require immediate decisions or actions. including speech recognition, logical reasoning, and creative responses.

Examples of MIS are: Example 1:


 Sales management systems A medical diagnosis expert system could be used in a doctor's waiting room. Patients would use a
 Inventory control systems touch screen to answer questions on symptoms etc. created by the system. Based on the patient
 Budgeting systems responses, the system could use its database of diseases and symptoms, along with its programmed
 Management reporting systems rules, to prepare a list of possible diagnosis for the doctor to investigate further.

3.2.2. Decision Support Systems Advantages


Decision support systems are designed to help tactical and strategic decision-making in situations o The doctor saves time because they do not have to ask the patient to describe their
where there is uncertainty about the possible outcomes of those decisions. They provide interactive symptoms in person.
support for non-routine decisions or problems. o The doctor is given a suggested list of possible diagnosis to investigate further.
TPS and MIS provide information on a regular basis. However, managers need information not o The computer can store far more information than the doctor and can search it far faster
provided in their reports to help them make decisions. Decision support systems therefore use data and more efficiently.
from internal (TPS and MIS) and external sources. o The database can easily be updated or extended.
o Internal sources of data might include sales, manufacturing, inventory, or financial data
from an organization’s database. Disadvantages
o Data from external sources could include interest rates, population trends, and costs of new o It can be difficult to describe symptoms to a computer system.
housing construction or raw material pricing.
o It relies on a basic level of skills from the user.
Examples of DSS are:
o It lacks the 'human touch' of a doctor actually talking to a patient.
 Logistics Systems
 Financial Planning Systems
Example 2:
 Spreadsheet Models
A expert system used by a car mechanic could help to diagnose faults in a car by asking the mechanic
to carry out tests or answer questions. This could also be automated as the computer could have

© 2014- BGS Molyko 39


Bilingual Grammar School Advanced Level Computer Science
inputs from sensors or have a direct interface with a computer system built into the car. The system
System Investigation
would then give the mechanic a list of probable faults with the car even make automatic adjustments
using the computer system built into the car. It would also be helpful to a newly qualified mechanic as
they would have access to a wider range of knowledge, could save time compared to having to contact
Maintenance Systems Analysis
an expert and the system could be used as a training aid.
Advantages
o The user saves time because the mechanic is taken through a logical series of things to
try out that are likely to solve common problems. Implementation Systems Design
o The system can directly access computer systems built into many modern cars.
o The system can store details of a huge range of common faults with different makes of
cars.
Construction
o The database can easily be updated or extended as new problems are identified.

System Development Life Cycle


Disadvantages
o It can be difficult to answer questions on something the user may know nothing about.
o It relies on a basic level of skills from the user. 5.1. System Investigation
System investigation is a brief study of the system under consideration that gives a clear picture of
4.2. Geographic Information System what actually it is. During this phase, the system is evaluated and deficiencies are identified. This can
A geographic information system (GIS) is a computer system for capturing, storing, checking, and be done by interviewing users of the system and consulting with support personnel. Main activities at
displaying data related to positions on the earth’s surface. GIS stores information about the world as a this stage are:
collection of layers that can be linked together by a common locational component such as latitude and  Determining whether a business problem or opportunity exists. i.e. identifying problems and
longitude, a postal zip code, census tract name, or road name. opportunities.
Data in many different forms can be entered into GIS. Data that are already in map form can be o A problem is a basic condition that is causing undesirable results
included in GIS. This includes such information as the location of rivers and roads, hills and valleys. o An opportunity is a basic condition that presents the potential for desirable results.
Digital or computerized data can also be entered into GIS. An example of this kind of information is  Conducting a preliminary feasibility study to determine whether a new or improved
data collected by satellites that show land use - the location of farms, towns, or forests. GIS can also information system is a feasible solution.
include data in table form, such as population information. GIS technology allows all these different  Developing a project management plan and obtaining management approval.
types of information, no matter their source or original format, to be overlaid on top of one another on  Building the project team
a single map.
5.2. System Analysis
5. Design of Information Systems Systems analysis is an in-depth study of end user information needs which produces functional
Most computer-based information systems are conceived, designed, and implemented using some requirements that are used as the basis for the design of a new information system. Here, the systems
form of systematic development process called software development process. In this process, end analysts analyses end-user requirements and refines projects goals into defined functions and
users and system analysts design systems based on an analysis of the information requirements of the operations of the intended system. System analysis describes what a system should do to meet the
information system to be built. The software development process is also called system development information needs of users. It involves:
life cycle (SDLC).
SDLC is a structured step-by-step approach for creating and maintaining information systems. It  Analysis of the present (old) system
consists of a number of stages that describe the activities involved in an information system Analysis of present system involves:
development process. SDLC involves the following stages: system study, system analysis, system o Collecting factual data about the present system (questionnaires, interviews, observations,
design, development and testing, implementation, and maintenance. etc.)
o Identifying how input, processing, storage and output are being accomplished.
o Analyzing how the present system uses resources (hardware, software and people) to
convert input data into useful information
o Understanding information flow within the system
o Identifying problems with the system

 Gathering Business Requirement


Business requirements are the detailed set of knowledge users request the system must meet to be
successful. They explain what has to be done by identifying the necessary tasks, actions or activities
that must be accomplished.
It involves:

© 2014- BGS Molyko 40


Bilingual Grammar School Advanced Level Computer Science
o Determining specific information needs o Attributes (characteristics) of the entities about which the proposed system needs to
o Determining the information processing capabilities required for each system activity maintain information.
(input, processing, output, storage, and control) to meet the needs. The goal here is to o Relationships between these entities (E-R diagrams, data flow diagrams)
identify “what” should be done not “how” to do it. o Specific data elements (databases, files, records, etc.) that need to be maintained for each
o Determining functional requirements (information requirements that are not tied to the entity.
hardware, software, and people resources that end users presently use or might use in the o Data dictionary
new system). o Integrity rules (data validation and verification) that govern how each data element is
specified and used in the system.
 Feasibility Analysis
Feasibility analysis is a study which investigates the information needs of prospective users and  Process Design
determines the resource requirements, cost, benefits, and workability of a proposed project. Its goal is Process design focuses on the design of software resources, that is, computer programs and of
to evaluate alternative systems and propose the most feasible and desirable system for development. procedures needed by the proposed system. It concentrates on developing detailed specifications for
Feasibility of a system can be evaluated in terms of four major categories: the program modules that will have to be purchased as software packages or developed by custom
o Organizational feasibility focuses on how well a proposed information system supports the programming. Process design produces:
objectives of the organization and its strategic plan for information systems. o Detailed specification of algorithms (pseudo-codes, flow charts, etc.)
o Technical feasibilityfocuses on the reliability/capabilities of the hardware and software to o Detailed specifications of the procedures needed to meet the user interface and data design
meet the needs of the proposed system, and whether they can be acquired or developed in specifications.
the required time. o Detailed specification of the database schema (E-R diagram, object diagrams)
o Economic feasibilityfocuses on whether the tangible costs and benefits of the proposed The design stage is very important because it is the place where quality is fostered in software
system will exceed the costs of developing and operating it. engineering. Design provides us with representations of software that can be assessed for quality.
o Operational feasibility focuses on the ability of the end users to operate, use, and support Design is the only way that we can accurately translate a customer's requirements into a finished
the proposed system. software product or system.

The outcome of a feasibility analysis is a feasibility report which is presented to the user management 5.4. Construction
for approval. It may be accepted or accepted with modifications or rejected. Once the design of the system is complete, it has to be converted into a computer understandable form.
Development is the stage where the design is converted into a computer program.
 Documenting System Analysis
The outcome of systems analysis is a system proposal or requirements specification document which  Coding (programming)
describes what the new system should do without specifying how to do it. At the end of systems Coding is an important activity by which a programmer converts the systems specifications from the
analysis phase, the system analyst produces a system proposal that will be used as basis for the design design stage into computer instructions referred to as programs. It is generally felt that the programs
phase. must be modular in nature. This helps in fast development, maintenance and future change if required.

5.3. System Design  Prototyping


Systems design consists of design activities, which produce systems specifications satisfying the Prototyping is the rapid development and testing of a working model of a product in an interactive and
functional requirements developed in the systems analysis stage. While system analysis specifies what iterative process involving both systems analysts and end users. This working model or prototype, is a
is to be done by the new system, system design describes how the system will accomplish what is to be partially developed product that enables customers and developers to examine some aspects of the
done. proposed product and decide if it is suitable for a finished product.
System design focuses on three main activities: user interface design, data design and process design. Various types of prototyping exist.

 User Interface Design o Throw-away prototyping


A user interface is a means of interaction between the user and the computer-based application. This In throw-away prototyping, the prototype is discarded once the actual requirements have been
activity focuses on designing how data will be introduced into the system and how the information understood and the final system is developed with a much clear understanding of user requirements.
generated will be retrieved. It produces detailed specifications for information products such as:
o Display screens o Evolutionary Prototyping
o Interactive user/computer dialogues In evolutionary prototyping, a functional prototype with minimal functionality is built in the beginning
o Forms (on-screen forms for data input and output) and is refined over time, as requirements are better understood.
o Reports (on-screen and printed)
o Incremental Prototyping
 Data Design In incremental prototyping, functional prototypes of the various subsystems are built and then
Data design focuses on the design of the structure of data and files to be used by the proposed (new) integrated to form a complete system. In other words, the product is built as separate prototypes
system. It provides detailed descriptions of: which are later merged into a final product.

© 2014- BGS Molyko 41


Bilingual Grammar School Advanced Level Computer Science
- Definition for hardware and Operating System requirements
 Testing - The format of the output data
Testing is the process of executing a program with the intent of finding an error. During testing, trial - Explanation of common error messages and how to recover from them
runs are done to check for errors and whether or not the new system meets the users' needs. Once - Description of how to make backups against accidental data loss
source code has been generated, the software must be tested to uncover and correct as many errors as
possible before delivery. o Technical Documentation
There are three sets of data that can be used to test the system: normal data and abnormal data. Technical documentation is a description from the designer’s point of view. Technical documentation
o Normal data is data which the system will accept. often contains:
o Abnormal (erroneous) data is invalid data which the system will reject. - Detail functioning of the software showing algorithms, formulae, source codes etc.
o Extreme data are data values that are chosen at the absolute limits of the normal range. This - Description of data structures
is to ensure that all normal values will be accepted and processed correctly. - Test plans and testing procedures
- User interface and reports
Using these test data, the following test runs can be carried out: - Location and version of the software
o Unit testing tests the individual units or modules separately with prepared test data so that
any errors can be corrected. 5.5. Implementation/Conversion
Implementation is the conversion from the use of the present (old) system to the operation of the new
o Integration testing tests the complete system after the individual units have been tested system. It involves:
and put together. This tests that separately developed modules/units work together as  Installation of new system
planned without error.  Loading of data into new system
 Education and training of users of the system
o System testing tests the integrated system to evaluate the system's compliance with its
specified requirements. There are different types of conversions:

Two testing techniques that can be used are black-box testing and white-box testing. o Direct Conversion/Cutover: in which the old system is completely replaced by the new one.
Its disadvantage is that, if the new system fails, there is no back-up system, so data can be
o Black-box Testing lost.
Black-box testing is a test that relies on the input/output behavior of the system, without any
assumptions to what is happening within the system. It examines some fundamental aspects of a o Pilot Conversion: in which the new system is installed in one part of the business or
system with little regard for the internal logical structure of the system. Black-box tests are used to organization. This allows the new system to be fully developed and tested. Once the pilot
demonstrate that system functions are operational, that input is properly accepted and output is system is running successfully, the new system is introduced to all of the
correctly produced, while at the same time searching for errors in each function. business/organization.
- Its advantages are that, if something goes wrong with the new system, only a small part of
o White-box Testing the organization is affected, and the staff that were part of the pilot scheme can help train
White-box testing, also called glass-box testing, is a test that relies on information about how the other staff.
system has been designed and constructed. It requires knowledge of the internal structure or - As a disadvantage, there is no back-up system for the office/department doing the pilot, if
implementation of the system. White-box tests are conducted to ensure that internal operations are things go wrong.
performed according to specifications and all internal components have been adequately exercised.
o Parallel Conversion: in which old system and new system operate alongside each other (in
 Documentation parallel) until new system is proven capable.
The job of the programmer does not end with the code or software instructions. The organization or - It is advantageous in that, if the new system fails, the old system will act as a back-up. Also,
users need to know how to get the best out of the system. This is done through documentation. System the outputs from the old and new systems can be compared to check that the new system
documentation ensures continuity of the system. is running correctly.
There are two types of documentation; user documentation and technical documentation. - Its disadvantage is that, entering data into two systems, and running two systems together,
takes a lot of extra time and effort.
o User Documentation
User documentation is a complete description of the system from the user’s point of view detailing o Phased Conversion: in which the new system is installed in phases (stages or steps)
how to use or operate the system. It could be a paper-based user manual or help incorporated into the gradually replacing parts of the old system until eventually, the new system takes over.
software that can be accessed when the software is installed. User documentation always covers the - Its advantages are that, it allows users to gradually get used to the new system, and
following: training of staff can be done in stages.
- A guide that describes what the system is supposed to do in non-technical terms - Its disadvantage is that, if a part of the new system fails, there is no back-up system, so
- Instructions for installing and running the program data can be lost

© 2014- BGS Molyko 42


Bilingual Grammar School Advanced Level Computer Science
Definition: Project management is defined as the application of knowledge, skills, tools and techniques to
5.6. Maintenance activities of a project for the achievement of the project’s objectives/requirements.
Maintenance is the general process of changing a system after delivery to correct faults, improve
performance or adapt the system to a changing environment or business requirements. Maintenance is Project management ensures that an acceptable system is developed within time and budget.
necessary to eliminate errors in the system during its working life and to tune the system to any
variations in its working environment. 6.1. Project Life Cycle
Maintenance can be adaptive, preventive, corrective or perfective. The activities related to a project can be structured and grouped into stages according to the aim of the
activities. A typical project goes through the following stages called project life cycle: initiation,
 Adaptive Maintenance planning, execution, monitoring and control, and closing.
Adaptive maintenance focuses on adjusting a software product to properly interface with a changing
environment. Changes are made to increase system functionality to meet new business requirements.

 Preventive Maintenance
Preventive maintenance aims in retaining the system’s capabilities before the occurrence of any a. Initiation
problem (e.g. system failure). It locates weaknesses in the system and provides repairs in order to Project initiation determines the main objective of the project and forms a clear understanding about
avoid any eventual breakdown of the system. Making changes to prevent future system failures. the necessity and suitability of the project. This stage answers the questions “what?” and “why?”
Common activities at this stage are:
 Corrective Maintenance  Identification and initial analysis of the business needs.
Corrective maintenance aims in restoring a defective system to a required state. This implies that  Determination of the main objective(s).
repairs are made after a breakdown of the system. (Making changes to repair system defects)  Resource analysis (people, equipment, financial; needs and availability).
 Composition of the project charter.
 Perfective Maintenance (Project charter - document issued by the project initiator or sponsor that formally authorizes
Perfective maintenance refers to enhancements to the product in order to either add new capabilities the existence of a project, and provides the project manager with the authority to apply
or modify existing functions. Making changes to enhance the system and improve such things as organizational resources to project activities.)
processing performance and usability.
b. Planning
6. Project Management Project planning involves the project plan development and approval. It determines an optimal
A project is an endeavor to accomplish a specific objective through a unique set of interrelated tasks scheme/algorithm for project execution. This stage answers the question “how?” The main activities at
and the effective utilization of resources. A project has a definite start and finish time, well-defined this stage are:
outcomes or performance goals, and consumes scarce resources such as money, personnel, material,  Needs analysis
and equipment.  Description of the project (including determination of activities and necessary resources)
A project is considered constrained by three functions:  Composition of project plan
 Scope: what it is intended to accomplish. In other words, the customer’s requirements for  Planning and performing necessary PR-activities.
the project. (PR is the practice of managing the spread of information between an individual or an
 Time allocation: the time schedule for the project. organization and the public. Public relations activities include: launchings, media conferences,
 Cost: the money, budget, and resources for a project. sales promotions, open day, product testing, websites, press release, newsletters.)
These three functions are called the Triple Constraint. The relationship between them is represented
using the Project Management Triangle. c. Execution
Project execution is the phase within which the deliverables are physically constructed and presented
to the customer for acceptance. It integrates people and other resources to carry out the project
Time
management plan for the project. The activities undertaken to construct each deliverable will vary
Cost
depending on the type of project being undertaken. Main activities are:
 Starting up the execution.
 Building the deliverables
Scope
 Day-to-day management and reporting
The Project Management Triangle visualizes the fact that time, cost and scope of a project are
d. Monitoring and Control
interdependent; changing one of them causes changes in the other two. For example, if you want to
Project control measures and monitors progress to identify variances from the project management
shorten a schedule, you can hire more resources which would increase cost, or reduce customer
plan so that corrective action can be taken when necessary to meet project objectives. Control occurs
requirements which would affect quality. This simply means “you can have any two of quick, good or
throughout the duration of the project and has a range relatively similar to that of execution. While the
cheap, but not all three.”

© 2014- BGS Molyko 43


Bilingual Grammar School Advanced Level Computer Science
project is being executed, a series of management processes are undertaken to monitor and control the o Critical path: a sequence of dependent tasks that have the largest sum of most likely
deliverables being output by the project. This includes: durations. The critical path determines the earliest possible completion date of the project.
 Requesting, evaluating and approving changes to the project scope, deliverables, timescales o Critical task: a task found on the critical path. A critical task cannot be delayed without
or resources (change management) delaying the entire project schedule.
 Controlling the amount of time spent undertaking each activity within the project (time o Work Breakdown Structure: a hierarchical decomposition of the project into phases,
management) activities, and tasks.
 Identifying, approving and paying cost/expenses incurred on project (cost management) o Project management plan (PMP): a document that describes how the project is to be
 Reviewing deliverable quality (quality management) executed, monitored and controlled, which includes creating a project work breakdown
 Identifying, quantifying and managing risks to the project (risk management) structure, identifying and planning to mitigate risk, identifying manners in which to
 Identifying and handling issues currently affecting the ability of the project to produce the effectively communicate with stakeholders and other project team members, and
required deliverables (issue management) developing a plan to manage changes.
 Measuring each deliverable produced against acceptance criteria (acceptance management)
 Handling sourcing of products from an external supplier (procurement management)
 Identifying, creating, and reviewing communication messages within the project 6.3. Project Analysis and Scheduling
(communication management) Project scheduling is the process of converting a general or outline plan for a project into a time-based
 Performing a phase review at the end of execution to ensure the project has achieved its schedule based on the available resources and time constraints. Different techniques exist for
objectives as planned. analyzing and scheduling project activities.

e. Closing a. Critical Path Method (CPM)


Once all the deliverables have been produced and the customer has accepted the final solution, the CPM is an analysis technique used to predict project duration by analyzing which sequence of activities
project is ready for closure. (which path) has the least amount of scheduling flexibility (the least amount of total float). Early dates
Project closure involves: are calculated by means of a forward pass using a specified start date while late dates are calculated by
 releasing the final deliverables to the customer means of a backward pass starting from a specified completion date, usually the forward pass’s
 handing over project documentation to the business calculated project early finish date.
 terminating supplier contracts,
 releasing project resources  Forward pass: The calculation of the early start and early finish dates for the uncompleted portions
 communicating the closure of the project to all stakeholders of all network activities, determined by working forward through the schedule network logic from
the project’s start date.
6.2. Basic Project management Terminology  Backward pass: The calculation of late finish and late start dates for the uncompleted portions of
all schedule activities, determined by working backward through the schedule network logic from
o Task/Activity: anything that needs to be done that requires time and consumes resources. the project’s end date.
o Dependent task: a task that can only begin after a previous one is finished. For example,
roofing a house depends on the construction of the walls. CPM models the events and activities of a project as a network. Activities are depicted as nodes on the
o Slack time or float time: the amount of delay that can be tolerated between the starting network and events that signify the beginning or ending of activities are depicted as arcs or lines
time and completion time of a task without causing a delay in the completion date of the between the nodes.
entire project. If we have tasks A and B that start at the same time and task C that is a)
dependent on both tasks A and B. If task A takes 3 days and task B takes 5 days, then task A
has 2 days slack time. That is, it can run for 2 days before it affects the planned starting time
for task C.
o Lag time: the delay or amount of time that passes between the end of one activity and the
beginning of another if the two are dependent. For example, if task A is laying of cement
blocks and dependent task B is building the walls of the house, there would be some lag time
between the end of task A and the start of task B to let the blocks get dry.
o Lead time: occurs when a task should theoretically wait for its predecessor to finish, but can
b)
actually start a little early. The time that the tasks overlap is lead time.
o Milestone: an event that signifies the accomplishment or completion of a major deliverable
during a project.
o Deliverable: some concrete thing which is to be delivered, to the client or internally to the
development team.
o Leveling: the process of adjusting tasks to match resources available. There are two
techniques for leveling: task delay and task split.

© 2014- BGS Molyko 44


Bilingual Grammar School Advanced Level Computer Science
The critical path is A-E-D-F-I-J
The total estimated duration of the project = sum of duration of critical tasks = 7 + 10 + 8 + 2 + 2 + 3 =
32 𝑑𝑎𝑦𝑠

Exercise 1: Given the task description table below:

Activity Duration Precedence


A 3 -
Network diagrams
B 3 A
In the above network diagram, C 4 -
o Tasks are lettered from A to J. There are two ways of representing the activities on a D 1 C
network diagram: (a) activity on node and (b) activity on arc.
E 3 B, D
o Joining task A to E shows that task A must be completed before task E can be started.
F 2 A, B, D
o Joining tasks A and B to E shows that both task A and B must be completed before task E can
be started. G 2 C, F
o The number marked on each arc (arrow) shows the duration of the task from which the arc H 4 G
starts. I 1 C
The critical path can be identified by determining the following four parameters for each activity:
J 3 E, G
o ES – earliest start time: the earliest time at which an activity can begin given that its
K 5 F, H, I
predecessor activities must be completed first.
o EF – earliest finish time, equal to the earliest start time for the activity plus the time
required to complete the activity. 1. Draw the corresponding PERT diagram for this project
o LF – latest finish time: the latest time at which an activity can be completed without 2. Determine the critical path
delaying the project. 3. Calculate the total estimated duration of the project
o LS – latest start time, equal to the latest finish time minus the time required to complete the 4. State the float time for all non-critical activities
activity.
Activities with the same earliest and latest start times (ES=LS) or with same earliest and latest finish Exercise 2: Find the critical path for each of the activity networks below.
times (EF=LF) define the critical path. This means that these activities have a float time of 0.

For the above network diagram, we have: a.

Start times Float


Activity Duration
Earliest Latest time

A 7 0 0 0
B 2 0 5 5
C 15 0 12 12 b.
E 10 7 7 0

D 8 17 17 0

F 2 25 25 0

G 5 17 19 2

H 8 22 24 2
c.
I 2 27 27 0

J 3 29 29 0

Finish 32 32

© 2014- BGS Molyko 45


Bilingual Grammar School Advanced Level Computer Science

c) 𝑡 = 256, 𝑇 = 246 and σT 2 = 25


256 − 246 6
𝑃(𝑡 ≥ 𝑇) = = = 0.24
25 25

Definition: A PERT chart/diagram is a graphic illustration of a project as a network diagram consisting


of numbered nodes (either circles or rectangles) representing events, or milestones in the project linked
Remark! CPM was developed for complex but fairly routine projects with minimal uncertainty in by labeled vectors (directional lines) representing tasks in the project. The direction of the arrows on the
project completion times. For less routine projects there is more uncertainty in the completion times, lines indicates the sequence of tasks.
and this uncertainty limits the usefulness of the deterministic CPM model. An alternative to CPM is the
PERT (Program Evaluation and Review Technique) project planning model. c. Comparison between CPM and PERT
CPM task durations are known with certainty. CPM is therefore said to be deterministic while PERT is
b. Program Evaluation and Review Technique (PERT) probabilistic.
PERT is an event-oriented network analysis technique used to estimate project duration when there is
a high degree of uncertainty with the individual activity duration estimates. Each activity is assigned CPM PERT
three time estimates 1 Uses network, calculate float or
m= most likely time estimate, (mode) slack, identify critical path and
Same as CPM
a = optimistic time estimate (best case) activities, guides to monitor and
controlling project
b = pessimistic time estimate (worst case)
2 Requires 3 estimates of activity
time
These three estimates are then used to calculate a weighted duration for each task by using the Uses one value of activity time
Calculates standard deviation and
formula𝑇𝐸 = (𝑎 + 4𝑚 + 𝑏)/6 variance of time
The weighted durations are then used as a more realistic estimate of task durations for constructing a 3 Used where times can be Used where times cannot be
PERT chart (network diagram). estimated with confidence, estimated with confidence.
Using PERT, the probability of completing the project by a certain date t, can now be found by finding familiar activities Unfamiliar or new activities
4 Meeting time target or estimating
Minimizing cost is more
𝑡−𝑇 𝑡−𝑇 percent completion is more
important
𝑃(𝑡 ≥ 𝑇) = = important
√σT 2 σ
Where d. Gantt Chart
𝑇 is the expected completion time of the project A Gantt chart is a horizontal bar graph that helps plan and monitor project development or resource
And allocation on a horizontal time scale. It depicts project tasks against a calendar.
𝑏−𝑎 2 A Gantt chart is constructed with a horizontal axis representing the total time span of the project,
σT 2 = ( )
6 broken down into increments (days, weeks, or months) and a vertical axis representing the tasks that
is the variance of T = (variances of activities on the critical path). make up the project. Horizontal bars of varying lengths represent the sequences, timing, and time span
Example: for each task. The bar spans may overlap, as, for example, you may conduct research and choose
If a project’s expected completion time is 𝑇 = 246 𝑑𝑎𝑦𝑠 with its variance σT 2 = 25, then what is the software during the same time span. As the project progresses, secondary bars, arrowheads, or
probability that the project darkened bars may be added to indicate completed tasks, or the portions of tasks that have been
a) is actually completed within 246 days? completed. A vertical line is used to represent the report date.
b) is actually completed within 240 days?
c) is actually completed within 256 days

Solution
a) 𝑡 = 246, 𝑇 = 246 and σT 2 = 25
246 − 246
𝑃(𝑡 ≥ 𝑇) = =0
25

b) 𝑡 = 240, 𝑇 = 246 and σT 2 = 25


240 − 246 −6
𝑃(𝑡 ≤ 𝑇) = = = −0.24
25 25
∴ 𝑃(𝑡 ≤ 𝑇) = 1 − (𝑃(𝑡 < 0.24)) = 1 − 0.24 = 0.76

© 2014- BGS Molyko 46


Bilingual Grammar School Advanced Level Computer Science
A Gantt chart E- Review the minister’s Cannot start until A is
25 mins
career completed
The critical path is A-C-D-F-H = 5+6+4+2 = 17 days F- Prepare film for Cannot start until E and
20 mins.
archives C are completed
Cannot start until A, B, C,
Exercises! G- Edit 20 mins.
D, E and F are completed
Exercise 1: A project has been defined to contain the following list of activities along with their
required times for completion.
b. Construct an activity network for this problem and by finding the critical path, in your
network, show that the news item can be ready before 6 pm that day.
Activity Time Immediate
Activity c. Construct the corresponding Gantt chart for this project
No. (weeks) Predecessors

1 Collect requirements 3

2 Analyze processes 2 1

3 Analyze data 2 2

4 Design processes 6 2

5 Design data 3 3

6 Design screens 2 3,4

7 Design reports 4 4,5

8 Program 5 6,7

9 Test and Document 7 7

10 Install 2 8,9

b. Draw a network diagram for the activities.


c. Calculate the earliest completion time of the project
d. Show the critical path.
e. What would happen if activity 6 were revised to take 6 weeks instead of 2 weeks?
f. Construct a Gantt chart for this project

Exercise 2: At 4:30 pm one day CRTV news team hear of a Government Minister resigning. They
wish to prepare an item on the event for that evening’s 6 o’clock news. The table below list the jobs
needed to prepare this news item, the time each job takes and the constraints on when the job can
commence.

Time
Job Constraints
needed
A - Interview the
15 mins. Starts at 4:30 pm
resigning minister
B - Film the ministry 20 mins. None
C - Get reactions from Cannot start until A and B
25 mins.
regions are completed
D - Review possible Cannot start until B is
40 mins
replacements completed

© 2014- BGS Molyko 47


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 5: DATABASE DESIGN SYSTEMS AND MODELING 2.1. First Normal Form
A relation (Table) is in first normal form (1NF) if and only if
Introduction  It contains a primary key. A primary key is an attribute that identifies each entity in a
A database is an organized collection of related data stored in a way that it can be easily retrieved unique way.
and manipulated. A telephone directory, a library catalogue and a class register are examples of  It contains no multivalued field or repeating groups. A multivalued field is one that may
manual or paper-based database systems. A paper-based database requires much paper as the take several values for a single record. A repeating group is a set of one or more
database becomes larger, making it difficult to manipulate the database. The problems caused by multivalued attributes that are related.
paper-based systems are solved by the development of computer-based systems.
The capacity for computers to store large amounts of data and their ability to quickly and efficiently For example:
retrieve the data makes them ideal for creating and using electronic or computerized databases. A
computerized database refers to a collection of related files that are digitized. Computerized StudID Stud_Name School Subject Grade
databases are created using database software called database management systems (DBMS).
7023 Mary Watson BGS Molyko Chem, Phy, Maths A, C, B
1. Database Models
7140 Peter Rowling BGS Molyko Bio, Chem, Maths B, C, D
1.1. Flat-file Database
A flat file database is a single table database, with separate copies of data in each part of the 7254 Quincy Greg BGS Molyko CSC, Maths, FMaths A, C, D
business. An example is a phone directory.
The problems encountered with flat file databases are Problems:
 Data duplication: data is repeated and hence stored many times. This wastes disk space and  The table has no primary key
slows down query time.  It contains multivalued fields “Subject” and “Grade”
 Maintenance is difficult as every occurrence of a piece of data needs to be updated if its
value changes To solve the problem
 More manual data entry is required and therefore a greater likelihood of errors when data is  We take StudID as the primary key
being entered.  Create new rows so each cell contains only one value

The solution to these problems is to divide the data into logical groups and store the data in multiple StudID StudName School Subject Grade
tables, then connect (relate) the tables to each other. This results to a Relational database.
7023 Mary W. BGS Molyko Chem A
1.2. Relational Database Model
In a relational database, data is organized in two dimensional tables called relations, which are 7023 Mary W. BGS
BGSMolyko
Molyko Phy
Phy CC
linked. A relation has the following features:
 Name: the name of the table 7023 Mary W. BGS Molyko Maths BB
 Tuples: a tuple is a single row of a table, which contains a single record for that relation.
7140 Peter R. BGS Molyko Bio B
 Attributes: an attribute is a single column in the table, which contains a fact about each
record in the relation.
7140 Peter E. BGS Molyko Chem C

1.3. Object-Oriented Database Model


7140 Peter E BGS Molyko Maths D
An object-oriented database tries to keep the advantages of the relational model and at the same
time allows applications to access structured data. 7254 Quincy G. BGS Molyko CSC A

7254 Quincy G. BGS Molyko Maths C


1.4. Hierarchical Database Model
7254 Quincy G. BGS Molyko FMaths D
2. Database Normalization
Database normalization is the process of organizing the fields and tables of a relational database to
minimize redundancy and dependency. Normalization usually involves dividing large tables into But still, there is a problem because StudID is no longer valid as primary key. It no longer identifies
smaller and less redundant tables and defining relationships between them. Normalization works each row (record) uniquely.
through a series of stages known as normal forms. In order to achieve one level of normal form, To solve this problem, we declare StudID and Subject together to uniquely identify each row.
each previous level must be met.
Now, the new primary key is StudID and Subject. It is a composite key.

© 2014- BGS Molyko 48


Bilingual Grammar School Advanced Level Computer Science
2.2. Second Normal Form
Name
A relation is in second normal form (2NF)if and only if Number
 It is in 1NF
PERSON Owns HOUSE
 Every non-key attribute is fully dependent on the primary key. In other words, there
should be no partial dependencies. DOB Street

To put the data model to 2NF, we have to ensure that every non-key attribute is functionally
dependent on the entire primary key. An attribute B is said to be functionally dependent on another An E-R diagram
attribute A if A determines B, and is written as AB.
The basic elements of an E-R diagram are entity sets, attributes and relationship types.
{StudID} {StudName}
{StudID}  {School} 3.1. Entity Set
{StudID}  {Grade} An entity is a person, place, concept or thing for which we intend to collect data. For example, a
{Subject}  {StudName} customer, an employee, a book, an appointment.
{Subject}  {School} A group of entities that share the same properties is an entity set. An entity is therefore a member or
{Subject}  {Grade} an instance of an entity set. In an E-R diagram, an entity set is represented by a rectangle. In the
above E-R diagram, PERSON and HOUSE are entity sets
StudName is dependent on StudID but it is not dependent on subject, the other part of the key.
School is neither dependent on StudID nor Subject. 3.2. Attributes
Grade is dependent on Subject but to have the grade in a subject you need a StudID. Therefore, An attribute is a fact about an entity or a property that describes an entity. For example, a person’s
grade is dependent on both Subject and StudID. name, date of birth or gender, a vehicle’s model, color or brand. Attributes store the actual data we
want to keep about each entity within an entity set. An attribute is represented by an ellipse. In the
To solve these problems, we create separate tables for the fields that are not functionally dependent above E-R diagram, name and date of birth are attributes of the entity set PERSON while Number
on the entire key. The primary key for these tables is the part of the primary key on which they are and Street are attributes of the entity set HOUSE.
dependent. An attribute can be simple, composed, derived, single valued or multi-valued.

We now have, a. Simple attribute: simple attribute is an atomic value, which cannot be divided further.
For example, a person’s phone number is an atomic value of 9 digits.
STUDENT: (StudID, StudName)
SCHOOL: (SchoolID, SchoolName) b. Composite attribute: an attribute made of more than one simple attribute. For example,
SUBJECT: (SubjCode, SubjTitle) a person’s complete name may have FName, MName and LName.
STUDENT_SUBJECT: (StudID,SubjCode, Grade)
c. Derived attribute: an attribute which does not exist physically in the database, but its
2.3. Third Normal Form value is derived from other attributes present in the database. For example, a person’s
A relation is in third normal form (3NF) if and only if age can be derived from his date_of_birth.
 It is in 2NF
 There are no transitive dependencies. Transitive dependency is a situation where a non- d. Single-valued attribute: an attribute that contains one single value. For example ID car
key attribute depends on another non-key attribute. number.

3. Entity-Relationship Modeling e. Multi-valued attribute: an attribute than can contain more than one value for the same
When a relational database is to be designed, an entity-relationship model is drawn at an early stage entity. For example, a person can have more than one phone numbers or e-mail
and developed as the requirements of the database and its processing become better understood. addresses.

Definition: An E-R model is a diagram which uses basic graphic symbols to show the organization of 3.3. Relationship Type
and relationships between data in a database. A relationship type is a named association between entities. A person (entity) owns (relationship) a
house (entity), a teacher (entity) teaches (relationship) a subject (entity). Normally, individual
An E-R diagram serves as a schema diagram for the required database. A schema diagram is any entities have individual relationships of the type between them but in an E-R diagram, this is
diagram that attempts to show the structure of the data in a database. generalized to entity sets and relationship types. For example, the entity set PERSON is related to
the entity set HOUSE by the relationship type OWNS.A relationship type is represented by a
diamond.

© 2014- BGS Molyko 49


Bilingual Grammar School Advanced Level Computer Science
A relationship can be characterized by a degree and cardinality ratio.
 In the relationship RECEIVES between STUDENT and SLIP, each student receives one and
3.3.1. Degree of a Relationship only one result slip. The cardinality of student is one and the optionality is one. Each result
The degree of a relationship refers to the number of participating entities in the relationship. It can slip is issued to one and only one student. The cardinality of SLIP is one and the optionality
be unary, binary, ternary or n-ary. is one. This relationship is described as one-to-one (1:1).

 A unary relationship type is one that involves entities from a single entity set. E.g. the (1,1) (1,1)
STUDENT Receives SLIP
relationship MANAGES between entities within the entity set EMPLOYEE.

Employee Manages
(1:1) relationship
 In the relationship TEACHES between TEACHER and SUBJECT, a teacher teaches one or
many subjects. The cardinality of TEACHER is many and the optionality is one.
 A binary relationship type is a relationship between entities from two different entity sets. A subject is taught by one or many teachers. The cardinality of SUBJECT in the inverse
An example is the relationship OWNS in the E-R diagram above. relationship IS_TAUGHT_BY, is many and the optionality is one. This relationship is
described as many-to-many (M:N).

PERSON Owns HOUSE

 A ternary relationship type is one that involves entities from three different entity sets. An (1,M) (1,N)
TEACHER Teaches SUBJECT
example is a LECTURER who teaches a certain COURSE in a DEPARTMENT.

LECTURER Teaches COURSE (M:N) relationship


Remark In a normalized database, many-to-many relationships are eliminated by creating a link
entity between the entities involved in the relationship.
DEPARTMENT The above TEACHES relationship when normalized becomes

 An 𝑛-ary relationship type involves entities from 𝑛 different entity sets. (1,1) (1,N) (1,N) (1,1)
TEACHER TEACHES SUBJECT
3.3.2. Cardinality Ratio of a Relationship Type
Cardinality is the maximum number of entities within each entity set that can take part in a Normalized (M,N) relationship
relationship. For example, what is the maximum number of houses that a person can own? On the The primary key of the link entity is a composite key that consists of the primary keys of the entities
other hand, the minimum number of entities within each entity that can take part in the relationship TEACHER and SUBJECT.
is the Optionality. For example, what is the minimum number of houses that can be owned by a
person? The above representation of an E-R diagram is the Chen Convention. Another way of representing E-
The cardinality ratio is a ratio of the cardinalities of the entity sets involved in a relationship. It can R diagrams is the crow’s foot notation that uses three symbols to show cardinality ratios. Here, a
be one-to-one (1:1), one-to-many (1:N) or many-to-many (M:N). circle means zero, a line means one and a crow’s foot means many. The cardinality is shown next to
the entity type and the optionality (if shown at all) is shown behind it.
 In the relationship OWNS between PERSON and HOUSE, a person can own zero or many
houses. Therefore, the cardinality of PERSON in the relationship OWNS is many while the
optionality is zero.
On the other hand, a house is owned by one person. The cardinality of HOUSE in the inverse
relationship IS_OWNED_BY, is one while the optionality is one. The relationship OWNS is
therefore described as a one-to-many (1:N) relationship.

(1,1) (0,N)
PERSON Owns HOUSE Where A and B are entity sets and R is the relationship type.

Exercise! Exercise! Exercise!


(1:N) relationship

© 2014- BGS Molyko 50


Bilingual Grammar School Advanced Level Computer Science
1) Identify the cardinality ratios of the following relationships. Year, etc) and an “AUTHORS” table to store information about authors (name, birth date, birth place,
etc).

 A field is a specific piece of data stored in a table. The above mentioned ‘BOOKS’ table has
fields ‘Title’, ‘Publisher’, ‘Year’ etc.

 A record is an individual entry in a database table. It comprises of one or more fields,


depending on the number of fields defined to the table. For example: if five books are
entered in our books and authors database, the “BOOKS” table would have five records (one
for each book).

 Each field in a database table is assigned a data type when the field is created. The data type
determines the kind and format of the information stored in the field. Example: the “Title”
field in the “BOOKS” table will store text that will vary with each book in the database, so the
data type in this case will be text or character type.
2) A database will be made to store information about patients in a hospital. On arrival, each
patient’s personal details (name, address, and telephone number) are recorded where a. Creating a New Table
possible, and they are given an admission number. They are then assigned to a particular To create a new table,
ward (Accident and Emergency, Cardiology, Oncology, etc.). In each ward there are a o Click the Create Tab
number of doctors and nurses. A patient will be treated by one doctor and several nurses o Select Table in the Tables group to create a new table in Datasheet view or Table
over the course of their stay, and each doctor and nurse may be involved with several Design to create a new table in Design view
patients at any given time.
b. Adding Fields in a Table
From the description, draw a corresponding E-R diagram showing all entity sets, To add a field to a table in Datasheet View,
attributes, relationship types and cardinality ratios. o Click the Add New Field column label.
o Click Rename in the Fields & Columns group.
4. Database Management Systems o Type the field name and press Enter. Access creates the field. Continue until you have
A database management system (DBMS) is a computer program that is used to create, manipulate created all of the fields in your table.
and access a database. Examples are MS Access, MySQL, Oracle, Sybase, dBase, Paradox, Objecstore o Press Enter without entering a field name to end your entries.
and O2.
A DBMS provides users with: To add a field to a table in Design View,
 Data Definition Language (DDL): language which programs the structure (schema) of the o Select a cell in the Field Name column
database o Type a name for the first field in the table and press Enter
 Data Manipulation Language (DML): language which changes the contents (instance) of the o Select a data type and press Enter
database o Type a description and press Enter
 Data Control Language (DCL)
c. Naming and Saving a Table
4.1. Microsoft Access 2007 To name and save a table,
MS Access 2007 is made up of several components including: o Click the Save button on the Quick Access toolbar. The Save As dialog box appears.
 Tables o Type the name you want to give your table.
 Forms o Click OK. Access names your table.
 Queries
 Reports Tip: You can use the Rename option at any time to rename any column. For example, you can
rename the ID column Author_ID.
These components are called database objects. One or more of these components are formed when
a database is created. These components are stored in a single database file. d. Setting a Primary Key
A primary key is a field in a table that allows each entry in the table to be identified in a unique way.
4.1.1. Tables No two entries in the database can have the same primary key. For example your ID card number is
A table is an area of the database where information is stored. Tables organize data into columns unique. By default, Access sets the first field in the table as the Primary Key field.
(called fields) and rows (called records). Example: a database storing information about books and To set a Primary Key:
authors for a library could have a “BOOKS” table to store information about books (title, publisher, o Switch to Design View

© 2014- BGS Molyko 51


Bilingual Grammar School Advanced Level Computer Science
o Position your cursor in the field you wish to set as the Primary Key o Enter a name for the query
o Click the Primary Key button on the Ribbon o Click OK

e. The Foreign Key 4.1.4. Forms


The primary key is used to link the table with other tables in the database. When a primary key in A form is an interface that allows users to enter and view data. Forms give the ability to choose the
one table (known as the source table) is linked to another table (known as the target table), the format and arrangement of fields. They can be used to enter, edit and display data. Forms can
connecting field in the target table is called the foreign key. A foreign key must have the same retrieve data from one or more tables, and display the output on the screen.
structure, data type, and field size as the associated primary key, but it must not have the same
name. Also, the foreign key in a relationship between two tables need not be a primary key in its To create a Form using the Form Wizard
own table.  Navigate to the table you want to base the form on
 Click Create on the Ribbon
4.1.2. Relationships  Click Forms
Relating tables reduces the unnecessary duplication of data (redundancy).The general procedure You are able to navigate using the navigation arrows at the bottom of the form.
for creating relationships in Access is to
o Determine the type of the relationship and identify the source and target tables To enter a record on the Form:
o Create the foreign key field(s) in the target table if they are not already present  Click the View button on the Ribbon to switch from Layout View to Form View
o Select the Database Tools tab  Enter the data for each field in the record, pressing the Enter key to move to the next field
o Click on the Relationships command  Press Enter after you have entered data for the last field
o Add all the tables involved in the relationship to the window
o Create the relationships by dragging the primary keys from the source table(s) and NB. The form feeds the table. If you edit a record on the form, or create a new record, that data will
dropping them on the associated foreign key(s) in the target table(s). be passed to the table it is associated with.

For example: Let’s create a relation between the AUTHORS table and the BOOKS table. 4.1.5. Reports
A report is an effective way to analyze and present data in printable format using a specific layout.
4.1.3. Queries Reports are the primary method of retrieving and viewing information. Using queries, reports pull
A query is a command that tells the database what data the user wants to see. A query allows information the user has requested and either print that information or display it on screen. The
information to be found and retrieved from one or more tables based on a set of search conditions information that appears and the formatting and appearance of a report are set when the report is
you define. For example: a query can be written specifying that the database should retrieve all the created.
books from the “BOOKS” table written by William Shakespeare.
To create a Report using the Report Wizard:
To create a query,  Click the Create tab on the Ribbon
o Click the Create tab on the Ribbon  Click the Report Wizard command
o Click the Query Design command
 Select the table or query upon which the report will be based
o Double-click Create Query in Design View
 Select the fields that you want to include on the report by double clicking on them
o Select the table that you would like to base your Query on
 Click Next
o Click Add
 Select a style for the report
o Close the Show Table window
 Click Next
 Type a title for the report
In order to control which records are displayed, you must define criteria in a Query.
Click Finish
To define criteria for your query:
o Position your cursor in the criteria row in the field for which you wish to define the
4.2. Structured Query Language
criteria for
Structured query language (SQL)
o Enter the criteria
o Click the Run Query button

For example: a query to find the books written by Barack Obama

The result of a query is called a recordset.

To Save the Query:


o Click the Save Icon

© 2014- BGS Molyko 52


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 6: ALGORITHM DESIGN AND PROGRAMMING 2.1.1. Arrays
An array is a data structure, which allows a set of items of identical data type to be stored together
1. Data Types and Data Structures using the same identifier name. When an array is created, its dimension (size) and the type of its
1.1. Data Types elements are specified.
Computers manipulate data of different types like numbers, letters, sound and images. No matter
the type, each data is stored as a pattern of binary digits. Numbers can be added, subtracted, divided For example: String Names[5]
and multiplied whereas letters cannot. This implies that data of a given type will be treated Names : Array [1..5] of string
differently from data of another type. As such, the type of any data stored in the computer must be
specified so that the correct operations will be performed on it. The above statements create an array called “Names” of five elements in C and Pascal respectively.
A data type is defined as a set of values and a collection of operations on those values. Examples of The size of the array is 5 and its elements are of type string.
data types are integer, real, string and Boolean. To reference an element in an array, an index is used. An index is an integer that gives the element
at the indexed position in the array.
a. Integer For example in C, Names[0] references the first element in the array Names, Names[1] references
An integer is a whole number that can be positive, negative or zero. Examples: -3, 5, 67, -134 and the second element, Names[2] references the third and so on…
4231. In Pascal, the referencing starts from 1 rather than 0.

b. Real a. One-dimensional Arrays


A real is a number that contains a decimal point. Computers manipulate numbers with fractions as A one-dimensional array is an array which is declared using a single index and can be visually
floating point numbers. Examples: 3.14, 12.25 and 0.001. represented as a list. The array “Names” above is one-dimensional.
If the array “Names” contains five elements (names), Raissa, Peter, James, Leticia and Isaac, it can be
c. Boolean visually represented as follows:
A Boolean data type stores one of only two values – true or false, yes or no, or on or off. Usually
these values are stored as 1 for true and 0 for false. Element Raissa Peter James Leticia Isaac

d. Character Index [0] [1] [2] [3] [4]


A character is any letter, digit, space, punctuation mark, or symbol that can be typed on a computer. Names[0] == Raissa, Names[4] == Isaac
The word "computer" for example, consists of eight characters. The phrase "data type" takes up nine
characters. A character data type stores only a single character or digit. Each character requires one b. Two-dimensional Arrays
byte of space, so "computer" takes up 8 bytes (8 × 8 = 64 𝑏𝑖𝑡𝑠). Examples: A, 5, -, and !. A two-dimensional array is an array which is declared using two indices and can be visually
represented as a table.
e. String/Text For example:
A string is a set of characters grouped together. A string is sometimes just referred to as ‘text’. It can
contain a mixture of numbers, letters and, spaces. Numeric data stored as text is only for int Tab[3][2] or Tab : Array [1..3, 1..2] of integer
representation not for calculation. Any type of alphabetic or numeric data can be stored as a string. 3 is the number of rows and 2 is the number of columns in the table Tab.
Examples: “Limbe City”, “10base-2” and “36.85”.
The elements of Tab will be referenced as:
f. Date/ Timestamp Tab[0][0] Tab[0][1]
Date and timestamp are data types for storing date and time respectively. The format used for date Tab[1][0] Tab[1][1]
is either dd-mm-yy or mm-dd-yy and hh:mm:ss or ss:mm:hh for time. Tab[2][0] Tab[2][1]

g. Container Example: Given the 2-dimensional array Tab[4][2] below, what are the elements given by the
A container is a data type used for storing images, video, sound or another type of ‘complex’ file. In references Tab[0][0], Tab[1][1], Tab[3][0] and Tab[2][1]?
some languages, binary large object (blob) is used rather than container.
Index [0] [1]
1.2. Data Structures
[0] 5 3
A data structure is a way of organizing and storing data in memory so that it can be used efficiently.
Any data structure is designed to organize data so that it can be accessed and worked with in [1] 1 4
appropriate ways. A well-designed data structure allows a variety of critical operations to be
performed, using as few resources, both execution time and memory space, as possible. Data [2] 3 1
structures include arrays, records, stacks, queues, trees, graphs and hash tables. [3] 2 8

© 2014- BGS Molyko 53


Bilingual Grammar School Advanced Level Computer Science

Each individual element can be referenced by its row and column indices. For
ClassList[0].Gender == F; ClassList[4].DOB == 29 Feb 1995; ClassList[3].DOB.Month == Dec
example:
Tab[0][0] = 5 2.1.3. Stack
Tab[1][1] = 4 A stack is a linear list in which items are added and removed from the same end (head). Items being
Tab[3][0] = 2 added and removed from the same end means that the last item to be added will be the first to be
removed. As such stacks are also called last in, first out (LIFO) lists as they use the LIFO principle.
2.1.2. Record (FILO)
A record is a data structure which allows items of different types that define a particular structure Stack operations are:
or object, to be stored together. The elements of a record are usually called fields or members.  Stack(S): creates an empty stack named S
Defining a record includes specifying the data type of each field and a name (label) by which the  Push(S,x): inserts the element x to the top of the stack S. Inserting an element into a stack
field can be accessed. that is full leads to a situation known as overflow. (START == NULL)
For example,  Pop(S): removes an element from the top of the stack S. Removing an element from an
empty stack leads to a situation known as underflow. (START == HEAD)
Student = RECORD struct Student
Date= RECORD  IsEmpty(S): checks whether the stack S is empty. Returns true if it is empty and false
Name: String {
Day: Integer otherwise.
Gender: Character string Name
Month: String
DOB: Date char Gender
Year: Integer Application of stacks:
End RECORD Date DOB
End RECORD
}
a. Converting a Decimal Number to Binary
The above Date record has a numeric field Day, a text field Month and a numeric field Year. The Initially we push the binary digit formed into the stack, instead of printing it directly. After the
Student record has fields Name, Gender and DOB which is of type Date. The table below gives entire digit has been converted into the binary form, we pop one digit at a time from the stack and
examples of student records. print it. Therefore we get the decimal number converted into its proper binary form.

b. Evaluating Arithmetic Expressions


Name Gender DOB
Arithmetic expressions are usually written in the form(𝑎 + 𝑏), where the operator is in between the
Raissa F 01 Apr 1996 operands. This is known as the infix notation. This notation poses problems for more complicated
expressions. For example:
Peter M 17 Oct 1995
Records (𝑎 × 𝑏) + 𝑐?
James M 05 May 1995 𝑎×𝑏+𝑐 ={
𝑎 × (𝑏 + 𝑐)?
Leticia F 09 Dec 1997
(2 × 6) + 5 = 17?
Isaac M 29 Feb 1995 2×6+5 ={ 𝑜𝑟
2 × (6 + 5) = 22?
Each row in the table corresponds to a different record. This table has 5 records.
Infix notation requires the use of order of precedence of operators and parentheses making it
A field in a record is referenced as follows:
complicated and difficult for computers to evaluate expressions in this form.
To ease evaluation of arithmetic expressions, other notations are used: the prefix and postfix
RecordName.fieldName = “”
notations.
Raissa.DOB = 01 Apr 1996
In prefix notation also called polish notation, operations are written before the operands. For
example the expression (𝑎 × 𝑏) + 𝑐 will be written in prefix notation as
Record data structures are always used in association with arrays. That is, we define an array whose
(𝑎 × 𝑏) + 𝑐 = (× 𝑎𝑏) + 𝑏
elements are of type record. When this is done, we have an array of records.
= + × 𝑎𝑏𝑐
For example: let’s define an arrayClassList, which stores information about the students in the table
In postfix notation also called reverse polish notation, operands come before operators. For example
above.
(𝑎 × 𝑏) + 𝑐 = (𝑎𝑏 ×) + 𝑐 = 𝑎𝑏 × 𝑐 + (2 × 3) + 1 = 23 × 1 +
Also,
Student ClassList[5] or ClassList : Array [1..5] of Student
𝑎 × (𝑏 + 𝑐) = 𝑎 × (𝑏𝑐 +) = 𝑎𝑏𝑐 +× 2 × (3 + 1) = 231 +×
An element in this type of array is referenced as follows:
ArrayName[index].fieldName

© 2014- BGS Molyko 54


Bilingual Grammar School Advanced Level Computer Science
Prefix and postfix notations do not require parentheses or precedence rules. Calculators use postfix
notation to evaluate arithmetic expressions. A simple way to understand is by using the following 2.1.4. Queues
expression: Pre A In B Pos. A queue is a linear list in which items are inserted at one end (tail/rear) and removed from the
other end (head/front) such the first item added to the queue is the first to be removed. Queues are
To convert from infix to prefix or postfix, priorities are assigned to operators as follows: 𝑝𝑟𝑖𝑜𝑟𝑖𝑡𝑦(× also called FIFO lists as they use the FIFO principle. (LILO)
) = 𝑝𝑟𝑖𝑜𝑟𝑖𝑡𝑦(/) > 𝑝𝑟𝑖𝑜𝑟𝑖𝑡𝑦(+) = 𝑝𝑟𝑖𝑜𝑟𝑖𝑡𝑦 (−) and the following rules are used. Queue operations include:
- When an operand lies between two operators, it associates with the operator that has higher  Create(Q): creates a queue Q.
priority.  Enqueue(Q,x): inserts the element x to the tail of the queue Q.
- When an operand lies between operators of same priority, it associates with the operator on  Dequeue(Q): removes the first element from the head of the queue Q
the left.  Top(): checks the next element to be removed (do not remove)
 IsEmpty(): checks whether the queue is empty. Returns true if it is empty and false
Example 1: Let’s convert the expression P: 𝐴 + 𝐵 × 𝐶/𝐷 to postfix. otherwise.
Considering the priority rules given above, we can rewrite P as follows:
P:𝐴 + ((𝐵 × 𝐶)/𝐷) Application of queues:

Stack[empty] a. Spooling
Output: [ ] It is a method used to place input and output on a fast access storage device, such as a disk, so that
Read A push it into stack stack[A] output: [𝐴 ] slow peripheral devices do not hold up the processor. For example, print spooler stores output to be
Read + stack[+] output: [𝐴 ] printed in a queue while waiting for the user’s program to finish creating the output. The spooler
Read ( stack[+(] output: [ ] then sends the stored output to the printer at the proper speed. If new output arrives for printing, it
Read ( stack[+((] output: [ ] is added to the queue.
Read B stack[+((] output: [ 𝐴𝐵 ]
Read * stack[+((*] output: [ 𝐴𝐵 ] b. Scheduling
Read C stack [+((*] output: [𝐴𝐵𝐶] It is the process of determining which of the jobs in memory will be executed by the CPU. When a
Read ) stack [+(] output: [𝐴𝐵𝐶 ×] pop until you meet an opening ) job is created, it is added to a queue, the ready queue. Any other job that arrives is added to the tail
Read / stack [+(/] output: [𝐴𝐵𝐶 ×] of the queue. A scheduling algorithm like round-robin is then used to allocate the jobs one by one, to
Read D stack [+(/] output: [𝐴𝐵𝐶 × 𝐷] the CPU for execution.
Read )  stack [+] output: [𝐴𝐵𝐶 × 𝐷/]
stack[ ] output: [𝐴𝐵𝐶 × 𝐷/+] Remark A queue in which elements can be added and removed from any end is known as a double
ended queue (Deque).
𝐴 + ((𝐵 × 𝐶)/𝐷) in postfix notation is 𝐴𝐵𝐶 × 𝐷/+
2.1.5. Linked Lists
Example 2: Let’s evaluate the expression 234 × 5 + − written in postfix notation. A linked list is a linear list in which each element contains a pointer to the next element in the list.
Read 2  stack [2] Each element in a linked list is known as a node and consists of two parts: the data item and the
Read 3  stack [2, 3] pointer to the next element.
Read 4  stack [2, 3, 4]
Read ×  stack [2, 3 × 4 = 12]= [2, 12] A C E
Read 5  stack [2, 12, 5]
Read + stack [2, 12 + 5 = 17] = [2, 17]
Read −  stack [2 − 17 = −15] = [−15] Data Pointer
A linked list that stores characters
The result of the expression 234 × 5 + − is −15
Linked lists make it possible to insert items in the middle of the list without moving other items to
Exercise: Convert the following to postfix notation and evaluate them. make room.
i) 2−3×4+5 (34 × 2 − 5+)
ii) (2 − 3) × (4 + 5) (23 − 45 +×)
iii) 2 × 3/(2 − 1) + 5 × 3 (23x A B E

Exercise 2: Evaluate the following expressions


i) 623 + −382/+ × 2^3 + C D P
ii) 12, 7, 3, −,/, 2, 1, 5, +,×, + (June 2013, Paper 2, Q5) M E
Linked list with elements C and D inserted.
e 1
m
© 2014- BGS Molyko 55
or
Bilingual Grammar School Advanced Level Computer Science
a. Breadth First Traversal
NB: In a double linked list, every node has two pointers: one for its predecessor and another for its In a breadth first traversal all of the nodes on a given level are visited and then all of the nodes on
successor in the list. the next level are visited, usually in a left to right fashion. It is also called level order traversal.

2.1.6. Binary Tree Consider the following binary tree.


A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary
trees called the left sub-tree and the right sub-tree. In other words, it is a non-linear linked list
where each node may point to two other nodes. Binary trees are a very efficient way of storing items
that must be searched for and retrieved quickly. Suppose, for example, that you want to store the
following names in a computer using a binary tree:

Jones, Stephen, Agbor, William, Bate, Peter, Terence A level order traversal of this tree gives: ABCDEGHFJKL

The names can be arranged into a binary tree by using the following two-step procedure: b. Depth First Traversal
1. Use the first name on the list as the root of the tree. In depth first traversal, the left subtree is traversed, the right subtree is traversed and the root is
2. To find where to put each subsequent name, start at the root of the tree. If the name you are visited. There are three different depth first traversal techniques; preorder, in order and post order
dealing with precedes the root name alphabetically, follow the left pointer; otherwise follow the traversals. What distinguishes them is the order in which the subtrees and the root are visited.
right pointer. Proceed in this way until you come to an empty pointer; attach the name to it.
 Preorder Traversal:
Jones - Visit the root
- Traverse left subtree
- Traverse right subtree

A preorder of the above tree gives: ABDEFCGHJLK


Agbor Stephen
 Inorder Traversal:
- Traverse left subtree
- Visit the root
Peter William - Traverse right subtree
Bate

An in order traversal of the tree above gives: In order traversal: DBFEAGCLJHK

 Postorder Traversal:
Terence
- Traverse left subtree
- Traverse right subtree
- Visit the root
A binary tree that stores names

A post order traversal of the tree above give: DFEBGLJKHCA


The topmost node in the tree is known as the root node. Each node in a binary tree may have at most
two children or child nodes. A node that has a child is called the child's parent node (or ancestor 2.1.7. Hash Table
node, or superior). A node has at most one parent except the root node that has no parent. Nodes A hash table is an array in which data is stored at specific locations designated by a hash function. A
that have the same parent are called siblings. Every node in a tree can be seen as the root node of the hash function is a function that transforms the value of a record key into an index that corresponds
sub-tree rooted at that node. to a location for storing the record. A hash function maps the set of input data to a set of integers.
Nodes at the bottom most level of the tree are called leaf nodes. Since there are at the bottom most Each element to be stored in the array has a unique key that is mapped by the hash function to a
level, they will not have any children. numeric value that represents an index in the array.
For example,
Tree traversal is the process of systematically visiting all the nodes in a tree and performing some
computation. When describing a traversal strategy, we need not concern ourselves with what that
computation is. There are two methods for traversing a tree: breadth first traversal and depth first
traversal.

© 2014- BGS Molyko 56


Bilingual Grammar School Advanced Level Computer Science

Index Element - should be unambiguous (i.e. no doubts about what to do/ only one way of interpreting the
instructions)
Null - should be effective (i.e. produce good results)
Key
- should be finite (i.e. have a definite stopping place)
25 Agbor
3.1. Representation of Algorithms
36 2 Kome There are different ways for representing algorithms such as pseudo code, flow chart and
structured English.
3 x.Eyong
24
3 3.1.1. Pseudo code
44 x Epie
A pseudo code is an outline of a computer program, written in a mixture of a programming language
. and English. Writing pseudo code is one of the best ways to represent an algorithm as it allows the
66 5
4 Null
programmer to concentrate on how the program works while ignoring the details of the language.
In a pseudo code, some terms are commonly used to represent the various actions. For example, for
6 Sama
inputting data the terms may be (INPUT, GET, READ), for outputting data (OUTPUT, PRINT,
DISPLAY), for calculations (COMPUTE, CALCULATE), for incrementing (INCREMENT), in addition
A hash table
words like ADD, SUBTRACT, INITIALIZE are used for addition, subtraction, and initialization,
The above hash table stores the names Agbor, Epie, Sama, Kome and Eyong using the hash function respectively.
h(k) = k mod tablesize, where k, the key of each string is the sum of its letters’ positions in the For example, here is a pseudo code for an algorithm that reads two numbers, computes and displays
alphabet. This means that if an element p has key k, then p will be stored at position h(k) in the table. their sum:
Keys:
Agbor = 1+7+2+15+18 = 43 Begin
Epie = 5+16+9+5 = 25 Get A
Sama = 19+1+13+1 = 34 Get B
Kome =11+15+13+5 = 44 Result = A + B
Eyong = 5+25+15+14+7 = 66 Print Result
End
Applying the function ℎ to each key we get:
Agbor = 43 mod 7 = 1 3.1.2. Flowchart
Epie = 25 mod 7 = 4 A flow chart is a diagram that uses graphic symbols to describe the nature and flow of steps in an
Sama = 34 mod 7 = 6 algorithm. Each step in a flowchart is followed by an arrow that indicates which step to go next. The
Kome = 44 mod 7 = 2 following symbols are used in flow charting:
Eyong = 66 mod 7 = 3
a. Elongated circle: indicates the beginning (start) or end (stop) of the algorithm
Hash table operations are:
o Search: compute ℎ(𝑘) and see if an element exists Start/Stop
o Insert: compute ℎ(𝑘) and place element in the resulting position
o Delete: compute ℎ(𝑘) and remove element in that position b. Rectangle: indicates instructions or actions

Remarks! The size of the array should be preferably a prime number.


With hash tables, there always exists the possibility that two data elements will hash to
the same integer value. This situation is known as collision. Two methods to solve c. Diamond: indicates a decision that has to be made
collision are separate chaining and probing (closed hashing).

3. Algorithms
An algorithm is a well-defined set of step-by-step instructions for solving a problem in a finite
amount of time. A set of instructions is not an algorithm if there is no definite stopping place, or if d. Arrow: indicates the direction of flow
the instructions are too vague to be followed clearly.
A good algorithm:
- should be explicit (i.e. clear and obvious)
- should be precise (i.e. exact and accurate)

© 2014- BGS Molyko 57


Bilingual Grammar School Advanced Level Computer Science
e. Parallelogram: indicates data input and output  The assignment statement allows a value to be assigned to a variable. A variable can be
assigned the content of another variable, a constant, a literal, an arithmetic or Boolean
expression. The symbol used is .

f. Circle: serves as a connector Examples: 𝑧𝑥/𝑦, 𝑠𝑢𝑚𝑎 + 𝑏, 𝑡𝑜𝑡𝑎𝑙𝑡𝑜𝑡𝑎𝑙 + 1, 𝑝𝑖 3.14


In an assignment statement, the value to the right is assigned to the variable in the left.
In the case of 𝑠𝑢𝑚𝑎 + 𝑏, “𝑎 + 𝑏” is calculated and the result is assigned (kept) in the variable
sum.
Example: flow chart for an algorithm that divides two numbers x and y. For 𝑡𝑜𝑡𝑎𝑙𝑡𝑜𝑡𝑎𝑙 + 1, “𝑡𝑜𝑡𝑎𝑙 + 1” is calculatedand the result is assigned to the variable
total,meaning that the value of total has been increased by 1.
E.g. Let 𝑡𝑜𝑡𝑎𝑙 = 3
Start
𝑡𝑜𝑡𝑎𝑙𝑡𝑜𝑡𝑎𝑙 + 1 ⇒ 𝑡𝑜𝑡𝑎𝑙 = 3 + 1 = 4.

Get x, y Activity: Complete the table below.

𝐶𝑜𝑚𝑚𝑎𝑛𝑑 𝑥 𝑦 𝑧
𝑥← 2 − −
Is y=0
𝑥←𝑥 + 1 − −
𝑦← 1 −
z = x/y Error 𝑧←𝑥 + 𝑦
𝑦←𝑧 + 𝑥

Stop 3.4. Control Structures


The logic of a program may not always be a linear sequence of statements to be executed in that
order. The logic of a program may require execution of a statement based on a decision. It may
3.2. Variables, Constants and Literals repetitively execute a set of statements unless or until some condition is met. Control structures
A variable is an object in a program whose value can be modified during the execution of the specify the statements to be executed and their order of execution.
program. In the above flow chart, x, y and z are variables.
3.4.1. Sequential Control
A constant is an object whose value cannot be modified in the course of the algorithm or program. A A sequence control structure executes a set of instructions one after the other from the first to the
constant is given a value that remains the same all through the program. last in the order they are given.

Variables and constants are characterized by: Syntax: begin statement 1


o an identifier: which is the name of the object statement 1 Begin
o a value: which is the content of the object statement 2 get a
o a type: which defines the domain in which the object gets its value … get b statement 2
statement n c a + b
A literal is anything (numbers or text) that is usually written within double quotes. For example, end print “Sum =”, c
“Enter a number”, “The result is”. End
statement n

3.3. Basic Instructions


Three basic instructions used in an algorithm are input, output and assignment instructions: 3.4.2. Selection Control
 An input instruction allows information to be typed from the keyboard. Example: read (a, b), A selection control structure (condition control structure) chooses the instruction or instructions to
get (number) be executed based on the validity of a certain condition. Examples are IF and CASE statements.
 An output instruction allows:
 display of information on the screen b. The IF Statement
 printing of information on paper Syntax: if condition then
For example: write “a is greater than b” or print “b is greater than a” statement 1
else
statement 2

© 2014- BGS Molyko 58


Bilingual Grammar School Advanced Level Computer Science
It is used when an important number of choices are to be considered depending on the value of a
variable.
statement
E Get a, b
No1 Yes0 Get op
? caseop of
1: print a+b
2: print a*b
statement 1 statement 3: print a/b
4: print a-b
end case

Explanation Condition is a Boolean expression meaning that it can take only one of two values
true or false. The condition is evaluated, if it is true, Action3 is executed. If it is false, Action 2 is 3.4.3. Repetition Control
executed. The repetition (iteration) control structure executes a statement or group of statements many times
Note that actions 2 and 3 could be a block statements. until a certain condition is reached. Repetition structures define the order of operations and the
number of repetitions. They are also called loops. Examples are, the WHILE, REPEAT and FOR loops.
E Get a, b
if (a = 0) then a. The WHILE Loop
Print “Error”
else Syntax: while condition do
Print b/a statement(s);
end while No
?

It is possible to nest many selection structures. Yes

Syntax: if condition1 then statement(s)


E get a, b
if condition2 then if a <> 0 then
statement 1 x if b <> 0 then
else . print b/a
statement 2 else
print “Answer is 0” statement
else
else
statement 3
print “Error: division by 0”
end
Explanation The condition is evaluated, if it is true statement(s) is/are executed. Instruction(s)
is/are executed as long as condition remains true. When the condition becomes false, the loop stops.
Explanation If condition1 is true, we move to condition2. If condition2 is true, then statement 1 is The condition for the loop to stop comprises of a variable called control or iteration variable whose
executed otherwise, statement 2 is executed. If condition 1 is false, instruction 3 is executed. value must change at the end of each execution of the loop. In the example above, the control
Instruction1 or instruction 2 will be executed if and only if condition 1 is true. variable is “i”.

E Get n
c. The CASE Statement
x. i 1
while (i <= n) do
Syntax: case variable of
print “this is a while loop”
case 1: statement 1
ii + 1
case 2: statement 2
endwhile

case n: statement n
end case

Explanation The value of variable is evaluated, if it matches with case 1, instruction 1 is executed.
If it matches with case 2, instruction 2 is executed and so on. CASE is a multiple selection structure.

© 2014- BGS Molyko 59


Bilingual Grammar School Advanced Level Computer Science
b. The REPEAT Loop

Syntax: repeat Exercise! Exercise! Exercise!


statement(s);
until (condition) statement(s) 1) Write an algorithm that reads a number 𝑛 and returns the first 𝑛 numbers. n should be a
whole number greater than 0.
Yes
? 2) Write an algorithm that reads a number 𝑛 and returns the sum of the first 𝑛 numbers.
No
3) Write an algorithm to calculate the area of a circle.
statement
4) Write an algorithm to solve a linear equation

5) Write an algorithm that reads a person’s name and sex, and returns the message “good
Explanation The statement(s) is(are) executed and the condition is evaluated. If it evaluates to morning Mr. name” if the person is a man and “Good morning Mrs. Name” for a woman.
false, the statement or set statements is/are executed again. If condition evaluates to true, the
program exits the loop. 3.5. Recursion
Some problems are recursive in nature. This means that the solution to such problems involves the
repeated application of the solution to its own values until a certain condition is reached.
Get n
Algorithms for such problems are known as recursive algorithms.
i 1
A recursive algorithm is an algorithm that calls (invokes) itself during its execution. Examples are
repeat
the factorial function and the sum function.
print “This is a repeat loop”
Recursion can be defined as the calling of a procedure by itself, creating a new copy of the
i := i + 1
procedure.
until(i <= n)

Remark! The repeat loop must be executed at least once as the condition is evaluated only at the
end of the loop. a. Factorial Function
Factorial is defined as:
c. The FOR Loop 1! = 1
2! = 2 × 1 = 2
Syntax: for var  low_limit to hi_limit do 3! = 3 × 2 × 1 = 6
statement(s); 4! = 4 × 3 × 2 × 1 = 24
end for 5! = 5 × 4 × 3 × 2 × 1 = 120
Or …
for var  hi_limit downto low_limit do 𝑛! = 𝑛 × (𝑛 − 1) × (𝑛 − 2) × … × 2 × 1
statement(s);
end for By studying the above equations closely, we see that the factorial of any number 𝑛 can be calculated
by multiplying the number by the factorial of the preceding number.
Explanation var (variable) is given a value low_limit or hi_limit depending on the loop, which is We therefore have:
automatically incremented or decremented (by 1) after each iteration of the loop. The loop stops
when low_limit becomes greater than hi_limit. In both cases, if hi_limit is less than low_limit, the loop 1! = 1
body is not executed at all. 2! = 2 × 1!
E Get n 3! = 3 × 2!
x. For i  1 to n do 4! = 4 × 3!
print “this is a for loop” 5! = 5 × 4!
end For …
Or
Get n 𝑛! = 𝑛 × (𝑛 − 1)!
For i n downto 1 do
print “this is a for loop” Factorial is defined recursively as follows:
end For

© 2014- BGS Molyko 60


Bilingual Grammar School Advanced Level Computer Science

Get n Get 𝑛
1 𝑖𝑓 𝑛 = 1 base case If𝑛 = 0or𝑛 = 1then 𝑓𝑖𝑏 0
𝑓𝑎𝑐𝑡 (𝑛) 𝑓𝑎𝑐𝑡1 if𝑛 = 0then
= 𝑛 × 𝑓𝑎𝑐𝑡(𝑛 − 1) 𝑖𝑓𝑛 > 1 else 𝑓𝑖𝑏 0
𝑓𝑎𝑐𝑡𝑛 × 𝑓𝑎𝑐𝑡(𝑛 − 1) else
return fact if𝑛 = 1then
𝑓𝑖𝑏 = 1
else
Remark 1! = 1 is known as the base case. Every recursive problem must always have some base 𝑓𝑖𝑏 fib(𝑛 − 1) + 𝑓𝑖𝑏(𝑛 − 2)
case which can be solved without recursion. For cases that are to be solved recursively, the return fib
recursive call must always make progress towards the base case.
Exercise! Exercise! Exercise!
b. The Sum Function Write a recursive algorithm to find the greatest common divisor (gcd) of two numbers.
The sum function is a function that calculates the sum of the first n integers. For example we want to
calculate the sum of the first 5 integers 1, 2, 3, 4 and 5. Their sum is calculated as follows: 3.6. Sort Algorithms
Sorting is a programming technique which is used to arrange a list of pre-stored data in an
Sum(5) = 1+2+3+4+5 ascending or descending order according to a preset criterion. There are lots of useful sorting
methods. For example: insertion sort, bubble sort, selection sort, quick sort, merge sort and heap
We can see that for any number n, the sum sum(n), is the number n plus the sum of the previous sort algorithms.
numbers.
The sum function can therefore be defined recursively as:
a. Bubble Sort
𝑠𝑢𝑚(1) = 1 Bubble sort algorithm arranges items in order as follows:
𝑠𝑢𝑚(2) = 2 + 𝑠𝑢𝑚(1) - First, examine the first two items in the list. If they are in order, leave them alone; if not,
𝑠𝑢𝑚(3) = 3 + 𝑠𝑢𝑚(2)
The base case is 𝑛 = 1 interchange them.
𝑠𝑢𝑚(4) = 4 + 𝑠𝑢𝑚(3) which gives 𝑠𝑢𝑚(1) = 1 - Do the same with the second and third items, then with the third and fourth items, until you
… have reached the last two. At this point you are guaranteed that the item that should come
𝑠𝑢𝑚(𝑛) = 𝑛 + 𝑠𝑢𝑚(𝑛 − 1) last in the list has indeed “bubbled” up to that position.
- Now repeat the whole process for the first (n-1) items in the list, then for (n-2) and so on until
the list is sorted.
getn
𝑠𝑢𝑚 0
begin
if𝑛 = 1then
for i = size downto 1 do
𝑠𝑢𝑚 1
for j  2 to i do
else
if (List[j-1] >List[j]) then
𝑠𝑢𝑚 n + 𝑠𝑢𝑚(𝑛 − 1)
temp List[j-1];
List[j-1]  List[j];
return sum
List[j]  temp;
end_if;
c. The Fibonacci Series end_for;
The Fibonacci series is a series in which each number is the sum of the two previous numbers in the end_for;
series. E.g. 0, 1, 1, 2, 3, 5, 8, 13, 21… end.

The Fibonacci series is defined as follows: Example: Sort the list [4, 3, 2, 1]

𝑓𝑖𝑏(0) = 0 List = [4, 3, 2, 1] size = 4


𝑓𝑖𝑏(1) = 1
𝑓𝑖𝑏(𝑛) = 𝑓𝑖𝑏(𝑛 − 1) + 𝑓𝑖𝑏(𝑛 − 2) i=4 (outer loop, 1st pass)
j = 2  [4, 3, 2, 1] becomes [3, 4, 2, 1]
𝑓𝑖𝑏(0) and 𝑓𝑖𝑏(1) are the base cases. j = 3  [3, 4, 2, 1] becomes [3, 2, 4, 1]

© 2014- BGS Molyko 61


Bilingual Grammar School Advanced Level Computer Science
j = 4  [3, 2, 4, 1] becomes [3, 2, 1, 4] j = 4 iMin = 3

i=3 (outer loop. 2nd pass) iMin = i, so no swap is done


j = 2  [3, 2, 1, 4] becomes [2, 3, 1, 4]
j = 3  [2, 3, 1, 4] becomes [2, 1, 3, 4]
i=2 (outer loop, 3rd pass) c. Insertion Sort
j = 2  [2, 1, 4, 3] becomes [1, 2, 3, 4]
begin
i=1 for i  2 to size do
Internal loop does not execute because j is greater than i. index List[i]
j i
b. Selection Sort while ((j > 1) and (List[j-1] > index)) do
Selection sort arranges the elements of a list by first selecting the lowest-valued item, then the next List[j] List[j-1]
lowest, and so on. In practice, the lowest-valued item is interchanged with the first item in the part jj - 1
of the list being searched, and the search is confined to the remainder of the list from then on. end_while
List[j]  index
begin end_for
for i 1to size-1 do end.
iMini
for j i+1 to sizedo For example:
if List(j) < List(iMin) then [4, 3, 2, 1] size = 4
iMin j; i=2 index = 3
end_for j = 2  [4, 3, 2, 1] becomes [_, 4, 2, 1]
if m <> i then j = 1  no execution of internal loop
temp List(iMin) insert index in the place vacated  [3, 4, 2, 1]
List(iMin) List(i)
List(i) temp i=3 index = 2
end_if j = 3  [3, 4, 2, 1] becomes [3, _, 4, 1]
end_for j = 2  [3, 4, 4, 1] becomes [_, 3, 4, 1]
end. j = 1  no execution
insert index in the place vacated  [2, 3, 4, 1]
Example: Sort the list [4, 3, 2, 1]
i=4 index = 1
List = [4, 3, 2, 1] size = 4 j = 4  [2, 3, 4, 1] becomes [2, 3, _, 4]
j = 3  [2, 3, 4, 4] becomes [2, _, 3, 4]
i=1 iMin = 1 j = 2  [2, 3, 3, 4] becomes [_, 2, 3, 4]
j = 2  iMin = 2 j = 1 no execution of internal loop
j = 3  iMin = 3 insert index in the place vacated  [1, 2, 3, 4]
j = 4  iMin = 4
3.7. Search Algorithms
iMin<> i, so swap item at position iMin (4) and item at position i (1). A search algorithm is a method of locating a specific item in a larger collection of data. They can be
[4, 3, 2, 1] becomes [1, 3, 2, 4] used to search for items within an array or list. Common search algorithms are sequential search
and binary search.
i=2 iMin = 2
j = 3  iMin = 3 a. Sequential Search
j = 4  iMin = 3 Sequential search is a simple technique for searching an item in a list by comparing each element
with the element searched for, beginning with the first element until the element is found.
iMin<> i, so swap item at position iMin (3) and item at position i (2).
[1, 3, 2, 4] becomes [1, 2, 3, 4] begin
index  1
i=3 iMin = 3 found  false

© 2014- BGS Molyko 62


Bilingual Grammar School Advanced Level Computer Science
while ((not found) and (index <sizeof(List))) do 4.1. Programming Languages
if List[index] = elemthen A programming language is a set of predefined words, symbols and rules that are used to write
found true computer programs. Programming languages can be grouped into two: low-level languages and
elemPos index high-level languages.
end-if
indexindex + 1 4.1.1. Low-Level Languages
end_while A low-level language is a language whose instruction set reflects the processor architecture. An
returnelemPos instruction set is the set of bit patterns or binary codes for the machine operations that a processor
end. has been designed to perform. Low-level languages include machine language and assembly
language.
For example: search for the 0 in the list [2, 3, 1, 0, 5, 4]
a. Machine Language
Machine language is the computer’s language. It is the language the computer understands. Machine
language instructions are written in binary (a series of 0s and 1s), and are directly executable by the
computer. Each machine language statement corresponds to one machine action. Machine language
is the first generation of programming languages. For example a short (3 instruction) program
2 3 1 0 5 4 might look like this:

found = false 0111 0001: 0000 1111


2≠0 index 2
1001 1011: 0001 1010
1110 0001: 0011 1110
2 3 1 0 5 4
b. Assembly Language
found = false
Assembly language is a low-level language consisting of mnemonic codes and symbolic addresses
3≠0 index 3
corresponding to machine language instructions. Assembly language is the second generation of
programming languages. For example:
2 3 1 0 5 4

found = false LOAD R0 Number1 Load number1 in register 0


3≠0 index 4 LOAD R1 Number2 Load Number2 in register 1
ADD R2 R0 R1 Add register 0 and register 1 and keep result in register 2
2 3 1 0 5 4
 Advantages of assembly language
found = true o It is easier to write and understand when compared to machine language.
3=0 elemPos  index = 4 o It can produce small program sizes
o It can produce very fast code as it allows low-level access to hardware features
b. Binary Search
Binary search is a more specialized algorithm than sequential search as it takes advantage of data  Disadvantages of assembly language
that has been sorted. The underlying idea of binary search is to divide the sorted data into two o Programs are not as easy to write and understand when compared to high level
halves and to examine the data at the point of the split. Since the data is sorted, we can easily ignore languages.
one half or the other depending on where the data we're looking for lies in comparison to the data at o Programs are tied to specific computer hardware and can’t be reused on another kind of
the split. This makes for a much more efficient search than linear search. computer.
o Writing programs is very time consuming, tedious, and error-prone.
4. Programming
Programming is the activity of writing computer programs. A computer program is a set of 4.1.2. High-Level Languages
instructions that will be followed by a computer to perform a computation. These instructions are High-level languages are closer to human language. They allow programmers to write programs
made up of statements written in some languages specially designed for this purpose. These without having to understand the inner workings of the computer. One high-level language
languages are called programming languages. statement will generally be translated into several low-level language statements. They are the third
In other words, a program is an algorithm expressed in a programming language. generation of programming languages. Examples are C, BASIC (Beginner’s All-purpose Symbolic
Instruction Code), Pascal, Java, FORTRAN (Formula Translator) and COBOL (Common Business-
Oriented Language). Below is a small code for adding two numbers in Pascal and C.

© 2014- BGS Molyko 63


Bilingual Grammar School Advanced Level Computer Science

Pascal C Source program


program addition; #include <stdio.h>
uses wincrt; int main()
var number1, number2, sum: integer; { int number1, number2, sum; Lexical analyzer
begin scanf(“%d”, &number1);
read(Number1); scanf(“%d”, &number2);
read(Number2); sum = number1 + number2; Syntactic analyzer
sum := Number1 + Number2; printf(“%d”, sum);
write(sum); return 0;
end. } Semantic analyzer
Symbol table Error
manager handler
Intermediate code
 Advantages of high-level languages
generator
o easy to understand and write programs as they are user oriented
o they have built in libraries to perform routine tasks
o programs can be ported to multiple hardware setups from same code Code optimizer

 Disadvantages of high-level languages


o programs may be slower than second generation language programs Code generator
o may produce larger program files for same functionality as second generation languages.
o may not allow for low level hardware access
Target program
4.2. Language Translators
To run a program on a computer, the program needs to be translated into the machine language of
the computer on which it will run. A language translator is a computer program that translates a. Lexical Analysis
program instructions from one programming language to another without loss of original meaning. During lexical analysis, a lexical analyzer (scanner) reads input characters from source code and
There are three types of language translators: compiler, interpreter and assembler. produces a sequence of tokens as output. A token is a symbolic name for an entity that makes up the
text of the program.
4.2.1. Assembler When the lexical analyzer reads the input characters, it groups them into lexemes which are then
An assembler translates assembly language into machine language. The process is called replaced by tokens. A lexeme is a group of characters that matches the pattern for a token. In other
assembling. words, it is an instance of a token. A pattern is a rule that specifies when a sequence of characters
constitutes a token. It is simply a rule that describes how a token can be formed.
4.2.2. Compiler
A compiler translates the entire high-level program into a machine language program. The high- For example: sum := x + 2;
level language program is called source program or source code and the generated machine
language program is called object program or object code. This process is called compilation. Lexeme Token

Definition: Compilation is the process of translating a program in one language (the source language) sum ident(sum)
into an equivalent program in another language (the object or target language).
:= assign_op
The process of compilation is split up into six phases: lexical analysis, syntactic analysis, semantic
analysis, intermediate code generation, code optimizing and code generation. x ident(x)

+ bin_op

2 integer

; semicolon

Lexical analysis performs the following:

© 2014- BGS Molyko 64


Bilingual Grammar School Advanced Level Computer Science
o Divides the character stream into meaningful sequences called lexemes. 4.3. Program Errors and Correction
o Labels each lexeme with a token that is passed to the parser (syntax analysis) 4.3.1. Syntax Errors
o Updates the symbol tables with all identifiers (and numbers) Syntax is the set of rules that specify how the symbols of a language can be put together to form
o Removes non-significant blanks and comments meaningful statements. In other words, syntax defines the structure of legal statements in a
language. A syntax error is an error in a program that occurs due to the non-respect of the syntax
b. Syntactic analysis rules of the language used. A syntax error will cause a compiler/interpreter to stop trying to
Syntactic analysis determines how the tokens retuned by the lexical analyser should be grouped and generate machine code and will not create an executable. However, a compiler will usually not stop
structured according to the syntax rules of the language. at the first error it encounters but will attempt to continue checking the syntax of a program right to
the last line. For example, a misspelled key word, a missing punctuation mark or the incorrect use of
converts a token stream, from lexical analysis, to an abstract syntax tree. The syntactic analyzer an operator is a syntax error.
(parser)
4.3.2. Semantic Errors
c. Semantic analysis Semantics specify the meaning of a well-formed program. A semantic error occurs when you write a
program that works, but does not do what you intend it to do. Compilation and interpretation do not
d. Intermediate code generation detect semantic errors. Semantic or logic errors are detected from wrong results. Something may be
syntactically correct but semantically incorrect.
e. Code optimizing
4.3.3. Run-time Errors
f. Code Generation A run-time error is an error that occurs during program execution. For example, a run-time error
may occur if division by 0 is attempted. A run-time error may cause the program to stop execution,
 Advantages of a Compiler or it may be handled by an error-trapping routine.
o Fast in execution
o The object code produced by a compiler can be distributed or executed without having to 4.3.4. Debugging
have the compiler present. An error in a computer program is known as a bug. Debugging is the process of detecting and
o The object program can be used whenever required without the need of recompilation. removing bugs. Syntax errors and semantic errors are bugs. A debugger is the software tool used for
this purpose.
 Disadvantages of a Compiler
o Debugging a program is much harder. Therefore not so good at finding errors 4.4. Programming Paradigms
o When an error is found, the whole program has to be re-compiled A programming paradigm (or technique) is a fundamental style of computer programming. It
describes a programming language’s approach to solving a problem. Paradigms differ in the
4.2.3. Interpreter concepts and abstractions used to represent the elements of a program and the steps that compose
An interpreter is a computer program that translates and executes instructions written in a high- a computation. High level languages can be classified under four different paradigms: procedural,
level language into machine language instructions one line at a time. The interpreter translates an functional, object-oriented and declarative paradigms.
instruction and allows it to be executed before translating the next line. If a program performs a
section code 1000 times, then the section is translated into machine code 1000 times since each line 4.4.1. Procedural Paradigm
is interpreted and then executed. In the procedural/imperative paradigm, a program is a collection of statements and procedures that
affect data. Here, a program can be seen as an active agent that manipulates passive objects
 Advantages of an Interpreter (variables). These objects are passive because they cannot initiate an action by themselves, but can
o It is good at locating errors in programs only receive actions from active agents. The focus in procedural programming is to write good
o Debugging is easier since the interpreter stops when it encounters an error. functions and procedures.
o If an error is corrected, there is no need to retranslate the whole program Examples of imperative languages are Pascal, C, Ada, FORTRAN, and COBOL.

 Disadvantages of an Interpreter 4.4.2. Object Oriented Paradigm


o It is slow as interpretation and execution is done line by line. The object-oriented paradigm presents a program as a collection of classes for interacting objects.
o Translation has to be done every time the program is to be executed since no object code Unlike in imperative programming, object-oriented programming deals with active objects instead
is produced. of passive objects. These objects are active because the actions to be performed on the objects are
o For the program to run, the interpreter must be present included in them (the objects). The objects need only to receive the appropriate stimulus from
outside to perform one of the actions.
Examples of object-oriented languages are C++, Java, Visual Basic and Smalltalk.
Some important concepts related to object oriented programming (OOP) are: class, object,
abstraction, encapsulation, inheritance and polymorphism.

© 2014- BGS Molyko 65


Bilingual Grammar School Advanced Level Computer Science

a. Class e. Inheritance
A class is a description of an object or a real life concept. Classes are templates for creating objects, Inheritance is the derivation of one class from another so that the attributes and methods of the
providing initial values for instance variables (attributes) and the bodies for methods. All objects derived class are part of the definition of the initial class. The initial class is often called the base
generated from the same class share the same methods, but contain separate copies of the instance class, parent class or super class while the derived class is often referred to as the child class or sub-
variables. New objects can be created from a class by applying the new operator to the name of the class. The subclass usually contains all the attributes and methods of the superclass plus some of its
class. own.
For example: the class Student inheriting from the class person will have all the attributes and
Class Person { methods of Person plus the following:
private:
char name[20]; Class Student extends Person {
char sex; private
date birthdate; int admNumber;
public: int level;
updateInfo(); public
returnAge(); changeLevel(int newLevel) {
}; level=newLevel;
}
The name of the class is person. It has four instance variables (attributes) name, sex and age, and }
three methods: updateInfo(),and returnAge(). These methods act on the instance variables when
invoked. Inheritance is usually represented using an inheritance diagram.
For example: if the classes Student and Teacher are derived from the superclass Person, this is
b. Object represented as:
An object is an instance of a class. An object consists of a collection of attributes, representing the
state of the object, and a collection of methods, representing the behavior that the object is capable Person Person
of performing. Attributes are sometimes referred to as the fields of an object. The methods are
routines that are capable of accessing and manipulating the values of the attributes of the object.
Objects interact with each other by sending messages. When a message is sent to an object, the
corresponding method of the object is executed. Student Teacher
There are two types of Inheritance: multiple inheritance and multilevel inheritance.
c. Abstraction
Abstraction is the process of representing important details and hiding away the implementation  Multiple inheritance is when a derived class inherits features from more than one
details. Through abstraction unnecessary details are removed so that one can focus on only the superclass. It is illustrated as follows:
relevant parts of a problem in order to solve it. Abstraction is obtained by separating the interface
and the implementation. For example, functions use the concept of abstraction. Base class 1 Base class 2

The following are the advantages of abstraction.


o The programmer does not have to write the low-level code. Derived class
o The programmer does not have to specify all the register/binary-level steps or care about the
hardware or instruction set details.  Multi-level inheritance is when a class inherits from a class which is itself inherited from
o Code duplication is avoided and thus programmer does not have to repeat fairly common another class. It is illustrated as follows:
tasks every time a similar operation is to be performed.
o It allows internal implementation details to be changed without affecting the users of the Base class
abstraction.

d. Encapsulation Derived class 1


Encapsulation is the process of combining together the attributes and methods of a class into a
single abstract data type with a public interface and a private implementation. The goal of
encapsulation is to protect the implementation from the users of the object. It ensures that all access
Derived class 2
to the internal representation of the object pass through the class methods, which act as an
"interface" to the object. This is done by making properties and methods “private.” f. Polymorphism

© 2014- BGS Molyko 66


Bilingual Grammar School Advanced Level Computer Science
Polymorphism is the use of different methods, each with the same name, which are associated with
different object types. In other words, it is the ability for different objects to respond to the same
message in different, class-specific ways. Polymorphic methods are used which have one name but
different implementations for different classes.
Assume you have a “shape” super class. This class has a method called “area” which returns the area
of the shape. Polymorphism allows you to make subclasses like “circle,” “square,” and “triangle”
which inherit the “area” method, but each subclass would return the correct value even though they
have different formulas to calculate their areas.

4.4.3. Functional Paradigm


In functional (applicative) programming, a program is a collection of function definitions. Lambda
calculus forms the basis of almost all functional programming languages. Lambda calculus is the use
of lambda expressions to define functions. A lambda expression is a formula that defines a function.
For example: 𝑓(𝑥) = 𝑥 + 2
Examples of functional languages are Haskell, LISP, ML and Scheme.

Sum function in Haskell

𝑎𝑑𝑑 ∶ : (𝐼𝑛𝑡, 𝐼𝑛𝑡) → 𝐼𝑛𝑡


𝑎𝑑𝑑 (𝑥, 𝑦 ) = 𝑥 + 𝑦

Quick sort in Haskell


𝑓:: [ 𝑎] → [𝑎 ]
𝑓[ ] = [ ]
𝑓(𝑥: 𝑥𝑠) = 𝑓𝑦𝑠 + + [𝑥] + + 𝑓𝑧𝑠
Where
𝑦𝑠 = [𝑎 | 𝑎 ← 𝑥𝑠, 𝑎 ≤ 𝑥]
𝑧𝑠 = [𝑏 | 𝑏 ← 𝑥𝑠, 𝑏 > 𝑥]

4.4.4. Declarative Paradigm


In declarative (logic) programming, a program is a collection of facts and rules involving relational
expressions. Declarative paradigm uses the principle of logical reasoning to answer queries. It is
based on formal logic defined by Greek mathematicians and later developed into first-order
predicate calculus. The point of logic programming is to bring the style of mathematical logic to
computer programming. An example of a declarative programming language is PROLOG
(programming logic).

These facts are given:


human (John)
mortal (human)

The user asks the following question:


?-mortal (John)

The program answers yes.

© 2014- BGS Molyko 67


Bilingual Grammar School Advanced Level Computer Science
CHAPTER 7: COMPUTATIONAL COMPLEXITY THEORY
1.1.1. Big-O Notation
Introduction Big-O notation also called Landau's symbol, is a symbolism used to describe the asymptotic
There may be several different methods for solving a particular problem. How can one decide which behavior of functions. Basically, it assesses by what factor execution time increases when the size of
method is the best in a certain situation? How would one define "best" – is it the fastest method or the input is increased. The letter O is used because the rate of growth of a function is also called its
the one that takes up the least amount of memory space? order of growth.
Understanding the relative efficiencies of algorithms designed to do the same task is very important For example, let’s suppose that the execution time for an algorithm of input size 𝑛 is given by:
in every area of computing.
𝑇(𝑛) = 4𝑛2 − 2𝑛 + 2
1. Computational Complexity
Complexity theory is the mathematical study of the time and amount of memory needed to perform Ignoring constants as they depend on the particular hardware the program is running on, and
a computation. The goal of computational complexity is to classify algorithms according to their slower growing terms, we could say "T(n) grows at the order of 𝑛2 " and write:
performances.
The efficiency of an algorithm can be measured in terms of: 𝑇(𝑛) = 𝑂(𝑛2 )
 The execution time (time complexity)
 The amount of memory required (space complexity). This simply means that if the input size (n) doubles, the algorithm takes four times longer to execute
and the order of growth is said to be quadratic.
1.1. Time Complexity
Time complexity is a measure of the amount of time required to execute an algorithm. It is Some programs perform the same number of operations every time they are executed while others
expressed as the number of times the algorithm’s basic operations are executed on inputs of size n. may perform different numbers of operations, depending on the value of a parameter.
Time in seconds is not used because there are too many factors that can vary e.g. computer speed. Suppose a computer is going to process 𝑛 items of input. The time complexity of the calculation may
As an illustration, consider a pseudo code algorithm that calculates the mean (average) of a set of n be any of the following:
numbers:
a. Constant Time or O(1)
1. n = read input from user An algorithm is said to run in constant time if the computation takes the same number of steps
2. sum = 0 regardless of how many items are to be processed. For example storing and retrieving array
3. i=0 elements.
4. while(i<n)
5. number = read input from user b. Linear Time or O(n)
6. sum = sum + number An algorithm is said to run in linear time if its time of execution (number of steps) is directly
7. i=i+1 proportional to the input size n. That is, time grows linearly as input size increases. An example
8. mean = sum / n would be finding the sum of n numbers, or any program that contains only one loop.

Statements 1, 2, and 3 are each executed once. Statements 5, 6, and 7 are each executed n times. c. Quadratic Time or O(𝒏𝟐 )
Statement 4 (which controls the loop) is executed n + 1 times (one additional check is required), and An algorithm is said to run in quadratic time if its execution time is proportional to n squared. For
statement 8 is executed once. The running time T(n) of this algorithm is given as follows: example, if the computation involves comparing each item of input with all of the other items, it will
take 𝑛2 steps. Many sorting algorithms are O(𝑛2 ).
Number of
Statement
times executed
d. Polynomial Time or O(𝒏𝒌 )
1 1 An algorithm is said to run in polynomial time if its execution time is proportional to n raised to
2 1 some constant power. A program that contains k nested loops, each with a number of steps
3 1 proportional to n, will take time proportional to 𝑛𝑘 .
4 n+1
e. Exponential Time or O(𝒌𝒏 )
5 n An algorithm is said to run in exponential time if its execution time is proportional to some constant
6 n k raised to the nth power. Exponential-time computations are generally not practical.
7 n
f. Logarithmic Time or O(log n)
8 1
An algorithm is said to run in logarithmic time if its execution time is proportional to the logarithm
of the input size. An example is binary search.
𝑇(𝑛) = 1 + 1 + 1 + 𝑛 + 1 + 𝑛 + 𝑛 + 𝑛 + 1 = 4𝑛 + 5

© 2014- BGS Molyko 68


Bilingual Grammar School Advanced Level Computer Science
Remark! Big-O expressions do not have constants or low-order terms. This is because, when 𝑛 gets
large enough, constants and low-order terms don't matter.
A constant-time algorithm will be faster than a linear-time algorithm, which will be faster than a
quadratic-time algorithm.

Formally, the time complexity of an algorithm is of the order f(n)

1.1.2. Best Case, Worst Case and Average Case


Some algorithms perform differently on various inputs of similar size. It is sometimes helpful to
consider the Worst-Case, Best-Case, and Average-Case efficiencies of algorithms. For example, say
we want to search an array A of size n for a given value K. Formally, a TM is defined as:
 Best Case: K is the first item that we check, so only one comparison. TM = <S, T, s0, d, H> where,
 Worst Case: K is not in the array, then we must search every item (𝑛 comparisons) S is a set of TM states
 Average Case: T is a set of tape symbols
s0 is the start state
Exercise! Exercise! Exercise! H ⊂ S is a set of halting states
d : S x T ⟶ S x T x {L,R} is the transition function
1. The big-O notation is often used to describe the efficiency of an algorithm.
A TM begins computation at state s0. At each computational step, it reads the present tape symbol,
(a) Place the following algorithms in order of efficiency, the most efficient first. changes its internal state, optionally writes another symbol onto tape, and moves one cell to the left
or right in the tape.
Algorithm A that is O(n) The TM halts computation (and accepts the input string) when it reaches one of the halt states in H.
Algorithm B that is O(aⁿ)
Algorithm C that is O(n²) (1 mark) 2.2. The Church-Turing Thesis

(b) Describe a linear search and explain why it is O(n).


(4 marks) 3. Computable Functions
A function is computable if it can be computed by a Turing machine.
(c) Describe a bubble sort and explain why it is O(n²).
(4 marks) 4. Decidability
5. The Halting Problem
1.2. Space Complexity
Space complexity is essentially the amount of memory (number of cells) which a program needs to
execute. A good algorithm keeps this number as small as possible.

2. Computability
Computability deals with whether a problem can be solved at all, regardless of the resources
required.

2.1. Turing Machines


A Turing machine (TM) is an imaginary machine conceived by Alan Turing in the 1930s to help
identify the kinds of problems that are potentially solvable by machines. It consists of a read/write
head and an infinite string of paper tape made up of cells where each cell can hold a symbol from the
tape alphabet.
The head scans at a cell on the tape and can read, erase, and write a symbol on the cell. In each
move, the head can move to the right cell or to the left cell or stay in the same cell.

© 2014- BGS Molyko 69

You might also like