0% found this document useful (0 votes)
17 views

A-Level Computer Science

Uploaded by

nkwenti278
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)
17 views

A-Level Computer Science

Uploaded by

nkwenti278
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/ 79

Bilingual Grammar School Advanced Level Computer Science

CHAPTER 1: COMPUTER ORGANISATION AND ARCHITECTURE pressed, a number (code) representing each character, is sent to the
computer to tell it which key has been pressed. The keyboard has a total of
Introduction 101-104 keys divided into different groups or keypads.
The term computer is derived from the word “compute” which means “to calculate.”  Function keys, labeled F1-F12, perform specific functions based on the
This simply means that the computer is a calculating machine. Every thousandth of software used. F1 for example is used in most software to display help.
a second or so, a computer performs thousands, millions, or even billions of simple  Alphabetical keys
arithmetic operations in order to carry out its tasks.  Numerical keys
Formally, a computer is defined as an electronic device that can accept, store and  Navigation keys also called direction keys are used to navigate through
process data to produce information. It can also be defined as a machine that can documents and websites. Examples of navigation keys are the up, down, left
accept instructions and perform computations based on those instructions. and right arrows.
The term computer organization refers to the physical organization of the  Action keys
components in a computer system, and to the characteristics of those components.
It includes the high-level aspects of a computer’s design, such as the memory The way keys are arranged on a keyboard is known as the layout of the keyboard.
system, the memory interconnect, and the design of the internal processor or CPU. There are different keyboard layouts but the best known are QWERTY mainly used by
English speakers and AZERTY used by French speakers. Another keyboard layout
1. Hardware modified greatly from a standard layout is DVORAK, devised to increase typing
Hardware refers to the physical and tangible components of the computer like the speed by placing frequently used keys more naturally.
keyboard, mouse, monitor and internal circuits. Computer hardware components can A keyboard connects to the computer through cable PS/2 cable, USB cable or
be grouped into five functionally independent main units: input, control, arithmetic wireless (cordless).
and logic, memory and output units.
The input unit accepts coded information from human operators using devices such 1.1.2. Mouse
as keyboards, or from other computers over digital communication lines. The A mouse is a handheld device which is moved across a flat surface to control the
information received is stored in the computer’s memory, either for later use or to movement of a cursor or pointer on the computer screen. It is a pointing device. A
be processed immediately by the arithmetic and logic unit. The processing steps are standard mouse has two buttons, the right and the left buttons, which are pressed to
specified by a program that is also stored in the memory. Finally, the results are sent enter commands into the computer.
back to the outside world through the output unit. All of these actions are Different actions that can be performed with a mouse are:
coordinated by the control unit.  Click: Pressing the left mouse button. This action can be used to select
objects (files, folders, commands) or options in a menu.
Processing Unit  Double-click: Pressing the left button two times in quick succession. It can
be used to open a file, folder or program.
Control
Input Unit Unit
 Right-click: Pressing the right mouse button. A right-click opens a context
Output Unit
menu from which options like cut, copy and paste can be selected.
Arithmetic  Drag and drop: Pressing the left mouse button and moving the mouse while
Logic Unit holding, is a 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.
Memory Unit

A mouse connects to a computer through PS/2 cable (PS/2 mouse), USB cable (USB
Functional Units of a Computer mouse), or wireless (optical mouse).

1.1.3. Scanner
1.1. Input Unit
A scanner is a device that is used to input printed images such as photographs or
The input unit consists of hardware components that allow the computer user to
pages of text directly into the computer. It converts hardcopy information into
enter data and commands into the computer. These components are called input
electronic form (softcopy) for storage in the computer. A scanner works by
devices. Examples of input devices are keyboard, mouse, scanner, joystick, light
pen, touchpad, tracker ball and microphone. shining a light at the image being scanned and measuring how much light
is reflected back using an optical sensor. The amount of light that is
1.1.1. Keyboard reflected back tells the computer how light or dark the image is at each
The keyboard is the standard input device attached to computers. It is a device with point. Common scanner devices are the flatbed scanner, optical mark reader,
keys that are pressed to enter data and commands into the computer. These keys optical character reader, barcode reader and magnetic ink character reader.
represent letters, numbers, symbols and control characters. When a key is
© 2014- BGS Molyko 1
Bilingual Grammar School Advanced Level Computer Science

a. Flatbed Scanner  The size of a monitor refers to how big the monitor is. It is measured in
A flatbed scanner is a scanner in which the object to be scanned is placed flat inches along the diagonal from the bottom left hand corner to the top right
against a piece of glass. When the object is placed, t he scanner moves the light hand corner of the screen. Typical sizes are 10" or 12" for LCDs and 14",
and sensor itself and scans the whole image automatically. Most flatbed 15" or 21" for desktop monitors.
scanners are A4 size
1.2.2. Printer
A printer is a device that produces computer-generated information on paper. Such
b. Optical Mark Reader (OMR)
output is referred to as printout or hardcopy. Based on the technology used, printers
c. Optical Character Reader (OCR)
can be classified into impact and non-impact printers.
d. Barcode Reader
 Impact printers have mechanical contact between paper and printing head
e. Magnetic Ink Character Recognition (MICR)
(e.g. daisy wheel, dot matrix and line printers).
 Non-impact printers have no mechanical contact between paper and printing
1.2. Output Unit
head (e.g. ink-jet, desk- jet, laser printers).
The output unit consists of devices that allow the user to retrieve information from
the computer. Output devices provide the results of computations to the person
Question: What are the advantages and disadvantages of impact and non-impact
using the computer, in a way they can understand. Examples are monitor, printer,
printers?
speaker and projector.

1.3. The Processing Unit


1.2.1. Monitor
The processing unit, also called central processing unit (CPU), is an integrated circuit
Also referred to as VDU (Visual Display Unit), the monitor is the most popular output
or “chip” which processes instructions and data. It is the part of the computer that
device. It displays information generated by a computer on a screen. Such output is
interprets and executes program instructions. It also controls the other components
known as softcopy output. Monitors are characterized by the technology they use,
of the system. The CPU is made up of three main components: the arithmetic-logic
their resolution and their size.
unit (ALU), the control unit (CU) and registers. Examples of CPUs are Intel Pentium II,
 By the technology used, monitors are of two main types: Cathode Ray Tube III, IV, Pentium Celeron, and AMD Athlon.
(CRT) monitors and Flat Panel Display.
o CRT monitors are similar to a television set. 1.3.1. Control Unit
o Flat panel display monitors are of different types: Liquid Crystal Display The control unit acts like supervisor seeing that things are done as they ought to. It
(LCD), Electroluminescent Display (ELD), Gas Plasma (GP) and Thin Film locates and retrieves program instructions from memory, interprets them and
Transistor (TFT) monitors. ensures that they are executed in proper sequence. It also ensures that data is
selected from memory as necessary and information is stored correctly as well.
Question: What are the advantages of flat panel monitors over CRT?
1.3.2. Arithmetic-Logic Unit
 Monitor resolution refers to the number of dots (pixels – picture elements) The arithmetic-logic unit (ALU) performs arithmetic and logic operations. It contains
on the screen. It is expressed as a pair of numbers that give the number of arithmetic circuits that perform arithmetic operations like addition, subtraction,
dots on a row and the number of rows. A variety of different resolutions are multiplication and division, and logic circuits that perform comparisons like equal to,
available. For example, VGA is 640 x 480. This means that there are 640 less than, greater than, greater than or equal to and less than or equal to.
pixels in each row across the screen and 480 pixels in each column up and
down the screen. SVGA is 800x600. 1.3.3. Registers
Registers are special storage locations within the CPU that offer an advantage of
640 pixels speed. They work under the direction of the control unit to accept and hold data that
is being processed. Since the CPU uses registers for the processing of data, the
640 pixelsVGA Screen number of registers in a CPU and the size of each register affect the power and
speed of the CPU.
Registers are grouped into two: special purpose registers and general purpose
The size of a pixel is known as dot pitch. The smaller the dot pitch, the higher the registers.
number of dots the screen has. Displays with lots of pixels are called high
resolution while those with fewer pixels are called low resolution. The higher the  Special purpose registers are dedicated to specific tasks like:
resolution, the clearer and sharper the image will appear on the monitor. Most o the accumulator which collects the result of computations,
monitors come with a .28 dot pitch. o the memory address register (MAR) which keeps track of where a given
instruction or piece of data is stored in memory

© 2014- BGS Molyko 2


Bilingual Grammar School Advanced Level Computer Science

o the memory data register (MDR)which holds data values. disk drive. The speed of the system clock is just one factor that influences a
o the program counter (PC) which holds the address of the next instruction computer’s performance. Other factors, such as the type of processor chip, amount
to be executed. of cache, memory access time, bus width, and bus clock speed.
o The current instruction register (CIR) which holds the instruction being
executed. 1.4. Memory Unit
The memory unit, also called storage unit, consists of computer components that
 General purpose registers on the other hand have no specific function; they hold programs and data for use in the computer. Memory or storage devices hold
are used according to the need of the program being executed. programs and data that can be made available for initial or additional processing
when required. A storage device is made of two parts: the storage medium and the
Question: How would you define processing? device.
 The medium is the surface or substrate that holds actual data
1.3.4. The Instruction Cycle  The device reads information from or stores information onto the medium
The instruction cycle describes how program instructions are repeatedly fetched,
decoded and executed, one instruction at a time, until an instruction to HALT is Computer storage can be classified basically into two: primary storage and
encountered. Before an instruction can be fetched, it must be placed into memory secondary storage.
as well as related data, from an input or secondary storage device. Once the
necessary data and instructions are in memory, the central processing unit performs 1.4.1. Primary Memory
the following four steps for each instruction: Primary memory/storage is directly accessible to the CPU. It holds programs and
1. The control unit fetches (gets) data and instructions from memory. data that the CPU is currently working with. Primary memory is also called internal
2. The control unit decodes the instructions i.e. determines what they mean, and memory, immediate access memory or primary storage. Primary memory consists of
directs that the necessary data be moved to the arithmetic-logic unit. random access memory, read only memory and cache memory.
3. The arithmetic-logic unit then executes the instruction on the data. That is, the
ALU is given control and performs the actual operation on the data. a. Random Access Memory
4. The arithmetic-logic unit stores the result of this operation in memory or in a Random access memory (RAM) also called “main memory” is the temporary storage
register. space into which a computer loads programs and user data when it is running. It is
the computer’s working space. It is read/write meaning that data can be read from
and written onto it. RAM is also volatile meaning that everything held in it is lost
when power is switched off. Two types of RAM exist: Static RAM and dynamic RAM.

 Dynamic RAM (DRAM) consists of capacitors that slowly leak their charge over
time. Thus, they must be refreshed every few milliseconds to prevent data
The Instruction Cycle loss. DRAM is cheap memory owing to its simple design.

Steps 1 and 2 together are called instruction time or I-time and steps 3 and 4  Static RAM (SRAM) consists of circuits that retain their charge over time. SRAM
together are called execution time or E-time. The combination of I-time and E-time is is faster and more expensive than dynamic RAM, and does not need to be
called the machine or instruction cycle or the fetch-decode-execute cycle. The refreshed as DRAM does. Due to its cost it is not used as main memory but
length of time taken to fetch, decode and execute an instruction is measured in rather to build cache memory.
clock cycles.
b. Read Only Memory
1.3.5. System Clock Read only memory (ROM) is a kind of memory whose contents can only be read by
The CPU has a small quartz crystal circuit called the system clock that controls the the computer. Data found in ROM is written by the manufacturer and cannot be
timing of all computer operations. The system clock generates regular electronic modified by the user. ROM is useful for holding data that never changes like the
pulses, or ticks, that set the operating pace of components of the system unit. Each “boot” or start-up program which is run when the computer is switched on.ROM is
tick is known as clock cycle and the pace of the system clock is called clock speed. non-volatile meaning that its content is preserved even without power. There are
Clock speed is measured in megahertz (Mhz) or gigahertz (Ghz) and refers to the four types of ROM:
number of clock cycles per second that the CPU runs at. Mega and giga stand for
million and billion respectively while hertz means cycles per second. Thus, 1Ghz  Masked ROM is ROM programmed with its data when the chip is fabricated.
means one billion cycles per second. A computer that operates at 3 Ghz has 3 billion  Programmable ROM (PROM) is ROM that can be programmed once but not
(giga) clock cycles in one second (hertz). reprogrammed.
The faster the clock speed, the more instructions the processor can execute per
second. The speed of the system clock has no effect on devices such as a printer or
© 2014- BGS Molyko 3
Bilingual Grammar School Advanced Level Computer Science

 Erasable Programmable ROM (EPROM) is ROM that can be erased by strong Factors that determine the performance of hard disks are, seek time and drive
ultraviolet light and new data burnt into it. To do this the chip has to be rotational speed.
removed from the machine and put back after the changes have been made. o Seek time is the time taken to move the read/write head over the right
 Electrically Erasable Programmable ROM (EEPROM) is ROM whose content can track and sector.
be erased electrically. In this case, the chip need not be removed from the o Drive rotational speed is the total number of revolutions the disk platters
machine. The programming is done using special software. make per minute. Higher rotational speed leads to higher transfer rate.

c. Cache Memory
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 is to speed up accesses by storing recently used data
closer to the CPU, instead of storing it in main memory. Cache is static RAM and is
usually organized in levels:
 Level 1 (L1) cache, Level 2 and Level 3 cache.
 Level 1 cache is closest to the CPU or within it.
 L2 and L3 caches are outside it.

When the CPU needs to access memory, cache memory is examined first. If the data  Magnetic Tape
is found in cache, it is read from it. Otherwise, main memory is accessed. When the A magnetic tape consists of a magnetically coated stripe on which data is stored.
CPU refers to memory and finds the data in cache, it is said to be a HIT. Otherwise, it Data is stored on the magnetic tape in chronological order or sequentially. This
is a MISS. 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 the preceding data
1.4.2. Secondary Memory before it can access the desired data. This mode of access is known as sequential
Secondary memory is not directly accessible to the CPU. It is used to store programs access. Less susceptible to environment, they are suitable for long-term storage and
and data for backup purposes (future use). It could be placed within the computer or backup.
connected externally. Programs and data from secondary memory must be
transferred to main memory for processing. Secondary memory is also called b. Optical Storage
secondary storage, mass storage, backing storage or external storage. It can be Optical storage devices store data as microscopic light and dark spots on the disk
divided into magnetic storage, optical storage and solid state storage. surface. Examples are Compact discs, digital versatile discs and Blu-ray discs. They
are less susceptible to environmental damage.
a. Magnetic Storage
Magnetic storage devices store data as electromagnetic charges on the magnetic  Compact Disc (CD)
surfaces of the storage units. Examples are floppy disks, hard disks and magnetic A CD is a round disk coated with a metallic surface on which data can be stored and
tape. accessed via laser technology. To store or access data on a CD, the CD drive focuses
 Floppy Disk a laser beam on the disc surface. Different variations of CD exist: CD-ROM, CD-R and
A floppy disk consists of a round flexible plastic disk coated with a magnetic CD-RW. A CD can store 650MB to 700MB of data.
substance and protected by a plastic cover lined with a soft material that wipes the o CD-ROM stands for compact disc read only memory. CD-ROMs can only be
disk clean as it spins. The disk is made of two recordable surfaces which are divided read but not recorded on by the user’s computer. Their content is set during
into a number of circular paths called tracks. The number of tracks per surface manufacture.
varies with the particular type of disk. Each track is in turn divided into a number of o CD-R stands for compact disc recordable. It is a type of CD that can be
smaller units called sectors. A sector is the basic unit of storage on the disk and has recorded by the user. Once the user records on the CD, the content is set
a capacity of 512 bytes. and cannot be changed. CD-R can be read by CD-ROM drives but to write
on them, you need a CD-R drive.
 Hard Disk o CD-RW stands for compact disc rewritable. It is a type of CD that can be
A hard disk consists of several metallic platters which store data. Each platter has recorded, erased and reused by the user. CD-RW cannot be read by a CD-
two sides and is divided into a number of rings called tracks. Tracks on a platter are ROM and CD-R drives. CD-RW drives are required to read and write on
numbered 0 from the outside and usually go up to 1023. Each track is divided into them.
sectors. A sector is the basic unit of storage on the disk and has a capacity of 512
bytes. Sectors are grouped together to form clusters. A cluster is the smallest logical  Digital Versatile Disc (DVD)
amount of disk space that can be allocated to hold a file. A cylinder is a sum set of
all the tracks on all the platters that have the same track value.

© 2014- BGS Molyko 4


Bilingual Grammar School Advanced Level Computer Science

A DVD is similar to a CD in size and thickness but has a higher storage capacity than 1 bit = 0 or 1
the CD. DVDs use a laser beam of wavelength shorter than used by CDs. This allows 4 bits = 1 nibble
for smaller indentations and increased storage capacity. Just like the CD, different 8 bits = 1 byte 1 character
ions of the DVD exist: DVD-ROM, DVD-R and DVD-RW. A DVD can store up to 17GB of 1024 bytes = 1 kilobyte (KB) approx. 1/2 page
data. Common DVD storage capacities are: 1024 KB = 1 megabyte (MB) approx. 500,000 pages
1024 MB = 1 gigabyte (GB) approx. 5 million pages
Types Characteristics Capacity 1024 GB = 1 terabyte (TB) approx. 5 billion pages
DVD-5 Single-sided, Single- 4.7GB
layer b. Access time
DVD-9 Single-side, Dual-layer 8.5GB Access time is the average time taken for a storage device to search and read
DVD-10 Double-side, Single-layer 9.4GB required data on its medium. In other words, it is how fast data can be read from or
DVD-18 Double-side, Dual-layer 17.1GB written to a memory device’s medium. It is measured in seconds. Units of time are
summarized as follows:
 Blu-Ray Disc Millisecond (ms) =
A Blu-ray disc is an optical disc similar to a DVD and of same size, but read and Microsecond (µs) =
written with a blue or violet laser, whose shorter wavelength makes a higher data Nanosecond (ns) =
density possible. Blu-ray discs can hold 25 GB for single layer or 50 GB for double Picoseconds (ps) =
layer. Femtoseconds (fs) =

c. Solid State Storage c. Access Method


The term solid-state essentially means no moving parts. Solid-state storage devices An access method is the technique used to retrieve information from or store
are based on electronic circuits with no moving parts (no reels, no spinning disks). information to a medium. Storage media can be accessed in two ways: sequentially
They store data using a special type of memory called flash memory. Flash memory or randomly.
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  Sequential Access
memory is usually used for storing larger amounts of data while EEPROM is used for The medium is accessed by proceeding from the beginning of the medium until the
small amounts of data, such as machine configuration. Examples of solid state designated area is reached. Any new data is stored in the next available space on
devices are USB memory sticks, memory cards and secure digital cards. the medium. To read any data stored on the medium, the device has to start from
the beginning going through each data until the required data is found. An example
 USB Flash Drive of sequential access medium is magnetic tape.
A flash drive is a small, keychain-sized flash memory device with a USB interface,
treated by the computer as if it were a disk drive. A flash drive is also called thumb  Random Access
drive, jump drive or memory stick.USB flash drives have practically replaced Random access means that any location in storage can be accessed at any moment
diskettes as a handy way to transport data. They can be carried in one’s pocket and in approximately the same amount of time. Data is accessed in any order, regardless
plugged into any computer for immediate access. of its location on the medium. To read any data stored on the medium, the device
does not need to go through all preceding data. It is also called direct access.
 Secure Digital Cards Examples of direct access devices are RAM, ROM, CDs, DVDs and magnetic disks.
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 d. Volatility
music players and digital cameras. Volatility refers to the behavior of the device without power. A device can be volatile
or non-volatile. Volatile means that the device loses its content when power is
1.4.3. Characteristics of Storage Devices switched off. Examples of volatile devices are Cache and RAM.
Five important characteristics of storage devices are capacity, access time, access Non-volatile means that the device preserves its content even without power.
method, volatility and mutability. Examples of non-volatile devices are ROM, magnetic disks, optical discs and solid
state devices.
a. Capacity
The capacity of a storage device is the maximum amount of data that can be stored e. Mutability
on the device’s medium. It is expressed in terms of the number of data bytes the Mutability simple refers to the ability for the device to be accessed for reading
device can hold. This simply means the unit of measurement of storage capacity is and/or writing. Storage devices to which data can be written and read from are said
byte. Units of storage are summarized as follows: to be mutable (read/write). Examples are RAM, Flash memory, CD-RW, DVD-RW.

© 2014- BGS Molyko 5


Bilingual Grammar School Advanced Level Computer Science

Those that can be accessed only for reading are immutable (read only). Examples The data bus carries data between the CPU and main memory or peripherals. During
are ROM, CD and DVD. a write operation, data is carried from the CPU and during a read operation, data is
carried into the CPU. This means that the data bus is bidirectional. The size of the
1.4.4. Memory Hierarchy data us determines how much data can be transferred in a single operation.
Modern computers manage memory by organizing memory into a hierarchy in which
large and slower memories feed data into smaller but faster memories for faster b. The Address Bus
processing of data. This organization of computer memory is known as memory The address bus carries address information from the CPU to main memory or
hierarchy. At the top of the hierarchy are the CPU registers followed by cache peripherals. It is unidirectional. The CPU uses the address bus to send the address of
memory. The next level in the hierarchy is made up of main memory, which is the memory location to be written to or read from. Also, when the CPU reads data
followed by magnetic disk. from or writes to a port, it sends the port address out on the address bus. The size of
the address bus determines the maximum amount of main memory (RAM) that can
Registers be addressed. A computer with a 32 bit bus size can address a maximum RAM of 2 32
bits = 4GB.
Cache Memory

Faster and Main Memory c. The Control Bus


Slower and
smaller in size The control bus is used by the CPU to send out signals to enable the outputs of
Magnetic Disk larger in size
addressed memory devices or port devices. Typical control bus signals are memory
Optical Disc/Solid State Devices read, memory write, I/O read and I/O write.

Magnetic Tape
When the CPU wants to read data from a memory location, it sends out the memory
address of the desired data on the address bus and then sends out a Memory Read
Memory hierarchy signal on the control bus. The memory read signal enables the addressed memory
device to output the data onto the data bus. The data from the memory travels
along the data bus to the CPU.
1.5. The Motherboard
The motherboard is the main printed circuit board in the computer which holds the 1.5.3. Input/Output Interfaces
chipset and other electronic components that give function to the computer. The The CPU communicates with I/O devices through bus interfaces connected to the
motherboard is indispensable to the computer and provides the main computing system bus. These bus interfaces also called expansion buses are then connected to
capability. ports which allow the exchange of data and information between the computer and
external (peripheral) devices.
1.5.1. Motherboard Form Factor
Motherboard types are better described by what we call the motherboard form a. I/O Ports
factor. The form factor of a motherboard determines the specifications for its A port is a pathway for data and information to go into and out of the computer from
general shape and size. It also specifies what type of case and power supply will be external devices such as keyboards, monitors and printers.
supported, the placement of mounting holes, and the physical layout and There are many standard ports as well as custom electronic ports designed for
organization of the board. The most common form factors found in modern PCs are: special purposes. Examples of ports are:
 Advanced Technology (AT) o PS/2 ports for connecting the keyboard and mouse
 Advanced Technology Extended (ATX) o VGA (Video Graphics Adapter) port for connecting the monitor
 Low Profile Extension (LPX) o RJ45 port for connection to an Ethernet network
 New Low profile Extended (NLPX) o RJ14 for connection to the Internet via phone line
o USB port for connecting USB devices like Flash drives, printers, keyboards
1.5.2. The System Bus and mice
A computer bus is a set of parallel lines that interconnects various components o Serial ports for connecting serial devices like PDAs
inside the computer, allowing the exchange of data between them. It is the pathway o Parallel port connecting parallel devices like printers
between these components, enabling data to be transferred from one component to
o Firewire is high performance serial bus, for connecting devices to your
another. The width or size of a bus is determined by the number of lines it has. The
personal computer. FireWire provides a single plug-and-socket connection
system bus is made up of three different busses: the data bus, the address bus and
on which up to 63 devices can be attached with data transfer speeds up to
the control bus.
400 mbps.

a. The Data Bus


b. I/O Bus Standards

© 2014- BGS Molyko 6


Bilingual Grammar School Advanced Level Computer Science

Ports follow standards that define their use. Examples of such standards are: executed sequentially. That is, instructions are executed one after the other, one at a
o SCSI: Small Computer System Interface time. Hence these machines are also called sequential or serial processor machines.
o USB: Universal Serial Bus They are typical examples of Von Neumann’s computer model.
o IDE: Integrated Device Equipment
o PCI: Peripheral Component Interconnect
Control Unit Processor
o ISA: Industry Standard Architecture
o EISA: Extended ISA Instruction stream Data stream
o VESA: Video Electronics Standard Architecture
Memory
o SIMM: Single Inline Memory Module
o DIMM: Dual Inline Memory Module SISD Architecture
o PCMCIA: Personal Computer Memory Card International Association
2.2.2. Single Instruction, Multiple Data Stream
2. Computer Architecture
SIMD machines are multiprocessor machines which are capable of executing the
Computer architecture refers to those attributes of a system that have a direct
same instruction on all the processors at the same time. They have n identical
impact on the logical execution of a program like the instruction set, the number of
processors which operate under the control of a single instruction stream issued by
bits used to represent various data types, I/O mechanisms and techniques for
a central control unit on different data sets. At any given moment, the control unit
addressing memory.
broadcasts the same instruction to all processors which operate on different data
sets from distinct data streams. SIMD machines are also called array processor
2.1. The Von Neumann Architecture
machines. An example is the CRAY’s vector processing machine.
The term Von Neumann computer in its strictest definition refers to a specific type of
computer architecture in which instructions and data are stored together in a
common memory. This type of architecture is distinguished from the Harvard PE 1 DS 1
architecture in which separate memories are used to store instructions and data. It
is a stored-program computer model that was designed by the Hungarian born DS 2
Control Unit PE 2
Mathematician, John Von Neumann. It is based on three concepts:
IS DS = Data Stream
o Both data and instructions (programs) are stored in a single storage
DSn IS =Instruction Stream
structure called memory PE n
Instruction stream PE = Processor Element
o The contents of this memory are addressable by location, without regard to
the type of data contained there.
o It has a single processing unit which is. As such, execution occurs in a Memory
sequential fashion from one instruction to the next.
SIMD Architecture
Programs being stored in memory ensures that by altering the stored program, the
computer can perform a different task – reason why a computer is called a general 2.2.3. Multiple Data, Single Instruction Stream
purpose machine. MISD machines are multiprocessor machines capable of executing different
Neumann divided the computer into four functional units: input, processing, storage instructions on different processors, but all of them operating on the same data set.
and output. They have n processors, each with its own control unit, that share a common
memory. Each processor receives a distinct instruction stream but all operate on the
2.2. Flynn’s Taxonomy of Computer Architecture same data stream. Such machines no longer exist.
Michael Flynn classified computer architecture into four distinct categories based on
the notion of stream or flow of information into the CPU. He identified two types of
Control Unit 1 PE 1
information streams:
 The instruction stream which is the flow of instructions into the processing unit
 The data stream which is the flow of the data on which the instructions are
Control Unit 2 PE 2
performed.
IS = Instruction Stream
PE = Processor
2.2.1. Single Instruction, Single Data Stream Control Unit n PE Element
A SISD machine is a uniprocessor machine which receives a single stream of
instructions that operate on a single stream of data. At any given moment, a single
instruction is being executed on a given data set. In SISD machines, instructions are Data
Memory
Stream
© 2014- BGS Molyko 7
MISD Architecture
Bilingual Grammar School Advanced Level Computer Science

b. Multiprocessors
Computer systems may contain many processors, each possibly containing multiple
cores. Such 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 have access to all of the memory in such
2.2.4. Multiple Data, Multiple Instruction Stream systems, and the term shared-memory multiprocessor is often used to make this
MIMD machines are multiprocessor machines capable of executing multiple clear. The high performance of these systems comes with much higher complexity
instructions on multiple data sets. They have n processors, n streams of instructions and cost, arising from the use of multiple processors and memory units, along with
and n streams of data. Each processor element in this model has a separate more complex interconnection networks.
instruction stream and data stream hence such machines are well suited for any
kind of application. Examples of MIMD machines include multi-core computers like 2.3.2. Pipelining
the Blue Gene, Fujitsu K computer and CRAY Jaguar. The simplest way to execute a sequence of instructions in a processor is to complete
all steps of the current instruction before starting the steps of the next instruction. If
IS 1 DS1 we overlap the execution of the steps of successive instructions, total execution
Control Unit 1 PE 1
time will be reduced.
For example, the next instruction could be fetched from memory at the same time
IS 2 DS 2 that an arithmetic (execute) operation is being performed on the register operands
Control Unit 2 PE 2 DS = Data Stream of the current instruction. This form of parallelism is called pipelining.
IS = Instruction Stream
IS DS n
Control Unit PE n Definition: Pipelining is a technique that allows for the simultaneous execution of
the parts of an instruction.

Below is an example of a four-stage pipeline with three instructions. The stages are:
Memory
IF: instruction fetch ID: instruction decode EX: execute WB: write back

MIMD Architecture Instr. 1 IF ID EX WB

Instr. 2 IF ID EX WB
Question: SIMD, MISD and MIMD machines are known as parallel processing
machines. Instr. 3 IF ID EX WB
What do you understand by parallel processing?
Clock Cycle 1 2 3 4 5 6
2.3.Parallelism
The performance of computers can be increased by making them perform a number Cycle 1: Instruction 1 is being fetched from memory.
of operations in parallel. This is known as parallelism. Parallelism can be achieved Instructions 2 and 3 have not entered the pipeline yet
through parallel processing and pipelining.
Cycle 2: Instruction 1 is being decoded
2.3.1. Parallel Processing Instruction 2 is being fetched
Parallel processing is the use of multiple (independent) processors simultaneously to Instruction 3 has not entered the pipeline yet
execute a single program or task. The problem is divided into portions so that
multiple processors work on their assigned portion of the problem at the same time. Cycle 3: Instruction 1 is being executed
Parallel processing requires special software that recognizes how to divide the Instruction 2 is being decoded
problem and then bring the results back together again. Instruction 3 is being fetched
Some personal computers implement parallel processing with multiprocessors while
others have multicore processors. Cycle 4: Instruction 1’s results are being written back to register or memory
Instruction 2 is being executed
a. Multicore Processors Instruction 3 is being decoded
Multiple processing units can be fabricated on a single chip. In this case, each of
these processors is termed core. The term processor is then used for the complete Cycle 4: Instruction 1 is completed
chip. Hence, we have the terminology dual-core, quad-core, and octo-core Instruction 2’s results are being written back to register or memory
processors for chips that have two, four, and eight cores, respectively. Instruction 3 is being executed

© 2014- BGS Molyko 8


Bilingual Grammar School Advanced Level Computer Science

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
 the use of simple addressing modes
Cycle 6: Instruction 1 is completed  fixed length instructions (easier to decode)
Instruction 2 is completed  pipelining possible because of fixed length instructions
Instruction 3 is completed
Examples of RISC processors are: IBM RS6000, MC88100
2.4.Instruction Set Architecture DEC’s Alpha 21064, 21164 and 21264 processors, Motorola/IBM PowerPC
Every CPU has a predefined instruction set which defines the primitive operations
that it can perform. 2.4.3. Addressing Modes
A machine instruction specifies to the CPU what to do, where the data is located,
Definition: An instruction set is the collection of bit patterns or binary codes for the and where the output data (if any) will be put. Every instruction is made up of two
machine operations that a processor has been designed to perform. parts: Op-code and operand.
 The Op-code (operation code) denotes the basic machine operation e.g.
An instruction set architecture (ISA) consists of the instruction set together with the ADD, STORE, SHIFT, XOR.
resources needed for their execution. It provides the interface between the  The operand (one or more) provides the data which the instruction
computer's software and hardware and can be viewed as the programmer's view of manipulates.
the machine. Besides instructions, the ISA defines items in the computer that are
available to a program - e.g. data types, registers, addressing modes, and memory. For example,
There are two types of fundamental CPU architectures based on the notion of ADD A, $0E ADD is the op-code; A and $0E are operands
instruction set: complex instruction set computers and reduced instruction set MOV AX, #0 MOV is the op-code; AX and #0 are operands
computers.
Operands can be specified in different ways in an instruction. The way an operand is
2.4.1. Complex Instruction Set Computer (CISC) specified in an instruction is known as an addressing mode.
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- Definition: An addressing mode refers to the way in which the processor locates
electronic circuitry to generate a set of control signals and each micro-circuitry is the data (operand) associated with an instruction.
activated by a microcode. Complex instructions are first decoded and the
corresponding microcode routine dispatched to the execution unit. a. Register Addressing
The standard features of CISC processors are: In register mode, operand is the contents of a processor register; the name of the
 a large number of different and complex instructions. register
 the use of complex addressing modes. is given in the instruction. For example:
 execution of different machine programs on a CISC machine.
 the use micro-program control unit. ADD R1, R2, R3
 limited number of registers.
 variable length instruction encoding The above instruction uses three register to hold all operands. Registers R2 and R3
 direct memory access hold the two source operands while register R1 holds the result of the computation.

Examples of CISC processors are: Intel 386, 486, Pentium, Pentium Pro, Pentium II, b. Immediate Addressing
Pentium III, Motorola’s 68000, 68020, 68040, etc. In immediate mode, the operand is given explicitly in the instruction. In other words,
the value to be manipulated by the instruction is immediately part of it. There is no
need for any additional information. For example:
2.4.2. Reduced Instruction Set Computers (RSIC)
RISC (pronounced risk) is a CPU design with a small number of basic and simple ADD R2, R3, #10
machine language instructions, from which more complex instructions can be
composed. RISC instructions are hardwired. That is, they are built into the chip with This instruction adds the number 10 to the content of register R3 and stores the
hardware rather than programming. Hardware implementation of instructions is result in register R2. The operand 10 has been addressed immediately.
much faster and uses less silicon than a microcode implementation.
The standard features of RISC processors are: c. Direct Addressing
 a small and limited number of instructions.

© 2014- BGS Molyko 9


Bilingual Grammar School Advanced Level Computer Science

In this addressing mode, the operand is in a memory location; the address of this
location is given explicitly in the instruction. It is also called absolute addressing. For It can be written as Object 12

example:
Object 14

LOAD R2, $0FF

The above instruction loads the content of the memory location $0FF into register
0
R2. The operand $00FF has been addressed directly.
This means that there are two one hundreds, three tens and four ones in the number
d. Indirect Addressing
Here, the effective address of the operand is the contents of a register that is Object 18
.
specified in the instruction. For example:
For any n-digit number, the value each digit represents depends on its position in
ADD R2, R2, #R3 the number. Decimal positions (place values) are powers of ten as shown below:

Least Significant
This instruction adds the contents of the memory location held in register R3 to the Most Significant
… Digit (LSD)
content of register R2 and the result of the operation is held in register R2. Digit (MSD)

e. Indexed Addressing Decimal positions for an -bit number


The effective address of the operand is generated by adding a constant value to the
contents of a register.
Where, 0 is the ones place
3. Number Systems and Data Representation
Computers use binary patterns (fixed number of bits) to represent data, which could Object 22
is the ten’s place
be numbers, letters, videos, images or other symbols. It is important to decide on
how these patterns will be interpreted. The interpretation of binary patterns is called B is the hundreds place
data representation or encoding. Different representation schemes exist.

3.1.Number Systems
The value of any digit in a given n-digit number is obtained by multiplying the digit
A number system is a set of symbols and rules used to represent numbers. The
by its place value. The value of the number is the sum of the products of the digits
number of different symbols used in a given number system is known as the base or
and their place values. That is, we multiply each digit by its place value, then we
radix of the system. The largest value of a symbol (digit) in a given number system
add the different products obtained.
is always one less than the base or radix of that system. If the base of a system is

represented by 0 , then the largest value a digit in that system can assume is
Remark Each digit position in decimal has a weight that is ten times the one to its

immediate right. That is, is ten times greater than which is ten
1
Object 26 Object 28

Examples of number systems include the binary, octal, decimal (denary) and times greater than 1
hexadecimal systems.

3.1.1. The Decimal System 3.1.2. The Binary System


The decimal system has a base value of 10. Its maximum or largest value of digit is 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
1 , meaning thatthe decimal system uses the digits commonly bits. To express any quantity in binary we use powers much like in the
decimal system but this time, the weights are powers of 2 as shown below.
0 and 1 to represent any quantity. Least Significant
Most Significant
Bit (MSB) … Bit (LSB)

Consider the number 23410 Binary positions for an -bit number

© 2014- BGS Molyko 10


Bilingual Grammar School Advanced Level Computer Science

e.g. the binary number 0 is expressed as Example 2: Convert Object 60 to binary

1
Object 62
,
This means that there are 1 ones, 0 twos, 1 fours, and 1 eights in the number
1 . 0

a. Decimal to Binary Conversion B + AC


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 C
number system.
Step 1: divide the decimal number you want to convert by 2 in regular long
division until you obtain a final remainder
Step 2: use the remainder as the least significant bit of the binary number A
Step 3: divide the quotient you got from the first division operation by 2 until
you obtain a final remainder
Step 4: use the remainder as the next digit of the binary number
Example 3: Convert: 1 to decimal.
Step 5: repeat steps 3 and 4 as many times as necessary until you get a
quotient that cannot be divided by 2.
Step 6: use the last remainder (that cannot be divided by 2) as the most b. Binary to Decimal Conversion
significant bit of the binary number. To convert a binary number to decimal, we proceed as follows:
Step 1: starting with the 1s place, write the binary place value over each digit in
Example 1: Convert Object 38 to base 1 the binary number to be converted.
Step 2: add up all the place values that have a “1” in them
0 remainder 1 LSB
Example 1: Convert Object 74 to base 10
remainder 0
1
Object 44

1 remainder 1
1
1 remainder 0

0 remainder 1
1
0 remainder 0
Convert: 1 (15), 0 (19), 0 (21) to base 10.
Object 54
remainder 1

0 remainder 1 MSB Example 2: Convert Object 88 to base y←1

Therefore, 1 −¿
© 2014- BGS Molyko 11
Bilingual Grammar School Advanced Level Computer Science

111×101=100011 7 ×5=35
−¿ ii.

iii. Object 136


…………………………. (

……………… (
27 ×13=351
)

)
Object 96

 Division
Object 98
Rules for division:
0/1 = 0; 1/1 = 1; 1/0 = undefined.
Command
i. 1000÷ 10=100 ………………………. (
8 ÷ 2=4 )
Exercise: Convert the following binary numbers to decimal
1010.1012 (10.625) (ii) 10011.0012 (19.125) ii. Object 144
……………………….(
33 ÷3=11 )

c. Binary Arithmetic 11011÷ 101=101 r 10 ………………….(


27 ÷ 5=5 r 2 )
 Addition
Rules for addition:
0+0=0; 0+1=1; 1+0=1; 1+1=10; 1+1+1 = (1+1) + 1 = 10+1 = 11
3.1.3. The Octal System
100+01=101 (4 +1=5) The octal system has a base value of 8. It uses the digits 0-7 to represent any
i. …………………………………. quantity. Weights in octal are powers of eight as shown below.

1101+101=10010 (13+5=18) Least Significant


ii. …………………………. Most Significant
… Digit (LSD)
Digit (MSD)

iii. 1111+110=10101 …………………………..


(15+6=21) Octal positions

Where 80 is the one’s place


 Subtraction
Rules for subtraction:
0-0 = 0; 1-0 = 1; 0-1 = 0 (we borrow a digit); 1-1 = 0
81 is the eights place

10101−100=10001 21−4=17 82 is the sixty fours place


i. ( )

ii. 1010−101=101 …... we borrow a digit worth 2 to continue with the


Example: 3678=3× 82 +6 ×8 1+7 × 80
calculation ( 10−5=5 )
(This means that there are 3 sixty fours, 6 eight’s and 7 one’s in 367 )
iii. Object 122
( Object 124
)
a. Binary to Octal Conversion
Theorem
 Multiplication
If base R1 is the integer power of another base, R 2 (i.e. R1 = R2d), then every group of
Rules for multiplication:
d digits in R2 is equivalent to 1 digit in the R1 base.
Object 126 For example:
Assume that: R1 = 8 (octal) and R2 = 2 (binary)

i. Object 128
……………………………….. (
5 ×2=10 )
From the theorem, 8 = 23
Hence, 3 digits in base-2 is equivalent to 1 digit in base-8.

© 2014- BGS Molyko 12


Bilingual Grammar School Advanced Level Computer Science

From the stated theorem, the following is a binary-octal conversion table.

Example 2: Convert
450 8 to binary
Binary Octal Binary Octal

000 0 100 4 4 8=1002 , 58=1012 , 08=000 2


001 1 101 5

010 2 110 6
∴ 450 8=1001010002
011 3 111 7
3.1.4. The Hexadecimal System
The prefix “hex” means 6 and “deci” means 10. The hexadecimal number system is
To convert from binary to decimal, proceed as follows
thus a base-16 number system. Each digit position represents a power of 16. The
Step1: make groups of three bits starting from the least significant bit and move
digits used in this system are 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F, where
towards the most significant bit.
Step 2: replace each group of bits by its octal representation. A=10 10 , B=1110 , C=1210 , D=1310 , E=14 10 , F=1510 .

Example: 1. Convert
1001102 to base 8
Assume that:
R1 = 16 (hexadecimal)
1001102=100 110 R2 = 2 (binary)

1002=48 , 1102=68 From the theorem, 16 = 24


Hence, 4 digits in a binary number is equivalent to 1digit in the hexadecimal number
system.
∴ 1001102 =46 8
The following is the binary-hexadecimal conversion table

Example 2: Convert
10111012 to base 8
Binary Hexadecimal Binary Hexadecimal

0000 0 1000 8
10111012 =001 011101
0001 1 1001 9

0012=18 , 0112=3 8 ,1012=5 8 0010 2 1010 A

0011 3 1011 B

0100 4 1100 C
∴ 10111012=1358
0101 5 1101 D

0110 6 1110 E
b. Octal to Binary Conversion
To convert from octal to binary, we replace every octal digit by its 3-bits binary 0111 7 1111 F
equivalent.
 To convert from binary to hexadecimal

Example1: Convert
738 to binary
Step1: make groups of four bits starting from the least significant bit and move
towards the most significant bit.
Step 2: replace each group of bits by its hexadecimal value representation.
78=1112 , 38=1012
Example 1: Convert
1001102 to base 16
∴ 738=111101 2

© 2014- BGS Molyko 13


Bilingual Grammar School Advanced Level Computer Science

1001102=0010 0110 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 and 1s.
00102=216 , 01102=616
3.2.1. Representation of Unsigned Integers
Unsigned integers can represent zero and all positive integers. The value of an
∴ 100110 2=2616 unsigned integer is interpreted as “the magnitude of its underlying binary pattern”.
That is, for an unsigned integer, all the bits in the binary pattern are used to
represent the magnitude of the integer.
n
10111012 In binary, an n-bit pattern can represent 2 distinct integers. Therefore, an n-bit
Example 2: Convert to base 16

10111012 =0000 01011101 pattern will represent integers from 0 to 2n−1 .

00002=016 , 01012=516 , 11012=C 16 For example:

o A 4-bit pattern will represent the integers 0 to ( 24 ) −1=3


∴ 10111012=5 C16
o An 8-bit pattern will represent the integers 0 to ( 28 )−1=255
 To convert from hexadecimal to binary, we carry out the inverse operation.
That is, we replace every hexadecimal digit by its 4-bits binary equivalent. 3.2.2. Representation of Signed Integers
Signed integers can represent zero, positive integers, as well as negative integers.
Four representation schemes are available for signed integers:
Example 1: Convert
450 8 to binary 1. Sign-Magnitude representation
2. 1's Complement representation
4 16=01002 , 516=01012 , 016=00002 3. 2's Complement representation

4. Biased representation (Excess- n )


∴ 450 16=100010100002
a. Sign-Magnitude Representation
In sign-magnitude representation, the most significant bit is the sign bit with 0 for
Example 2: Convert 6E to base 2
positive and 1 for negative. The remaining (n−1) bits represent the absolute
6=0110, E=1110 value of the integer. The absolute value of the integer is interpreted as "the

∴ 6 E=11011102 magnitude of the ( n−1 )-bit pattern".

Assignment: Example 1: Suppose n=8 and the binary representation Object 240
.
1) Convert the following octal numbers to hexadecimal.
Sign bit is 0 ⇒number is positive
i) 658 (ii) 538
Absolute value is 1000001=65
2) Convert the following hexadecimal numbers to octal.
i) 12B16 (ii) F2E16 Hence, the integer is 65 .

3.2.Representation of Numbers

© 2014- BGS Molyko 14


Bilingual Grammar School Advanced Level Computer Science

Example 2: Suppose n=8 and the binary representation 10001001 . i) 0010 0001 .

Sign bit is 1 number is negative Sign bit is 0 ⇒ positive

Absolute value is 0001001=9 Absolute value is 010 0001=33

Hence, the integer is −9 Hence, the integer is +33

The drawbacks of sign-magnitude representation are:


ii) 1000 0001
o There are two representations (0000 0000 and 1000 0000) for the number
zero, which could lead to inefficiency and confusion. Sign bit is 1 ⇒ negative
o Arithmetic is cumbersome making the design of electronic circuits for this
scheme difficult. Absolute value is the complement of 000 0001 , i.e., 1111110=126

b. 1’s Complement Representation Hence, the integer is −126


In 1's complement representation the most significant bit is still the sign bit. The

remaining (n−1) bits represent the magnitude of the integer as follows: The problem with this representation is that there are still two representations for
zero (0000 0000 and 1111 1111).
o for positive integers, the absolute value of the integer is equal to "the
 Addition in 1’s Complement
magnitude of the ( Object 256
)-bit pattern". o Add binary representations of the two numbers
o for negative integers, the absolute value of the integer is equal to "the o If there is a carry (referred to as end-round carry), add it to the result.

magnitude of the complement (inverse) of the ( n−1 )-bit pattern".  Subtraction in 1’s complement
Subtraction is implemented using addition as follows:
o Determine the 1’s complement of the negative number
Example 1: Using 1’s complement, represent the following base 10 numbers on 8 o Add the binary representations of the two numbers
bits. o If there is any carry, add it to the result
i)
2610=11010
Example: subtract 37 from 51 in binary
Number is positive ⇒ sign bit is 0 37=0100101⇒37=1011010 ⇒−37=1101101 in 1’s complement

2610=0 0011010
(51) Object 290

ii) −25 (-37) + 11011010


Number is negative ⇒ sign bit is 1 --------------
25=11001 1 00001101

Complement of 0011001 is 1100110 + 1

⇒ −25=1 1100110 ---------------

(14) 00001110
Example 2: Give the decimal equivalent of the following 1’s complement binary
representations.

© 2014- BGS Molyko 15


Bilingual Grammar School Advanced Level Computer Science

c. 2’s Complement Representation


i) 01100000
In 2's complement representation, the remaining (n−1) bits represent the
Sign bit is 0 ⇒ positive number
magnitude of the integer as follows:
Absolute value is 100+01=101
o for positive integers, the absolute value of the integer is equal to "the

magnitude of the ( Object 302


)-bit pattern". Hence, the integer is +96
o for negative integers, the absolute value of the integer is equal to "the

n−1 ii) 1 0010001


magnitude of the complement of the ( )-bit pattern plus one". That

is, we just add one to 1’s complement to get 2’s complement.


Sign bit is Object 342
negative number
An alternative and simple way of getting 2’s complement is
o to write the representation of the positive number Absolute value is the complement of 001 0001 plus 1, i.e.,
o starting from the least significant bit, flip all the bits to the left of the first 1.
110 1110+1=111
Example 1: Using 2’s complement, store the following base 10 numbers.

i) −24 Hence, the integer is −111 (

Number is negative ⇒ sign bit is 1


7 4 0
−2 +2 +2 =−128+16+1=−111¿
24=11000=0011000
Modern computers use 2's complement in representing signed integers. This is

1’s complement of 24 is 1100111 because:


1. There is only one representation for the number zero unlike in sign-
magnitude and 1's complement representations.
2’s complement of 24 is 1100111+1=1101000 2. Positive and negative integers can be treated together in addition and
subtraction. Subtraction can be carried out using the "addition logic".
⇒−24 is represented by
11101000
 Addition in 2’s Complement
o Add binary representations of the two numbers
¿13.375 o If there is a carry, ignore it
ii)
 Subtraction in 2’s Complement
Number is negative ⇒ sign bit is 1 Subtraction is implemented as follows:
o Determine the 2’s complement for the negative number
13=1101=0001101 o Add the binary representations of the two numbers
o If there is any carry, ignore it
1’s complement of 13 is 1110010
Example: subtract 37 from 51

2’s complement of 13 is 1110010+1=1110011 37=0100101⇒37=1011010 (1’s C)


⇒−37=11011011 (2’s C)

⇒−13 is represented by
11110011 (51) 00110011
(-37) + 11011011
- ------------
Example 2: Give the decimal equivalent of the following 2’s complement binary (14) 1 00001110 discard end-round carry
representations.

© 2014- BGS Molyko 16


Bilingual Grammar School Advanced Level Computer Science

d. Excess-n Representation
a. 32.2
In excess-n notation, where n is the number of bits used, the value represented is
the unsigned value with a fixed value 2n-1 subtracted from it.
b. −15.37
Example 1: Represent the
c. 0.125
3.2.3. Representation of Real Numbers
Computers represent real numbers in a form similar to that of scientific notation of
E Solution:
mantissa (M) and an exponent (E) of a certain radix (R), in the form of M×R . a. We convert the number to binary
32=100000
Both M and E can be positive as well as negative. For example, 1.25× 10−1 is
0.2=0.2 ×2=0.4 0 MSB
expressed in scientific notation where 1.25 represents the mantissa, −1 the
¿ 0.4 ×2=0.8 0
exponent and 10 , the radix.
¿ 0.8 ×2=1.6 1
The IEEE 754 standard for representing floating-point numbers in the computer has
two representation schemes: 32-bit single-precision and 64-bit double-precision. ¿ 0.6 ×2=1.21
 In 32-bit single-precision floating-point representation:
 the most significant bit is the sign bit (S), with 0 for negative numbers and 1
¿ 0.2× 2=0.4 0
for positive numbers.
 the following 8 bits represent the exponent (E). ¿ 0.4 ×2=0.8 0
 the remaining 23 bits represent the mantissa (M) or fraction (F).
¿ 0.8 ×2=1.6 1

¿ 0.6 ×2=1.21

So a binary representation of 0.2 is given by 0.001100110011


 In 64-bit single-precision floating-point representation:
o the most significant bit is the sign bit (S), with 0 for negative numbers and 1 64.2 is
100000.001100110011
for positive numbers.
o the following 16 bits represent the exponent (E).
o the remaining 47 bits represent the mantissa (M) or fraction (F). Step 2: we normalize the binary representation
5
1000000.001100110011 becomes 1.00000001100110011× 2
In floating-point representation, the mantissa and exponent play two important
roles. The mantissa 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 Step 3: 5 is the true exponent.
with the set of numbers that can be represented.
In excess-16, we have 5+16=21
For simplicity, we will use a 14-bit pattern for floating point with a 5-bit exponent
and an 8-bit mantissa. In this case, we will use excess-16 representation for the 21 in 5-bit unsigned representation is
10101
exponent.
Examples:
1. Represent the following numbers as 32-bit single precision floating-point Step 4: The mantissa stored is what is on the right side of the radix point of the
numbers. normal form.

© 2014- BGS Molyko 17


Bilingual Grammar School Advanced Level Computer Science

So M is 0000000110011001100110 0=0000

1111+110=10101
Putting all these together we have 64.2 represented as:

0.25 ×2=0.5 0
0 1010100000001 [ 10011001100110 ¿
0.5 ×2=1.0 1
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.
0.125=0.001
b. −15.375
−3
Normalized we have, 1.0 ×2
Negative number ⇒ sign bit is 1
E=−3+16=13=01101
15=1111

0.375 ×2=0.75 0 MSB 1.125 is represented as 0 01100 00000000

0.75 ×2=1.5 1
2. Suppose the following 14-bit floating-point representation patterns, what decimal
numbers do they represent?
Object 424

a. 01000011000000
0.5 ×2=1.0 1 b. 10111010000000
c. 11111000000001

Solutions:
0.375=0101
a. 010000110 00000
15.375=1111.0101 Sign bit is S=0 ⇒ positive number

1.1110101×23 E=10000=16 (in normalized form)


Normalized we have,

E=3 ⇒ 19 16 Fraction is 1.11 (with an implicit leading 1) ¿ 1+1× 2−1+1 ×2−2=1.75


in excess-
(16−16) 0
Object 438 The number is +1.75 ×2 =+1.75 × 2 =+1.75

−15.375 is represented as
110010 11101010
b. 10111010000000

Sign bit S=1 ⇒ negative number


c. 0.125
E=01110=13 (in normalized form)
Positive number ⇒ Sign bit is 0

© 2014- BGS Molyko 18


Bilingual Grammar School Advanced Level Computer Science

1.1 −1 encoding scheme could represent characters in all languages. Unicode is backward
Fraction is (with an implicit leading 1) ¿ 1+1× 2 =1.5 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 same as Latin-1.
The number is −1.5 × 2(13−16)=−1.5× 2−3=−1.625 The original 16-bit range of U+0000H to U+FFFFH (65536 characters) is known as
Basic Multilingual Plane (BMP), covering all the major languages in use currently. The
characters outside BMP are called Supplementary Characters, which are not
frequently-used.
c. 1 11110 00000001
UCS-4 (Universal Character Set - 4 Byte), uses 4 bytes (32 bits), covering BMP and
Sign bit S=1 ⇒ negative number the supplementary characters.

(15+6=21) 4. Digital Electronics


(in normalized form)
4.1.Boolean Algebra
Fraction is 10101−100=10001 (with an implicit leading 1) ¿ 1+2−8 Boolean algebra also known as the algebra of logic was developed by an English
mathematician called George Boole. It deals with binary variables and logic
−8 (30−16 ) operators operating on these variables. A binary variable has only two possible
The number is −(1+2 )×2
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:
3.3.Representation of Characters
AND
Characters are represented using a chosen character encoding scheme (character OR
NOT
set, charset, character map, or code page). The most commonly-used character
encoding schemes are: ASCII, Latin-x for western European characters, and Unicode
for internationalization.

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

Code numbers 48 to 57 represent '0' to '9', respectively.
A ( B+C)=( AB)+( AC ) |
A +(BC )=( A+ B)( A+C)

3.3.2. Latin-1
o Identity law
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 A· 1= A |
A +0=A
Latin script, which covers languages like English, German, Italian, Portuguese and
Spanish. Latin-1 is backward compatible with the 7-bit ASCII code. That is, the first
128 characters in Latin-1 (code numbers 0 to 127 (7FH)), is the same as ASCII. Code o Redundancy law
numbers 128 (80H) to 159 (9FH) are not assigned. Code numbers 160 (A0H) to 255
A· 0=0 |
21−4=17
(FFH) represent other special characters like Å, Æ, Ç, ~, £, ¤, ¥, § and ©.

3.3.3. Unicode Character Code


o Complement law
Unicode originally uses 16 bits (called UCS-2 or Unicode Character Set - 2 byte),
which can represent up to 65,536 characters. Before Unicode, no single character

© 2014- BGS Molyko 19


Bilingual Grammar School Advanced Level Computer Science

1010−101=101 | A + Á=1 ¿ B+ AC (
AB+ B=B )

o Idempotence law Example 2: Simplify the expression


A · A= A A + A=A ´
A B́+ A ( B+C)+ ´
B( B+C)= A B́+ A ( B́ Ć)+ B( B́ Ć)
| De

Morgan’s
o Absorption law ¿ A B́+ A B́ Ć+ B B́ Ć
A ( A +B )= A |
A + ( AB )= A
¿ A B́+ A B́ Ć+ 0 Ć (
o Involution law
B B́=0 )
Á= A
¿ A B́+ A B́ Ć+ 0 (
o No name

10−5=5 | A ( Á + B )= AB 0 C' =0 )

¿ A B́ (1+ C) (
AB + A B́= A | ( A+ B)( A + B́)=A
1+C ’=1 )
o De Morgan’s Theorems
¿ A B́ · 1 (
´ Á + B́
AB= ´ B= Á · B́
A+
|
A B́ · 1= A B́ )
4.1.2. Simplifying Boolean Expressions
Simplifying a Boolean expression consists of using the laws of Boolean algebra to ¿ A B́ ( A B́ · 1 )
write the expression in its simplest form.

AB+ A (B +C)+B (B+ C) Example 3: Use De Morgan’s theorems to simplify the following
Example 1: Simplify the expression
´ +CB)
( A+ BC
i)
Solution:
AB+ A ( B+C ) +B ( B+C )= AB+ AB+ AC + BB+BC ( A B́+´ A Ć )
ii)

¿ AB+ AB+ AC+ B+ BC ( BB=B


Example 4: Show that
)
i) A + AB= A
¿ AB+ AC + B+ BC ( Object 552

´ B)= B́( Á+ B)


( A+
) ii)
¿ AB + AC+ B (
iii) ( A+ B)(A + B́)=A
B+ BC =B )

© 2014- BGS Molyko 20


Bilingual Grammar School Advanced Level Computer Science

ii) Á BC + AB Ć [ B ( A xor C )¿
4.1.3. Constructing Truth Tables
A truth table shows the output for all possible values of the input variables for a
given Boolean expression. To construct a truth table, we evaluate the Boolean iii) A ( A+ Ć )( A +B)
expression for all possible combinations of values for the input variables. The

number of possible combinations is always equal to Object 596 where n is the 4.2.Logic Gates and Circuits
Logic gates and circuits are simply ways of representing Boolean functions and
number of input variables. expressions electronically.

Example 1: Construct a truth table for the expression A + Á B 2.1. Logic Gates
A logic gate is an electronic device that implements a simple Boolean function. Logic
gates carry out the operations that the microprocessor performs. When a
We have 2 input variables A and B⇒ we will have 22=4 different microprocessor is designed, a logic gate cell library (collection of all low level logic
functions used to implement the logic) is also deeply planned and developed.
combinations. There are six basic logic gates: AND, OR, NOT, NAND, NOR and XOR.
B Á a. AND Gate
Object 801
Object 804 Object 805

It is a logic gate whose output is “true” only when both inputs are “true”. If neither
0 0 1 0 Object 810
or only one of the inputs is “false”, the output is “false”. The following illustration
and table show the circuit symbol and logic combinations for an AND gate.
0 1 1 1 1
Example 2: Construct a truth table for the A B A.B
1 0 0 1
B+ AC
Object 818

0 0 0
expression
1 Object 822
5×2=10 0 1 0 1 0

3 input variables ⇒ 23=8 different Logic AND 1 0 0


1 1 1
combinations
b. OR Gate
A B C AC B+ AC It is a logic gate whose output is “true” when either or both of the inputs are “true”.
If both inputs are "false," then the output is "false."
0 0 0 0 0
A B A Or B
0 0 1 0 0 0 0 0
0 1 1
0 1 1×101=10 01 0 0 1 Logic OR 1 0 1

0 1 1 0 1 1 1 1
c. NOT Gate
1 0 0 Object 838 Object 839

Example 3: Construct the truth tables for


It is a logic gate whose output is “false” if its input is “true” and vice versa. It is
called logical inverter, because it reverses the state of its input. A NOT gate accepts
the following one input and produces a single output.
1 0 1 1 1
i) Á B+ A B́ Outpu
A
1 1 0 0 1 t
0 1
1 1 1 1
Logic NOT (inverter)
Object 851

1 0
© 2014- BGS Molyko 21
Bilingual Grammar School Advanced Level Computer Science

2.2. Logic Circuits


d. NAND Gate Circuits are made by combining two or more logic gates. Gates are combined into
The NAND gate operates as an AND gate followed by a NOT gate. The output is circuits by using the output of one gate as the input for another.
"false" if both inputs are "true." Otherwise, the output is "true. Examples

A B ¬(A B)

0 0 0
0 1 1
Logic NAND
1 0 1

1 1 1

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 "false." Otherwise, the output is "false."

A B ¬(A+B Exercise 1: Construct logic circuits for the following expressions

0 0 0 1) Á B+ A B́
0 1 1
Logic NOR 2) 27 ×13=351
1 0 1

1 1 1
3) Á ( B́+ A)
f. XOR Gate
Exclusive-OR is a logic gate whose output is “true” when one but not both of its
´ )
( Á+ B ) ( ABC
4)
inputs is “true”. The output is "false" if both inputs are "false" or if both inputs are
"true." Another way of looking at this circuit is to observe that the output is “true” if
5)
the inputs are different, but “false” if the inputs are the same.
Object 800

Outpu Exercise 2: What are the outputs for the following logic circuits
A B
t
0 0 0
Logic XOR
0 1 1

1 0 1
CHAPTER 2: SYSTEM SOFTWARE System software control and coordinate computer resources (hardware and
1 1 0 operations) so that the computer user and applications can smoothly interact. They
Introduction help the computer carry out its basic operating tasks. System software are designed
Computer hardware require instructions to perform tasks. These instructions are to perform computer related tasks. They include operating systems, firmware, utility
provided by the programs or software installed in them. Software refers to the programs, device drivers, library programs and language translators.
collection of computer programs and data that run on a computer, and which make
the hardware useful. They are the intangible components of the computer system. 1. Operating System
Computer software has two major categories namely system software and The operating system is the essential software that is required for a computer to
application software. become operational. It is the software layer that is on top of the hardware to provide

© 2014- BGS Molyko 22


Bilingual Grammar School Advanced Level Computer Science

functionality to computer components, manage the hardware and serve as interface


between the computer user and the computer. When a user logs in, a shell is started up.

Definition: An operating system is software that manages the computer hardware c. System Calls
resources and provides basic interface for execution of various application software. 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
The operating system is called a virtual machine as it hides the complexity of the operating system.
hardware and presents the user with an interface that is easier to understand and
work with. Definition: System call is the mechanism by which a program requests a service
The operating system is stored on disk, but it needs to be loaded into memory (RAM) from the operating system’s kernel.
once the computer is switched on and before any other program can be run. The
term bootstrapping refers to the process of loading the operating system into a When a running program needs a service from the operating system, it calls a
computer’s memory. This process is done by a program called the bootstrap loader system call.
that is stored permanently in the computer’s electronic ROM chip. Examples of
operating systems are Windows (95, 98, 2000, XP, Vista, 7 and 8), Macintosh 1.2. Operating System Functions
Operating System (Mac OS), Linux and UNIX. 1.2.1. Memory Management
For a program to be executed, it must be found in main memory (RAM). In a
1.1. Operating System Structure multiprogramming environment in which several programs can reside in memory at
The operating system can be divided into two main components: kernel and the same time, every program and its data must be protected from the actions of
command interpreter (shell). other programs. Memory management keeps track of what programs are in memory
and where in memory they reside.
Memory allocation determines where a program as well as its related data will be
kept in memory for execution. Memory needs to be allocated efficiently to pack as
many jobs in memory as possible. 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
OS structure process.
a. OS Kernel o Best fit allocates the smallest block among those that are large enough for
The kernel is the central part of an operating system that is running at all times on the new process.
the computer. It loads first and remains in memory as long as the computer is on. It o Worst fit allocates the largest block among those that are large enough for
consists of utilities (file manager, memory manager, device drivers, process the new process.
manager etc.) that perform basic required functions. In many operating systems,
only the kernel can access hardware directly. b. Paging
Paging is when memory is divided into fixed-size units called frames. Jobs are broken
b. The Shell up into blocks of same size as frames called pages which are allocated a number of
The shell, command shell or command interpreter, is the part of the operating frames. The OS then uses a page table to map program pages to memory frames.
system that provides an interface between users and operating system of a The pages for each job could be in logical order or they may be scattered about
computer to access the services of the kernel. It understands and executes wherever there is a free frame.
commands that are entered interactively by a human being or from a program.
There are two types of shell: c. Virtual Memory
1. Command-line shell eg. Bash (sh), Command Prompt (cmd), C shell, Bourne A program may require more memory than it is available. To solve this problem,
shell, Korn shell (ksh) etc.. virtual memory is used. Virtual memory is part of the hard disk that is used as an
2. GUI-shell eg. Windows Explorer or Windows Shell extension of RAM. It is slower, but it is considerably bigger. As execution goes on,
data is being swapped between RAM and virtual memory.
A third type of shell is recently developed - a GCLI (Graphical Command Line When a program is running, only the pages that contain the necessary data are kept
Interface) shell. A GCLI shell combines the features of both CLI and GUI shell and in RAM while those that are not needed are kept on disk. For example, a program
provides an interface which is both user-friendly and powerful.

© 2014- BGS Molyko 23


Bilingual Grammar School Advanced Level Computer Science

that has been minimized for a long time may be transferred to virtual memory so as
not to fill up the main memory. b. Process Synchronization
Disk thrashing occurs when the OS has to spend a considerable proportion of its In a multi-tasking system, processes compete for resources. A resource is anything
time swapping data between virtual and real memory. that is required by a process to accomplish its task (processor, memory, I/O device,
bus, file etc). Some resources can only be used in a non-sharable or exclusive mode.
1.2.2. Process Management That is, they cannot be used by more than one process at a time. Such resources are
A process is a program in execution. It consists of the program’s instructions and the known as critical resources. A critical section is a part of a program where it has
resources allocated to it for execution. A program is static while a process is active. access to a non-sharable (critical) resource. To prevent two or more processes from
The operating system performs process management to carefully track the progress entering their critical sections over the same resource, processes must be
of a process and all of its intermediate states. synchronized.
A process changes state as it executes. The different states a process can have are
shown in the diagram below. Definition: Process synchronization is about getting processes to coordinate
together in order to avoid two or more processes entering into critical section over
the same resource.

If processes are not synchronized, it leads to deadlock and starvation.

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

© 2014- BGS Molyko 24


Bilingual Grammar School Advanced Level Computer Science

 Non preemptive scheduling is scheduling in which the currently executing


process gives up the CPU voluntarily. Scheduling under (1) and (4) is non-
preemptive.

There exist different algorithms used for scheduling. Examples are first come, first
served, shortest job first and round robin algorithms.
1.2.4. Management of I/O Devices
a. First Come, First Served
First come first served algorithm moves processes to the CPU in the order in which a. Interrupts
they arrive in the ready queue. It is non-preemptive. As such, when a process has An interrupt is a signal generated by hardware or software that causes the CPU to
the CPU it runs to completion before giving up the CPU. suspend what it is doing to handle another task of higher priority. Any event that will
Consider that the following processes arrive in the order they are given below. cause an interrupt is called an interrupt request (IR). For example, a key pressed on
the keyboard. An interrupt handler or interrupt service routine (ISR) is a program
that services an interrupt request. It contains the actions that will be executed for a
Process Service time given interrupt request.
P1 140
b. Polling
P2 75

P3 320 c. Buffering
A buffer is an area of memory used to temporarily store data while it is being moved
P4 280 from one place to another.
P5 125
1.2.5. File Management
The file system is the portion of the operating system that manages how files are
Using FCFS algorithm to schedule the processes, we stored. Examples of file systems are FAT used in MS DOS, NTFS used in Windows,
get ext2 used in Linux and HPFS used in OS/2. The operating system is responsible for
the following activities in connection with file management:
o File creation and deletion.
o Directory creation and deletion.
b. Shortest Job First o Support of primitives for manipulating files and directories
Shortest job first (SJF) algorithm looks at all the processes in the ready state and o Mapping files onto secondary storage.
dispatches the one with the smallest execution time. It is also generally o File backup on stable (nonvolatile) storage media.
implemented as a non-preemptive algorithm. Using the SJF algorithm, we have
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 communication or interaction between the user and the computer. The
operating system provides this means that enables an individual to see and work
when using a computer.
Disadvantage Different operating systems provide different types of user interfaces.
 Some jobs may never be executed as they have a high service time
(starvation). a. Command Line Interface (CLI)
A command line interface allows the user to interact with the computer by typing
c. Round Robin the commands in a specified format. It provides a prompt through which the user
Round-robin algorithm distributes time equitably among all ready processes by types the commands. Here the user mostly makes use of the keyboard.
establishing a particular time slice (or time quantum), during which each process In this type of interface, the user has to remember the name and format of the
executes. At the end of the quantum, the process is preempted. It returns to the commands. Spelling mistakes and deviations in format lead to errors and the task is
ready state to allow another process its turn. Using round-robin algorithm with time not performed. Examples of operating systems that provide a command line
slice of 50, the above processes will be scheduled as follows: interface are MS DOS, early versions of UNIX and Linux.

b. GraphicalUserInterface (GUI)

© 2014- BGS Molyko 25


Bilingual Grammar School Advanced Level Computer Science

A graphical user interface allows the user to interact with the computer through 1.3.3. Single task OS
graphical items such as icons, menus, dialog boxes, etc. Here, the user mostly A single task operating system allows a user to execute one and only program at a
makes use of the mouse to point and click on these graphical items. GUI is also time. The user cannot run two or more programs at the same time. It is not possible
known as WIMP system where WIMP stands for windows, icons, menus and pointers. to be preparing a worksheet on the computer while printing a report or listening to
This type of user interface requires a lot of memory space to store the graphics and music. Once a user invokes a program, the computer gets dedicated to that task
can cause machines with low processing power to be slow. Examples of operating only.
systems with a graphical user interface are Windows, Macintosh operating systems, CP/M and MS-DOS are examples of single user single task operating systems.
some versions of Linux and UNIX.
1.3.4. Multiprogramming OS
c. VoiceRecognition Interface A multi-programming operating system is an operating system that allows multiple
A speech recognition interface allows the user to give verbal commands to the programs to be held in main memory at the same time. The concept of multi-
computer. The user communicates with the computer through natural language. programming is that the operating system keeps several jobs in memory
They are also called natural language interface simultaneously and decides which can be executed at a given moment.

1.2.7. Providing Security 1.3.5. Multitasking OS


Security is the most desirable characteristic of any operating system. An operating A multitasking operating system allows a user to execute more than one program at
system should provide a means for safeguarding system resources from a time. It allows a user to be preparing a worksheet on the computer while printing a
unauthorized users and protection of one user's resources from other users of the report or listening to music. Multitasking is an extension of multiprogramming as two
system. programs cannot be executed simultaneously if they are not found in memory at the
Popular operating systems offer security features through incorporation of the same time.
following: Windows Me, Windows-XP, Macintosh operating system, OS/2 are examples of single
o Login name. user, multitasking operating systems.
o Login password.
o Read/write access file permissions. 1.3.6. Embedded OS
o Encryption of data An embedded operating system is an operating system that is used in an embedded
o Virus protection software layers. system. An embedded system is a small computing device that is built into a larger
equipment often as a single chip and dedicated to a given task. Embedded systems
1.3. Types of Operating Systems control many devices in use today such as digital watches, mobile phones,
1.3.1. Single User OS microwave ovens, washing machines, vehicles, photocopiers, cameras and process
A single user operating system is an operating system which allows only one user to controllers.
work on the system at a time. No two or multiple users can work on the system Embedded OS are ROM based. That is, they cannot be modified as ROM is read only.
simultaneously.
Examples are Control Program for Microcomputers (CP/M) and Microsoft Disk 1.3.7. Network OS
Operating System (MS DOS). A network operating system is an operating system which includes networking
features. It contains special functions, protocols and device drivers that enable the
1.3.2. Multi User OS computer to be connected to a network.
A multi-user operating system is an operating system which allows multiple users to Examples of network operating systems are Windows-NT, Windows-2000 server,
work on the system simultaneously. This type of operating system is larger and more Windows server 3000, Novell Netware and Artisoft LANstatic.
complex than a single user operating system. Some multi-purpose operating systems like Windows XP, Windows 7 and Mac OS 10,
Features of multi-user operating systems, which are not provided in single user come with capabilities that enable them to be described as network operating
operating systems, are: systems.
o Time sharing (CPU devotes time to all the users in round robin fashion).
o Tight security features. 2. System BIOS
Basic input output system (BIOS) is software that contains hundreds of programs
o Resource sharing among users.
that allow for communication between the CPU and devices. It is stored on ROM,
o System administrator privileges
which is a permanent chip on the motherboard.
Examples of multi-user operating systems are Linux, Unix and Virtual Machine
There are three kinds of BIOS for hardware devices:
System (VMS).
 Permanent never changing BIOS for never changing hardware like the
keyboard

© 2014- BGS Molyko 26


Bilingual Grammar School Advanced Level Computer Science

 BIOS for hardware that changes occasionally. It requires extra volatile  Disk partition utilities divide an individual drive into multiple logical drives,
information so it is stored on a separate chip called CMOS (Complementary each with its own file system which can be mounted by the operating system
Metal Oxide Semiconductor). and treated as an individual drive.
 Disk formatters
3. Utility Programs  Virus checkers prevent, detect, and remove malware.
Utility software is used to enhance the operating system, or in some other way
improve the usefulness of the system. They help analyze, configure, optimize and 4. Device Drivers
maintain the computer. Rather than providing user-oriented or output-oriented A device driver is software that allows interaction between the operating system and
functionality, utility software focuses on how the computer infrastructure operates. a hardware device. It is an interface for communicating with the device through the
Most major operating systems come with several pre-installed utilities. Examples of specific computer bus that the hardware is connected to. Without an appropriate
utility software include: disk defragmenters, backup utilities, disk compression device driver the system cannot communicate with a device, rendering the device
utilities, disk cleaners, file managers, disk formatters and virus checkers. useless. Installation of device drivers usually happens automatically when hardware
 Disk defragmenters detect computer files whose contents are broken across is connected (plug n play), or from a CD provided with the device. Sometimes a
several locations on a disk, and move the fragments to one location to device driver needs to be updated to stay functional.
increase efficiency.
 Disk cleaners find and delete files that are unnecessary to computer operation, 5. Library Programs
or take up considerable amounts of space. They help users decide what to
delete when their hard disk is full.
 Backup utilities make copies of all information stored on a disk, and restore 6. Language Translators
either the entire disk (e.g. in an event of disk failure) or selected files (e.g. in A language translator is a computer program that translates program instructions
an event of accidental deletion). from one programming language to another. There are three types of language
 Disk compression utilities reduce the space that a file takes up on disk, translators: compilers, interpreters and assemblers.
increasing the capacity of the disk.  Compilers translate instructions written in a high-level language into machine
 File managers provide a convenient method of performing routine data language instructions.
management tasks, such as deleting, renaming, moving, copying, merging,  Interpreters translate instructions written in a high-level language into
generating and modifying files. machine language instructions and execute them, one line at a time.
 Assemblers translate instructions written in assembly language to machine
language instructions.
CHAPTER 3: COMMUNICATION SYSTEMS more than a mile. It is fast, with speeds from 10 Mbps to 10 Gbps. An example of
LAN is the network in the Multimedia Resource Centre.
1. Computer Networks
A computer network is a collection of computers and other devices that are 1.1.2. Metropolitan Area Network
connected together so they can communicate and share resources. The smallest A metropolitan area network (MAN) is a large computer network that usually spans a
network can be as simple as two computers linked together. The resources shared city or a large campus. It is optimized for a larger geographical area than a LAN,
include files, folders, printers, disk drives and anything else that exists on a ranging from several blocks of buildings to entire cities. A MAN typically covers an
computer. Any computer or device on a network is called a node. area of between 5 and 50 km diameter. An example of a MAN is a cable TV network.
Networking is the term that describes the processes involved in designing,
implementing, upgrading, managing and otherwise working with networks and 1.1.3. Wide Area Network
network technologies A wide area network (WAN) covers a large geographic area such as a country, a
continent or even the whole world. It is a distributed collection of LANs. That is, it
1.1. Types of Computer Networks connects two or more LANs together. This is done using devices such as bridges,
Different criteria exist for classifying computer networks. According to geographical routers or gateways, which enable them to share data. The largest and most well-
area covered, networks can be classified as local area networks, wide area networks, known example of a WAN is the Internet.
metropolitan area networks, personal area networks etc.
1.1.4. Personal Area Network
1.1.1. Local Area Network A personal area network (PAN) is a network that is used for communication among
A local area network (LAN) is a network that is used for communication among computers and computer devices in close proximity of around a few meters within a
computer devices, usually within an office building or home. It enables the sharing of room. A PAN usually includes laptops, mobile phones, personal digital assistants,
resources such as files or hardware devices that may be needed by multiple users in digital cameras and headsets. It can be used for communication between the
an organization. A LAN is limited in size, spanning a few hundred meters, and not devices themselves, or for connection to a larger network such as the Internet. The

© 2014- BGS Molyko 27


Bilingual Grammar School Advanced Level Computer Science

most popular is the Wireless PAN (WPAN), a Bluetooth connection between two A MAC address is a built-in number (i.e. set by the manufacturer) consisting of 12
laptop computers or phones. hexadecimal digits that uniquely and permanently identifies the network adapter of
a computer. Examples of a MAC addresses are 00-14-22-DA-67-15 and 00-13-02-31-
1.2. Computer Network Components E8-BA.MAC address is also called the physical address. Under Windows, the MAC
All types of computer networks require special networking software and hardware to address of a computer can be displayed by typing ipconfig/all at a Command
allow different computers to communicate with each other. The most important prompt.
software component required for a network is the network operating system (NOS)
while there are many types of hardware devices which are either installed or 1.2.5. Repeater
connected to the computer terminals in order to construct a network. A repeater is a device used to expand the boundaries of a wired or wireless network.
With physical media, data transmissions can only span a limited distance before the
1.2.1. Network Operating System quality of the signal degrades. Repeaters are used to preserve signal integrity and
A network operating system is an operating system which includes networking extend the distance over which data can safely travel by regenerating the signals
features. It contains special functions, protocols and device drivers that enable the they receive. Active hubs are considered as repeaters (multiport repeaters).
computer to be connected to a network. NOS provide the ability to share resources
and the ability to manage a network name directory, security, and other 1.2.6. Bridge
housekeeping aspects of a network. A bridge, also called a layer 2 switch, is a device used to create a connection
Examples of network operating systems are Windows-NT, Windows-2000 server, between two separate computer networks or to divide one network into segments.
Windows server 3000, Novell Netware and Artisoft LANstatic. Creating multiple segments in a local network reduces the network traffic making
Some multi-purpose operating systems like Windows XP, Windows 7 and Mac OS 10, the network to be faster and more efficient. A bridge performs its segmenting
come with capabilities that enable them to be described as network operating function by examining the data packet and forwarding it to other physical segments
systems. only if necessary.

1.2.2. Network Interface/Adapter Card 1.2.7. Router


A network interface card (NIC) provides the physical interface (link) between the A router is a device that joins several networks together and is responsible for
computer and the communication medium. A NIC manages the communication and routing data from one network to another. It keeps track of the IP addresses of the
network protocol for the PC.It prepares data, sends data and controls the flow of computers on the networks connected to its network interface cards and directs
data. It plugs into the system board and provides ports for connection to the data packets appropriately. It is more powerful than a bridge because instead of just
network. A NIC is also called a LAN card or network adapter card. There are two choosing network segments based on previous traffic, a router can look up the best
kinds of NIC: wired NIC for wired networks and wireless NIC (WNIC) for wireless route for a packet to take. Routers can be computers with operating systems and
networks. A NIC may be designed as an Ethernet card, a Token Ring card, or an FDDI special network software, or they can be other dedicated devices built by network
card (but not all three). manufacturers. The Internet relies heavily on routers.

1.2.3. Hub 1.2.8. Modem


A hub is a device that works as central connecting point for multiple computers in a A modem (modulator/demodulator) is a device that encodes data for transmission
network. It has ports to which the computers in the network are connected. Data over a particular medium, such as telephone line, coaxial cable, fiber optics, or
sent to the hub is broadcasted to all the ports but, only the destination computer microwaves. It converts digital signals from a computer to analog signals or
receives it. There are three kinds of hubs: waveform for transmission over a medium (modulation) and converts analog signals
 Passive hubs which only split the transmission signal so it can be sent to all the from the medium to digital signals understandable by the computer(demodulation).
ports Common types of modems are:
 Active hubs (also called Multiport Repeaters) which regenerate data bits to  Dial-up Modem
maintain a strong signal over extended cable lengths  Cable Modem
 Intelligent hubs (also called Concentrators) usually have their own  DSL Modem
microprocessor chips and network operating systems. They can be managed  Sat modem
remotely on the network.
1.2.9. Multiplexer
1.2.4. Switch A multiplexer abbreviated MUX, is a device that takes input signals from different
A switch is used at the same place as a hub but the difference between the two is sources and transmits them over a single transmission line. This process is known as
that a switch has a switching table within it. A switching table stores the Media multiplexing. There are different types of multiplexing:
Access Control (MAC) address of every computer connected to the switch and sends  Frequency-division multiplexing (FDM), in which the carrier bandwidth is
the data only to the requested address, unlike the hub which broadcasts the data to divided into sub channels of different frequency widths, each carrying a signal
all the ports. Switches can therefore be considered as an advanced form of hubs. at the same time in parallel.

© 2014- BGS Molyko 28


Bilingual Grammar School Advanced Level Computer Science

 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 channel but every signal is coded differently.

1.2.10. Cables
Cables are used to link computers in a LAN. There are three types of cables
commonly used: a. Advantages
 Coaxial cable  Breakdown of a node does not affect the network
 Twisted pair cable  No disruption of the network when connecting or removing devices
 Fiber optic cable  It is easy to detect faults

1.2.11. Gateway b. Disadvantage


A gateway is a device that connects two dissimilar computer networks using direct  Failure of the central node affects the entire network
and systematic translation between protocols. A gateway translates outgoing  It is costly due to the amount of cables required to connect the devices
network traffic to the protocol needed by the destination network. The term gateway
is also sometimes loosely used to describe any device that acts as the entry or exit 1.3.3. Ring Topology
point for a network. In ring topology, all the nodes are connected in the form of a closed loop such that
each node is connected to two others. It uses an empty data packet called a token
1.3. Network Topologies and a special protocol called token ring. Packets travel around the ring in a
Network topology is the layout or arrangement of the components of a network. It clockwise direction. To transmit, a node requires an empty token.
refers to the way in which computers and cables are connected together to build a
network. Different types of topologies exist.
1.3.1. Bus Topology
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 that any transmission can be received by all
stations. All ends of the cable must be terminated, that is plugged into a device such
as a computer or terminator, to avoid signals from bouncing back.

Ring
topology
a. Advantage
 No collision as a station needs the token to transmit
Bus
a. Advantages  Each computer acts like a repeater so signals are not attenuated
topology
 Easy and inexpensive to set up as little cabling is required
 Easy to include additional stations without disrupting the network b. Disadvantage
 Failure of one node does not affect network  If a node in the network fails, the entire network fails
 Network is disrupted when additional stations are added
b. Disadvantages
 High rate of data collision 1.4. Network Technologies
 Fails if there is any damage to the bus
 Any break in the bus is difficult to identify 1.4.1. Ethernet Network
Ethernet (IEEE 802.3 standard) is the most common and widely used technology to
1.3.2. Star Topology establish a local area network. An Ethernet network is formed by physically
In a star topology, all the computers are connected to a central device which could connecting the individual computer units to each other in a bus topology or a star
be a computer, a hub or a switch. Any communications between computers in this topology. Ethernet’s media access policy is CSMA/CD (Carrier Sense Multiple Access
topology must pass through the central node. As such, the central node controls all with Collision Detection).
the activities of the network.  CS: means that a station listens to (senses) the medium and transmits only if
medium is idle

© 2014- BGS Molyko 29


Star topology
Bilingual Grammar School Advanced Level Computer Science

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

a. Bluetooth
Remark A hybrid network combines client/server and peer-to-peer architectures.
Bluetooth is a low power, short-range wireless technology largely used to
It is the most commonly used network architecture.
interconnect computing devices into a personal area network. It is based on IEEE
standard 802.15 which gives specifications for Wireless Personal Area Network
1.6. Benefits and Limitations Of Computer Networks
(WPAN).
1.6.1. Benefits
 Sharing devices such as printers saves money.
b. Wi-Fi
 Site (software) licenses are likely to be cheaper than buying several standalone
Wi-Fi stands for Wireless Fidelity. It is based on a set of wireless networking
licenses.
technologies known as 802.11. These include 802.11b, 802.11a, 802.11g and
 Files can easily be shared between users.
802.11n. The range of Wi-Fi network transmission is about 30-40m indoors and up to
 Network users can communicate by email and instant messaging.
about 100m outdoors.
 Data is easy to backup as all the data is stored on the file server.
The table below shows the different 802.11 standards for wireless networking.
 Organizations can organize videoconferences ( videoconferencing)
 Employees can work from home (telecommuting)
Specificatio Popular Frequency Speed Compatible
n name with
1.6.2. Limitations
802.11a Wireless-A 5 GHz 54 Mbps
 Purchasing the network cabling and file servers can be expensive.
802.11b Wireless-B 2.4 GHz 11 Mbps Wireless-A

© 2014- BGS Molyko 30


Bilingual Grammar School Advanced Level Computer Science

 Managing a large network is complicated. It requires training and a network


manager usually needs to be employed.
 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.
 Viruses can easily spread to other computers throughout the network, if one
computer is infected.. 2.1.2. Digital Signals
 There is a danger of hacking, particularly with wide area networks. Security A digital signal is one in which information is represented as a sequence of binary
procedures are needed to prevent such abuse, eg a firewall. values 0 and 1.These two values represent two conditions, on or off, corresponding
to two known levels of voltage or current.
2. Data Communication Digital signals do not continuously vary as analogue signals. Signals are transmitted
Data communication refers to the exchange of data between two devices via some within the computer as digital signals. Systems that use digital technology are
form of communication channel. In data communication the following basic terms known as baseband systems.
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.


 Data Source: creates data for transmission Digital signal
 Transmitter: encodes data for transmission
 Communication channel: connecting medium between communicating 2.2. Broadband and Baseband Transmissions
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
 Destination: the final destination of the transmission any given time. 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
Example: John calls Peter on phone. communication is bi-directional, which means that the same channel can be used to
The data source is John, the transmitter is John’s phone, the communication channel send and receive signals. In Baseband, frequency-division multiplexing is not
is the telephone cable or microwave, the receiver is Peter’s phone and the possible.
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
Data is transmitted from one point to another by means of electrical signals that frequency channels. In a broadband system, data is sent in the form of an analog
may be in analogue or digital form. signal where each transmission is assigned a portion of the bandwidth. Broadband
communication is unidirectional, so in order to send and receive, two pathways are
2.1.1. Analogue Signals needed. This can be accomplished either by assigning a frequency for sending and
An analog signal is one in which information is represented as a continuous variation assigning a frequency for receiving along the same cable or by using two cables,
of some physical property or quantity. Analog signals are continuous waves that one for sending and one for receiving.
carry information by varying the frequency or amplitude of the wave.
 When the amplitude of the signal is varied the technique is called amplitude 2.3. Transmission Modes and Techniques
modulation (AM) Transmission modes simply refer to the direction of flow of information between two
 When the frequency of the signals is varied, the technique is called frequency communicating devices. It could be simplex, half duplex or full duplex.
modulation (FM).
Human speech is an example of an analog signal. Telephone lines use analog signals 2.3.1. Simplex
because they were originally designed for speech. In simplex mode, signals are transmitted in only one direction all the time. The flow
of information is unidirectional from transmitter to receiver always. Examples are
television broadcasting, computer to the printer connection and CPU to monitor
communication.

A B
© 2014- BGS Molyko 31
Analogue signal
Bilingual Grammar School Advanced Level Computer Science

transmitted; only data bits and no extra control bits. For this reason it is the choice
for network communications links.
2.3.2. Half Duplex
In half duplex mode, signals can be transmitted in both directions but only one way 2.4. Communication Switching Techniques
at a time. The flow of information is bidirectional but information can only be sent if Long distance transmission is done over a network of switched nodes. Data is routed
it is not being received. It is suitable for data transmission between a computer and by being switched from one node to another. Three switching techniques exist:
dumb terminals. An example is the police radio (walkie-talkie). packet switching, circuit switching and message switching.

A B 2.4.1. Packet Switching


Packet switching is a switching method in which the message to be transmitted is
2.3.3. Full Duplex broken into small data packets and sent over the network. Each packet contains a
In full duplex mode, signals can be transmitted in both directions simultaneously. portion of data and some control information. The packets may take different routes
The communicating devices can transmit at the same time. The flow of information to arrive their destination and they may arrive in any other. On arrival, they are put
is bidirectional. It is suitable for interactive systems. An example is the telephone. 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
A B sequence for reassembly at the destination. One packet contains information on how
many packets should be arriving. If a packet fails to arrive, the destination computer
2.3.4. Parallel Transmission sends a message to the sender’s computer asking it to send the missing packet
Parallel transmission is the method of transferring several bits at the same time over again. This method is suitable for transmission of data.
separate channels. For example, eight separate channels will be required if a block
of eight bits is to be transmitted in parallel. Parallel transmission is fast but it is 2.4.2. Circuit Switching
suited only for short distances as cabling for long distances will be expensive. It is Circuit switching is a switching method in which a dedicated communication path in
mainly used for connections within the computer and for connecting the computer to physical form between two stations within a network is established, maintained and
the printer. terminated for each communication session. This channel remains open throughout
the communication process and cannot be used by anyone else. It has basically
2.3.5. Serial Transmissions three phases: circuit establishment, data transfer and circuit disconnect. The
Serial transmission is the method of transferring data one bit at a time through the message is sent without being broken up, so it is received in the order it was sent.
same channel. If a block of 8 bits is to be transmitted in series, the bits will be This method was designed for voice transmissions. Telephone networks use circuit
transmitted one after the other on the same channel. Serial transmission can be switching for transmission of phone calls.
asynchronous or synchronous.
2.5. Transmission Media
a. Asynchronous Serial Transmission A transmission medium is the physical pathway that connects computers and other
Asynchronous transmission describes the process where transmitted data is devices on a network. Each transmission medium requires specialized network
encoded with start and stop bits, specifying respectively the beginning and end of hardware that is compatible with that medium, and most networks need to use a
each character. Data is sent character by character with each character preceded by combination of transmission media types selected based on the network's needs.
a start bit and a stop bit is added to the end. Other control bits like the parity bit are There are two categories of transmission media: guided and unguided media.
added to the group before the stop bit and small gabs are inserted to distinguish
each group. 2.5.1. Guided Media
Guided media are the physical links through which signals are confined to narrow
b. Synchronous Serial Transmission path. They are made up of an internal conductor bounded by jacket material. They
Synchronous transmission describes a continuous and consistent timed transfer of are also called bounded or conducted media. Three common types of guided media
data blocks. Data is sent as one long bit stream or block of data without start or stop are coaxial cable, twisted pair cable and fiber optical cable.
bits and with no gabs. Upon reception, the receiver counts the bits and reconstructs
bytes. It is essential that the same timing is maintained by both sender and receiver a. Coaxial Cable
as there are no start and stop bits and no gaps. Another channel is therefore used to Coaxial cable consists of an inner core and an outer flexible braided shield, both of
transfer timing signals to keep the both parties synchronized. Accuracy is conductive material separated by an insulator. The braided shield prevents the cable
dependent on the receiver keeping an accurate count of the bits as they arrive. from picking up or emitting electrical noise. There are two types of coaxial cable:
 thinnet and
Serial transmission is slower than parallel transmission but it is suited for long  thicknet.
distances. It is cheaper as only one transmission line is required. Synchronous
transmission is faster than asynchronous transmission because fewer bits have to be

© 2014- BGS Molyko 32


Coaxial cable
Bilingual Grammar School Advanced Level Computer Science

To connect coaxial cable to devices, we need coaxial connectors. The most common
type of connectors used today is the Bayone-Neill-Concelman, or BNC connector.

b. Twisted Pair Cable


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

a. Infrared
Twisted pair cable Infrared uses transmitters/receivers (transceivers) that modulate non-coherent
infrared light. Infrared signals do not penetrate walls as such transceivers must be
 Unshielded Twisted Pair within line-of-sight either directly or via reflection. Line of sight is a type of
UTP cables consist of 2 or 4 pairs of twisted cable. Cable with 2 pair use RJ-11 propagation that can transmit and receive data only where transmit and receive
connector and 4 pair cable use RJ-45 connector. RJ stands for registered jack. There stations are in view of each other without any sort of an obstacle between them.
are five levels of UTP:
b. Radio waves
Category 1: These are used in telephone lines and low speed data cable. Radio wave systems transmit signals by modulation of electromagnetic waves with
Category 2: These cables can support up to 4 mps implementation. frequencies below that of visible light. Radio waves carry information by
Category 3: These cable supports up to 16 mps and are mostly used in 10 mps. systematically changing some property of the radiated waves such as amplitude (AM
Category 4: These are used for large distance and high speed. It can support radio), frequency (FM radio) and phase. Radio waves are omnidirectional. This
20mps. means that signals spread out in all directions and can be received by many
Category 5: This is the highest rating for UTP cable and can support up to 100mps. antennas.

UTP can be connected as straight through or crossover. A straight-thru cable has c. Microwaves
identical ends. A crossover cable has different ends. Microwaves are electromagnetic radiations beyond the frequency range of radio and
television. There are two types of microwave systems: terrestrial microwave systems
c. Fiber Optic Cable and satellite systems.
Fiber optic cables use optical fibers that carry digital data signals in the form of
modulated light pulses. An optic fiber consists of an extremely thin cylinder of glass,  Terrestrial microwave systems are land-based. Microwaves being line-of-sight
called the core, surrounded by a concentric layer of glass, known as the cladding. and traveling in a straight line, the earth’s curvature poses a problem to long
Each cable has two fibers - one to transmit and one to receive. distance microwave transmissions. As such, long distance transmissions require
There are two types of optic fibers: directional antennas (repeaters)to be used at intervals of 25 to 30 kilometers
 A single mode fiber (SMF) uses a single ray of light to carry transmissions between the transmitting and receiving end.
over long distances.
 A multi-mode fiber (MMF) uses multiple rays of light simultaneously with each  Satellite systems use communication satellites to solve the problem posed by
ray of light running at a different reflection angle to carry transmissions over the earth’s curvature to terrestrial microwave systems. A communication satellite is
short distances. a microwave relay station placed in outer space. A microwave signal is transmitted
from earth to the satellite which amplifies the signal and sends it back to earth. The

© 2014- BGS Molyko 33


Bilingual Grammar School Advanced Level Computer Science

earth station transmits the signal to the satellite on an up-link, on one frequency and
the satellite repeats those signals on a down link which is on another frequency. i) 01101010 ii) 11000101 iii) 10011100

2.6.2. Checksum
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 checksum or hash sum may be computed
according to the number of set or unset bits in the message. On reception, the
receiver applies the same checksum function/algorithm to the message. If the
checksum obtained matches the one sent, the transmission is considered to be
successful and error-free.

2.6.3. Cyclic Redundancy Check


 Advantages of microwave systems A CRC is an error-detection code in which each segment of the original message is
o No cables needed combined with additional bits to make a binary number that is divisible by some
o Multiple channels available previously chosen divisor.
o Wide bandwidth  k is the length of the message we want to send, i.e., the number of information
bits.
 Disadvantages
 n is the total length of the message we will end up sending the information
o Line-of-sight will be disrupted if any obstacle, such as new buildings, are in
bits followed by the check bits. Peterson and Brown call this a code polynomial.
the way
o Signal absorption by the atmosphere. Microwaves suffer from attenuation
 n-kis the number of check bits. It is also the degree of the generating
polynomial. The basic (mathematical) idea is that we're going to pick the n-k
due to atmospheric conditions.
check digits in such a way that the code polynomial is divisible by the
o Towers are expensive to build
generating polynomial. Then we send the data, and at the other end we look to
see whether it's still divisible by the generating polynomial; if it's not then we
2.6. Transmission Checks
know we have an error, if it is, we hope there was no error.
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 thing. Because of these transmission errors, 2.7. Peripheral Device Control
network protocols very often use error-detection codes. 2.7.1. Buffering
An error detection code is a binary code that detects digital errors during A buffer is an area of memory used to temporarily store data while it is being moved
transmissions. The detected errors can be corrected, but can prompt the data to be from one place to another. Buffers are used to compensate for differences in rate of
retransmitted. Examples of error-detection codes include parity checking, flow of data or time of occurrence of events, when transferring data from one device
checksums and cyclic redundancy checks. to another. Routers use buffers to route data packets on the Internet. When a packet
is sent from one router to another via one or more intermediate routers, the packet
2.6.1. Parity Checking is received at each intermediate router in its entirety, stored there until the required
Parity checking refers to the process of using a parity bit to check that data has output line is free, then the packet is forwarded.
been transmitted accurately. A parity bit is an extra bit transmitted with a data unit
that will be used to check its integrity. There are two types of parity: odd parity and 2.7.2. Interrupt
even parity. An interrupt is a signal to the processor emitted by hardware or software indicating
 In odd parity, the parity bit is added such that the total number of bits at 1, in an event that needs immediate attention. An interrupt alerts the processor of a high-
the data unit, is an odd number. priority condition requiring the interruption of the current task the processor is
 In even parity, the parity bit is added so that the total number of 1s is an even executing. Interrupts are used to handle such events as data receipt from a modem
number. or network, or a key press or mouse movement.

Example: What are the parity bits for the following data units in odd parity? 2.7.3. Polling
Polling is the process by which the central computer or communications controller in
a network, "polls" or asks each device in the network if it has a message to send and
i) 11101100 ii) 00100101 iii) 11010101 then allows each in turn to transmit data. Access and control of star network
typically is maintained by a polling system.
Example 2: What are the parity bits for the following data units in even parity?

© 2014- BGS Molyko 34


Bilingual Grammar School Advanced Level Computer Science

2.7.4. Handshaking These layers can be recalled using the


Handshaking is the process by which two devices initiate communications. It begins following mnemonics: All People Seem
when one device sends a message to another device indicating that it wants to To Need Data Processing. (Layers 7 -
establish a communications channel. The two devices then send several messages 1)
back and forth that enable them to agree on a communications protocol.

2.8. Communication Protocols


For proper communication in a network, different entities must speak the same Layer 7: Application
language. There must be mutually acceptable conventions and rules about the It provides network services directly to the user’s applications such as a web
content, timing and underlying mechanisms. These conventions and associated browser or e-mail client. This layer is said to be “closest to the user”. Examples of
rules are referred as protocols. protocols that operate at this layer are: TELNET, HTTP, FTP, SMTP and POP.

Definition: A protocol is a set of rules that govern how devices on a network Layer 6: Presentation
communicate. The Presentation layer represents the data in a particular format to the Application
layer. It defines encryption, compression, conversion and other coding functions.
Protocols allow different computers from different vendors and with different Examples of specifications defined at this layer are: GIF, JPEG, MPEG, MIME and
operating characteristics to ‘speak the same language’. They set the message ASCII.
formats and procedures that allow machines and application programs to exchange
information. The same protocols must be followed by each machine involved in the Layer 5: Session
communication in order for the receiving host to be able to understand the It establishes, maintains and terminates end-to-end connections (session) between
message. A protocol may be physical or logical. two applications on two network nodes. It controls the dialogue between the source
and destination nodes, which node can send when and for how long. Examples of
2.8.1. Physical Protocols protocols that operate on this layer are: RPC, NETBIOS and X.225
Physical protocols are concerned with how a device connects to a medium. They
ensure that a device connected to a medium can transmit through the medium. Layer 4: Transport
They make sure that the layout of pins on the connectors is the same and that It is responsible for end-to-end delivery of entire messages. It allows data to be
devices are correctly connected and configured. Few examples of physical protocols transferred reliably and uses sequencing to guarantee that it will be delivered in the
are 802.11 for Wi-Fi connections and DSL for broadband. same order it was sent. It also provides services such as error checking and flow
control. Examples of protocols at this layer are: TCP, UDP, NETBEUI and SPX.
2.8.2. Logical Protocols
Logical protocols are concerned with data handling. They ensure that data are in the Layer 3: Network
right format for the application, the bit rates match at both ends, and the same error It is responsible for path determination, routing, and the delivery of packets across
correction is used. Examples of logical protocols are TCP/IP, HTTP, POP3, FTP, SMTP internetworks. It is also responsible for addressing (also known as logical addressing)
and WAP. for example IP addressing. Examples of protocols at this layer are: IP, IPX and ICMP.
Examples of devices that operate at this level are Layer-3 switches and routers.
2.8.3. The OSI Reference Model WAPs (wireless access points) with built-in routing capabilities also act at this layer.
The Open Systems Interconnection (OSI) reference model or more commonly the OSI
model is an ISO standard that defines how network communications take place by Layer 2: Data Link
providing a framework for standardization. The OSI model divides network It is responsible for reassembling bits taken off the wire by the physical layer to
7
communications Application
into seven Layer
layers. Each layer is responsible for carrying out specific frames and makes sure they are in the correct order and requests retransmission of
functions when transmitting data on the network. The table below shows the layered frames in case an error occurs. It provides error checking by adding CRC to the
6 Presentation Layer
architecture of the OSI reference model. frame. Examples of protocols at this layer are: Ethernet, Token Ring, PPP and ISDN.
5 Session Layer Examples of devices that operate at this layer are: switches, bridges, NICs and WAPs
(Wireless Access Points).
4 Transport Layer
Layer 1: Physical
3 Network Layer This layer communicates directly with the communication medium. It is responsible
for activating, maintaining and deactivating the physical link. It defines electrical
2 Data Link Layer and optical signaling, voltage levels, data transmission rates, as well as mechanical
specifications such as cable lengths, and connectors, the amount of pins and their
1 Physical Layer

© 2014- BGS
OSIMolyko
Reference Model 35
Bilingual Grammar School Advanced Level Computer Science

functions. Examples of devices that operate at this layer are: hubs, repeaters, and 3.2.2. Digital Subscriber Line
NICs. 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
These layers can be recalled using the following mnemonics: All People Seem To different types of DSL: asynchronous DSL (ADSL), synchronous DSL (SDSL), High bit-
Need Data Processing. (Layers 7 - 1) rate DSL (HDSL), Rate Adaptive DSL (RADSL) and ISDN DSL (IDSL).
 ADSL allows the telephone wires to be used for analog POTS system and digital
3. The Internet data transfer simultaneously. The download speed (downstream) for ADSL is
3.1. Brief History faster than the upload speed (upstream).
Many years ago, the military of the United States of America desired to interconnect  SDSL cannot share the physical medium with standard telephone
or link their computers in order to better understand and manage information and communications and has a download speed equal to the upload speed.
communication with respect to enemy attacks in times of crisis. In the year 1969 the A DSL connection requires a transceiver (DSL modem) which allows an Ethernet UTP
Department of Defense (DoD) then developed an experimental network called the or a USB connection directly to a PC, or to a hub, router, or switch to provide Internet
Advanced Research Project Agency Network (ARPANet) access to an entire network. The transceiver can be integrated into a router or
In the year 1980, the National Science Foundation of the United States of America switch.
then developed the technology of ARPANet to produce the National Science
Foundation Network (NSFNet) which now enabled universities and other school 3.2.3. Broadband Cable
establishments in the USA to be interconnected. After a great deal of work, a TV channels only take up 6MHz of cable bandwidth each, which usually leaves
network which enabled the transfer of large amounts of information at very high several hundred MHz available. This additional space on cable is used for high-
speed which is today called the Internet was developed. speed Internet connection. Information from the Internet travels through the cable
The Internet can be defined as a worldwide/global system of interconnected as a single TV channel. Just as with DSL, cable Internet requires a special transceiver
computer networks. It is the network of networks in which users can view (cable modem) which allows information to be sent and received on frequencies not
information on the World Wide Web, exchange electronic mail, participate in used by TV channels. The cable modem provides one or more LAN interfaces,
electronic discussion forums (newsgroups), send files from any computer to any usually Ethernet or USB which connect directly to a client or a device such as a hub,
other and even use each other’s computers directly if they have appropriate switch, or wireless router to allow additional clients or entire networks to use the
passwords. Another name for the Internet is information superhighway. same connection. The cable modem is also equipped with connections for TV and
3.2. ISP and Internet Access radio.
An Internet service provider (ISP), also sometimes referred to as an Internet access
provider (IAP), is a company that offers Internet access to individuals and 3.2.4. Wireless Internet Access
organizations. The ISP connects to its customers using a data transmission Wireless Internet access or wireless broadband is particularly useful for mobile
technology appropriate for delivering Internet Protocol Paradigm, such as dial-up, users. With handheld devices becoming more advanced and increasingly popular,
digital subscriber line (DSL), cable modem, wireless or dedicated high-speed wireless access is becoming one of the major ways of connecting to the Internet.
interconnects. This method provides an “always-on connection” which can be accessed from
ISPs may provide Internet e-mail accounts to users which allow them to anywhere as long as you are geographically within network coverage. Wireless
communicate with one another by sending and receiving electronic messages Internet access includes deploying Wi-Fi hotspots for accessing the Internet.
through their ISP's servers. They may also provide services such as remotely storing Technologies such as GPRS and UMTS (Universal Mobile Telecommunication System)
data files on behalf of their customers, as well as other services unique to each allow Smart phones and other handhelds with Internet capabilities to access the
particular ISP. Internet using existing cell phone networks.
Different methods exist for connection to the Internet.
3.2.5. Internet over Satellite
3.2.1. Dial-Up Connection Internet
Application
overLayer
satellite (IoS) allows a user to access the Internet via a satellite that
HTTP FTP SMTP DNS RIP
A dial-up connection is a connection that is established by dialing a telephone orbits the earth. A satellite placed
Application at a static point above the earth's surface,
Layer
number through a modem. A dial-up connection uses a dial-up modem to transmit Presentation Layer
communicates with the ISP’s dish giving the user access to the internet.
digital information over the Plain Old Telephone System (POTS). POTS refers to the
Session Transport Layer
LayerThe TCP/IP
standard telephone network designed for analog transmission of voice over copper 3.3. Model TCP UDP
(Host-to-host)
wire. This type of connection offers relatively slow transfer rates and is established The Internet uses a collection of protocols known as the TCP/IP protocol suite. It is
Transport Layer
on demand. This method has long been the most widely used method to connect to called TCP/IP after two of its most prominent protocols, but there are other protocols
the Internet but it has been replaced by high-speed broadband and wireless as Network
well. TheLayer
TCP/IP model is based
Internet on a four-layer model for IP
Layer networking.
IGMP The layers
ICMP
ARP
connections. from top to bottom are application layer, transport layer, Internet layer and network
access layer.Layer
Data Link Below is a comparison
Network Accessbetween
Layer the TCP/IP model and the OSI model.
Ethernet Token Ring Frame Relay ATM

Physical Layer

© 2014- BGS Molyko 36


OSI Model TCP/IP Model
TCP/IP Protocol Suite
Bilingual Grammar School Advanced Level Computer Science

 An IPv6 has eight sets of numbers separated by colons such as


3ffe:1900:4545:3:200:f8ff:fe21:67cf.

IP addresses are assigned manually by an administrator or automatically by DHCP


(Dynamic Host Control Protocol) or APIPA (Automatic Private IP Addressing). An IP
address is also known as a logical address.

b. Address Resolution Protocol


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.

Assignment: Differentiate between an IP address and a MAC address.

c. Internet Control Message Protocol


During a transmission, a message travels down all network layers at the source ICMP is responsible for diagnostics and error reporting. It is used to send control and
machine. Before sending a message to the next layer, each layer places it in an error messages to computers and servers.
envelope of overhead information related to that layer. This process is called
encapsulation. Encapsulation at each layer produces a data unit called protocol data d. Internet Group Management Protocol
unit (PDU). IGMP is responsible for management of group multicast.
At the receiving end, the message travels up through the network layers, each layer
removing the envelopes added when the message was sent. So, upon its receipt, the 3.3.3. Transport Layer
message is in its original state. The transport layer is responsible for sequencing and transmission of packets,
acknowledgment of receipts, recovery of packets and flow control. In essence, it
3.3.1. Network Access Layer engages in host-to-host transportation of data packets and the delivery of them to
This layer is responsible for sending and receiving TCP/IP packets on the network the application layer. A transport layer PDU is called segment.
medium (Physical/Data Link). The network Access layer PDU called frame, is Core protocols at this layer are TCP and UDP.
obtained by adding a header and a trailer to the PDU from the Internet layer.
Applicable LAN technologies: Ethernet, Token Ring, FDDI etc. a. Transmission Control Protocol
Applicable WAN technologies: X.25 (old), Frame Relay, ATM etc. TCP is a connection-oriented reliable protocol used in the accurate transmission of
large amounts of data. Data packets are verified using checksums and retransmitted
3.3.2. Internet Layer if they are missing or corrupted. The application plays no part in validating the
This layer is responsible for packaging, addressing and routing of packets. The PDU transfer.
at this layer is called datagram or packet.
Core Internet layer protocols are: IP, ARP, ICMP and IGMP. 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
a. Internet Protocol actually arrive at the destination, nor whether they were corrupted in transit. It is up
Internet Protocol (IP) specifies the format of packets and the addressing scheme. All to the application to determine these factors and request retransmissions. UDP is
computer devices (desktops, laptops, PDAs, phones, tablets) connected to the faster compared to TCP.
Internet, have IP addresses by which they are identified.
3.3.4. Application Layer
Definition: An IP address is a unique identifying number given to every single The application layer provides user applications with the ability to access the
computer on a TCP/IP network. services of the other layers. Some protocols of this layer are HTTP, FTP, POP, SMTP,
Telnet, IMAP and WAP.
Two versions of IP addresses are available: IPv4 that uses 32 bits and IPv6 that uses
128 bits. a. Hypertext Transfer Protocol
 An IPv4 is made up of four sets of numbers separated by dots such as HTTP is a standard method of publishing information as hypertext in HTML format on
123.23.168.22. This notation is known as dotted decimal notation. Each of the the Internet. It provides the ability to supply web pages between a browser and the
four numbers separated by dots can be any number from 0 to 255, making server. HTTPS is a secure version of HTTP used for accessing secure web servers,
for a total of 4.3 billion potential IPv4 addresses (i.e. 255×255×255×255). whereby all data transferred are encrypted.

© 2014- BGS Molyko 37


Bilingual Grammar School Advanced Level Computer Science

b. File Transfer Protocol


FTP is a standard for transferring files between a server and a client on a TCP/IP
network. It provides the ability to upload and download files between hosts on the
network.

c. Simple Mail Transfer Protocol


SMTP is used for sending e-mails between servers on the Internet and other TCP/IP Ports are usually combined with IP addresses to form a socket. For example
networks. It governs the transmission of mail messages and attachments. SMTP is 127.102.10.0:80.
used in the case of outgoing messages.
3.5. Internet Services
d. Post Office Protocol 3.5.1. The World Wide Web
POP is a standard protocol for delivering e-mails to personal computers. There are The World Wide Web (WWW) is a system of interconnected hypertext documents
different versions of the post office protocol indicated by POPn where n = 1, 2, 3 or4. that can be accessed via the Internet. Documents are connected to other documents
by hypertext links, enabling the user to search for information by moving from one
e. Telnet document to another. It consists of a large number of web servers that host
Telnet is a protocol that allows a computer on the network to be accessed remotely. websites. A website consists of a number of web pages connected by hypertext
It provides the ability to login into a remote host and administer the machine. Using links. A web page is a text file that contains information stored using a structured
Telnet a computer can be used as a terminal on another. language called HTML (Hypertext Markup Language).
A website can be accessed by typing its address or URL (Uniform/Universal Resource
f. Wireless Application Protocol Locator) into the address bar of a web browser. An example of a URL is
WAP is a protocol which runs on mobile phones and provides a universal open http://www.crtv.cmwhere http is the protocol used and www.crtv.cm, the domain
standard for bringing Internet content to mobile phones and other wireless devices. name (address) of the site.

Assignment: Give the full meaning of the following protocols and state their Example 1: http://www.bgsmolyko.edu/Ls3,4/ict796/intenet.pdf
functions.  http is the protocol used (hypertext transfer protocol)
i) IMAP (ii) RIP (iii) DNS  www.bgsmolyko.edu is the domain name (the machine at BGS Molyko that
hosts the website)
3.4. TCP/IP Ports  Ls3,4/ict796/internet.pdf is the path of the document (resource) on the host
A computer has a single physical connection to the network. All data destined for a computer. Ls3,4 is the folder, ict796 is the subfolder and internet.pdf is the
particular computer arrives through that connection. However, the data may be file(resource).
intended for different applications running on the computer. To identify the
application for which the data is intended, TCP requires port numbers on the host Example 2: www.minsup.gov.cm
and destination for communication.  gov is the top level domain which specifies that the URL is for a government
institution.
Definition: A communication port is a number (16-bits) that identifies an  cm specifies the country in which the URL is hosted or the country in which the
application on the Internet or TCP/IP network. institution is found.

Popular Internet application protocols are associated with well-known ports assigned Assignment: What is a home page?
by the Internet Assigned Number Authority (IANA). Sample TCP port numbers are:
a. Domain Name System
A domain name system (DNS) is a service which performs the function of turning
human-understandable domain names into IP addresses.
Port number Protocol

20 FTP data channel b. Web Browser


A web browser (or simply browser) is a computer program that enables a user to
21 FTP control channel read hypertext in files or on the World Wide Web. Popular browsers include Mozilla
Firefox, Microsoft Internet Explorer, Opera Mini and Netscape.
23 Telnet

25 SMTP c. Search Engine

80 HTTP
© 2014- BGS Molyko 38
110 POP
Bilingual Grammar School Advanced Level Computer Science

A search engine is a computer program that searches for specific words on the World a. Blogs
Wide Web and returns a list of documents in which they were found. Examples of A blog (web log) is a chronological, journal-style website which its author (or
search engines include Google and yahoo. "blogger") maintains like an online diary, with regular entries of commentary,
descriptions of events, or other material such as graphics or video. Many blogs
3.5.2. Electronic Mail provide commentary or news on a particular subject; others function as more
Electronic mail or e-mail (email) is a means of sending messages, text, and personal online diaries. They also provide the readers with the ability to leave
computer files between computers via the Internet. To send and receive e-mails, you comments in an interactive format.
need an Internet connection and an e-mail account which can be created within a
webmail service such as Yahoo, Hotmail or Gmail. When you create an e-mail b. Social Networking Sites
account, you are given a unique email address that gives you access to your mail Social networking sites are websites that allow user to build personalized
box. An email address is made up of two parts separated by the symbol @ communities to socialize with. Common features include a customizable profile, the
pronounced “at”. For example [email protected]. ability to add other users as friends, the ease of sharing pictures, music, text, and
In the above address, links, and built-in chat and mail features. Examples of social networking sites are
 bgsmolyko is the user ID, user name or login Facebook, Twitter and Instagram.
 yahoo.com is the domain name. The domain specifies the mail server
(computer) on which the mail box is located. c. Wikis
Wikis are websites that allow visitors to easily add, remove and edit content, hence
The part of the domain name after the dot is called top-level domain, and specifies enabling the collaborative authorship of comprehensive documents. The best
the type of organization or the country the host server is located. Some common example of a wiki is the multi-lingual, web-based encyclopedia Wikipedia, and which
top-level domains are: currently includes over two million articles.
o .com - for commercial enterprises
o .edu - for educational institutions and universities d. Viral Video Sites
o .gov - for United States government agencies A viral video is a video that is distributed by sharing. Viral video sites are websites
o .net - for organizations such as Internet Service Providers that allow anybody to post videos online. Whilst it is now not difficult to put a video
o .org - for non-commercial organizations on any website, the 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
3.5.3. Instant Messaging them. Examples are YouTube and Kaltura.
Instant messaging is a live (or real time) communication which occurs when brief
text messages are exchanged instantly over the Internet. Instant Messaging requires 3.5.6. Electronic Commerce
that both users be on-line at the same time. Common IM applications are AOL E-commerce refers to the buying and selling on the Internet. Different models of e-
Instant Messenger, Yahoo Messenger and Microsoft MSN messaging. commerce exists: business-to-business, business-to-consumer, business-to-
government and m-commerce
3.5.4. Internet Telephony
Internet telephony or voice over IP (VoIP) is the transmission of voice telephone a. Business-to-Consumer
conversations through the Internet or IP networks. It allows users to have voice-talk B2C model sells goods or services to the consumer, generally using online catalog
with others through the Internet. The telephone calls are digitized and transmitted and shopping cart transaction systems. For example, an online pharmacy giving
through the Internet. Internet telephone services can be mainly categorized into net- free medical consultation and selling medicines to patients is following a B2C
to-net and net-to-phone telephony. model. Amazon is an example of one of the first and still one of the most successful
In net-to-net telephony, both caller and receiver must be online. When both are B2C e-commerce companies.
online, one dials the other person’s phone number. If they accept the call, then voice
communication is established. b. Business-to-Business
In net-to-phone, only one person has to be online. This person dials the other B2B describes commerce transactions between businesses, such as between a
person’s phone number and the latter receives a ring on their phone. Yahoo manufacturer and a wholesaler, or between a wholesaler and a retailer. In this form,
messenger and Skype provide services for both types. the buyers and sellers are both business entities and do not involve an individual
consumer.
3.5.5. Interpersonal Computing
Interpersonal computing refers to person-to-person interactions facilitated by c. Business-to-Government
websites that enable collaborative content creation, sharing and manipulation. B2G is a derivative of B2B marketing. B2G sites provide a platform for businesses to
Interpersonal computing involves: blogs, social networks, wikis and viral video sites. bid on government opportunities which are presented as solicitations requests for
proposal (RFPs) to tender.

© 2014- BGS Molyko 39


Bilingual Grammar School Advanced Level Computer Science

d. M-Commerce o Some goods do not arrive after they are paid for.
M-commerce refers to the use of mobile devices for conducting transactions. The o It lacks human interaction as one only sees pictures and some text
mobile device holders can contact each other and can conduct the business. Even descriptions.
the web design and development companies optimize the websites to be viewed
correctly on mobile devices. 3.5.7. Online Banking
Online banking (Internet banking) is simply the use of the Internet to perform
Some e-commerce websites are: www.bruneiair.com for airline ticket bookings, banking operations like opening an account, accessing account information,
www.amazon.com for sales of books and magazines, www.brumedia.com/shop for transferring funds, getting a bank statement etc. In an Internet banking system, the
sales of computers, shirts, and cameras bank has a centralized database that is web-enabled. All the services that the bank
has permitted on the Internet are displayed in a menu. Any service can be selected
 Some advantages of setting up an e-commerce website are: and further interaction is dictated by the nature of service.
o Products can be sold to local customers and those from abroad.
o It is accessible 24 hours each day. 3.6. Intranet and Extranet
o It needs a small number of staff to run. An intranet is a private network that is set up using the same technology and
o It does not need huge office space. protocols as the Internet but is restricted to users inside an organization. It provides
o Products can be sold at cheap prices similar services within an organization to those provided by the Internet without
necessarily being connected to the Internet. An intranet can be seen as a private
 Some disadvantages of e-commerce are: version of the Internet. To access an intranet, some form of user authentication is
o Credit card fraud - hackers are able to steal credit card numbers on usually required. External access to an intranet is not always provided.
computers. An extranet is an interconnection of two or more intranets. It allows an organization
o Certain websites spy or track the buying habits of their customers. to share information with other organizations using Internet standards but with
security features preventing access to others.
CHAPTER 4: INFORMATION SYSTEMS Information=Data+Context
Introduction
A system is an integrated set of regularly interacting or interdependent components 1.1. Sources of Data
created to accomplish a defined objective, with defined and maintained relationships a. Questionnaire
among its components. Basically, there are three major units in every system A questionnaire is a set of questions used for collecting data from people. A
namely input, processing and output. The objective of a system demands that some questionnaire may be in paper format or online.
output be produced as a result of processing the suitable inputs.
An information system can therefore be seen as a set of interrelated components b. Interview
that collect data, process the data to produce information. An interview is a meeting during which somebody is asked questions. Interviews
allow you to collect a greater depth of data and understanding from people than is
1. Data and Information possible by just using a questionnaire.
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 c. Observation
computer system. When data has been processed it gives information. In observation, the data gatherer observes what is happening during a process or
Information is data that has been processed. The processing gives it meaning and a event and produces some kind of data file as a result
context. Information can also be defined as the useful knowledge derived from facts
placed in the right context with the purpose of reducing uncertainty. d. Data logging
For example, the number 12.5 is data because we do not know why or in what Data logging is an automated method of gathering data by using sensors.
context it is being used. However, if the number appears on a student’s report card
to show that they have an average of 12.5, then this data has changed into e. Document review
information, because it has acquired a context (it’s an average) and meaning. Document review is getting relevant data from a document, an article or a book.
Also, the binary patterns that describe an icon on your desktop are data. They
become information after the operating system software has processed them, f. Data mining
because then they become meaningful to you as the icons representative of your Data mining is the exploration of databases to collect data.
hard disk or Internet explorer.
In summary,

© 2014- BGS Molyko 40


Bilingual Grammar School Advanced Level Computer Science

1.2. Characteristics of Information Proofreading consists of reading the data entered either on screen or printout, to be
Good information is that which is used and which creates value. Experience and sure that it matches the data source. It is also known as visual check.
research show that good information has numerous qualities.
b. Data Validation
a. Timeliness Validation is a check on input data to ensure that the data is sensible or reasonable.
Delay destroys the value of information. For effective decision making, information It compares the input with a set of rules that the computer has been told the data
must reach the decision-maker at the right time. Timeliness means that information must follow. If the data does not match up with the rules then there must be an
must reach its recipients within the prescribed timeframes. error. Validation only checks that the data is valid. The data may be valid but not
correct. Five types of validation checks are:
b. Accuracy
Wrong information given to decision-makers would result in wrong decisions.  Type/Format check
Accuracy means that information should be free from mistakes and errors. A type check is used to ensure that data entered in a field fits the required data
type. For example, a person’s name will consist of letters of the alphabet and
c. Current sometimes hyphens and apostrophe. Any name that contains numbers will be
For the characteristic of timeliness to be effective, information should be current or rejected as invalid.
up-to-date. Information must be current as a fact of yesterday may not be a fact of
today.  Length check
A length check ensures that an entered value is no longer than a certain number of
d. Completeness characters. For example, a phone number has 8 digits. Entering fewer or more digits
Information should have every necessary part or everything that is wanted. If makes a number invalid.
information is not complete, it may lead to wrong decisions being made as only half
of an entirety of the information is known.  Range check
A range check is used to ensure that the data entered falls between a specified
e. Explicitness minimum and maximum values. For example, a mark in an exam is between 0 and
Good information should not require further analysis for decision making. It should 20. Any mark below 0 or above 20 is rejected as invalid.
be clear and obvious, leaving no doubts as to its intended meaning.
 Presence check
1.3. Data Collection A presence check ensures that an entry has been made in a particular field. If it has
All computer systems need to have data input into them otherwise they have not, the system will not allow the record to be saved or any entries to be made in
nothing to process. Getting the data for the computer to process is known as data later fields. Such fields called mandatory fields are indicated on some systems by
collection. Data collection can be manual or automatic. the used of an asterisk.

1.3.1. Manual Data Collection  Check digits


Manual data collection uses forms and questionnaires. Data collected through this A check digit is a digit attached to the end of a string of digits that can be used to
method has to be entered into the computer by typing and clicking. check that the string is correct. It is calculated from the other digits in the string.
Many different errors can occur when entering data into a system. To try and reduce One example where a check digit is used is in the 10 digit ISBN number which
the amount of input errors, a system designer can build in validation and verification uniquely identifies books. The last number of the ISBN is actually the check digit for
checks into the software that the data is entered into. the other numbers. For example, in the ISBN 1858134153, the 3 at the end of the
number is the check digit.
a. Data Verification The check digit for ISBNs is obtained using a calculation method known as the
Verification means checking the input data to make sure it has been entered Modulus-11 weighted check digit calculation.
correctly. Verification tries to ensure there have been no transcription errors. It is a
check on accuracy. Two methods of data verification are double entry and o Start with original number i.e. 185813415
proofreading. o Weight each digit by its position in the string and add up the results.

 Double Entry
Position 10 9 8 7 6 5 4 3 2 1
Double entry consists of entering the data twice. The two entries are then compared
against each other and a warning given if they do not match. For example, a new Digit 1 8 5 8 1 3 4 1 5
password is always entered twice.
Weightings 10 72 40 56 6 15 16 3 10

 Proof Reading Total = 10+72+40+56+6+15+16+3+10= 228


© 2014- BGS Molyko 41
Bilingual Grammar School Advanced Level Computer Science

typed from the keyboard. This method is suitable for capturing data from airline
o Divide the total by 11 and then subtract the remainder from 11. The check tickets; reading postal codes; capturing data from telephone and electric bills.
digit is the result of this operation.
228 / 11 = 20 remainder 8 => Check digit is 11-8 = 3. c. Magnetic Ink Character Recognition (MICR)
o Add the check digit to the end of the original number to get the complete The device used is a magnetic ink character reader that reads characters written in
product number. i.e. 1858134153. magnetic ink, using magnetic stripe readers or card swipe machines that capture the
information on the magnetic card. These are seen on the back of credit cards and
To check whether the ISBN is correct, bank cards.
o Input the number including the check digit.
o Weight each digit by its position in the string and add up the results. d. Barcode Reading
An optical device called barcode reader is used to read the barcode on products and
convert them into a form that can be processed by the computer. A bar code is a
Position 10 9 8 7 6 5 4 3 2 1 sequence of vertical lines and numbers that identify a product. They are used in
libraries, supermarkets and retail shops.
Digit 1 8 5 8 1 3 4 1 5 3

Weightings 10 72 40 56 6 15 16 3 10 3 e. Voice Recognition


This method converts speech into text or a sequence of computer commands. It is
Total = 10+72+40+56+6+15+16+3+10+3 = 231 most common for data entry and word processing environments.

o Divide the total by 11. If the remainder is 0, then the number has passed 2. Information System Components
the validation check and so it is likely that it has been inputted correctly. There are five basic components in an information system: hardware, software,
231 / 11 = 21 remainder 0 procedures, data and people.

Exercise:  Hardware
i) Dates are read into a computer in the following format: DDMMMYY e.g. Hardware refers to the physical devices that make up the system. They are the
15DEC92. The following dates were rejected by a validation program: whole set of equipment used for input, processing, storage and communication of
3JAN71, AUG2166, 31SEP72. State the validation check used to discover data.
each error.
 Software
ii) Calculate the check digits to complete the ISBNs: 019276150-1 and Software is the collection of computer programs used in the system. They provide
995640216-8. the instructions that tell the computer what to do.

iii) Set up a spreadsheet which will calculate and check the validity of Modulo-  Data
11 weighted check digits for any given ISBN. Data are raw, unorganized, potentially useful facts and figures that are processed to
produce information.
1.3.2. Automatic Data Collection
Automatic data collection is a form of data input in which there is no data entry. It  People
uses sensors and specialized input devices to collect data that is directly entered People are the main actors of the system. They are the users of the information
into the computer without any human involvement. It is also called data capture. system. They input data into the computer, give some direction to the computer to
Different automatic data collection methods are: perform tasks and review information on the computer for output.

a. Optical Mark Recognition (OMR)  Procedures


OMR uses a device called an optical mark reader to read marks made with Procedures are the series of documented actions taken to achieve a particular goal.
prescribed pens, pencils or special writing material on OMR forms, and convert them A procedure is more than a single simple task. It can be complex and involved, such
into information in the computer. This system is good for multiple choice as reinstalling software, performing a backup etc.
examination questions.
3. Organizational Information Systems
There are three levels at which information can be used in an organisation:
b. Optical Character Recognition (OCR) strategic, tactical and operational levels. This can be represented using the pyramid
This method uses a device called an optical character reader to read characters
below.
from printed or handwritten text and transmit them to the computer as if they were

© 2014- BGS Molyko 42


Bilingual Grammar School Advanced Level Computer Science

b. Online Transaction Processing


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

 At the operation level, employees with operational roles need information to 3.2. Management Support Systems
help them carry out their duties. Results of operational work are passed Management support systems provide information and support needed for effective
upwards to let the tactical planners evaluate their plans. decision making by managers. They act at the tactical and strategic levels of the
organization. Major categories of MSS are management information systems,
In order to meet with the information needs of the organization, different types of decision support systems and executive information systems.
information systems exist which can be grouped into two: operations support
systems and management support systems. 3.2.1. Management Information systems
Management information systems generate accurate, timely and organized
3.1. Operations Support Systems information needed by middle managers to take decisions, solve problems,
Operation support systems process data generated by business operations. They act supervise activities, and track progress. They provide routine information for routine
at the operational level of the organization. Major categories of OSS are transaction tasks. The source of data for an MIS usually comes from numerous databases. These
processing systems, office automation systems and process control systems. 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
3.1.1. Transaction Processing Systems such, MIS are sometimes called Management Reporting Systems (MRS).
A transaction is any event of interest to an organization. It may be a business MIS generate three basic types of information or reports: detailed, summary and
activity such as a payment, a deposit, a customer’s order, a reservation or a exception.
student’s registration. Transaction processing systems capture and process data  Detailed reports confirm transaction processing activities. A detailed order
generated during an organization’s day-to-day transactions and maintain records report is an example of a detail report.
about the transactions. They are vital for any organization or business as they
gather all the input necessary for other types of systems. TPS are also called Data  Summary reports consolidate data into a format that an individual can review
Processing Systems. quickly and easily. To help synopsize information, a summary report typically
contains totals, tables, or graphs. An inventory summary report is an example
There are two types of TPS: batch processing and online processing systems. of a summary report.

a. Batch Processing  Exception reports report information that is outside of a normal condition.
With batch processing, transaction data is collected over a period of time and all These conditions called the exception criteria, define the range of what is
processing is done as a group. Batch processing is ideal in situations where large considered normal activity or status. An example of an exception report is an
amounts of data requiring similar processing are to be processed. Examples are: inventory exception report that notifies the purchasing department of items it
 Payroll systems for calculating employee salaries needs to reorder. Exception reports help managers save time because they do
 Billing systems for calculating consumer bills. not have to search through a detailed report for exceptions. Instead, an
exception report brings exceptions to the manager’s attention in an easily

© 2014- BGS Molyko 43


Bilingual Grammar School Advanced Level Computer Science

identifiable form. Exception reports thus help them focus on situations that
require immediate decisions or actions. Expert systems are one part of an exciting branch of computer science called
artificial intelligence (AI). AI is the science and engineering of making intelligent
Examples of MIS are: machines which are able to simulate human behavior. AI technology can sense your
 Sales management systems actions and, based on logical assumptions and prior experience, will take the
 Inventory control systems appropriate action to complete the task. AI has a variety of capabilities, including
 Budgeting systems speech recognition, logical reasoning, and creative responses.
 Management reporting systems
Example 1:
3.2.2. Decision Support Systems A medical diagnosis expert system could be used in a doctor's waiting room.
Decision support systems are designed to help tactical and strategic decision- Patients would use a touch screen to answer questions on symptoms etc. created by
making in situations where there is uncertainty about the possible outcomes of the system. Based on the patient responses, the system could use its database of
those decisions. They provide interactive support for non-routine decisions or diseases and symptoms, along with its programmed rules, to prepare a list of
problems. possible diagnosis for the doctor to investigate further.
TPS and MIS provide information on a regular basis. However, managers need
information not provided in their reports to help them make decisions. Decision Advantages
support systems therefore use data from internal (TPS and MIS) and external o The doctor saves time because they do not have to ask the patient to
sources. describe their symptoms in person.
o Internal sources of data might include sales, manufacturing, inventory, or o The doctor is given a suggested list of possible diagnosis to investigate
financial data from an organization’s database. further.
o Data from external sources could include interest rates, population trends, o The computer can store far more information than the doctor and can
and costs of new housing construction or raw material pricing. search it far faster and more efficiently.
Examples of DSS are: o The database can easily be updated or extended.
 Logistics Systems
 Financial Planning Systems Disadvantages
 Spreadsheet Models o It can be difficult to describe symptoms to a computer system.
o It relies on a basic level of skills from the user.
3.2.3. Executive Information Systems o It lacks the 'human touch' of a doctor actually talking to a patient.
Executive information systems (EIS) are designed to support the information needs
of executive management. Their purpose is to analyse, compare and identify trends Example 2:
to help the strategic direction of the organisation. Information in an EIS is presented A expert system used by a car mechanic could help to diagnose faults in a car by
in charts and tables that show trends, ratios, and other managerial statistics. asking the mechanic to carry out tests or answer questions. This could also be
Because executives usually focus on strategic issues, EISs rely on external data automated as the computer could have inputs from sensors or have a direct
sources that can provide current information on interest rates, commodity prices, interface with a computer system built into the car. The system would then give the
and other leading economic indicators. mechanic a list of probable faults with the car even make automatic adjustments
To store all the necessary decision-making data, DSSs or EISs often use extremely using the computer system built into the car. It would also be helpful to a newly
large databases, called data warehouses. qualified mechanic as they would have access to a wider range of knowledge, could
save time compared to having to contact an expert and the system could be used as
4. Other Information Systems a training aid.
4.1. Expert Systems Advantages
An expert system is a computer program that tries to emulate the decision making o The user saves time because the mechanic is taken through a logical
of a human expert. It does this by combining the knowledge of human experts and series of things to try out that are likely to solve common problems.
then, following a set of rules, it draws inferences. An expert system is made up of o The system can directly access computer systems built into many
three parts: a knowledge base, an inference engine and a user interface.
modern cars.
 The knowledge base stores all of the facts, rules and information needed to o The system can store details of a huge range of common faults with
represent the knowledge of the expert.
different makes of cars.
 The inference engine is the part of the system that interprets the rules and o The database can easily be updated or extended as new problems are
facts using backward and forward chaining to find solutions to user queries. identified.
 The user interface allows the user to enter new knowledge and query the
system. Disadvantages

© 2014- BGS Molyko 44


Bilingual Grammar School Advanced Level Computer Science

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.

4.2. Geographic Information System


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

System Investigation  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
Maintenance Systems Analysis necessary tasks, actions or activities that must be accomplished.
It involves:
o Determining specific information needs
o Determining the information processing capabilities required for each
Implementation Systems Design
system activity (input, processing, output, storage, and control) to meet the
needs. The goal here is to identify “what” should be done not “how” to do
it.
Construction
© 2014- BGS Molyko 45
System Development Life Cycle
Bilingual Grammar School Advanced Level Computer Science

o Determining functional requirements (information requirements that are not Data design focuses on the design of the structure of data and files to be used by
tied to the hardware, software, and people resources that end users the proposed (new) system. It provides detailed descriptions of:
presently use or might use in the new system). o Attributes (characteristics) of the entities about which the proposed system
needs to maintain information.
 Feasibility Analysis o Relationships between these entities (E-R diagrams, data flow diagrams)
Feasibility analysis is a study which investigates the information needs of o Specific data elements (databases, files, records, etc.) that need to be
prospective users and determines the resource requirements, cost, benefits, and maintained for each entity.
workability of a proposed project. Its goal is to evaluate alternative systems and o Data dictionary
propose the most feasible and desirable system for development. o Integrity rules (data validation and verification) that govern how each data
Feasibility of a system can be evaluated in terms of four major categories: element is specified and used in the system.
o Organizational feasibility focuses on how well a proposed information
system supports the objectives of the organization and its strategic plan for  Process Design
information systems. Process design focuses on the design of software resources, that is, computer
o Technical feasibilityfocuses on the reliability/capabilities of the hardware programs and of procedures needed by the proposed system. It concentrates on
and software to meet the needs of the proposed system, and whether they developing detailed specifications for the program modules that will have to be
can be acquired or developed in the required time. purchased as software packages or developed by custom programming. Process
o Economic feasibilityfocuses on whether the tangible costs and benefits of design produces:
the proposed system will exceed the costs of developing and operating it. o Detailed specification of algorithms (pseudo-codes, flow charts, etc.)
o Operational feasibility focuses on the ability of the end users to operate, o Detailed specifications of the procedures needed to meet the user interface
use, and support the proposed system. and data design specifications.
o Detailed specification of the database schema (E-R diagram, object
The outcome of a feasibility analysis is a feasibility report which is presented to the diagrams)
user management for approval. It may be accepted or accepted with modifications The design stage is very important because it is the place where quality is fostered
or rejected. in software engineering. Design provides us with representations of software that
can be assessed for quality. Design is the only way that we can accurately translate
 Documenting System Analysis a customer's requirements into a finished software product or system.
The outcome of systems analysis is a system proposal or requirements specification
document which describes what the new system should do without specifying how 5.4. Construction
to do it. At the end of systems analysis phase, the system analyst produces a Once the design of the system is complete, it has to be converted into a computer
system proposal that will be used as basis for the design phase. understandable form. Development is the stage where the design is converted into a
computer program.
5.3. System Design
Systems design consists of design activities, which produce systems specifications  Coding (programming)
satisfying the functional requirements developed in the systems analysis stage. Coding is an important activity by which a programmer converts the systems
While system analysis specifies what is to be done by the new system, system specifications from the design stage into computer instructions referred to as
design describes how the system will accomplish what is to be done. programs. It is generally felt that the programs must be modular in nature. This
System design focuses on three main activities: user interface design, data design helps in fast development, maintenance and future change if required.
and process design.
 Prototyping
 User Interface Design Prototyping is the rapid development and testing of a working model of a product in
A user interface is a means of interaction between the user and the computer-based an interactive and iterative process involving both systems analysts and end users.
application. This activity focuses on designing how data will be introduced into the This working model or prototype, is a partially developed product that enables
system and how the information generated will be retrieved. It produces detailed customers and developers to examine some aspects of the proposed product and
specifications for information products such as: decide if it is suitable for a finished product.
o Display screens Various types of prototyping exist.
o Interactive user/computer dialogues
o Forms (on-screen forms for data input and output) o Throw-away prototyping
o Reports (on-screen and printed) In throw-away prototyping, the prototype is discarded once the actual requirements
have been understood and the final system is developed with a much clear
 Data Design understanding of user requirements.

© 2014- BGS Molyko 46


Bilingual Grammar School Advanced Level Computer Science

o Evolutionary Prototyping  Documentation


In evolutionary prototyping, a functional prototype with minimal functionality is built The job of the programmer does not end with the code or software instructions. The
in the beginning and is refined over time, as requirements are better understood. organization or users need to know how to get the best out of the system. This is
done through documentation. System documentation ensures continuity of the
o Incremental Prototyping system.
In incremental prototyping, functional prototypes of the various subsystems are built There are two types of documentation; user documentation and technical
and then integrated to form a complete system. In other words, the product is built documentation.
as separate prototypes which are later merged into a final product.
o User Documentation
 Testing User documentation is a complete description of the system from the user’s point of
Testing is the process of executing a program with the intent of finding an error. view detailing how to use or operate the system. It could be a paper-based user
During testing, trial runs are done to check for errors and whether or not the new manual or help incorporated into the software that can be accessed when the
system meets the users' needs. Once source code has been generated, the software software is installed. User documentation always covers the following:
must be tested to uncover and correct as many errors as possible before delivery. - A guide that describes what the system is supposed to do in non-technical
There are three sets of data that can be used to test the system: normal data and terms
abnormal data. - Instructions for installing and running the program
o Normal data is data which the system will accept. - Definition for hardware and Operating System requirements
o Abnormal (erroneous) data is invalid data which the system will reject. - The format of the output data
o Extreme data are data values that are chosen at the absolute limits of the - Explanation of common error messages and how to recover from them
normal range. This is to ensure that all normal values will be accepted and - Description of how to make backups against accidental data loss
processed correctly.
o Technical Documentation
Using these test data, the following test runs can be carried out: Technical documentation is a description from the designer’s point of view. Technical
o Unit testing tests the individual units or modules separately with prepared documentation often contains:
test data so that any errors can be corrected. - Detail functioning of the software showing algorithms, formulae, source
codes etc.
o Integration testing tests the complete system after the individual units - Description of data structures
have been tested and put together. This tests that separately developed - Test plans and testing procedures
modules/units work together as planned without error. - User interface and reports
- Location and version of the software
o System testing tests the integrated system to evaluate the system's
compliance with its specified requirements. 5.5. Implementation/Conversion
Implementation is the conversion from the use of the present (old) system to the
Two testing techniques that can be used are black-box testing and white-box testing. operation of the new system. It involves:
 Installation of new system
o Black-box Testing  Loading of data into new system
 Education and training of users of the system
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
There are different types of conversions:
fundamental aspects of a system with little regard for the internal logical structure
of the system. Black-box tests are used to demonstrate that system functions are
o Direct Conversion/Cutover: in which the old system is completely
operational, that input is properly accepted and output is correctly produced, while
at the same time searching for errors in each function. replaced by the new one. Its disadvantage is that, if the new system fails,
there is no back-up system, so data can be lost.
o White-box Testing
o Pilot Conversion: in which the new system is installed in one part of the
White-box testing, also called glass-box testing, is a test that relies on information
about how the system has been designed and constructed. It requires knowledge of business or organization. This allows the new system to be fully developed
the internal structure or implementation of the system. White-box tests are and tested. Once the pilot system is running successfully, the new system
conducted to ensure that internal operations are performed according to is introduced to all of the business/organization.
specifications and all internal components have been adequately exercised.

© 2014- BGS Molyko 47


Bilingual Grammar School Advanced Level Computer Science

- Its advantages are that, if something goes wrong with the new system, 6. Project Management
only a small part of the organization is affected, and the staff that were A project is an endeavor to accomplish a specific objective through a unique set of
part of the pilot scheme can help train other staff. interrelated tasks and the effective utilization of resources. A project has a definite
- As a disadvantage, there is no back-up system for the office/department start and finish time, well-defined outcomes or performance goals, and consumes
doing the pilot, if things go wrong. scarce resources such as money, personnel, material, and equipment.
A project is considered constrained by three functions:
o Parallel Conversion: in which old system and new system operate  Scope: what it is intended to accomplish. In other words, the customer’s
alongside each other (in parallel) until new system is proven capable. requirements for the project.
- It is advantageous in that, if the new system fails, the old system will act  Time allocation: the time schedule for the project.
as a back-up. Also, the outputs from the old and new systems can be  Cost: the money, budget, and resources for a project.
compared to check that the new system is running correctly. These three functions are called the Triple Constraint. The relationship between
- Its disadvantage is that, entering data into two systems, and running two them is represented using the Project Management Triangle.
systems together, takes a lot of extra time and effort.

o Phased Conversion: in which the new system is installed in phases Time Cost
(stages or steps) gradually replacing parts of the old system until
eventually, the new system takes over.
- Its advantages are that, it allows users to gradually get used to the new Scope
system, and training of staff can be done in stages.
- Its disadvantage is that, if a part of the new system fails, there is no back- The Project Management Triangle visualizes the fact that time, cost and scope of a
up system, so data can be lost project are interdependent; changing one of them causes changes in the other two.
For example, if you want to shorten a schedule, you can hire more resources which
5.6. Maintenance would increase cost, or reduce customer requirements which would affect quality.
Maintenance is the general process of changing a system after delivery to correct This simply means “you can have any two of quick, good or cheap, but not all
faults, improve performance or adapt the system to a changing environment or three.”
business requirements. Maintenance is necessary to eliminate errors in the system
during its working life and to tune the system to any variations in its working Definition: Project management is defined as the application of knowledge, skills,
environment. tools and techniques to activities of a project for the achievement of the project’s
Maintenance can be adaptive, preventive, corrective or perfective. objectives/requirements.

 Adaptive Maintenance Project management ensures that an acceptable system is developed within time
Adaptive maintenance focuses on adjusting a software product to properly interface and budget.
with a changing environment. Changes are made to increase system functionality to
meet new business requirements. 6.1. Project Life Cycle
The activities related to a project can be structured and grouped into stages
 Preventive Maintenance according to the aim of the activities. A typical project goes through the following
Preventive maintenance aims in retaining the system’s capabilities before the stages called project life cycle: initiation, planning, execution, monitoring and
occurrence of any problem (e.g. system failure). It locates weaknesses in the system control, and closing.
and provides repairs in order to avoid any eventual breakdown of the system.
Making changes to prevent future system failures.

 Corrective Maintenance
Corrective maintenance aims in restoring a defective system to a required state. a. Initiation
This implies that repairs are made after a breakdown of the system. (Making Project initiation determines the main objective of the project and forms a clear
changes to repair system defects) understanding about the necessity and suitability of the project. This stage answers
the questions “what?” and “why?” Common activities at this stage are:
 Perfective Maintenance  Identification and initial analysis of the business needs.
Perfective maintenance refers to enhancements to the product in order to either add  Determination of the main objective(s).
new capabilities or modify existing functions. Making changes to enhance the  Resource analysis (people, equipment, financial; needs and availability).
system and improve such things as processing performance and usability.  Composition of the project charter.

© 2014- BGS Molyko 48


Bilingual Grammar School Advanced Level Computer Science

(Project charter - document issued by the project initiator or sponsor that  Identifying, creating, and reviewing communication messages within the
formally authorizes the existence of a project, and provides the project project (communication management)
manager with the authority to apply organizational resources to project  Performing a phase review at the end of execution to ensure the project has
activities.) achieved its objectives as planned.

b. Planning e. Closing
Project planning involves the project plan development and approval. It determines Once all the deliverables have been produced and the customer has accepted the
an optimal scheme/algorithm for project execution. This stage answers the question final solution, the project is ready for closure.
“how?” The main activities at this stage are: Project closure involves:
 Needs analysis  releasing the final deliverables to the customer
 Description of the project (including determination of activities and  handing over project documentation to the business
necessary resources)  terminating supplier contracts,
 Composition of project plan  releasing project resources
 Planning and performing necessary PR-activities.  communicating the closure of the project to all stakeholders
(PR is the practice of managing the spread of information between an
individual or an organization and the public. Public relations activities 6.2.Basic Project management Terminology
include: launchings, media conferences, sales promotions, open day,
product testing, websites, press release, newsletters.) o Task/Activity: anything that needs to be done that requires time and
consumes resources.
c. Execution o Dependent task: a task that can only begin after a previous one is
Project execution is the phase within which the deliverables are physically finished. For example, roofing a house depends on the construction of the
constructed and presented to the customer for acceptance. It integrates people and walls.
other resources to carry out the project management plan for the project. The o Slack time or float time: the amount of delay that can be tolerated
activities undertaken to construct each deliverable will vary depending on the type between the starting time and completion time of a task without causing a
of project being undertaken. Main activities are: delay in the completion date of the entire project. If we have tasks A and B
 Starting up the execution. that start at the same time and task C that is dependent on both tasks A
 Building the deliverables and B. If task A takes 3 days and task B takes 5 days, then task A has 2
 Day-to-day management and reporting days slack time. That is, it can run for 2 days before it affects the planned
starting time for task C.
d. Monitoring and Control
o Lag time: the delay or amount of time that passes between the end of one
Project control measures and monitors progress to identify variances from the
activity and the beginning of another if the two are dependent. For
project management plan so that corrective action can be taken when necessary to
example, if task A is laying of cement blocks and dependent task B is
meet project objectives. Control occurs throughout the duration of the project and
building the walls of the house, there would be some lag time between the
has a range relatively similar to that of execution. While the project is being
end of task A and the start of task B to let the blocks get dry.
executed, a series of management processes are undertaken to monitor and control
o Lead time: occurs when a task should theoretically wait for its predecessor
the deliverables being output by the project. This includes:
to finish, but can actually start a little early. The time that the tasks overlap
 Requesting, evaluating and approving changes to the project scope,
is lead time.
deliverables, timescales or resources (change management)
o Milestone: an event that signifies the accomplishment or completion of a
 Controlling the amount of time spent undertaking each activity within the
major deliverable during a project.
project (time management)
o Deliverable: some concrete thing which is to be delivered, to the client or
 Identifying, approving and paying cost/expenses incurred on project (cost
internally to the development team.
management)
o Leveling: the process of adjusting tasks to match resources available.
 Reviewing deliverable quality (quality management)
 Identifying, quantifying and managing risks to the project (risk There are two techniques for leveling: task delay and task split.
management) o Critical path: a sequence of dependent tasks that have the largest sum of
 Identifying and handling issues currently affecting the ability of the project most likely durations. The critical path determines the earliest possible
to produce the required deliverables (issue management) completion date of the project.
 Measuring each deliverable produced against acceptance criteria o Critical task: a task found on the critical path. A critical task cannot be
(acceptance management) delayed without delaying the entire project schedule.
 Handling sourcing of products from an external supplier (procurement o Work Breakdown Structure: a hierarchical decomposition of the project
management) into phases, activities, and tasks.

© 2014- BGS Molyko 49


Bilingual Grammar School Advanced Level Computer Science

o Project management plan (PMP): a document that describes how the In the above network diagram,
project is to be executed, monitored and controlled, which includes creating o Tasks are lettered from A to J. There are two ways of representing the
a project work breakdown structure, identifying and planning to mitigate activities on a network diagram: (a) activity on node and (b) activity on arc.
risk, identifying manners in which to effectively communicate with o Joining task A to E shows that task A must be completed before task E can
stakeholders and other project team members, and developing a plan to be started.
manage changes. o Joining tasks A and B to E shows that both task A and B must be completed
before task E can be started.
o The number marked on each arc (arrow) shows the duration of the task
6.3.Project Analysis and Scheduling from which the arc starts.
Project scheduling is the process of converting a general or outline plan for a project The critical path can be identified by determining the following four parameters for
into a time-based schedule based on the available resources and time constraints. each activity:
Different techniques exist for analyzing and scheduling project activities. o ES – earliest start time: the earliest time at which an activity can begin
given that its predecessor activities must be completed first.
a. Critical Path Method (CPM) o EF – earliest finish time, equal to the earliest start time for the activity plus
CPM is an analysis technique used to predict project duration by analyzing which
the time required to complete the activity.
sequence of activities (which path) has the least amount of scheduling flexibility (the
o LF – latest finish time: the latest time at which an activity can be
least amount of total float). Early dates are calculated by means of a forward pass
completed without delaying the project.
using a specified start date while late dates are calculated by means of a backward
o LS – latest start time, equal to the latest finish time minus the time required
pass starting from a specified completion date, usually the forward pass’s calculated
to complete the activity.
project early finish date.
Activities with the same earliest and latest start times (ES=LS) or with same earliest
and latest finish times (EF=LF) define the critical path. This means that these
 Forward pass: The calculation of the early start and early finish dates for the
activities have a float time of 0.
uncompleted portions of all network activities, determined by working forward
through the schedule network logic from the project’s start date. For the above network diagram, we have:
 Backward pass: The calculation of late finish and late start dates for the
uncompleted portions of all schedule activities, determined by working Start times Float
backward through the schedule network logic from the project’s end date. Activity Duration
Earliest Latest time

CPM models the events and activities of a project as a network. Activities are A 7 0 0 0
depicted as nodes on the network and events that signify the beginning or ending of B 2 0 5 5
activities are depicted as arcs or lines between the nodes. C 15 0 12 12
a) 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

I 2 27 27 0
b)
J 3 29 29 0

Finish 32 32

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 days
Network diagrams

Exercise 1: Given the task description table below:

© 2014- BGS Molyko 50


Bilingual Grammar School Advanced Level Computer Science

uncertainty in the completion


times, Activity Duration Precedence and this uncertainty limits the
A 3 - usefulness of the deterministic
CPM B 3 A model. An alternative to CPM is
the PERT C 4 - (Program Evaluation and Review
D 1 C
Technique) project planning model.

E 3 B, D
b. Program Evaluation and
F 2 A, B, D Review Technique (PERT)
PERT is G 2 C, F an event-oriented network analysis
technique H 4 G used to estimate project duration
when I 1 C there is a high degree of
J 3 E, G
uncertainty with the individual
activity duration estimates. Each activity is
K 5 F, H, I
assigned three time estimates
m= most likely time estimate, (mode)
1. Draw the corresponding PERT diagram for this project a = optimistic time estimate (best case)
2. Determine the critical path b = pessimistic time estimate (worst case)
3. Calculate the total estimated duration of the project
4. State the float time for all non-critical activities These three estimates are then used to calculate a weighted duration for each task

Exercise 2: Find the critical path for each of the activity networks below. by using the formula
T E =(a+ 4 m+b)/6
The weighted durations are then used as a more realistic estimate of task durations
a. for constructing a PERT chart (network diagram).
Using PERT, the probability of completing the project by a certain date t, can now be
found by finding

t−T t−T
P (t ≥T )= =
√σT 2 σ
b.
Where
T is the expected completion time of the project

And
2
b−a
σ T 2= ( )
6
c.
is the variance of T = (variances of activities on the critical path).
Example:

If a project’s expected completion time is T =246 days with its variance

σ T 2=25 , then what is the probability that the project

a) is actually completed within 246 days?


Remark! CPM was developed for complex but fairly routine projects with minimal b) is actually completed within 240 days?
uncertainty in project completion times. For less routine projects there is more c) is actually completed within 256 days

© 2014- BGS Molyko 51


Bilingual Grammar School Advanced Level Computer Science

estimating percent
important
Solution completion is more important

a) t=246 ,
T =246 and
σ T 2=25 d. Gantt Chart
A Gantt chart is a horizontal bar graph that helps plan and monitor project
246−246 development or resource allocation on a horizontal time scale. It depicts project
P (t ≥T )= =0 tasks against a calendar.
25 A Gantt chart is constructed with a horizontal axis representing the total time span
of the project, broken down into increments (days, weeks, or months) and a vertical
axis representing the tasks that make up the project. Horizontal bars of varying

b) t=240,T =246 and


σ T 2=25 lengths represent the sequences, timing, and time span for each task. The bar spans
may overlap, as, for example, you may conduct research and choose software
during the same time span. As the project progresses, secondary bars, arrowheads,
240−246 −6
P (t ≤T )= = =−0.24 or darkened bars may be added to indicate completed tasks, or the portions of tasks
25 25 that have been completed. A vertical line is used to represent the report date.

∴ P ( t ≤T )=1−(P ( t< 0.24 ) )=1−0.24=0.76

c) t=256 ,
T =246 and
σ T 2=25

256−246 6
P (t ≥T )= = =0.24
25 25

A Gantt chart
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 The critical path is A-C-D-F-H = 5+6+4+2 = 17 days
events, or milestones in the project linked by labeled vectors (directional lines)
representing tasks in the project. The direction of the arrows on the lines indicates Exercises!
the sequence of tasks. Exercise 1: A project has been defined to contain the following list of activities along
with their required times for completion.
c. Comparison between CPM and PERT
CPM task durations are known with certainty. CPM is therefore said to be
Activit Time Immediate
deterministic while PERT is probabilistic. Activity
y No. (weeks) Predecessors
CPM PERT 1 Collect 3
1 Uses network, calculate requirements
float or slack, identify
critical path and activities, Same as CPM 2 Analyze processes 2 1
guides to monitor and
controlling project 3 Analyze data 2 2
2 Requires 3 estimates of
Uses one value of activity activity time 4 Design processes 6 2
time Calculates standard deviation
and variance of time
5 Design data 3 3
3 Used where times can be Used where times cannot be
estimated with confidence, estimated with confidence.
6 Design screens 2 3,4
familiar activities Unfamiliar or new activities
4 Minimizing cost is more Meeting time target or

© 2014- BGS Molyko 52


Bilingual Grammar School Advanced Level Computer Science

7 Design reports 4 4,5 A - Interview the 15


Starts at 4:30 pm
resigning minister mins.
8 Program 5 6,7 B - Film the ministry 20
None
mins.
9 Test and Document 7 7 C - Get reactions 25 Cannot start until A
from regions mins. and B are completed
10 Install 2 8,9 D - Review possible Cannot start until B is
40 mins
replacements completed
E- Review the Cannot start until A is
25 mins
minister’s career completed
b. Draw a network diagram for the activities.
Cannot start until E
c. Calculate the earliest completion time of the project F- Prepare film for 20
and
d. Show the critical path. archives mins.
C are completed
e. What would happen if activity 6 were revised to take 6 weeks instead of 2 Cannot start until A,
weeks? 20
G- Edit B, C, D, E and F are
mins.
f. Construct a Gantt chart for this project completed

Exercise 2: At 4:30 pm one day CRTV news team hear of a Government Minister b. Construct an activity network for this problem and by finding the critical path,
resigning. They wish to prepare an item on the event for that evening’s 6 o’clock in your network, show that the news item can be ready before 6 pm that day.
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. c. Construct the corresponding Gantt chart for this project

Time
Job Constraints
needed

6.4.CHAPTER 5: DATABASE DESIGN SYSTEMS AND MODELING  Maintenance is difficult as every occurrence of a piece of data needs to be
6.5. updated if its value changes
6.6.Introduction  More manual data entry is required and therefore a greater likelihood of errors
6.7.A database is an organized collection of related data stored in a way when data is being entered.
that it can be easily retrieved and manipulated. A telephone directory, 6.13.
a library catalogue and a class register are examples of manual or 6.14. The solution to these problems is to divide the data into logical
paper-based database systems. A paper-based database requires much groups and store the data in multiple tables, then connect (relate) the
paper as the database becomes larger, making it difficult to tables to each other. This results to a Relational database.
manipulate the database. The problems caused by paper-based 6.15.
systems are solved by the development of computer-based systems. 1.2. Relational Database Model
6.8.The capacity for computers to store large amounts of data and their 6.16. In a relational database, data is organized in two dimensional
ability to quickly and efficiently retrieve the data makes them ideal for tables called relations, which are linked. A relation has the following
creating and using electronic or computerized databases. A features:
computerized database refers to a collection of related files that are  Name: the name of the table
digitized. Computerized databases are created using database  Tuples: a tuple is a single row of a table, which contains a single record for
software called database management systems (DBMS). that relation.
6.9.  Attributes: an attribute is a single column in the table, which contains a fact
1. Database Models about each record in the relation.
6.17.
6.10. 1.3. Object-Oriented Database Model
1.1. Flat-file Database 6.18. An object-oriented database tries to keep the advantages of the
6.11. A flat file database is a single table database, with separate copies relational model and at the same time allows applications to access
of data in each part of the business. An example is a phone directory. structured data.
6.12. The problems encountered with flat file databases are 6.19.
 Data duplication: data is repeated and hence stored many times. This wastes 6.20.
disk space and slows down query time. 1.4. Hierarchical Database Model
6.21.

© 2014- BGS Molyko 53


Bilingual Grammar School Advanced Level Computer Science

2. Database Normalization 6.55.


6.56.
6.22. Database normalization is the process of organizing the fields and 6.57.
tables of a relational database to minimize redundancy and 6.58.
dependency. Normalization usually involves dividing large tables into 6.59.
smaller and less redundant tables and defining relationships between 6.60. But still, there is a problem because StudID is no longer valid as
them. Normalization works through a series of stages known as normal primary key. It no longer identifies each row (record) uniquely.
forms. In order to achieve one level of normal form, each previous level 6.61. To solve this problem, we declare StudID and Subject together to
must be met. uniquely identify each row.
6.23. 6.62.
2.1. First Normal Form 6.63. Now, the new primary key is StudID and Subject. It is a composite
6.24. A relation (Table) is in first normal form (1NF) if and only if key.
 It contains a primary key. A primary key is an attribute that identifies each 2.2. Second Normal Form
entity in a unique way. 6.64. A relation is in second normal form (2NF)if and only if
 It contains no multivalued field or repeating groups. A multivalued field is  It is in 1NF
one that may take several values for a single record. A repeating group is a  Every non-key attribute is fully dependent on the primary key. In other
set of one or more multivalued attributes that are related. words, there should be no partial dependencies.
6.25. 6.65.
6.26. For example: 6.66. To put the data model to 2NF, we have to ensure that every non-
6.27. key attribute is functionally dependent on the entire primary key. An
StudID
6.28. Stud_Name School Subject Grade attribute B is said to be functionally dependent on another attribute A
6.29. if A determines B, and is written as AB.
70236.30. Mary Watson BGS Molyko Chem, Phy, Maths A, C, B 6.67.
6.31. 6.68. {StudID} S{StudName}
71406.32. Peter Rowling BGS Molyko Bio, Chem, Maths B, C, D 6.69. {StudID}  {School}
6.33. 6.70. {StudID}  {Grade}
72546.34. Quincy Greg BGS Molyko CSC, Maths, FMaths A, C, D 6.71. {Subject}  {StudName}
6.35. 6.72. {Subject}  {School}
6.36. Problems: 6.73. {Subject}  {Grade}
 The table has no primary key 6.74.
 It contains multivalued fields “Subject” and “Grade” 6.75. StudName is dependent on StudID but it is not dependent on
6.37. subject, the other part of the key.
6.38. To solve the problem 6.76. School is neither dependent on StudID nor Subject.
 We take StudID as the primary key 6.77. Grade is dependent on Subject but to have the grade in a subject
 Create new rows so each cell contains only one value you need a StudID. Therefore, grade is dependent on both Subject and
6.39.
StudID StudName School Subject Grade StudID.
6.40. 6.78.
6.41.
7023 Mary W. BGS Molyko Chem A 6.79. To solve these problems, we create separate tables for the fields
6.42. that are not functionally dependent on the entire key. The primary key
6.43.
7023 Mary W. BGS Molyko Phy C for these tables is the part of the primary key on which they are
6.44. BGS Molyko Phy C dependent.
6.45.
7023 Mary W. BGS Molyko Maths B 6.80.
6.46. B 6.81. We now have,
6.47.
7140 Peter R. BGS Molyko Bio B 6.82.
6.48. 6.83. STUDENT: (StudID, StudName)
6.49.
7140 Peter E. BGS Molyko Chem C 6.84. SCHOOL: (SchoolID, SchoolName)
6.50. 6.85. SUBJECT: (SubjCode, SubjTitle)
7140
6.51. Peter E BGS Molyko Maths D 6.86. STUDENT_SUBJECT: (StudID,SubjCode, Grade)
6.52. 6.87.
7254
6.53. Quincy G. BGS Molyko CSC A 2.3. Third Normal Form
6.54. 6.88. A relation is in third normal form (3NF) if and only if
7254 Quincy G. BGS Molyko Maths C
© 2014- BGS Molyko 54
7254 Quincy G. BGS Molyko FMaths D
Bilingual Grammar School Advanced Level Computer Science

 It is in 2NF 6.113. An attribute can be simple, composed, derived, single valued or


 There are no transitive dependencies. Transitive dependency is a situation multi-valued.
where a non-key attribute depends on another non-key attribute. 6.114.
6.89. a. Simple attribute: simple attribute is an atomic value, which cannot be
3. Entity-Relationship Modeling divided further. For example, a person’s phone number is an atomic value
of 9 digits.
6.90. When a relational database is to be designed, an entity-
6.115.
relationship model is drawn at an early stage and developed as the
requirements of the database and its processing become better b. Composite attribute: an attribute made of more than one simple
understood. attribute. For example, a person’s complete name may have FName,
6.91. MName and LName.
6.92. Definition: An E-R model is a diagram which uses basic graphic 6.116.
symbols to show the organization of and relationships between data in c. Derived attribute: an attribute which does not exist physically in the
a database. database, but its value is derived from other attributes present in the
6.93. database. For example, a person’s age can be derived from his
6.94. An E-R diagram serves as a schema diagram for the required date_of_birth.
database. A schema diagram is any diagram that attempts to show the 6.117.
structure of the data in a database. d. Single-valued attribute: an attribute that contains one single value. For
6.95. example ID car number.
6.96. 6.118.
6.97.
6.98. e. Multi-valued attribute: an attribute than can contain more than one
Name value for the same entity. For example, a person can have more than one
6.99. Number
6.100. phone numbers or e-mail addresses.
PERSON Owns HOUSE
6.101. 6.119.
6.102. Street 3.3. Relationship Type
DOB
6.103. 6.120. A relationship type is a named association between entities. A
6.104. person (entity) owns (relationship) a house (entity), a teacher (entity)
6.105. An E-R diagram teaches (relationship) a subject (entity). Normally, individual entities
6.106. have individual relationships of the type between them but in an E-R
6.107. The basic elements of an E-R diagram are entity sets, attributes diagram, this is generalized to entity sets and relationship types. For
and relationship types. example, the entity set PERSON is related to the entity set HOUSE by
6.108. the relationship type OWNS.A relationship type is represented by a
3.1. Entity Set diamond.
6.109. An entity is a person, place, concept or thing for which we intend 6.121.
to collect data. For example, a customer, an employee, a book, an 6.122. A relationship can be characterized by a degree and cardinality
appointment. ratio.
6.110. A group of entities that share the same properties is an entity set. 6.123.
An entity is therefore a member or an instance of an entity set. In an E- 3.3.1. Degree of a Relationship
R diagram, an entity set is represented by a rectangle. In the above E-
R diagram, PERSON and HOUSE are entity sets 6.124. The degree of a relationship refers to the number of participating
6.111. entities in the relationship. It can be unary, binary, ternary or n-ary.
3.2. Attributes 6.125.
6.112. An attribute is a fact about an entity or a property that describes  A unary relationship type is one that involves entities from a single entity set.
an entity. For example, a person’s name, date of birth or gender, a E.g. the relationship MANAGES between entities within the entity set
vehicle’s model, color or brand. Attributes store the actual data we EMPLOYEE.
want to keep about each entity within an entity set. An attribute is 6.126.
represented by an ellipse. In the above E-R diagram, name and date of 6.127.
birth are attributes of the entity set PERSON while Number and Street 6.128. Employee Manages
are attributes of the entity set HOUSE. 6.129.
6.130.

© 2014- BGS Molyko 55


Bilingual Grammar School Advanced Level Computer Science

 A binary relationship type is a relationship between entities from two different 6.154.
entity sets. An example is the relationship OWNS in the E-R diagram above. 6.155. (1,1) (1,1)
Receives
6.131. 6.156. STUDENT SLIP

6.132. Owns 6.157.


PERSON HOUSE
6.133. 6.158.
6.134. 6.159. (1:1) relationship
 A ternary relationship type is one that involves entities from three different  In the relationship TEACHES between TEACHER and SUBJECT, a teacher
entity sets. An example is a LECTURER who teaches a certain COURSE in a teaches one or many subjects. The cardinality of TEACHER is many and the
DEPARTMENT. optionality is one.
6.135. 6.160. A subject is taught by one or many teachers. The cardinality of
6.136. SUBJECT in the inverse relationship IS_TAUGHT_BY, is many and the
LECTURER Teaches COURSE
6.137. optionality is one. This relationship is described as many-to-many (M:N).
6.138. 6.161.
6.139. 6.162.
6.140. DEPARTMENT 6.163.
6.141. 6.164. (1,M (1,N
TEACHER Teaches SUBJECT
) )
 An n -ary relationship type involves entities from n different entity
6.165.
6.166.
sets. 6.167.
6.168. (M:N) relationship
6.142.
3.3.2. Cardinality Ratio of a Relationship Type 6.169. Remark In a normalized database, many-to-many relationships
are eliminated by creating a link entity between the entities involved in
6.143. Cardinality is the maximum number of entities within each entity the relationship.
set that can take part in a relationship. For example, what is the 6.170. The above TEACHES relationship when normalized becomes
maximum number of houses that a person can own? On the other 6.171.
hand, the minimum number of entities within each entity that can take 6.172. (1,1) (1,N) (1,N) (1,1)
TEACHER TEACHES SUBJECT
part in the relationship is the Optionality. For example, what is the 6.173.
minimum number of houses that can be owned by a person? 6.174.
6.175. Normalized (M,N) relationship
6.144. The cardinality ratio is a ratio of the cardinalities of the entity sets
involved in a relationship. It can be one-to-one (1:1), one-to-many (1:N) 6.176. The primary key of the link entity is a composite key that consists
or many-to-many (M:N). of the primary keys of the entities TEACHER and SUBJECT.
6.145. 6.177.
 In the relationship OWNS between PERSON and HOUSE, a person can own 6.178. The above representation of an E-R diagram is the Chen
zero or many houses. Therefore, the cardinality of PERSON in the relationship Convention. Another way of representing E-R diagrams is the crow’s
OWNS is many while the optionality is zero. foot notation that uses three symbols to show cardinality ratios. Here,
6.146. On the other hand, a house is owned by one person. The a circle means zero, a line means one and a crow’s foot means many.
cardinality of HOUSE in the inverse relationship IS_OWNED_BY, is one while The cardinality is shown next to the entity type and the optionality (if
the optionality is one. The relationship OWNS is therefore described as a one- shown at all) is shown behind it.
to-many (1:N) relationship.
6.147.
6.148. (1,1) (0,N
PERSON Owns HOUSE
6.149. )
6.150.
6.151.
6.179.
6.152. (1:N) relationship
6.153. 6.180.
 In the relationship RECEIVES between STUDENT and SLIP, each student 6.181. Where A and B are entity sets and R is the relationship type.
receives one and only one result slip. The cardinality of student is one and the 6.182.
optionality is one. Each result slip is issued to one and only one student. The 6.183. Exercise! Exercise! Exercise!
cardinality of SLIP is one and the optionality is one. This relationship is 6.184.
described as one-to-one (1:1). 1) Identify the cardinality ratios of the following relationships.

© 2014- BGS Molyko 56


Bilingual Grammar School Advanced Level Computer Science

4.1.1. Tables

6.199. A table is an area of the database where information is stored.


Tables organize data into columns (called fields) and rows (called
6.185. records). Example: a database storing information about books and
authors for a library could have a “BOOKS” table to store information
about books (title, publisher, Year, etc) and an “AUTHORS” table to
store information about authors (name, birth date, birth place, etc).
6.200.
6.186.
 A field is a specific piece of data stored in a table. The above mentioned
‘BOOKS’ table has fields ‘Title’, ‘Publisher’, ‘Year’ etc.
6.201.
 A record is an individual entry in a database table. It comprises of one or
6.187. more fields, depending on the number of fields defined to the table. For
6.188. example: if five books are entered in our books and authors database, the
2) A database will be made to store information about patients in a hospital. “BOOKS” table would have five records (one for each book).
On arrival, each patient’s personal details (name, address, and telephone 6.202.
number) are recorded where possible, and they are given an admission  Each field in a database table is assigned a data type when the field is
number. They are then assigned to a particular ward (Accident and created. The data type determines the kind and format of the information
Emergency, Cardiology, Oncology, etc.). In each ward there are a number stored in the field. Example: the “Title” field in the “BOOKS” table will store
of doctors and nurses. A patient will be treated by one doctor and several text that will vary with each book in the database, so the data type in this
nurses over the course of their stay, and each doctor and nurse may be case will be text or character type.
involved with several patients at any given time. 6.203.
6.189. a. Creating a New Table
6.190. From the description, draw a corresponding E-R diagram showing 6.204. To create a new table,
all entity sets, attributes, relationship types and cardinality ratios. o Click the Create Tab
6.191. o Select Table in the Tables group to create a new table in Datasheet
4. Database Management Systems view or Table Design to create a new table in Design view
6.205.
6.192. A database management system (DBMS) is a computer program b. Adding Fields in a Table
that is used to create, manipulate and access a database. Examples 6.206. To add a field to a table in Datasheet View,
are MS Access, MySQL, Oracle, Sybase, dBase, Paradox, Objecstore and o Click the Add New Field column label.
O2 . o Click Rename in the Fields & Columns group.
6.193. A DBMS provides users with: o Type the field name and press Enter. Access creates the field. Continue
 Data Definition Language (DDL): language which programs the structure
until you have created all of the fields in your table.
(schema) of the database
o Press Enter without entering a field name to end your entries.
 Data Manipulation Language (DML): language which changes the contents
6.207.
(instance) of the database
6.208. To add a field to a table in Design View,
 Data Control Language (DCL)
o Select a cell in the Field Name column
6.194.
o Type a name for the first field in the table and press Enter
4.1. Microsoft Access 2007
o Select a data type and press Enter
6.195. MS Access 2007 is made up of several components including:
 Tables o Type a description and press Enter
 Forms 6.209.
 Queries c. Naming and Saving a Table
 Reports 6.210. To name and save a table,
6.196. o Click the Save button on the Quick Access toolbar. The Save As dialog
6.197. These components are called database objects. One or more of box appears.
these components are formed when a database is created. These o Type the name you want to give your table.
components are stored in a single database file. o Click OK. Access names your table.
6.198. 6.211.

© 2014- BGS Molyko 57


Bilingual Grammar School Advanced Level Computer Science

6.212. Tip: You can use the Rename option at any time to rename any database should retrieve all the books from the “BOOKS” table written
column. For example, you can rename the ID column Author_ID. by William Shakespeare.
6.213. 6.224.
d. Setting a Primary Key 6.225. To create a query,
6.214. A primary key is a field in a table that allows each entry in the o Click the Create tab on the Ribbon
table to be identified in a unique way. No two entries in the database o Click the Query Design command
can have the same primary key. For example your ID card number is o Double-click Create Query in Design View
unique. By default, Access sets the first field in the table as the Primary o Select the table that you would like to base your Query on
Key field. o Click Add
6.215. To set a Primary Key: o Close the Show Table window
o Switch to Design View 6.226.
o Position your cursor in the field you wish to set as the Primary Key 6.227. In order to control which records are displayed, you must define
o Click the Primary Key button on the Ribbon criteria in a Query.
6.216. 6.228. To define criteria for your query:
e. The Foreign Key o Position your cursor in the criteria row in the field for which you wish to
6.217. The primary key is used to link the table with other tables in the define the criteria for
database. When a primary key in one table (known as the source table) o Enter the criteria
is linked to another table (known as the target table), the connecting o Click the Run Query button
field in the target table is called the foreign key. A foreign key must 6.229.
have the same structure, data type, and field size as the associated 6.230. For example: a query to find the books written by Barack Obama
primary key, but it must not have the same name. Also, the foreign key 6.231.
in a relationship between two tables need not be a primary key in its 6.232. The result of a query is called a recordset.
own table. 6.233.
6.218. 6.234. To Save the Query:
4.1.2. Relationships o Click the Save Icon
o Enter a name for the query
6.219. Relating tables reduces the unnecessary duplication of data
o Click OK
(redundancy).The general procedure for creating relationships in
6.235.
Access is to
4.1.4. Forms
o Determine the type of the relationship and identify the source and target
tables
6.236. A form is an interface that allows users to enter and view data.
o Create the foreign key field(s) in the target table if they are not already
Forms give the ability to choose the format and arrangement of fields.
present
They can be used to enter, edit and display data. Forms can retrieve
o Select the Database Tools tab
data from one or more tables, and display the output on the screen.
o Click on the Relationships command 6.237.
o Add all the tables involved in the relationship to the window 6.238. To create a Form using the Form Wizard
o Create the relationships by dragging the primary keys from the source  Navigate to the table you want to base the form on
table(s) and dropping them on the associated foreign key(s) in the target  Click Create on the Ribbon
table(s).  Click Forms
6.220. 6.239. You are able to navigate using the navigation arrows at the bottom
6.221. For example: Let’s create a relation between the AUTHORS table of the form.
and the BOOKS table. 6.240.
6.222. 6.241. To enter a record on the Form:
4.1.3. Queries  Click the View button on the Ribbon to switch from Layout View to Form
View
6.223. A query is a command that tells the database what data the user
 Enter the data for each field in the record, pressing the Enter key to move
wants to see. A query allows information to be found and retrieved
to the next field
from one or more tables based on a set of search conditions you
 Press Enter after you have entered data for the last field
define. For example: a query can be written specifying that the
6.242.

© 2014- BGS Molyko 58


Bilingual Grammar School Advanced Level Computer Science

6.243. NB. The form feeds the table. If you edit a record on the form, or 6.247. To create a Report using the Report Wizard:
create a new record, that data will be passed to the table it is  Click the Create tab on the Ribbon
associated with.  Click the Report Wizard command
6.244.  Select the table or query upon which the report will be based
4.1.5. Reports  Select the fields that you want to include on the report by double clicking
on them
6.245. A report is an effective way to analyze and present data in  Click Next
printable format using a specific layout. Reports are the primary  Select a style for the report
method of retrieving and viewing information. Using queries, reports  Click Next
pull information the user has requested and either print that  Type a title for the report
information or display it on screen. The information that appears and 6.248. Click Finish
the formatting and appearance of a report are set when the report is 6.249.
created. 4.2. Structured Query Language
6.246. 6.250. Structured query language (SQL)
6.251. CHAPTER 6: ALGORITHM DESIGN AND PROGRAMMING digit. Each character requires one byte of space, so "computer" takes
6.252.
1. Data Types and Data Structures up 8 bytes ( 8 ×8=64 bits ¿ . Examples: A, 5, -, and !.
1.1. Data Types
6.263.
6.253. Computers manipulate data of different types like numbers,
e. String/Text
letters, sound and images. No matter the type, each data is stored as a
6.264. A string is a set of characters grouped together. A string is
pattern of binary digits. Numbers can be added, subtracted, divided
sometimes just referred to as ‘text’. It can contain a mixture of
and multiplied whereas letters cannot. This implies that data of a given
numbers, letters and, spaces. Numeric data stored as text is only for
type will be treated differently from data of another type. As such, the
representation not for calculation. Any type of alphabetic or numeric
type of any data stored in the computer must be specified so that the
data can be stored as a string. Examples: “Limbe City”, “10base-2”
correct operations will be performed on it.
and “36.85”.
6.254. A data type is defined as a set of values and a collection of
6.265.
operations on those values. Examples of data types are integer, real,
f. Date/ Timestamp
string and Boolean.
6.266. Date and timestamp are data types for storing date and time
6.255.
respectively. The format used for date is either dd-mm-yy or mm-dd-yy
a. Integer
and hh:mm:ss or ss:mm:hh for time.
6.256. An integer is a whole number that can be positive, negative or
6.267.
zero. Examples: -3, 5, 67, -134 and 4231.
g. Container
6.257.
6.268. A container is a data type used for storing images, video, sound or
b. Real
another type of ‘complex’ file. In some languages, binary large object
6.258. A real is a number that contains a decimal point. Computers
(blob) is used rather than container.
manipulate numbers with fractions as floating point numbers.
6.269.
Examples: 3.14, 12.25 and 0.001.
1.2. Data Structures
6.259.
6.270. A data structure is a way of organizing and storing data in memory
c. Boolean
so that it can be used efficiently. Any data structure is designed to
6.260. A Boolean data type stores one of only two values – true or false,
organize data so that it can be accessed and worked with in
yes or no, or on or off. Usually these values are stored as 1 for true and
appropriate ways. A well-designed data structure allows a variety of
0 for false.
critical operations to be performed, using as few resources, both
6.261.
execution time and memory space, as possible. Data structures include
d. Character
arrays, records, stacks, queues, trees, graphs and hash tables.
6.262. A character is any letter, digit, space, punctuation mark, or symbol
6.271.
that can be typed on a computer. The word "computer" for example,
2.1.1. Arrays
consists of eight characters. The phrase "data type" takes up nine
6.272. An array is a data structure, which allows a set of items of identical
characters. A character data type stores only a single character or
data type to be stored together using the same identifier name. When
an array is created, its dimension (size) and the type of its elements
are specified.

© 2014- BGS Molyko 59


Bilingual Grammar School Advanced Level Computer Science

6.273. 6.309.
6.274. For example: String Names[5] 6.310.
6.275. Names : Array [1..5] of string 6.311.
Each individual element can be referenced by its row and column
6.276. 6.312.
6.277. The above statements create an array called “Names” of five
indices.
6.313.
For example:
elements in C and Pascal respectively. The size of the array is 5 and its Tab[0][0]
6.314.= 5
elements are of type string. Tab[1][1]
6.315.= 4
6.278. To reference an element in an array, an index is used. An index is Tab[3][0]
6.316.= 2
an integer that gives the element at the indexed position in the array. 6.317.
6.279. For example in C, Names[0] references the first element in the 2.1.2. Record
array Names, Names[1] references the second element, Names[2] 6.318. A record is a data structure which allows items of different types
references the third and so on… that define a particular structure or object, to be stored together. The
6.280. In Pascal, the referencing starts from 1 rather than 0. elements of a record are usually called fields or members.
6.281. 6.319. Defining a record includes specifying the data type of each field
a. One-dimensional Arrays and a name (label) by which the field can be accessed.
6.282. A one-dimensional array is an array which is declared using a 6.320. For example,
single index and can be visually represented as a list. The array 6.321.
Student = RECORD struct Student
“Names” above is one-dimensional. Date=6.322.
RECORD
Name: String {
6.283. If the array “Names” contains five elements (names), Raissa, Day:6.323.
Integer
Gender: Character string Name
Peter, James, Leticia and Isaac, it can be visually represented as Month: String
6.324.
DOB: Date char
follows: Year:6.325.
Integer
End RECORD Gender
6.284. End RECORD
6.326.
Date DOB
Element 6.285.
Raissa Peter James Leticia Isaac 6.327.
}
6.286. 6.328. The above Date record has a numeric field Day, a text field Month
Index 6.287.
[0] [1] [2] [3] [4] and a numeric field Year. The Student record has fields Name, Gender
6.288. Names[0] == Raissa, Names[4] == Isaac and DOB which is of type Date. The table below gives examples of
6.289. student records.
b. Two-dimensional Arrays 6.329.
6.290. A two-dimensional array is an array which is declared using two 6.330.
Name Gender DOB
indices and can be visually represented as a table. 6.331.
6.291. For example: 6.332.
Raissa F 01 Apr 1996
6.292. 6.333.
6.293. int Tab[3][2] or Tab : Array [1..3, 1..2] of integer Peter
6.334. M 17 Oct 1995
6.294. 3 is the number of rows and 2 is the number of columns in the 6.335.
James M 05 May 1995 Records
table Tab. 6.336.
6.295. Leticia
6.337. F 09 Dec 1997
6.296. The elements of Tab will be referenced as: 6.338.
Isaac M 29 Feb 1995
6.297. Tab[0][0] Tab[0][1] 6.339.
6.298. Tab[1][0] Tab[1][1] 6.340.
6.299. Tab[2][0] Tab[2][1] 6.341. Each row in the table corresponds to a different record. This table
6.300. has 5 records.
6.301. Example: Given the 2-dimensional array Tab[4][2] below, what are 6.342. A field in a record is referenced as follows:
the elements given by the references Tab[0][0], Tab[1][1], Tab[3][0] 6.343.
and Tab[2][1]? 6.344. RecordName.fieldName = “”
6.302. 6.345. Raissa.DOB = 01 Apr 1996
Index
6.303. [0] [1] 6.346.
6.304. 6.347. Record data structures are always used in association with arrays.
[0] 5 3
6.305. That is, we define an array whose elements are of type record. When
6.306.
[1] 1 4 this is done, we have an array of records.
6.307. 6.348.
[2]
6.308. 3 1

[3] Molyko2
© 2014- BGS 8 60
Bilingual Grammar School Advanced Level Computer Science

6.349. For example: let’s define an arrayClassList, which stores


( 2 ×6 ) +5=17 ?
information about the students in the table above.
6.350.
6.351. Student ClassList[5]
Student
or ClassList : Array [1..5] of
6.369.
2× 6+5=
{ ¿
2× ( 6+5 )=22?
6.352. 6.370.
6.353. An element in this type of array is referenced as follows: 6.371. Infix notation requires the use of order of precedence of operators
6.354. ArrayName[index].fieldName and parentheses making it complicated and difficult for computers to
6.355. evaluate expressions in this form.
6.356. ClassList[0].Gender == F; ClassList[4].DOB == 29 Feb 1995; 6.372. To ease evaluation of arithmetic expressions, other notations are
ClassList[3].DOB.Month == Dec used: the prefix and postfix notations.
6.357. 6.373. In prefix notation also called polish notation, operations are written
2.1.3. Stack
6.358. A stack is a linear list in which items are added and removed from before the operands. For example the expression (a × b)+ c will
the same end (head). Items being added and removed from the same
end means that the last item to be added will be the first to be be written in prefix notation as
removed. As such stacks are also called last in, first out (LIFO) lists as
6.374. ( a × b ) +c=( × ab ) +b
they use the LIFO principle. (FILO)
6.359. Stack operations are:
 Stack(S): creates an empty stack named S 6.375. ¿+× abc
 Push(S,x): inserts the element x to the top of the stack S. Inserting an
6.376.
element into a stack that is full leads to a situation known as overflow. (START
6.377. In postfix notation also called reverse polish notation, operands
== NULL)
come before operators. 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 6.378. ( a ×b ) +c=( ab× ) +c =ab × c+¿
== HEAD)
 IsEmpty(S): checks whether the stack S is empty. Returns true if it is empty
and false otherwise. ( 2× 3 ) +1=23 × 1+ ¿
6.360.
6.361. Application of stacks: 6.379. Also,
6.362. bc +¿
a. Converting a Decimal Number to Binary
6.380.
¿ 2× ( 3+1 )=231+×
6.363. Initially we push the binary digit formed into the stack, instead of
a × ( b +c )=a× ¿
printing it directly. After the entire digit has been converted into the
binary form, we pop one digit at a time from the stack and print it.
6.381.
Therefore we get the decimal number converted into its proper binary
6.382. Prefix and postfix notations do not require parentheses or
form.
precedence rules. Calculators use postfix notation to evaluate
6.364.
arithmetic expressions. A simple way to understand is by using the
b. Evaluating Arithmetic Expressions
following expression: Pre A In B Pos.
6.365. Arithmetic expressions are usually written in the form 8÷ 2=4 , 6.383.
6.384. To convert from infix to prefix or postfix, priorities are assigned to
where the operator is in between the operands. This is known as the
infix notation. This notation poses problems for more complicated +¿
expressions. For example: ¿
6.366. operators as follows: −¿
priority(×)= priority ( ¿ ) > priority ¿
a ×b +c= ( a × b ) +c ?
6.367. {
a × ( b+c ) ?
-
and the following rules are used.
When an operand lies between two operators, it associates with the operator
6.368. that has higher priority.

© 2014- BGS Molyko 61


Bilingual Grammar School Advanced Level Computer Science

- When an operand lies between operators of same priority, it associates with


6.408. Read 2  stack [2]
the operator on the left.
6.385.
3 [2, 3]
6.386. Example 1: Let’s convert the expression P: A + B× C /D to
6.409. Read  stack

postfix. 6.410. Read 4  stack


[2, 3, 4 ]
6.387. Considering the priority rules given above, we can rewrite P as
follows:
× [2, 3 × 4=12] 2,12
6.411. Read  stack =
6.388. P: A +(( B ×C)/ D) ¿
]
6.389.
6.390. Stack[empty] 6.412. Read 5  stack
[2, 12, 5]
6.391. Output: [ ]

6.392. Read A push it into stack stack[A] output: [A] +¿ 2,12+5=17


6.413. Read stack ¿ ] =

6.393. Read + stack[+] output:


[A]
[2, 17]
6.394. Read ( stack[+(] output:
[]
6.414. Read −¿  stack
[2−17=−15] =
6.395. Read ( stack[+((] output: [ ]

6.396. Read B stack[+((] output:


[ AB] [−15 ]

6.397. Read * stack[+((*] output:


[ AB] 6.415.

6.416. The result of the expression 234 ×5±¿ is −15


6.398. Read C stack [+((*] output:
[ ABC ]
6.417.

6.399. Read ) stack [+(] output:


[ ABC ×] pop
6.418. Exercise: Convert the following to postfix notation and evaluate
them.
until you meet an opening )
i) 2−3 × 4+5 (
34 ×2−5+¿
6.400. Read / stack [+(/] output:
[ AB C ×]
ii) (2−3) ×(4+ 5) (
23−45+× ¿
6.401. Read D stack [+(/] output: [ AB C × D]
iii) 2× 3/(2−1)+5 × 3 (23x
ABC × D/¿
6.402. Read )  stack [+] output: ¿ 6.419.
6.420. Exercise 2: Evaluate the following expressions
ABC × D /+ ¿ i) 623±382/+× 2 +¿
3
6.403. stack[ ] output: ¿
6.404. ii) 12,7, 3,−,/ ,2, 1, 5,+ ,× ,+¿ (June 2013, Paper 2, Q5)

6.405. A +(( B ×C)/ D) in postfix notation is ABC × D /+ ¿ 6.421.


2.1.4. Queues
6.406. 6.422. A queue is a linear list in which items are inserted at one end
6.407. Example 2: Let’s evaluate the expression 234 ×5±¿ written
(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 also
in postfix notation. called FIFO lists as they use the FIFO principle. (LILO)

© 2014- BGS Molyko 62


Bilingual Grammar School Advanced Level Computer Science

6.423. Queue operations include: 6.450. NB: In a double linked list, every node has two pointers: one for its
 Create(Q): creates a queue Q. predecessor and another for its successor in the list.
 Enqueue(Q,x): inserts the element x to the tail of the queue Q. 6.451.
 Dequeue(Q): removes the first element from the head of the queue Q 2.1.6. Binary Tree
 Top(): checks the next element to be removed (do not remove) 6.452. A binary tree is a finite set of nodes that is either empty or
 IsEmpty(): checks whether the queue is empty. Returns true if it is empty consists of a root and two disjoint binary trees called the left sub-tree
and false otherwise. and the right sub-tree. In other words, it is a non-linear linked list
6.424. where each node may point to two other nodes. Binary trees are a very
6.425. Application of queues: efficient way of storing items that must be searched for and retrieved
6.426. quickly. Suppose, for example, that you want to store the following
a. Spooling names in a computer using a binary tree:
6.427. It is a method used to place input and output on a fast access 6.453.
storage device, such as a disk, so that slow peripheral devices do not 6.454. Jones, Stephen, Agbor, William, Bate, Peter, Terence
hold up the processor. For example, print spooler stores output to be 6.455.
printed in a queue while waiting for the user’s program to finish 6.456. The names can be arranged into a binary tree by using the
creating the output. The spooler then sends the stored output to the following two-step procedure:
printer at the proper speed. If new output arrives for printing, it is 6.457. 1. Use the first name on the list as the root of the tree.
added to the queue. 6.458. 2. To find where to put each subsequent name, start at the root of
6.428. the tree. If the name you are dealing with precedes the root name
b. Scheduling alphabetically, follow the left pointer; otherwise follow the right pointer.
6.429. It is the process of determining which of the jobs in memory will be Proceed in this way until you come to an empty pointer; attach the
executed by the CPU. When a job is created, it is added to a queue, the name to it.
ready queue. Any other job that arrives is added to the tail of the 6.459.
queue. A scheduling algorithm like round-robin is then used to allocate 6.460. Jones
the jobs one by one, to the CPU for execution. 6.461.
6.430. 6.462.
6.431. Remark A queue in which elements can be added and removed 6.463.
from any end is known as a double ended queue (Deque). 6.464.
6.432. 6.465. Agbor Stephen
2.1.5. Linked Lists 6.466.
6.433. A linked list is a linear list in which each element contains a 6.467.
pointer to the next element in the list. Each element in a linked list is 6.468.
known as a node and consists of two parts: the data item and the 6.469.
Bate Peter William
pointer to the next element. 6.470.
6.434. 6.471.
6.435. A C E 6.472.
6.436. 6.473.
6.437. 6.474. Terence
Data Pointer
6.438. 6.475.
6.439. A linked list that stores characters 6.476.
6.440. 6.477. A binary tree that stores names
6.441. Linked lists make it possible to insert items in the middle of the list 6.478.
without moving other items to make room. 6.479. The topmost node in the tree is known as the root node. Each
6.442. node in a binary tree may have at most two children or child nodes. A
6.443. node that has a child is called the child's parent node (or ancestor
6.444. node, or superior). A node has at most one parent except the root node
6.445. that has no parent. Nodes that have the same parent are called
6.446. siblings. Every node in a tree can be seen as the root node of the sub-
6.447. tree rooted at that node.
6.448. Linked list with elements C and D inserted .
6.449.
© 2014- BGS Molyko 63
Bilingual Grammar School Advanced Level Computer Science

6.480. Nodes at the bottom most level of the tree are called leaf nodes. 6.498.
Since there are at the bottom most level, they will not have any 6.499. A post order traversal of the tree above give: DFEBGLJKHCA
children. 6.500.
6.481. 2.1.7. Hash Table
6.482. Tree traversal is the process of systematically visiting all the nodes 6.501. A hash table is an array in which data is stored at specific locations
in a tree and performing some computation. When describing a designated by a hash function. A hash function is a function that
traversal strategy, we need not concern ourselves with what that transforms the value of a record key into an index that corresponds to
computation is. There are two methods for traversing a tree: breadth a location for storing the record. A hash function maps the set of input
first traversal and depth first traversal. data to a set of integers. Each element to be stored in the array has a
6.483. unique key that is mapped by the hash function to a numeric value
a. Breadth First Traversal that represents an index in the array.
6.484. In a breadth first traversal all of the nodes on a given level are 6.502. For example,
visited and then all of the nodes on the next level are visited, usually in 6.503.
a left to right fashion. It is also called level order traversal. 6.504.
6.485. 6.505.
6.486. Consider the following binary tree. 6.506.
6.507.
6.508. Index Element
6.509.
6.510. Null
Key
6.511.
6.512.
25
6.487.
6.513.
6.488. A level order traversal of this tree gives: ABCDEGHFJKL Kome
6.514.
36
6.489.
6.515.
b. Depth First Traversal 3
6.516.
6.490. In depth first traversal, the left subtree is traversed, the right
6.517.
subtree is traversed and the root is visited. There are three different Epie
6.518.44
depth first traversal techniques; preorder, in order and post order
6.519.
traversals. What distinguishes them is the order in which the subtrees 66 5 Null
6.520.
and the root are visited.
6.521.
6.491. Sama
6.522.
 Preorder Traversal:
6.523.
- Visit the root A hash table
6.524.
- Traverse left subtree
6.525. The above hash table stores the names Agbor, Epie, Sama, Kome
- Traverse right subtree
and Eyong using the hash function h(k) = k mod tablesize, where k, the
6.492.
key of each string is the sum of its letters’ positions in the alphabet.
6.493. A preorder of the above tree gives: ABDEFCGHJLK
This means that if an element p has key k, then p will be stored at
6.494.
position h(k) in the table.
 Inorder Traversal:
6.526. Keys:
- Traverse left subtree 6.527. Agbor = 1+7+2+15+18 = 43
- Visit the root 6.528. Epie = 5+16+9+5 = 25
- Traverse right subtree 6.529. Sama = 19+1+13+1 = 34
6.495. 6.530. Kome =11+15+13+5 = 44
6.496. An in order traversal of the tree above gives: In order traversal: 6.531. Eyong = 5+25+15+14+7 = 66
DBFEAGCLJHK 6.532.
6.497.
6.533. Applying the function h to each key we get:
 Postorder Traversal:
- Traverse left subtree 6.534. Agbor = 43 mod 7 = 1
- Traverse right subtree 6.535. Epie = 25 mod 7 = 4
- Visit the root
© 2014- BGS Molyko 64
Bilingual Grammar School Advanced Level Computer Science

6.536. Sama = 34 mod 7 = 6 6.557. For example, here is a pseudo code for an algorithm that reads
6.537. Kome = 44 mod 7 = 2 two numbers, computes and displays their sum:
6.538. Eyong = 66 mod 7 = 3 6.558.
6.539. 6.559. Begin
6.540. Hash table operations are: 6.560. Get A
h( k) 6.561. Get B
o Search: compute and see if an element exists 6.562. Result = A + B
6.563. Print Result
o Insert: compute h(k) and place element in the resulting position 6.564. End
6.565.

o Delete: compute h(k) and remove element in that position


3.1.2. Flowchart
6.566. A flow chart is a diagram that uses graphic symbols to describe
6.541. the nature and flow of steps in an algorithm. Each step in a flowchart is
6.542. Remarks! The size of the array should be preferably a prime followed by an arrow that indicates which step to go next. The
number. following symbols are used in flow charting:
6.543. With hash tables, there always exists the possibility that two data 6.567.
elements will hash to the same integer value. This situation is known a. Elongated circle: indicates the beginning (start) or end (stop) of the
as collision. Two methods to solve collision are separate chaining and algorithm
probing (closed hashing). 6.568.
6.569. Start/Stop
6.544.
3. Algorithms 6.570.
6.545. An algorithm is a well-defined set of step-by-step instructions for b. Rectangle: indicates instructions or actions
solving a problem in a finite amount of time. A set of instructions is not 6.571.
an algorithm if there is no definite stopping place, or if the instructions 6.572.
are too vague to be followed clearly. 6.573.
6.546. A good algorithm: c. Diamond: indicates a decision that has to be made
6.547. - should be explicit (i.e. clear and obvious) 6.574.
6.548. - should be precise (i.e. exact and accurate) 6.575.
6.549. - should be unambiguous (i.e. no doubts about what to do/ only 6.576.
one way of interpreting the instructions) 6.577.
6.550. - should be effective (i.e. produce good results) d. Arrow: indicates the direction of flow
6.551. - should be finite (i.e. have a definite stopping place) 6.578.
6.552. 6.579.
3.1. Representation of Algorithms 6.580.
6.553. There are different ways for representing algorithms such as 6.581.
pseudo code, flow chart and structured English. e. Parallelogram: indicates data input and output
6.554. 6.582.
3.1.1. Pseudo code 6.583.
6.555. A pseudo code is an outline of a computer program, written in a 6.584.
mixture of a programming language and English. Writing pseudo code f. Circle: serves as a connector
Start
is one of the best ways to represent an algorithm as it allows the 6.585.
programmer to concentrate on how the program works while ignoring 6.586.
the details of the language. 6.587. Get x, y
6.556. In a pseudo code, some terms are commonly used to represent the 6.588. Example: flow chart for an algorithm that divides two numbers x
various actions. For example, for inputting data the terms may be and y.
(INPUT, GET, READ), for outputting data (OUTPUT, PRINT, DISPLAY), for 6.589. Is y=0
calculations (COMPUTE, CALCULATE), for incrementing (INCREMENT), in 6.590.
addition words like ADD, SUBTRACT, INITIALIZE are used for addition, 6.591.
subtraction, and initialization, respectively. 6.592.z = x/y Error
6.593.

© 2014- BGS Molyko 65


Stop
Bilingual Grammar School Advanced Level Computer Science

6.594. 6.619. In an assignment statement, the value to the right is assigned to


6.595. the variable in the left.
6.596.
6.597. 6.620. In the case of ∑ a+ b , “ a+b ” is calculated and the
6.598.
result is assigned (kept) in the variable sum.
6.599.
6.600. 6.621. For totaltotal +1 ,“ total+ 1 ” is calculatedand the result
6.601.
6.602. is assigned to the variable total,meaning that the value of total has
6.603. been increased by 1.
6.604.
6.622. E.g. Let total=3
6.605.
3.2. Variables, Constants and Literals
6.606. A variable is an object in a program whose value can be modified 6.623. total total +1 ⇒ total=3+1=4 .
during the execution of the program. In the above flow chart, x, y and z
6.624.
are variables.
6.625. Activity: Complete the table below.
6.607.
6.626.
6.608. A constant is an object whose value cannot be modified in the
6.627. 1.1. 1.2. 1.3. 1.4.
course of the algorithm or program. A constant is given a value that
6.628.
remains the same all through the program.
6.629.
Command x y z
6.609.
6.630.
6.610. Variables and constants are characterized by: 1.5. 1.6. 1.7. 1.8.
6.631.
o an identifier: which is the name of the object
o a value: which is the content of the object
−¿ −¿
3.4. Control
Object 1168

o a type: which defines the domain in which the object gets its value
1.10. Structures
6.611. 1.9. 1.11. 1.12.
6.632. The logic of a
6.612. A literal is anything (numbers or text) that is usually written within x ← x+1 −¿ −¿ program may not
double quotes. For example, “Enter a number”, “The result is”. always be a linear
6.613. 1.14. 1.15. sequence of
1.13. 1.16.
3.3. Basic Instructions statements to be
6.614. Three basic instructions used in an algorithm are input, output and y←1 −¿ executed in that
assignment instructions: order. The logic of
 An input instruction allows information to be typed from the keyboard. 1.17. 1.18. 1.19. 1.20.a program may
Example: read (a, b), get (number) require execution
 An output instruction allows: z ← x+ y of a statement
 display of information on the screen based on a
 printing of information on paper 1.21. 1.22. 1.23. 1.24.
decision. It may
6.615. For example: write “a is greater than b” or print “b is
greater than a” y← z+x repetitively
execute a set of
6.616. statements unless
 The assignment statement allows a value to be assigned to a variable. A or until some condition is met. Control structures specify the
variable can be assigned the content of another variable, a constant, a literal, statements to be executed and their order of execution.
an arithmetic or Boolean expression. The symbol used is . 6.633.
6.617. 3.4.1. Sequential Control

6.618. Examples: z x/ y , ∑ a+b , total total +1 ,


6.634. A sequence control structure executes a set of instructions one
after the other from the first to the last instatement
the order 1they are given.
6.635.
pi3.14 6.636. Syntax: Begin
begin
6.637. statementget 1 a statement 2
6.638. get b
statement 2

c a+b
© 2014- BGS Molyko statement n 66
print “Sum
Bilingual Grammar School Advanced Level Computer Science

6.639. … 6.682.
6.640. statement n 6.683.
6.641. end 6.684.
6.642. 6.685. Explanation If condition1 is true, we move to condition2. If
6.643. condition2 is true, then statement 1 is executed otherwise, statement
6.644. 2 is executed. If condition 1 is false, instruction 3 is executed.
3.4.2. Selection Control Instruction1 or instruction 2 will be executed if and only if condition 1 is
6.645. A selection control structure (condition control structure) chooses true.
the instruction or instructions to be executed based on the validity of a 6.686.
certain condition. Examples are IF and CASE statements. c. The CASE Statement
6.646. 6.687.
b. The IF Statement 6.688. Syntax: case variable of
6.647. Syntax: if condition then 6.689. case 1: statement 1
6.648. statement 1 6.690. case 2: statement 2
6.649. else 6.691. …
6.650. statement 2 6.692. case n: statement n
6.651. 6.693. end case
6.652. 6.694.
statement
6.653. 6.695. Explanation The value of variable is evaluated, if it matches
6.654. with case 1, instruction 1 is executed. If it matches with case 2,
6.655. No1 Yes0
? instruction 2 is executed and so on. CASE is a multiple selection
6.656. structure. It is used when an important number of choices are to be
6.657. considered depending on the value of a variable.
6.658. 6.696.
6.659. statement 1 statement 243
Get a, b
E x.Eyong
6.697.
6.660. 6.698. Get op
6.661. 6.699. caseop of
6.662. 6.700. 1: print a+b
6.663. Explanation Condition is a Boolean expression meaning that it 6.701. 2: print a*b
can take only one of two values true or false. The condition is 6.702. 3: print a/b
evaluated, if it is true, Action3 is executed. If it is false, Action 2 is 6.703. 4: print a-b
executed. 6.704. end case
6.664. Note that actions 2 and 3 could be a block statements. 6.705. Agbor
6.665. 6.706.
Ex.6.666.
4 Get a, b 3.4.3. Repetition Control
6.667.
if (a = 0) then 6.707. The repetition (iteration) control structure executes a statement or
6.668.
Print “Error” group of statements many times until a certain condition is reached.
6.669.
else Repetition structures define the order of operations and the number of
6.670.Print b/a repetitions. They are also called loops. Examples are, the WHILE,
6.671. 2 REPEAT and FOR loops.
6.672. 6.708.
6.673. It is possible to nest many selection structures. a. The WHILE Loop
6.674. 6.709. No
6.675. Syntax: if condition1 then 6.710. Syntax: while condition do ?
6.676. E x.get a, b
if condition2 then 6.711. statement(s);
if a <> 0 then Yes
6.677. statement 1 0 then
if b <> 6.712. end while
6.678. else print b/a 6.713. statement(s)
6.679. statement 2 6.714.
else
6.680. else 6.715.
print “Answer is 0”
6.681. 6.716.
else
print “Error: division by 0”
© 2014- BGS Molyko end statement 67
6
Bilingual Grammar School Advanced Level Computer Science

6.717. 6.758.
6.718. 6.759.
6.719. 6.760.
6.720. 6.761. Remark! The repeat loop must be executed at least once as the
6.721. condition is evaluated only at the end of the loop.
6.722. 6.762.
6.723. c. The FOR Loop
6.724. Explanation The condition is evaluated, if it is true statement(s) 6.763.
is/are executed. Instruction(s) is/are executed as long as condition 6.764. Syntax: for var  low_limit to hi_limit do
remains true. When the condition becomes false, the loop stops. 6.765. statement(s);
6.725. The condition for the loop to stop comprises of a variable called 6.766. end for
control or iteration variable whose value must change at the end of 6.767. Or
each execution of the loop. In the example above, the control variable 6.768. for var  hi_limit downto low_limit do
is “i”. 6.769. statement(s);
6.726. 6.770. end for
Get n
E x.6.727. 6.771.
i1
6.728. 6.772. Explanation var (variable) is given a value low_limit or hi_limit
while (i <= n) do
6.729. depending on the loop, which is automatically incremented or
print “this is a while loop”
6.730. decremented (by 1) after each iteration of the loop. The loop stops
ii + 1
6.731. when low_limit becomes greater than hi_limit. In both cases, if hi_limit
endwhile
6.732. E x. Get
is less than low_limit, n loop body is not executed at all.
the
6.733. 6.773. For i 1 to n do
6.734. 6.774. print “this is a for loop”
6.735. 6.775. end For
6.736. 6.776. Or
6.737. 6.777. Get n
b. The REPEAT Loop 6.778. For i n downto 1 do
6.738. 6.779. print “this is a for loop”
6.739. Syntax: repeat 6.780. end For
6.740. statement(s); 6.781.
statement(s)
6.741. until (condition) 6.782.
6.742. 6.783. Exercise! Exercise! Exercise!
6.743. Yes 6.784.
?
6.744.
1) Write an algorithm that reads a number
n and returns the first
n
6.745.
No
6.746. numbers. n should be a whole number greater than 0.
6.747. statement
6.785.
6.748.
6.749. 2) Write an algorithm that reads a number
n and returns the sum of the
6.750.
6.751. Explanation The statement(s) is(are) executed and the
first n numbers.
condition is evaluated. If it evaluates to false, the statement or set
statements is/are executed again. If condition evaluates to true, the 6.786.
program exits the loop. 3) Write an algorithm to calculate the area of a circle.
6.752. 6.787.
6.753. Get n 4) Write an algorithm to solve a linear equation
6.754. i 1 6.788.
6.755. repeat 5) Write an algorithm that reads a person’s name and sex, and returns the
6.756. print “This is a repeat loop” message “good morning Mr. name” if the person is a man and “Good
6.757. i := i + 1 morning Mrs. Name” for a woman.
until(i <= n)
© 2014- BGS Molyko 68
Bilingual Grammar School Advanced Level Computer Science

6.789.
6.812. 5 !=5 × 4 !
3.5. Recursion
6.790. Some problems are recursive in nature. This means that the
solution to such problems involves the repeated application of the 6.813. …
solution to its own values until a certain condition is reached.
Algorithms for such problems are known as recursive algorithms. 6.814. n !=n×( n−1)!
6.791. A recursive algorithm is an algorithm that calls (invokes) itself
during its execution. Examples are the factorial function and the sum 6.815.
function. 6.816. Factorial is defined recursively as follows:
6.792. Recursion can be defined as the calling of a procedure by itself, 6.817.
creating a new copy of the procedure. 6.818.
6.793. 6.819. Get n
base case
If n=0 or n=1
6.794. 6.820.
6.795. 6.821.
a. Factorial Function 6.822. then
6.796. Factorial is defined as: 6.823. 1!
6.797. 1!=1 6.824.
6.825.
else
6.826.
6.798. 2!=2 ×1=2 6.827. Remark 1! = 1 is known as the base case. Every recursive
problem must always have some base case which can be solved
6.799. 3 !=3 × 2× 1=6 without recursion. For cases that are to be solved recursively, the
recursive call must always make progress towards the base case.
6.800. 4 !=4 ×3 × 2×1=24 6.828.
b. The Sum Function
6.829. The sum function is a function that calculates the sum of the first
6.801. 5 !=5 × 4 × 3× 2× 1=120
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:
6.802. … 6.830.
6.831. Sum(5) = 1+2+3+4+5
6.803. n !=n× ( n−1 ) × ( n−2 ) × …× 2× 1 6.832.
6.833. We can see that for any number n, the sum sum(n), is the number
6.804. n plus the sum of the previous numbers.
6.805. By studying the above equations closely, we see that the factorial 6.834. The sum function can therefore be defined recursively as:
6.835.
of any number n can be calculated by multiplying the number by
6.836. Object 1093

the factorial of the preceding number.


6.806. We therefore have:
6.807. 6.837. ∑ (2)=2+The
∑ (1)base case is

1!=1 n=1 which gives


6.808.
6.838. ∑ (3)=3+ ∑ (2)
6.809. 2!=2 ×1 !
6.839. ∑ (4)=4 + ∑ (3)
6.810. 3 !=3 × 2!
6.840. …
6.811. 4 !=4 ×3 !
6.841. ∑ (n)=n+ ∑ (n−1)
© 2014- BGS Molyko 69
Bilingual Grammar School Advanced Level Computer Science

6.842. 6.879.
6.843. getn a. Bubble Sort
6.844. 6.880. Bubble sort algorithm arranges items in order as follows:
6.845. ∑ 0 - First, examine the first two items in the list. If they are in order, leave them
6.846. alone; if not, interchange them.

if n=1 then
6.847. - Do the same with the second and third items, then with the third and fourth
6.848. items, until you have reached the last two. At this point you are guaranteed
6.849. that the item that should come last in the list has indeed “bubbled” up to that
6.850. ∑ 1 position.
6.851. - Now repeat the whole process for the first (n-1) items in the list, then for (n-2)
6.852. and so on until the list is sorted.
c. The Fibonacci Series 6.881.
6.853. The Fibonacci series is a series in which each number is the sum of 6.882. begin
the two previous numbers in the series. E.g. 0, 1, 1, 2, 3, 5, 8, 13, 21… 6.883. for i = size downto 1 do
6.854.
6.855. The Fibonacci series is defined as follows: 6.884. for j 2 to i do
6.856. 6.885. if (List[j-1] >List[j]) then
6.857. fib (0)=0
6.886. temp List[j-1];

6.858. fib (1)=1 6.887. List[j-1] Object 1145


List[j];

6.859. fib (n)=fib(n−1)+ fib(n−2) 6.888. List[j] temp;

6.860. 6.889. end_if;


fib (0) fib (1) 6.890. end_for;
6.861. and are the base cases. 6.891. end_for;
6.892. end.
6.862.
6.893.
Get n
6.863.
6.894. Example: Sort the list [4, 3, 2, 1]
6.864.
6.895.
6.865. fib 0
6.896. List = [4, 3, 2, 1] size = 4
6.866.
6.897.
6.867.
6.868. if n=0 then
6.898. i = 4 (outer loop, 1st pass)
6.899. j = 2  [4, 3, 2, 1] becomes [3, 4, 2, 1]
6.869.
6.900. j = 3  [3, 4, 2, 1] becomes [3, 2, 4, 1]
6.870. fib 0
6.901. j = 4  [3, 2, 4, 1] becomes [3, 2, 1, 4]
6.871.
6.902.
6.872. else
6.903. i = 3 (outer loop. 2nd pass)
6.873.
6.904. j = 2  [3, 2, 1, 4] becomes [2, 3, 1, 4]
6.874. Exercise! Exercise! Exercise!
6.905. j = 3  [2, 3, 1, 4] becomes [2, 1, 3, 4]
6.875. Write a recursive algorithm to find the greatest common divisor
6.906. i = 2 (outer loop, 3rd pass)
(gcd) of two numbers.
6.907. j = 2  [2, 1, 4, 3] becomes [1, 2, 3, 4]
6.876.
6.908.
3.6. Sort Algorithms
6.909. i = 1
6.877. Sorting is a programming technique which is used to arrange a list
6.910. Internal loop does not execute because j is greater than i.
of pre-stored data in an ascending or descending order according to a
6.911.
preset criterion. There are lots of useful sorting methods. For example:
b. Selection Sort
insertion sort, bubble sort, selection sort, quick sort, merge sort and
6.912. Selection sort arranges the elements of a list by first selecting the
heap sort algorithms.
lowest-valued item, then the next lowest, and so on. In practice, the
6.878.
lowest-valued item is interchanged with the first item in the part of the
© 2014- BGS Molyko 70
Bilingual Grammar School Advanced Level Computer Science

list being searched, and the search is confined to the remainder of the 6.960. while ((j > 1) and (List[j-1] > index)) do
list from then on. 6.961. List[j] List[j-1]
6.913. 6.962. jj - 1
6.914. begin 6.963. end_while
6.915. for i 1to size-1 do 6.964. List[j]  index
6.916. iMini 6.965. end_for
6.917. for j i+1 to sizedo 6.966. end.
6.918. if List(j) < List(iMin) then 6.967.
6.919. iMin j; 6.968. For example:
6.920. end_for 6.969. [4, 3, 2, 1] size = 4
6.921. if m <> i then 6.970. i = 2 index = 3
6.922. temp List(iMin) 6.971. j = 2  [4, 3, 2, 1] becomes [_, 4, 2, 1]
6.923. List(iMin) List(i) 6.972. j = 1  no execution of internal loop
6.924. List(i) temp 6.973. insert index in the place vacated  [3, 4, 2, 1]
6.925. end_if 6.974.
6.926. end_for 6.975. i = 3 index = 2
6.927. end. 6.976. j = 3  [3, 4, 2, 1] becomes [3, _, 4, 1]
6.928. 6.977. j = 2  [3, 4, 4, 1] becomes [_, 3, 4, 1]
6.929. Example: Sort the list [4, 3, 2, 1] 6.978. j = 1  no execution
6.930. 6.979. insert index in the place vacated  [2, 3, 4, 1]
6.931. List = [4, 3, 2, 1] size = 4 6.980.
6.932. 6.981. i = 4 index = 1
6.933. i = 1 iMin = 1 6.982. j = 4  [2, 3, 4, 1] becomes [2, 3, _, 4]
6.934. j = 2  iMin = 2 6.983. j = 3  [2, 3, 4, 4] becomes [2, _, 3, 4]
6.935. j = 3  iMin = 3 6.984. j = 2  [2, 3, 3, 4] becomes [_, 2, 3, 4]
6.936. j = 4  iMin = 4 6.985. j = 1 no execution of internal loop
6.937. 6.986. insert index in the place vacated  [1, 2, 3, 4]
6.938. iMin<> i, so swap item at position iMin (4) and item at position i 6.987.
(1). 3.7. Search Algorithms
6.939. [4, 3, 2, 1] becomes [1, 3, 2, 4] 6.988. A search algorithm is a method of locating a specific item in a
6.940. larger collection of data. They can be used to search for items within
6.941. i = 2 iMin = 2 an array or list. Common search algorithms are sequential search and
6.942. j = 3  iMin = 3 binary search.
6.943. j = 4  iMin = 3 6.989.
6.944. a. Sequential Search
6.945. iMin<> i, so swap item at position iMin (3) and item at position i 6.990. Sequential search is a simple technique for searching an item in a
(2). list by comparing each element with the element searched for,
6.946. [1, 3, 2, 4] becomes [1, 2, 3, 4] beginning with the first element until the element is found.
6.947. 6.991.
6.948. i = 3 iMin = 3 6.992. begin
6.949. j = 4 iMin = 3 6.993. index  1
6.950. 6.994. found  false
6.951. iMin = i, so no swap is done 6.995. while ((not found) and (index <sizeof(List))) do
6.952. 6.996. if List[index] = elemthen
6.953. 6.997. found true
6.954. c. Insertion Sort 6.998. elemPos index
6.955. 6.999. end-if
6.956. begin 6.1000. indexindex + 1
6.957. for i  2 to size do 6.1001. end_while
6.958. index List[i] 6.1002. returnelemPos
6.959. j i 6.1003. end.

© 2014- BGS Molyko 71


Bilingual Grammar School Advanced Level Computer Science

6.1004. 4.1.1. Low-Level Languages


6.1005. For example: search for the 0 in the list [2, 3, 1, 0, 5, 4] 6.1037. A low-level language is a language whose instruction set reflects
6.1006. the processor architecture. An instruction set is the set of bit patterns
6.1007. or binary codes for the machine operations that a processor has been
6.1008. designed to perform. Low-level languages include machine language
6.1009. and assembly language.
6.1010. 6.1038.
6.1011.2 3 1 0 5 4 a. Machine Language
6.1012. 6.1039. Machine language is the computer’s language. It is the language
6.1013. found = false the computer understands. Machine language instructions are written
2≠0
6.1014. index 2 in binary (a series of 0s and 1s), and are directly executable by the
6.1015. computer. Each machine language statement corresponds to one
6.1016.2 3 1 0 5 4 machine action. Machine language is the first generation of
6.1017. programming languages. For example a short (3 instruction) program
found = false
6.1018. might look like this:
6.1019.
3≠0 index 3
6.1040.
6.1020. 6.1041. 0111 0001: 0000 1111
2 3 1 0 5 4
6.1021. 6.1042. 1001 1011: 0001 1010
6.1022. 6.1043. 1110 0001: 0011 1110
found = false
6.1023. 6.1044.
3 ≠ 0 index 4
6.1024. b. Assembly Language
6.1025.2 3 1 0 5 4 6.1045. Assembly language is a low-level language consisting of
6.1026. mnemonic codes and symbolic addresses corresponding to machine
6.1027. found = true language instructions. Assembly language is the second generation of
6.1028. 3=0 elemPos index = 4 programming languages. For example:
6.1029. 6.1046.
b. Binary Search 6.1047. LOAD R0 Number1 Load number1 in register 0
6.1030. Binary search is a more specialized algorithm than sequential 6.1048. LOAD R1 Number2 Load Number2 in register 1
search as it takes advantage of data that has been sorted. The 6.1049. ADD R2 R0 R1 Add register 0 and register 1 and keep
underlying idea of binary search is to divide the sorted data into two result in register 2
halves and to examine the data at the point of the split. Since the data 6.1050.
is sorted, we can easily ignore one half or the other depending on  Advantages of assembly language
where the data we're looking for lies in comparison to the data at the o It is easier to write and understand when compared to machine language.
split. This makes for a much more efficient search than linear search. o It can produce small program sizes
6.1031. o It can produce very fast code as it allows low-level access to hardware
4. Programming features
6.1032. Programming is the activity of writing computer programs. A 6.1051.
computer program is a set of instructions that will be followed by a  Disadvantages of assembly language
computer to perform a computation. These instructions are made up of o Programs are not as easy to write and understand when compared to high
statements written in some languages specially designed for this level languages.
purpose. These languages are called programming languages. o Programs are tied to specific computer hardware and can’t be reused on
6.1033. In other words, a program is an algorithm expressed in a another kind of computer.
programming language. o Writing programs is very time consuming, tedious, and error-prone.
6.1034. 6.1052.
4.1. Programming Languages 4.1.2. High-Level Languages
6.1035. A programming language is a set of predefined words, symbols 6.1053. High-level languages are closer to human language. They allow
and rules that are used to write computer programs. Programming programmers to write programs without having to understand the
languages can be grouped into two: low-level languages and high-level inner workings of the computer. One high-level language statement will
languages. generally be translated into several low-level language statements.
6.1036. They are the third generation of programming languages. Examples

© 2014- BGS Molyko 72


Bilingual Grammar School Advanced Level Computer Science

are C, BASIC (Beginner’s All-purpose Symbolic Instruction Code), 6.1076. Definition: Compilation is the process of translating a program in
Pascal, Java, FORTRAN (Formula Translator) and COBOL (Common one language (the source language) into an equivalent program in
Business-Oriented Language). Below is a small code for adding two another language (the object or target language).
numbers in Pascal and C. 6.1077.
6.1054. 6.1078. The process of compilation is split up into six phases: lexical
6.1055. analysis, syntactic analysis, semantic analysis, intermediate code
Pascal
6.1056. C generation, code optimizing and code generation.
program
6.1057.addition; #include <stdio.h> 6.1079.
uses6.1058.
wincrt; int main() 6.1080.
var 6.1059.
number1, number2, sum: integer;{ int number1, number2, sum; 6.1081.
begin
6.1060. scanf(“%d”, &number1); 6.1082.
read(Number1);
6.1061. scanf(“%d”, &number2); 6.1083.
read(Number2);
6.1062. sum = number1 + number2; 6.1084.
sum6.1063.
:= Number1 + Number2; printf(“%d”, sum); 6.1085.
write(sum);
6.1064. return 0; 6.1086.
end.6.1065. } 6.1087.
6.1066. 6.1088. Source program
6.1067. 6.1089.
 Advantages of high-level languages 6.1090.
o easy to understand and write programs as they are user oriented 6.1091. Lexical analyzer
o they have built in libraries to perform routine tasks 6.1092.
o programs can be ported to multiple hardware setups from same code 6.1093.
6.1094. Syntactic analyzer
6.1068.
 Disadvantages of high-level languages 6.1095.
o programs may be slower than second generation language programs 6.1096.
Semantic analyzer
o may produce larger program files for same functionality as second 6.1097.
Symbol
6.1098. table manager Error handler
generation languages.
o may not allow for low level hardware access 6.1099.
Intermediate code generator
6.1069. 6.1100.
4.2. Language Translators 6.1101.
6.1070. To run a program on a computer, the program needs to be 6.1102.
translated into the machine language of the computer on which it will 6.1103. Code optimizer
run. A language translator is a computer program that translates 6.1104.
program instructions from one programming language to another 6.1105.
without loss of original meaning. There are three types of language 6.1106. Code generator
translators: compiler, interpreter and assembler. 6.1107.
6.1071. 6.1108.
4.2.1. Assembler 6.1109. Target program
6.1072. An assembler translates assembly language into machine 6.1110.
language. The process is called assembling. 6.1111.
6.1073. a. Lexical Analysis
4.2.2. Compiler 6.1112. During lexical analysis, a lexical analyzer (scanner) reads input
6.1074. A compiler translates the entire high-level program into a machine characters from source code and produces a sequence of tokens as
language program. The high-level language program is called source output. A token is a symbolic name for an entity that makes up the text
program or source code and the generated machine language program of the program.
is called object program or object code. This process is called 6.1113. When the lexical analyzer reads the input characters, it groups
compilation. them into lexemes which are then replaced by tokens. A lexeme is a
6.1075. group of characters that matches the pattern for a token. In other
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.

© 2014- BGS Molyko 73


Bilingual Grammar School Advanced Level Computer Science

6.1114. 6.1140.
6.1115. For example: sum := x + 2; 4.2.3. Interpreter
6.1116. 6.1141. An interpreter is a computer program that translates and executes
Lexeme
6.1117. Token instructions written in a high-level language into machine language
6.1118. instructions one line at a time. The interpreter translates an instruction
sum
6.1119. ident(sum) and allows it to be executed before translating the next line. If a
6.1120. program performs a section code 1000 times, then the section is
:=
6.1121. assign_op translated into machine code 1000 times since each line is interpreted
6.1122. and then executed.
x
6.1123. ident(x) 6.1142.
6.1124.  Advantages of an Interpreter
+
6.1125. bin_op o It is good at locating errors in programs
6.1126. o Debugging is easier since the interpreter stops when it encounters an error.
2
6.1127. integer o If an error is corrected, there is no need to retranslate the whole program
6.1128. 6.1143.
;
6.1129. semicolon
 Disadvantages of an Interpreter
6.1130. o It is slow as interpretation and execution is done line by line.
6.1131. Lexical analysis performs the following: o Translation has to be done every time the program is to be executed since
o Divides the character stream into meaningful sequences called lexemes. no object code is produced.
o Labels each lexeme with a token that is passed to the parser (syntax analysis) o For the program to run, the interpreter must be present
o Updates the symbol tables with all identifiers (and numbers) 6.1144.
o Removes non-significant blanks and comments 4.3. Program Errors and Correction
6.1132. 4.3.1. Syntax Errors
b. Syntactic analysis 6.1145. Syntax is the set of rules that specify how the symbols of a
6.1133. Syntactic analysis determines how the tokens retuned by the language can be put together to form meaningful statements. In other
lexical analyser should be grouped and structured according to the words, syntax defines the structure of legal statements in a language.
syntax rules of the language. A syntax error is an error in a program that occurs due to the non-
respect of the syntax rules of the language used. A syntax error will
6.1134. converts a token stream, from lexical analysis, to an abstract cause a compiler/interpreter to stop trying to generate machine code
syntax tree. The syntactic analyzer (parser) and will not create an executable. However, a compiler will usually not
stop at the first error it encounters but will attempt to continue
c. Semantic analysis checking the syntax of a program right to the last line. For example, a
6.1135. misspelled key word, a missing punctuation mark or the incorrect use
d. Intermediate code generation of an operator is a syntax error.
6.1136. 6.1146.
e. Code optimizing 4.3.2. Semantic Errors
6.1137. 6.1147. Semantics specify the meaning of a well-formed program. A
f. Code Generation semantic error occurs when you write a program that works, but does
6.1138. not do what you intend it to do. Compilation and interpretation do not
 Advantages of a Compiler detect semantic errors. Semantic or logic errors are detected from
o Fast in execution wrong results. Something may be syntactically correct but semantically
o The object code produced by a compiler can be distributed or executed incorrect.
without having to have the compiler present. 6.1148.
o The object program can be used whenever required without the need of 4.3.3. Run-time Errors
recompilation. 6.1149. A run-time error is an error that occurs during program execution.
6.1139. For example, a run-time error may occur if division by 0 is attempted. A
 Disadvantages of a Compiler run-time error may cause the program to stop execution, or it may be
o Debugging a program is much harder. Therefore not so good at finding handled by an error-trapping routine.
errors 6.1150.
o When an error is found, the whole program has to be re-compiled

© 2014- BGS Molyko 74


Bilingual Grammar School Advanced Level Computer Science

4.3.4. Debugging 6.1168. date birthdate;


6.1151. An error in a computer program is known as a bug. Debugging is 6.1169. public:
the process of detecting and removing bugs. Syntax errors and 6.1170. updateInfo();
semantic errors are bugs. A debugger is the software tool used for this 6.1171. returnAge();
purpose. 6.1172. };
6.1152. 6.1173.
4.4. Programming Paradigms 6.1174. The name of the class is person. It has four instance variables
6.1153. A programming paradigm (or technique) is a fundamental style of (attributes) name, sex and age, and three methods: updateInfo(),and
computer programming. It describes a programming language’s returnAge(). These methods act on the instance variables when
approach to solving a problem. Paradigms differ in the concepts and invoked.
abstractions used to represent the elements of a program and the 6.1175.
steps that compose a computation. High level languages can be b. Object
classified under four different paradigms: procedural, functional, 6.1176. An object is an instance of a class. An object consists of a
object-oriented and declarative paradigms. collection of attributes, representing the state of the object, and a
6.1154. collection of methods, representing the behavior that the object is
4.4.1. Procedural Paradigm capable of performing. Attributes are sometimes referred to as the
6.1155. In the procedural/imperative paradigm, a program is a collection of fields of an object. The methods are routines that are capable of
statements and procedures that affect data. Here, a program can be accessing and manipulating the values of the attributes of the object.
seen as an active agent that manipulates passive objects (variables). Objects interact with each other by sending messages. When a
These objects are passive because they cannot initiate an action by message is sent to an object, the corresponding method of the object
themselves, but can only receive actions from active agents. The focus is executed.
in procedural programming is to write good functions and procedures. 6.1177.
6.1156. Examples of imperative languages are Pascal, C, Ada, FORTRAN, c. Abstraction
and COBOL. 6.1178. Abstraction is the process of representing important details and
6.1157. hiding away the implementation details. Through abstraction
4.4.2. Object Oriented Paradigm unnecessary details are removed so that one can focus on only the
6.1158. The object-oriented paradigm presents a program as a collection relevant parts of a problem in order to solve it. Abstraction is obtained
of classes for interacting objects. Unlike in imperative programming, by separating the interface and the implementation. For example,
object-oriented programming deals with active objects instead of functions use the concept of abstraction.
passive objects. These objects are active because the actions to be 6.1179.
performed on the objects are included in them (the objects). The 6.1180. The following are the advantages of abstraction.
objects need only to receive the appropriate stimulus from outside to o The programmer does not have to write the low-level code.
perform one of the actions. o The programmer does not have to specify all the register/binary-level steps or
6.1159. Examples of object-oriented languages are C++, Java, Visual Basic care about the hardware or instruction set details.
and Smalltalk. o Code duplication is avoided and thus programmer does not have to repeat
6.1160. Some important concepts related to object oriented programming fairly common tasks every time a similar operation is to be performed.
(OOP) are: class, object, abstraction, encapsulation, inheritance and o It allows internal implementation details to be changed without affecting the
polymorphism. users of the abstraction.
6.1161. 6.1181.
a. Class d. Encapsulation
6.1162. A class is a description of an object or a real life concept. Classes 6.1182. Encapsulation is the process of combining together the attributes
are templates for creating objects, providing initial values for instance and methods of a class into a single abstract data type with a public
variables (attributes) and the bodies for methods. All objects generated interface and a private implementation. The goal of encapsulation is to
from the same class share the same methods, but contain separate protect the implementation from the users of the object. It ensures that
copies of the instance variables. New objects can be created from a all access to the internal representation of the object pass through the
class by applying the new operator to the name of the class. class methods, which act as an "interface" to the object. This is done
6.1163. by making properties and methods “private.”
6.1164. Class Person { 6.1183.
6.1165. private: e. Inheritance
6.1166. char name[20]; 6.1184. Inheritance is the derivation of one class from another so that the
6.1167. char sex; attributes and methods of the derived class are part of the definition of
© 2014- BGS Molyko 75
Bilingual Grammar School Advanced Level Computer Science

the initial class. The initial class is often called the base class, parent it is the ability for different objects to respond to the same message in
class or super class while the derived class is often referred to as the different, class-specific ways. Polymorphic methods are used which
child class or sub-class. The subclass usually contains all the attributes have one name but different implementations for different classes.
and methods of the superclass plus some of its own. 6.1223. Assume you have a “shape” super class. This class has a method
6.1185. For example: the class Student inheriting from the class person called “area” which returns the area of the shape. Polymorphism
will have all the attributes and methods of Person plus the following: allows you to make subclasses like “circle,” “square,” and “triangle”
6.1186. which inherit the “area” method, but each subclass would return the
6.1187. Class Student extends Person { correct value even though they have different formulas to calculate
6.1188. private their areas.
6.1189. int admNumber; 6.1224.
6.1190. int level; 4.4.3. Functional Paradigm
6.1191. public 6.1225. In functional (applicative) programming, a program is a collection
6.1192. changeLevel(int newLevel) { of function definitions. Lambda calculus forms the basis of almost all
6.1193. level=newLevel; functional programming languages. Lambda calculus is the use of
6.1194. } lambda expressions to define functions. A lambda expression is a
6.1195. }
6.1196. formula that defines a function. For example: f ( x)=x +2
6.1197. Inheritance is usually represented using an inheritance diagram.
6.1226. Examples of functional languages are Haskell, LISP, ML and
6.1198. For example: if the classes Student and Teacher are derived from
the superclass Person, this is represented as: Scheme.
6.1227.
6.1199.
6.1200. 6.1228. Sum function in Haskell
Person Person 6.1229.
6.1201.
6.1202. ,6.1230.
∫∫ ¿→ ¿∫
6.1231.
6.1203.
Student Teacher
add ::¿
6.1232.
6.1204.
6.1233. Quick sort in Haskell
6.1205. There are two types of Inheritance: multiple inheritance and
multilevel inheritance. 6.1234. f ::[ a]→[a]
6.1206.
 Multiple inheritance is when a derived class inherits features from more
6.1235. f []=[ ]
than one superclass. It is illustrated as follows:
6.1207.
6.1208. Base class 1 Base class 2 6.1236. f (x : xs)=fys++[x ]++ fzs
6.1209.
6.1210. 6.1237. Where
6.1211. Derived class 6.1238.
ys=[a∨a ← xs , a ≤ x ]
6.1212.
 Multi-level inheritance is when a class inherits from a class which is itself
6.1239.
zs=[b∨b ← xs , b> x ]
inherited from another class. It is illustrated as follows:
6.1213.
6.1240.
6.1214. Base class 4.4.4. Declarative Paradigm
6.1215.
6.1241. In declarative (logic) programming, a program is a collection of
6.1216.
facts and rules involving relational expressions. Declarative paradigm
6.1217. Derived class uses the principle of logical reasoning to answer queries. It is based on
6.1218.
1 formal logic defined by Greek mathematicians and later developed into
6.1219.
first-order predicate calculus. The point of logic programming is to
6.1220.
Derived class bring the style of mathematical logic to computer programming. An
6.1221.
2 example of a declarative programming language is PROLOG
f. Polymorphism
(programming logic).
6.1222. Polymorphism is the use of different methods, each with the same
6.1242.
name, which are associated with different object types. In other words,

© 2014- BGS Molyko 76


Bilingual Grammar School Advanced Level Computer Science

6.1243. These facts are given: 6.1248. ?-mortal (John)


6.1244. human (John) 6.1249.
6.1245. mortal (human) 6.1250. The program answers yes.
6.1246. 6.1251.
6.1247. The user asks the following question:
6.1252. CHAPTER 7: COMPUTATIONAL COMPLEXITY THEORY executed n + 1 times (one additional check is required), and statement
6.1253. 8 is executed once. The running time T(n) of this algorithm is given as
6.1254. Introduction follows:
6.1255. There may be several different methods for solving a particular 6.1274.
problem. How can one decide which method is the best in a certain 6.1275.
situation? How would one define "best" – is it the fastest method or 6.1276.
the one that takes up the least amount of memory space? 6.1277.
6.1256. Understanding the relative efficiencies of algorithms designed to 6.1278.
do the same task is very important in every area of computing. 6.1279.
6.1257. 6.1280.
1. Computational Complexity 6.1281.
6.1258. Complexity theory is the mathematical study of the time and 6.1282.
amount of memory needed to perform a computation. The goal of 6.1283.
computational complexity is to classify algorithms according to their 6.1284.
performances. 6.1285.
6.1259. The efficiency of an algorithm can be measured in terms of: 6.1286.
 The execution time (time complexity) 6.1287.
 The amount of memory required (space complexity). T (n)=1+1+1+n+1+n+n+ n+1=4 n+5
6.1260. 6.1288.
1.1. Time Complexity
6.1289.
6.1261. Time complexity is a measure of the amount of time required to
1.1.1. Big-O Notation
execute an algorithm. It is expressed as the number of times the
6.1290. Big-O notation also called Landau's symbol, is a symbolism used to
algorithm’s basic operations are executed on inputs of size n. Time in
describe the asymptotic behavior of functions. Basically, it assesses by
seconds is not used because there are too many factors that can vary
what factor execution time increases when the size of the input is
e.g. computer speed.
increased. The letter O is used because the rate of growth of a function
6.1262. As an illustration,
is also called its order of growth.
1.26. consider a pseudo code
6.1291. For example, let’s suppose that the execution time for an
Numbe algorithm that calculates
1.25.
r of the mean (average) of a algorithm of input size n is given by:
1.27. set of n numbers:
St
6.1263. times 6.1292.
exe
6.1264.
cut
1. n = read input from user
6.1293. T ( n )=4 n2−2 n+2
6.1265. 2. sum = 0
6.1266. ed 3. i = 0
1.28. 1.29. 6.1294.
6.1267. 4. while(i<n)
1 1 6.1295. Ignoring constants as they depend on the particular hardware the
6.1268. 5. number = read input from user
1.30. 1.31. program is running on, and slower growing terms, we could say "T(n)
6.1269. 6. sum = sum + number
2 1
6.1270.
1.32. 1.33.
7. i = i + 1
grows at the order of n2 " and write:
6.1271. 8. mean = sum / n
3 1
6.1272. 6.1296.
1.34. 1.35.
6.1273. Statements 1, 2, and
4 n+1
3 are each executed once. 6.1297. T (n)=O(n2 )
1.36. 1.37.
Statements 5, 6, and 7 are
5 n 6.1298.
1.38. 1.39. each executed n times.
6 n Statement 4 (which
1.40. 1.41. controls the loop) is
7
© 2014- BGS Molyko n 77
1.42. 1.43.
8 1
Bilingual Grammar School Advanced Level Computer Science

6.1299. This simply means that if the input size (n) doubles, the algorithm 6.1313. An algorithm is said to run in logarithmic time if its execution time
takes four times longer to execute and the order of growth is said to be is proportional to the logarithm of the input size. An example is binary
quadratic. search.
6.1314.
6.1300. Some programs perform the same number of operations every 6.1315. Remark! Big-O expressions do not have constants or low-order
time they are executed while others may perform different numbers of
operations, depending on the value of a parameter. terms. This is because, when n gets large enough, constants and

6.1301. Suppose a computer is going to process n items of input. The low-order terms don't matter.
6.1316. A constant-time algorithm will be faster than a linear-time
time complexity of the calculation may be any of the following: algorithm, which will be faster than a quadratic-time algorithm.
6.1302. 6.1317.
a. Constant Time or O(1) 6.1318. Formally, the time complexity of an algorithm is of the order f(n)
6.1303. An algorithm is said to run in constant time if the computation 6.1319.
takes the same number of steps regardless of how many items are to 1.1.2. Best Case, Worst Case and Average Case
be processed. For example storing and retrieving array elements. 6.1320. Some algorithms perform differently on various inputs of similar
6.1304. size. It is sometimes helpful to consider the Worst-Case, Best-Case, and
b. Linear Time or O(n) Average-Case efficiencies of algorithms. For example, say we want to
6.1305. An algorithm is said to run in linear time if its time of execution search an array A of size n for a given value K.
(number of steps) is directly proportional to the input size n. That is,  Best Case: K is the first item that we check, so only one comparison.
time grows linearly as input size increases. An example would be
finding the sum of n numbers, or any program that contains only one  Worst Case: K is not in the array, then we must search every item ( n
loop.
6.1306. comparisons)
2  Average Case:
c. Quadratic Time or O( n ¿ 6.1321.
6.1322. Exercise! Exercise! Exercise!
6.1307. An algorithm is said to run in quadratic time if its execution time is 6.1323.
proportional to n squared. For example, if the computation involves
1. The big-O notation is often used to describe the efficiency of an algorithm.
comparing each item of input with all of the other items, it will take 6.1324.
n2 steps. Many sorting algorithms are O( n2 ).
6.1325. (a) Place the following algorithms in order of efficiency, the most
efficient first.
6.1308. 6.1326.
k 6.1327. Algorithm A that is O(n)
d. Polynomial Time or O( n ) 6.1328. Algorithm B that is O(aⁿ)
6.1329. Algorithm C that is O(n²) (1 mark)
6.1309. An algorithm is said to run in polynomial time if its execution time 6.1330.
is proportional to n raised to some constant power. A program that 6.1331. (b) Describe a linear search and explain why it is O(n).
contains k nested loops, each with a number of steps proportional to n,
(4 marks)
will take time proportional to nk . 6.1332.
6.1333. (c) Describe a bubble sort and explain why it is O(n²).
6.1310. 6.1334. (4 marks)
e. Exponential Time or O( kn ) 6.1335.
1.2. Space Complexity
6.1311. An algorithm is said to run in exponential time if its execution time 6.1336. Space complexity is essentially the amount of memory (number of
is proportional to some constant k raised to the nth power. cells) which a program needs to execute. A good algorithm keeps this
Exponential-time computations are generally not practical. number as small as possible.
6.1312. 6.1337.
f. Logarithmic Time or O(log n) 6.1338.

© 2014- BGS Molyko 78


Bilingual Grammar School Advanced Level Computer Science

2. Computability
6.1339. Computability deals with whether a problem can be solved at all,
regardless of the resources required.
6.1340.
2.1. Turing Machines
6.1341. 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.
6.1342. 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.
6.1343.

6.1344.
6.1345.
6.1346. Formally, a TM is defined as:
6.1347. TM = <S, T, s0, d, H> where,
6.1348. S is a set of TM states
6.1349. T is a set of tape symbols
6.1350. s0 is the start state
6.1351. H ⊂ S is a set of halting states
6.1352. d : S x T ⟶ S x T x {L,R} is the transition function
6.1353.
6.1354. A TM begins computation at state s0. At each computational step,
it reads the present tape symbol, changes its internal state, optionally
writes another symbol onto tape, and moves one cell to the left or right
in the tape.
6.1355. The TM halts computation (and accepts the input string) when it
reaches one of the halt states in H.
6.1356.
2.2. The Church-Turing Thesis
6.1357.
6.1358.
3. Computable Functions
6.1359. A function is computable if it can be computed by a Turing
machine.
6.1360.
4. Decidability
5. The Halting Problem
6.1361.

© 2014- BGS Molyko 79

You might also like