A-Level Computer Science
A-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.
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.
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) =
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
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.
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
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
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.
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
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)
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.
1
Object 62
,
This means that there are 1 ones, 0 twos, 1 fours, and 1 eights in the number
1 . 0
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
Therefore, 1 −¿
© 2014- BGS Molyko 11
Bilingual Grammar School Advanced Level Computer Science
111×101=100011 7 ×5=35
−¿ ii.
……………… (
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 )
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.
Example 2: Convert
450 8 to binary
Binary Octal Binary Octal
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)
Example 2: Convert
10111012 to base 8
Binary Hexadecimal Binary Hexadecimal
0000 0 1000 8
10111012 =001 011101
0001 1 1001 9
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
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
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
Example 2: Suppose n=8 and the binary representation 10001001 . i) 0010 0001 .
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
(14) 00001110
Example 2: Give the decimal equivalent of the following 1’s complement binary
representations.
⇒−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.
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 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.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
−15.375 is represented as
110010 11101010
b. 10111010000000
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.
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 ©.
1010−101=101 | A + Á=1 ¿ B+ AC (
AB+ B=B )
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)
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
0 1 1 0 1 1 1 1
c. NOT Gate
1 0 0 Object 838 Object 839
1 0
© 2014- BGS Molyko 21
Bilingual Grammar School Advanced Level Computer Science
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."
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
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.
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.
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.
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)
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.
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
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.
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
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
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
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.
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.
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
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.
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?
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
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
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.
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,
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.
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
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
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.
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
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
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.
- 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.
(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.
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
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:
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
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
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.
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
4.1.1. Tables
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.
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.
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.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 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
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
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];
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. jj - 1
6.914. begin 6.963. end_while
6.915. for i 1to size-1 do 6.964. List[j] index
6.916. iMini 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. indexindex + 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.
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.
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
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,
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.
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.