A Level Computer Science 1 1
A Level Computer Science 1 1
CHAPTER 1: COMPUTER ORGANISATION AND ARCHITECTURE Function keys, labeled F1-F12, perform specific functions based on the software used. F1 for
example is used in most software to display help.
Introduction Alphabetical keys
The term computer is derived from the word “compute” which means “to calculate.” This simply Numerical keys
means that the computer is a calculating machine. Every thousandth of a second or so, a computer Navigation keys also called direction keys are used to navigate through documents and
performs thousands, millions, or even billions of simple arithmetic operations in order to carry out websites. Examples of navigation keys are the up, down, left and right arrows.
its tasks. Action keys
Formally, a computer is defined as an electronic device that can accept, store and process data to
produce information. It can also be defined as a machine that can accept instructions and perform The way keys are arranged on a keyboard is known as the layout of the keyboard. There are
computations based on those instructions. different keyboard layouts but the best known are QWERTY mainly used by English speakers and
The term computer organization refers to the physical organization of the components in a AZERTY used by French speakers. Another keyboard layout modified greatly from a standard layout
computer system, and to the characteristics of those components. It includes the high-level aspects is DVORAK, devised to increase typing speed by placing frequently used keys more naturally.
of a computer’s design, such as the memory system, the memory interconnect, and the design of the A keyboard connects to the computer through cable PS/2 cable, USB cable or wireless (cordless).
internal processor or CPU.
1.1.2. Mouse
1. Hardware A mouse is a handheld device which is moved across a flat surface to control the movement of a
Hardware refers to the physical and tangible components of the computer like the keyboard, mouse, cursor or pointer on the computer screen. It is a pointing device. A standard mouse has two buttons,
monitor and internal circuits. Computer hardware components can be grouped into five functionally the right and the left buttons, which are pressed to enter commands into the computer.
independent main units: input, control, arithmetic and logic, memory and output units. Different actions that can be performed with a mouse are:
The input unit accepts coded information from human operators using devices such as keyboards, Click: Pressing the left mouse button. This action can be used to select objects (files, folders,
or from other computers over digital communication lines. The information received is stored in the commands) or options in a menu.
computer’s memory, either for later use or to be processed immediately by the arithmetic and logic Double-click: Pressing the left button two times in quick succession. It can be used to open
unit. The processing steps are specified by a program that is also stored in the memory. Finally, the a file, folder or program.
results are sent back to the outside world through the output unit. All of these actions are Right-click: Pressing the right mouse button. A right-click opens a context menu from
coordinated by the control unit. which options like cut, copy and paste can be selected.
Drag and drop: Pressing the left mouse button and moving the mouse while holding, is a
Processing Unit drag while releasing the left mouse button after a drag is a drop. Drag and drop can be used
to move files or documents from one place to another, and to select text.
Control Unit
Input Unit Output Unit A mouse connects to a computer through PS/2 cable (PS/2 mouse), USB cable (USB mouse), or
wireless (optical mouse).
Arithmetic
Logic Unit
1.1.3. Scanner
A scanner is a device that is used to input printed images such as photographs or pages of text
Memory Unit directly into the computer. It converts hardcopy information into electronic form (softcopy) for
storage in the computer. A scanner works by shining a light at the image being scanned and
Functional Units of a Computer measuring how much light is reflected back using an optical sensor. The amount of light
that is reflected back tells the computer how light or dark the image is at each point.
Common scanner devices are the flatbed scanner, optical mark reader, optical character reader,
1.1. Input Unit
barcode reader and magnetic ink character reader.
The input unit consists of hardware components that allow the computer user to enter data and
commands into the computer. These components are called input devices. Examples of input
a. Flatbed Scanner
devices are keyboard, mouse, scanner, joystick, light pen, touchpad, tracker ball and microphone.
A flatbed scanner is a scanner in which the object to be scanned is placed flat against a piece of glass.
When the object is placed, the scanner moves the light and sensor itself and scans the whole
1.1.1. Keyboard
The keyboard is the standard input device attached to computers. It is a device with keys that are image automatically. Most flatbed scanners are A4 size
pressed to enter data and commands into the computer. These keys represent letters, numbers,
symbols and control characters. When a key is pressed, a number (code) representing each b. Optical Mark Reader (OMR)
c. Optical Character Reader (OCR)
character, is sent to the computer to tell it which key has been pressed. The keyboard has a
d. Barcode Reader
total of 101-104 keys divided into different groups or keypads.
Question: What are the advantages and disadvantages of impact and non-impact printers?
© 2014- BGS Molyko 2
Bilingual Grammar School Advanced Level Computer Science
3. The arithmetic-logic unit then executes the instruction on the data. That is, the ALU is given meaning that everything held in it is lost when power is switched off. Two types of RAM exist: Static
control and performs the actual operation on the data. RAM and dynamic RAM.
4. The arithmetic-logic unit stores the result of this operation in memory or in a register.
Dynamic RAM (DRAM) consists of capacitors that slowly leak their charge over time. Thus,
they must be refreshed every few milliseconds to prevent data loss. DRAM is cheap memory
owing to its simple design.
Static RAM (SRAM) consists of circuits that retain their charge over time. SRAM is faster and
more expensive than dynamic RAM, and does not need to be refreshed as DRAM does. Due to
The Instruction Cycle its cost it is not used as main memory but rather to build cache memory. also used in registers
Steps 1 and 2 together are called instruction time or I-time and steps 3 and 4 together are called b. Read Only Memory
execution time or E-time. The combination of I-time and E-time is called the machine or instruction Read only memory (ROM) is a kind of memory whose contents can only be read by the computer.
cycle or the fetch-decode-execute cycle. The length of time taken to fetch, decode and execute an Data found in ROM is written by the manufacturer and cannot be modified by the user. ROM is
instruction is measured in clock cycles. useful for holding data that never changes like the “boot” or start-up program which is run when the
computer is switched on.ROM is non-volatile meaning that its content is preserved even without
1.3.5. System Clock power. There are four types of ROM:
The CPU has a small quartz crystal circuit called the system clock that controls the timing of all
computer operations. The system clock generates regular electronic pulses, or ticks, that set the Masked ROM is ROM programmed with its data when the chip is fabricated.
operating pace of components of the system unit. Each tick is known as clock cycle and the pace of Programmable ROM (PROM) is ROM that can be programmed once but not reprogrammed.
the system clock is called clock speed. Clock speed is measured in megahertz (Mhz) or gigahertz Erasable Programmable ROM (EPROM) is ROM that can be erased by strong ultraviolet light
(Ghz) and refers to the number of clock cycles per second that the CPU runs at. Mega and giga stand and new data burnt into it. To do this the chip has to be removed from the machine and put
for million and billion respectively while hertz means cycles per second. Thus, 1Ghz means one back after the changes have been made.
billion cycles per second. A computer that operates at 3 Ghz has 3 billion (giga) clock cycles in one Electrically Erasable Programmable ROM (EEPROM) is ROM whose content can be erased
second (hertz). electrically. In this case, the chip need not be removed from the machine. The programming is
The faster the clock speed, the more instructions the processor can execute per second. The speed done using special software.
of the system clock has no effect on devices such as a printer or disk drive. The speed of the system
clock is just one factor that influences a computer’s performance. Other factors, such as the type of c. Cache Memory
processor chip, amount of cache, memory access time, bus width, and bus clock speed. Cache memory is a smaller and faster memory between the CPU and main memory, which stores
copies of data from the most frequently accessed memory locations. The purpose of cache memory
1.4. Memory Unit is to speed up accesses by storing recently used data closer to the CPU, instead of storing it in main
The memory unit, also called storage unit, consists of computer components that hold programs and memory. Cache is static RAM and is usually organized in levels:
data for use in the computer. Memory or storage devices hold programs and data that can be made Level 1 (L1) cache, Level 2 and Level 3 cache.
available for initial or additional processing when required. A storage device is made of two parts: Level 1 cache is closest to the CPU or within it.
the storage medium and the device. L2 and L3 caches are outside it.
The medium is the surface or substrate that holds actual data
The device reads information from or stores information onto the medium When the CPU needs to access memory, cache memory is examined first. If the data is found in
cache, it is read from it. Otherwise, main memory is accessed. When the CPU refers to memory and
Computer storage can be classified basically into two: primary storage and secondary storage. finds the data in cache, it is said to be a HIT. Otherwise, it is a MISS.
Floppy Disk o CD-R stands for compact disc recordable. It is a type of CD that can be recorded by the
A floppy disk consists of a round flexible plastic disk coated with a magnetic substance and user. Once the user records on the CD, the content is set and cannot be changed. CD-R can
protected by a plastic cover lined with a soft material that wipes the disk clean as it spins. The disk be read by CD-ROM drives but to write on them, you need a CD-R drive.
is made of two recordable surfaces which are divided into a number of circular paths called tracks. o CD-RW stands for compact disc rewritable. It is a type of CD that can be recorded, erased
The number of tracks per surface varies with the particular type of disk. Each track is in turn and reused by the user. CD-RW cannot be read by a CD-ROM and CD-R drives. CD-RW
divided into a number of smaller units called sectors. A sector is the basic unit of storage on the disk drives are required to read and write on them.
and has a capacity of 512 bytes.
Digital Versatile Disc (DVD)
Hard Disk A DVD is similar to a CD in size and thickness but has a higher storage capacity than the CD. DVDs
A hard disk consists of several metallic platters which store data. Each platter has two sides and is use a laser beam of wavelength shorter than used by CDs. This allows for smaller indentations and
divided into a number of rings called tracks. Tracks on a platter are numbered 0 from the outside increased storage capacity. Just like the CD, different ions of the DVD exist: DVD-ROM, DVD-R and
and usually go up to 1023. Each track is divided into sectors. A sector is the basic unit of storage on DVD-RW. A DVD can store up to 17GB of data. Common DVD storage capacities are:
the disk and has a capacity of 512 bytes. Sectors are grouped together to form clusters. A cluster is
the smallest logical amount of disk space that can be allocated to hold a file. A cylinder is a sum set Types Characteristics Capacity
of all the tracks on all the platters that have the same track value. DVD-5 Single-sided, Single-layer 4.7GB
Factors that determine the performance of hard disks are, seek time and drive rotational speed. DVD-9 Single-side, Dual-layer 8.5GB
o Seek time is the time taken to move the read/write head over the right track and sector. DVD-10 Double-side, Single-layer 9.4GB
o Drive rotational speed is the total number of revolutions the disk platters make per DVD-18 Double-side, Dual-layer 17.1GB
minute. Higher rotational speed leads to higher transfer rate.
Blu-Ray Disc
A Blu-ray disc is an optical disc similar to a DVD and of same size, but read and written with a blue
or violet laser, whose shorter wavelength makes a higher data density possible. Blu-ray discs can
hold 25 GB for single layer or 50 GB for double layer.
The capacity of a storage device is the maximum amount of data that can be stored on the device’s Examples are RAM, Flash memory, CD-RW, DVD-RW. Those that can be accessed only for reading
medium. It is expressed in terms of the number of data bytes the device can hold. This simply means are immutable (read only). Examples are ROM, CD and DVD.
the unit of measurement of storage capacity is byte. Units of storage are summarized as follows:
1.4.4. Memory Hierarchy
1 bit = 0 or 1 Modern computers manage memory by organizing memory into a hierarchy in which large and
4 bits = 1 nibble slower memories feed data into smaller but faster memories for faster processing of data. This
8 bits = 1 byte 1 character organization of computer memory is known as memory hierarchy. At the top of the hierarchy are
1024 bytes = 1 kilobyte (KB) approx. 1/2 page the CPU registers followed by cache memory. The next level in the hierarchy is made up of main
1024 KB = 1 megabyte (MB) approx. 500,000 pages memory, which is followed by magnetic disk.
1024 MB = 1 gigabyte (GB) approx. 5 million pages
1024 GB = 1 terabyte (TB) approx. 5 billion pages Registers
Cache Memory
b. Access time
Access time is the average time taken for a storage device to search and read required data on its Faster and Main Memory
Slower and
medium. In other words, it is how fast data can be read from or written to a memory device’s smaller in size
Magnetic Disk larger in size
medium. It is measured in seconds. Units of time are summarized as follows:
Millisecond (ms) = Optical Disc/Solid State Devices
Microsecond (µs) =
Magnetic Tape
Nanosecond (ns) =
Picoseconds (ps) =
Femtoseconds (fs) = Memory hierarchy
c. Access Method
An access method is the technique used to retrieve information from or store information to a 1.5. The Motherboard
medium. Storage media can be accessed in two ways: sequentially or randomly. The motherboard is the main printed circuit board in the computer which holds the chipset and
other electronic components that give function to the computer. The motherboard is indispensable
Sequential Access to the computer and provides the main computing capability.
The medium is accessed by proceeding from the beginning of the medium until the designated area
is reached. Any new data is stored in the next available space on the medium. To read any data 1.5.1. Motherboard Form Factor
stored on the medium, the device has to start from the beginning going through each data until the Motherboard types are better described by what we call the motherboard form factor. The form
required data is found. An example of sequential access medium is magnetic tape. factor of a motherboard determines the specifications for its general shape and size. It also specifies
what type of case and power supply will be supported, the placement of mounting holes, and the
Random Access physical layout and organization of the board. The most common form factors found in modern PCs
Random access means that any location in storage can be accessed at any moment in approximately are:
the same amount of time. Data is accessed in any order, regardless of its location on the medium. To Advanced Technology (AT)
read any data stored on the medium, the device does not need to go through all preceding data. It is Advanced Technology Extended (ATX)
also called direct access. Examples of direct access devices are RAM, ROM, CDs, DVDs and magnetic Low Profile Extension (LPX)
disks. New Low profile Extended (NLPX)
This means that the data bus is bidirectional. The size of the data us determines how much data can o VESA: Video Electronics Standard Architecture
be transferred in a single operation. o SIMM: Single Inline Memory Module
o DIMM: Dual Inline Memory Module
b. The Address Bus o PCMCIA: Personal Computer Memory Card International Association
The address bus carries address information from the CPU to main memory or peripherals. It is
unidirectional. The CPU uses the address bus to send the address of the memory location to be 2. Computer Architecture
written to or read from. Also, when the CPU reads data from or writes to a port, it sends the port Computer architecture refers to those attributes of a system that have a direct impact on the logical
address out on the address bus. The size of the address bus determines the maximum amount of execution of a program like the instruction set, the number of bits used to represent various data
main memory (RAM) that can be addressed. A computer with a 32 bit bus size can address a types, I/O mechanisms and techniques for addressing memory.
maximum RAM of 232 bits = 4GB.
2.1. The Von Neumann Architecture
c. The Control Bus The term Von Neumann computer in its strictest definition refers to a specific type of computer
The control bus is used by the CPU to send out signals to enable the outputs of addressed memory architecture in which instructions and data are stored together in a common memory. This type of
devices or port devices. Typical control bus signals are memory read, memory write, I/O read and architecture is distinguished from the Harvard architecture in which separate memories are used to
I/O write. store instructions and data. It is a stored-program computer model that was designed by the
Hungarian born Mathematician, John Von Neumann. It is based on three concepts:
When the CPU wants to read data from a memory location, it sends out the memory address of the o Both data and instructions (programs) are stored in a single storage structure called
desired data on the address bus and then sends out a Memory Read signal on the control bus. The memory
memory read signal enables the addressed memory device to output the data onto the data bus. The o The contents of this memory are addressable by location, without regard to the type of
data from the memory travels along the data bus to the CPU. data contained there.
o It has a single processing unit which is. As such, execution occurs in a sequential fashion
1.5.3. Input/Output Interfaces from one instruction to the next.
The CPU communicates with I/O devices through bus interfaces connected to the system bus. These
bus interfaces also called expansion buses are then connected to ports which allow the exchange of Programs being stored in memory ensures that by altering the stored program, the computer can
data and information between the computer and external (peripheral) devices. perform a different task – reason why a computer is called a general purpose machine.
Neumann divided the computer into four functional units: input, processing, storage and output.
a. I/O Ports
A port is a pathway for data and information to go into and out of the computer from external 2.2. Flynn’s Taxonomy of Computer Architecture
devices such as keyboards, monitors and printers. Michael Flynn classified computer architecture into four distinct categories based on the notion of
There are many standard ports as well as custom electronic ports designed for special purposes. stream or flow of information into the CPU. He identified two types of information streams:
Examples of ports are: The instruction stream which is the flow of instructions into the processing unit
o PS/2 ports for connecting the keyboard and mouse The data stream which is the flow of the data on which the instructions are performed.
o VGA (Video Graphics Adapter) port for connecting the monitor
o RJ45 port for connection to an Ethernet network 2.2.1. Single Instruction, Single Data Stream
o RJ14 for connection to the Internet via phone line A SISD machine is a uniprocessor machine which receives a single stream of instructions that
o USB port for connecting USB devices like Flash drives, printers, keyboards and mice operate on a single stream of data. At any given moment, a single instruction is being executed on a
o Serial ports for connecting serial devices like PDAs given data set. In SISD machines, instructions are executed sequentially. That is, instructions are
o Parallel port connecting parallel devices like printers executed one after the other, one at a time. Hence these machines are also called sequential or serial
o Firewire is high performance serial bus, for connecting devices to your personal processor machines. They are typical examples of Von Neumann’s computer model.
computer. FireWire provides a single plug-and-socket connection on which up to 63
devices can be attached with data transfer speeds up to 400 mbps.
Control Unit Processor
b. I/O Bus Standards
Instruction Data
Ports follow standards that define their use. Examples of such standards are: stream
Memory stream
o SCSI: Small Computer System Interface
o USB: Universal Serial Bus
SISD Architecture
o IDE: Integrated Device Equipment
o PCI: Peripheral Component Interconnect
o ISA: Industry Standard Architecture
o EISA: Extended ISA
PE 1 DS 1
Control Unit PE 2 DS 2
IS
DS = Data Stream
DSn IS =Instruction Stream Question: SIMD, MISD and MIMD machines are known as parallel processing machines.
PE n PE = Processor Element
Instruction What do you understand by parallel processing?
stream
2.3. Parallelism
Memory
The performance of computers can be increased by making them perform a number of operations in
parallel. This is known as parallelism. Parallelism can be achieved through parallel processing and
SIMD Architecture
pipelining.
b. Multiprocessors
Data Computer systems may contain many processors, each possibly containing multiple cores. Such
Memory
Stream systems are called multiprocessors. These systems either execute a number of different application
tasks in parallel, or they execute subtasks of a single large task in parallel. All processors usually
MISD Architecture have access to all of the memory in such systems, and the term shared-memory multiprocessor is
often used to make this clear. The high performance of these systems comes with much higher
complexity and cost, arising from the use of multiple processors and memory units, along with more
2.2.4. Multiple Data, Multiple Instruction Stream complex interconnection networks.
MIMD machines are multiprocessor machines capable of executing multiple instructions on multiple
data sets. They have n processors, n streams of instructions and n streams of data. Each processor 2.3.2. Pipelining
element in this model has a separate instruction stream and data stream hence such machines are The simplest way to execute a sequence of instructions in a processor is to complete all steps of the
well suited for any kind of application. Examples of MIMD machines include multi-core computers current instruction before starting the steps of the next instruction. If we overlap the execution of
like the Blue Gene, Fujitsu K computer and CRAY Jaguar. the steps of successive instructions, total execution time will be reduced.
IS 1 DS1
Control Unit 1 PE 1
© 2014- BGS Molyko 7
IS 2 DS 2
Control Unit 2 PE 2 DS = Data Stream
Bilingual Grammar School Advanced Level Computer Science
For example, the next instruction could be fetched from memory at the same time that an arithmetic
(execute) operation is being performed on the register operands of the current instruction. This An instruction set architecture (ISA) consists of the instruction set together with the resources
form of parallelism is called pipelining. needed for their execution. It provides the interface between the computer's software and hardware
and can be viewed as the programmer's view of the machine. Besides instructions, the ISA defines
Definition: Pipelining is a technique that allows for the simultaneous execution of the parts of an items in the computer that are available to a program - e.g. data types, registers, addressing modes,
instruction. and memory.
There are two types of fundamental CPU architectures based on the notion of instruction set:
Below is an example of a four-stage pipeline with three instructions. The stages are: complex instruction set computers and reduced instruction set computers.
IF: instruction fetch ID: instruction decode EX: execute WB: write back
2.4.1. Complex Instruction Set Computer (CISC)
Instr. 1 IF ID EX WB CISC (pronounced sisk) is a CPU design with a large amount of different and complex instructions. In
CISC processors, the control unit contains a number of micro-electronic circuitry to generate a set of
Instr. 2 IF ID EX WB
control signals and each micro-circuitry is activated by a microcode. Complex instructions are first
Instr. 3 IF ID EX WB decoded and the corresponding microcode routine dispatched to the execution unit.
The standard features of CISC processors are:
Clock Cycle 1 2 3 4 5 6
a large number of different and complex instructions.
the use of complex addressing modes.
Cycle 1: Instruction 1 is being fetched from memory.
execution of different machine programs on a CISC machine.
Instructions 2 and 3 have not entered the pipeline yet
the use micro-program control unit.
Cycle 2: Instruction 1 is being decoded limited number of registers.
Instruction 2 is being fetched variable length instruction encoding
Instruction 3 has not entered the pipeline yet direct memory access
Cycle 3: Instruction 1 is being executed Examples of CISC processors are: Intel 386, 486, Pentium, Pentium Pro, Pentium II, Pentium III,
Instruction 2 is being decoded Motorola’s 68000, 68020, 68040, etc.
Instruction 3 is being fetched
Cycle 4: Instruction 1’s results are being written back to register or memory 2.4.2. Reduced Instruction Set Computers (RSIC)
Instruction 2 is being executed RISC (pronounced risk) is a CPU design with a small number of basic and simple machine language
Instruction 3 is being decoded instructions, from which more complex instructions can be composed. RISC instructions are
hardwired. That is, they are built into the chip with hardware rather than programming. Hardware
Cycle 4: Instruction 1 is completed implementation of instructions is much faster and uses less silicon than a microcode
Instruction 2’s results are being written back to register or memory implementation.
Instruction 3 is being executed The standard features of RISC processors are:
a small and limited number of instructions.
Cycle 5: Instruction 1 is completed the use of hardwired control unit.
Instruction 2 is completed consumption of less power and high performance
Instruction 3’s results are being written back to register or memory
instructions are very simple and consistent
2.4. Instruction Set Architecture Examples of RISC processors are: IBM RS6000, MC88100
Every CPU has a predefined instruction set which defines the primitive operations that it can DEC’s Alpha 21064, 21164 and 21264 processors, Motorola/IBM PowerPC
perform.
2.4.3. Addressing Modes
Definition: An instruction set is the collection of bit patterns or binary codes for the machine A machine instruction specifies to the CPU what to do, where the data is located, and where the
operations that a processor has been designed to perform. output data (if any) will be put. Every instruction is made up of two parts: Op-code and operand.
The Op-code (operation code) denotes the basic machine operation e.g. ADD, STORE,
SHIFT, XOR. e. Indexed Addressing
The operand (one or more) provides the data which the instruction manipulates. The effective address of the operand is generated by adding a constant value to the contents of a
register.
For example,
ADD A, $0E ADD is the op-code; A and $0E are operands 3. Number Systems and Data Representation
MOV AX, #0 MOV is the op-code; AX and #0 are operands Computers use binary patterns (fixed number of bits) to represent data, which could be numbers,
letters, videos, images or other symbols. It is important to decide on how these patterns will be
Operands can be specified in different ways in an instruction. The way an operand is specified in an interpreted. The interpretation of binary patterns is called data representation or encoding.
instruction is known as an addressing mode. Different representation schemes exist.
Definition: An addressing mode refers to the way in which the processor locates the data (operand) 3.1. Number Systems
associated with an instruction. A number system is a set of symbols and rules used to represent numbers. The number of different
symbols used in a given number system is known as the base or radix of the system. The largest
a. Register Addressing value of a symbol (digit) in a given number system is always one less than the base or radix of that
In register mode, operand is the contents of a processor register; the name of the register system. If the base of a system is represented by“𝑏”, then the largest value a digit in that system can
is given in the instruction. For example: assume is “𝑏 − 1”.
Examples of number systems include the binary, octal, decimal (denary) and hexadecimal systems.
ADD R1, R2, R3
3.1.1. The Decimal System
The above instruction uses three register to hold all operands. Registers R2 and R3 hold the two The decimal system has a base value of 10. Its maximum or largest value of digit is (𝑏 − 1) = 10 −
source operands while register R1 holds the result of the computation. 1 = 9, meaning thatthe decimal system uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent any
quantity.
b. Immediate Addressing
In immediate mode, the operand is given explicitly in the instruction. In other words, the value to be Consider the number 23410
manipulated by the instruction is immediately part of it. There is no need for any additional It can be written as234 = 200 + 30 + 4
information. For example: 234 = (2 × 100) + (3 × 10) + 4
234 = (2 × 102 ) + (3 × 101 ) + (4 × 100 )
ADD R2, R3, #10
This means that there are two one hundreds, three tens and four ones in the number 234.
This instruction adds the number 10 to the content of register R3 and stores the result in register For any n-digit number, the value each digit represents depends on its position in the number.
R2. The operand 10 has been addressed immediately. Decimal positions (place values) are powers of ten as shown below:
d. Indirect Addressing The value of any digit in a given n-digit number is obtained by multiplying the digit by its place
Here, the effective address of the operand is the contents of a register that is specified in the value. The value of the number is the sum of the products of the digits and their place values. That is,
instruction. For example: we multiply each digit by its place value, then we add the different products obtained.
ADD R2, R2, #R3 Remark Each digit position in decimal has a weight that is ten times the one to its immediate right.
That is, 102 is ten times greater than 101 which is ten times greater than 100 .
This instruction adds the contents of the memory location held in register R3 to the content of
register R2 and the result of the operation is held in register R2. 3.1.2. The Binary System
The binary system has a base value of 2. Only two digits 0 and 1, are used to represent any quantity
in binary. These digits are called binary digits or more commonly bits. To express any quantity in b. Binary to Decimal Conversion
binary we use powers much like in the decimal system but this time, the weights are powers of 2 as To convert a binary number to decimal, we proceed as follows:
shown below. Step 1: starting with the 1s place, write the binary place value over each digit in the binary
number to be converted.
Least Significant
Most Significant Step 2: add up all the place values that have a “1” in them
2𝑛−1 22 21 20 Bit (LSB)
Bit (MSB) …
Example 1: Convert 110102 to base 10
Binary positions for an 𝑛-bit number 16 8 4 2 1
1 1 0 1 0
e.g. the binary number 11012 is expressed as11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20
This means that there are 1 ones, 0 twos, 1 fours, and 1 eights in the number 1101. 16 + 8 + 2 = 2610
a. Decimal to Binary Conversion Convert: 11112 (15), 100112 (19), 101012 (21) to base 10.
To convert from decimal to binary we use the repeated division method. The general technique of
this method can be used to convert any decimal number to any other number system. Example 2: Convert 1101.0112 to base 10
Step 1: divide the decimal number you want to convert by 2 in regular long division until you 1101.0112 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 + 0 × 2−1 + 1 × 2−2 + 1 × 2−3
obtain a final remainder = 8 + 4 + 0 + 1 + 0 + 1⁄4 + 1⁄8
Step 2: use the remainder as the least significant bit of the binary number = 13 + 0.25 + 0.125
Step 3: divide the quotient you got from the first division operation by 2 until you obtain a final = 13 + 0.25 + 0.125
remainder = 13.375
Step 4: use the remainder as the next digit of the binary number
Step 5: repeat steps 3 and 4 as many times as necessary until you get a quotient that cannot be Exercise: Convert the following binary numbers to decimal
divided by 2. 1010.1012 (10.625) (ii) 10011.0012 (19.125)
Step 6: use the last remainder (that cannot be divided by 2) as the most significant bit of the
binary number. c. Binary Arithmetic
Addition
Example 1: Convert 21310to base 2 Rules for addition:
213/2 = 106 remainder 1 LSB 0+0=0; 0+1=1; 1+0=1; 1+1=10; 1+1+1 = (1+1) + 1 = 10+1 = 11
106/2 = 53 remainder 0
53/2 = 26 remainder 1 i. 100 + 01 = 101 ………………………………….(4 + 1 = 5)
26/2 = 13 remainder 0 ii. 1101 + 101 = 10010 …………………………. (13 + 5 = 18)
13/2 = 6 remainder 1 iii. 1111 + 110 = 10101 ………………………….. (15 + 6 = 21)
6/2 = 3 remainder 0
3/2 = 1 remainder 1 Subtraction
1/2 = 0 remainder 1 MSB Rules for subtraction:
0-0 = 0; 1-0 = 1; 0-1 = 0 (we borrow a digit); 1-1 = 0
Therefore, 21310 = 110101012
i. 10101 − 100 = 10001 (21 − 4 = 17)
Example 2: Convert 25.7510 to binary ii. 1010 − 101 = 101 …... we borrow a digit worth 2 to continue with the calculation (10 −
5 = 5)
2510 = 110012 , iii. 1001011 − 110101 = 10110 (75 − 53 = 22)
For example:
o A 4-bit pattern will represent the integers 0 to (24 ) − 1 = 3
o An 8-bit pattern will represent the integers 0 to (28 ) − 1 = 255
To convert from binary to hexadecimal
Step1: make groups of four bits starting from the least significant bit and move towards the most 3.2.2. Representation of Signed Integers
significant bit. Signed integers can represent zero, positive integers, as well as negative integers. Four
Step 2: replace each group of bits by its hexadecimal value representation. representation schemes are available for signed integers:
1. Sign-Magnitude representation
Example 1: Convert 1001102 to base 16 2. 1's Complement representation
1001102 = 0010 0110 3. 2's Complement representation
00102 = 216 , 01102 = 616 4. Biased representation (Excess-𝑛)
= 0.4 × 2 = 0.8 0
Example 1: Represent the = 0.8 × 2 = 1.6 1
= 0.6 × 2 = 1.2 1
3.2.3. Representation of Real Numbers
Computers represent real numbers in a form similar to that of scientific notation of mantissa (M) So a binary representation of 0.2is given by 0.001100110011
and an exponent (E) of a certain radix (R), in the form of 𝑀 × 𝑅 𝐸 . Both M and E can be positive as 64.2 is 100000.001100110011
well as negative. For example, 1.25 × 10−1 is expressed in scientific notation where 1.25 represents
the mantissa, −1 the exponent and 10, the radix. Step 2: we normalize the binary representation
The IEEE 754 standard for representing floating-point numbers in the computer has two 1000000.001100110011 becomes 1.00000001100110011 × 25
representation schemes: 32-bit single-precision and 64-bit double-precision.
Step 3: 5 is the true exponent.
In 32-bit single-precision floating-point representation: In excess-16, we have 5 + 16 = 21
the most significant bit is the sign bit (S), with 0 for negative numbers and 1 for positive 21in 5-bit unsigned representation is 10101
numbers.
Step 4: The mantissa stored is what is on the right side of the radix point of the normal form.
the following 8 bits represent the exponent (E).
So M is 0000000110011001100110
the remaining 23 bits represent the mantissa (M) or fraction (F).
Putting all these together we have 64.2 represented as:
0 10101 00000001[10011001100110]
NB: On 8 bits we see that part of the number will be missing. That is why we say the mantissa
determines the precision (exactness) of the number.
For simplicity, we will use a 14-bit pattern for floating point with a 5-bit exponent and an 8-bit 15.375 = 1111.0101
mantissa. In this case, we will use excess-16 representation for the exponent. Normalized we have, 1.1110101 × 23
Examples: 𝐸 = 3 ⇒ 19in excess-16
1. Represent the following numbers as 32-bit single precision floating-point numbers. 𝐸 = 10010
a. 32.2 −15.375is represented as1 10010 11101010
b. −15.37
c. 0.125 c. 0.125
Positive number ⇒Sign bit is 0
Solution: 0 = 0000
a. We convert the number to binary 0.125 × 2 = 0.25 0 𝑀𝑆𝐵
32 = 100000 0.25 × 2 = 0.5 0
0.2 = 0.2 × 2 = 0.4 0 𝑀𝑆𝐵 0.5 × 2 = 1.0 1
= 0.4 × 2 = 0.8 0
= 0.8 × 2 = 1.6 1 0.125 = 0.001
= 0.6 × 2 = 1.2 1 Normalized we have, 1.0 × 2−3
= 0.2 × 2 = 0.4 0 𝐸 = −3 + 16 = 13 = 01101
like English, German, Italian, Portuguese and Spanish. Latin-1 is backward compatible with the 7-bit
0.125 is represented as 0 01100 00000000 ASCII code. That is, the first 128 characters in Latin-1 (code numbers 0 to 127 (7FH)), is the same as
ASCII. Code numbers 128 (80H) to 159 (9FH) are not assigned. Code numbers 160 (A0H) to 255
2. Suppose the following 14-bit floating-point representation patterns, what decimal numbers do (FFH) represent other special characters like Å, Æ, Ç, ~, £, ¤, ¥, § and ©.
they represent?
3.3.3. Unicode Character Code
a. 01000011000000 Unicode originally uses 16 bits (called UCS-2 or Unicode Character Set - 2 byte), which can
b. 10111010000000 represent up to 65,536 characters. Before Unicode, no single character encoding scheme could
c. 11111000000001 represent characters in all languages. Unicode is backward compatible with the 7-bit ASCII and 8-bit
Latin-1. That is, the first 128 characters are the same as ASCII and the first 256 characters are the
Solutions: same as Latin-1.
The original 16-bit range of U+0000H to U+FFFFH (65536 characters) is known as Basic
a. 010000110 00000 Multilingual Plane (BMP), covering all the major languages in use currently. The characters outside
Sign bit is 𝑆 = 0 ⇒positive number BMP are called Supplementary Characters, which are not frequently-used.
𝐸 = 10000 = 16 (in normalized form) UCS-4 (Universal Character Set - 4 Byte), uses 4 bytes (32 bits), covering BMP and the
Fraction is 1.11 (with an implicit leading 1) = 1 + 1 × 2−1 + 1 × 2−2 = 1.75 supplementary characters.
The number is +1.75 × 2(16−16) = +1.75 × 20 = +1.75
4. Digital Electronics
b. 10111010000000
Sign bit 𝑆 = 1 ⇒ negative number 4.1. Boolean Algebra
𝐸 = 01110 = 13 (in normalized form) Boolean algebra also known as the algebra of logic was developed by an English mathematician
Fraction is 1.1 (with an implicit leading 1) = 1 + 1 × 2−1 = 1.5 called George Boole. It deals with binary variables and logic operators operating on these variables.
The number is −1.5 × 2(13−16) = −1.5 × 2−3 = −1.625 A binary variable has only two possible values 0 or 1. Logic operators operating on these variables
are AND (·), OR (+) and NOT (‘). Operations are defined for the values 0 and 1 as follows:
c. 1 11110 00000001
Sign bit 𝑆 = 1 ⇒ negative number AND
OR
0·0=0 NOT
𝐸 = 11110 = 30 (in normalized form) 0+0 =0
Fraction is 1.00000001 (with an implicit leading 1) = 1 + 2−8 0·1=0 0̅ = 1
0+1 =1
The number is −(1 + 2−8 ) × 2(30−16) 1·0=0 1̅ = 1
1+0 =1
1·1=1
1+1 =1
3.3. Representation of Characters
Characters are represented using a chosen character encoding scheme (character set, charset, 4.1.1. Laws and Theorems of Boolean Algebra
character map, or code page). The most commonly-used character encoding schemes are: ASCII, o Commutative law
Latin-x for western European characters, and Unicode for internationalization. 𝐴 · 𝐵 = 𝐵 · 𝐴|𝐴 + 𝐵 = 𝐵 + 𝐴
o Associative law
3.3.1. ASCII Character Code (𝐴 · 𝐵) · 𝐶 = 𝐴 · (𝐵 · 𝐶)|(𝐴 + 𝐵) + 𝐶 = 𝐴 + (𝐵 + 𝐶)
ASCII stands for American Standard Code for Information Interchange. The ASCII character code is a
7-bit code used to represent numeric, alphabetic, and special printable characters. It also includes o Distributive law
codes for control characters, which are not printed or displayed but specify some control function. A 𝐴(𝐵 + 𝐶) = (𝐴𝐵) + (𝐴𝐶) | 𝐴 + (𝐵𝐶) = (𝐴 + 𝐵)(𝐴 + 𝐶)
7-bit means a total of 27 = 128 characters can be represented.
Code numbers 0 to 31 and 127 are special control characters, which are non-printable o Identity law
(non-displayable) 𝐴·1 =𝐴 | 𝐴+0= 𝐴
Code numbers 65 to 90 represent 'A' to 'Z', respectively.
o Redundancy law
Code numbers 97to 122 represent 'a' to 'z', respectively.
𝐴·0 =0 | 𝐴+1 =1
Code numbers 48 to 57 represent '0' to '9', respectively.
o Complement law
3.3.2. Latin-1
𝐴 ∙ 𝐴̅ = 0 | 𝐴 + 𝐴̅ = 1
Latin alphabet No. 1 or Latin-1 in short, is the most commonly-used encoding scheme for western
European languages. It has 191 printable characters from the Latin script, which covers languages
© 2014- BGS Molyko 15
Bilingual Grammar School Advanced Level Computer Science
o Idempotence law
𝐴·𝐴 =𝐴 | 𝐴+𝐴 =𝐴 4.1.3. Constructing Truth Tables
A truth table shows the output for all possible values of the input variables for a given Boolean
o Absorption law expression. To construct a truth table, we evaluate the Boolean expression for all possible
𝐴(𝐴 + 𝐵) = 𝐴 | 𝐴 + (𝐴𝐵) = 𝐴 combinations of values for the input variables. The number of possible combinations is always equal
to 2𝑛 where 𝑛 is the number of input variables.
𝐴 𝐵 𝐴̅ 𝐴̅𝐵 𝐴 + 𝐴̅𝐵
o Involution law
0 0 1 0 0 Example 1: Construct a truth table for the expression 𝐴 + 𝐴̅𝐵
𝐴̿ = 𝐴
0 1 1 1 1 We have 2 input variables 𝐴 and 𝐵 ⇒ we will have 22 = 4 different combinations.
1 0 0 0 1 o No name
1 1 0 0 1 𝐴 + 𝐴̅𝐵 = 𝐴 + 𝐵 | 𝐴(𝐴̅ + 𝐵) = 𝐴𝐵
𝐴𝐵 + 𝐴𝐵̅ = 𝐴 | (𝐴 + 𝐵)(𝐴 + 𝐵̅ ) = 𝐴
o De Morgan’s Theorems
𝐴 𝐵 𝐶 𝐴𝐶 𝐵 + 𝐴𝐶 ̅̅̅̅ = 𝐴̅ + 𝐵̅ | ̅̅̅̅̅̅̅̅
𝐴𝐵 𝐴 + 𝐵 = 𝐴̅ ∙ 𝐵̅
0 0 0 0 0 Example 2: Construct a truth table for the expression 𝐵 + 𝐴𝐶
0 0 1 0 0 4.1.2. Simplifying Boolean 3 input variables ⇒ 23 = 8 different combinations
Expressions
0 1 0 0 1
Simplifying a Boolean expression consists of using
0 1 1 0 1 the laws of Boolean algebra to write the
1 0 0 0 0 expression in its simplest form.
1 0 1 1 1
Example 1: Simplify the expression 𝐴𝐵 + 𝐴(𝐵 +
1 1 0 0 1
𝐶) + 𝐵(𝐵 + 𝐶)
1 1 1 1 1 Solution:
𝐴𝐵 + 𝐴(𝐵 + 𝐶) + 𝐵(𝐵 + 𝐶) = 𝐴𝐵 + 𝐴𝐵 + 𝐴𝐶 +
𝐵𝐵 + 𝐵𝐶
= 𝐴𝐵 + 𝐴𝐵 + 𝐴𝐶 + 𝐵 + 𝐵𝐶 (𝐵𝐵 = 𝐵)
= 𝐴𝐵 + 𝐴𝐶 + 𝐵 + 𝐵𝐶 (𝐴𝐵 + 𝐴𝐵 = 𝐴𝐵)
= 𝐴𝐵 + 𝐴𝐶 + 𝐵 (𝐵 + 𝐵𝐶 = 𝐵)
= 𝐵 + 𝐴𝐶 (𝐴𝐵 + 𝐵 = 𝐵) Example 3: Construct the truth tables for the following
i) 𝐴̅𝐵 + 𝐴𝐵̅
Example 2: Simplify the expression ii) 𝐴̅𝐵𝐶 + 𝐴𝐵𝐶̅ [𝐵(𝐴 xor C)]
̅̅̅̅̅̅̅̅
𝐴𝐵̅ + 𝐴(𝐵 ̅̅̅̅̅̅̅̅
+ 𝐶 ) + 𝐵(𝐵 + 𝐶 ) = 𝐴𝐵̅ + 𝐴(𝐵̅ 𝐶̅ ) + 𝐵(𝐵̅ 𝐶̅) De Morgan’s iii) 𝐴(𝐴 + 𝐶̅ )(𝐴 + 𝐵)
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 𝐵𝐵̅ 𝐶̅
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 0𝐶̅ (𝐵𝐵̅ = 0) 4.2. Logic Gates and Circuits
= 𝐴𝐵̅ + 𝐴𝐵̅ 𝐶̅ + 0 (0𝐶 ′ = 0) Logic gates and circuits are simply ways of representing Boolean functions and expressions
= 𝐴𝐵̅ (1 + 𝐶) (1 + 𝐶’ = 1) electronically.
= 𝐴𝐵̅ ∙ 1 (𝐴𝐵̅ ∙ 1 = 𝐴𝐵̅)
= 𝐴𝐵̅ (𝐴𝐵̅ ∙ 1) 2.1. Logic Gates
A logic gate is an electronic device that implements a simple Boolean function. Logic gates carry out
Example 3: Use De Morgan’s theorems to simplify the following the operations that the microprocessor performs. When a microprocessor is designed, a logic gate
i) (𝐴̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅̅
+ 𝐵𝐶 + 𝐶𝐵 ) cell library (collection of all low level logic functions used to implement the logic) is also deeply
̅̅̅̅̅̅̅̅̅̅̅
̅ + 𝐴𝐶̅ ) planned and developed.
ii) (𝐴𝐵
There are six basic logic gates: AND, OR, NOT, NAND, NOR and XOR.
Example 4: Show that
i) 𝐴 + 𝐴𝐵 = 𝐴 a. AND Gate
ii) (𝐴 ̅̅̅̅̅̅̅̅
+ 𝐵 ) = 𝐵̅ (𝐴̅ + 𝐵)
iii) (𝐴 + 𝐵)(𝐴 + 𝐵̅ ) = 𝐴
© 2014- BGS Molyko 16
Bilingual Grammar School Advanced Level Computer Science
It is a logic gate whose output is “true” only when both inputs are “true”. If neither or only one of the
inputs is “false”, the output is “false”. The following illustration and table show the circuit symbol A B ¬(A+B
and logic combinations for an AND gate.
0 0 0
0 1 1
A B A.B Logic NOR
1 0 1
0 0 0
1 1 1
0 1 0
Logic AND 1 0 0 f. XOR Gate
1 1 1 Exclusive-OR is a logic gate whose output is “true” when one but not both of its inputs is “true”. The
output is "false" if both inputs are "false" or if both inputs are "true." Another way of looking at this
b. OR Gate circuit is to observe that the output is “true” if the inputs are different, but “false” if the inputs are
It is a logic gate whose output is “true” when either or both of the inputs are “true”. If both inputs the same.
are "false," then the output is "false."
A B Output
A B A Or B
0 0 0
0 0 0
0 1 1 Logic XOR
0 1 1
Logic OR 1 0 1
1 0 1
1 1 0
1 1 1
c. NOT Gate 2.2. Logic Circuits
It is a logic gate whose output is “false” if its input is “true” and vice versa. It is called logical inverter, Circuits are made by combining two or more logic gates. Gates are combined into circuits by using
because it reverses the state of its input. A NOT gate accepts one input and produces a single output. the output of one gate as the input for another.
Examples
A Output
0 1
1 0
Logic NOT (inverter)
d. NAND Gate
The NAND gate operates as an AND gate followed by a NOT gate. The output is "false" if both inputs
are "true." Otherwise, the output is "true.
A B ¬(A B)
0 0 0
0 1 1
Exercise 1: Construct logic circuits for the following expressions
Logic NAND
1 0 1 1) 𝐴̅𝐵 + 𝐴𝐵̅
2) (𝐴 + 𝐵)(𝐴 ̅̅̅̅̅̅̅̅
+ 𝐵̅ )
1 1 1
̅ ̅
3) 𝐴(𝐵 + 𝐴)
4) (𝐴̅ + 𝐵)(ABC
̅̅̅̅̅̅)
5) (𝐴 + 𝐵̅ )𝐴𝐶
e. NOR Gate
A NOR gate is equivalent to an OR gate followed by a NOT gate. Its output is "true" if both inputs are Exercise 2: What are the outputs for the following logic circuits
"false." Otherwise, the output is "false."
a. Segmentation
Segmentation is when memory is divided into variable sized units called segments. When segments
are used, memory allocation can be done in three different ways:
o First fit allocates the first free segment that is large enough for the new process.
o Best fit allocates the smallest block among those that are large enough for the new
process.
o Worst fit allocates the largest block among those that are large enough for the new
process.
OS structure
b. Paging
a. OS Kernel Paging is when memory is divided into fixed-size units called frames. Jobs are broken up into blocks
The kernel is the central part of an operating system that is running at all times on the computer. It of same size as frames called pages which are allocated a number of frames. The OS then uses a page
loads first and remains in memory as long as the computer is on. It consists of utilities (file manager, table to map program pages to memory frames. The pages for each job could be in logical order or
memory manager, device drivers, process manager etc.) that perform basic required functions. In they may be scattered about wherever there is a free frame.
many operating systems, only the kernel can access hardware directly.
1.2.2. Process Management Definition: Process synchronization is about getting processes to coordinate together in order to avoid
A process is a program in execution. It consists of the program’s instructions and the resources two or more processes entering into critical section over the same resource.
allocated to it for execution. A program is static while a process is active. The operating system
performs process management to carefully track the progress of a process and all of its intermediate If processes are not synchronized, it leads to deadlock and starvation.
states.
A process changes state as it executes. The different states a process can have are shown in the c. Deadlock
diagram below. Deadlock is a permanent blocking of a set of processes competing for resources. It is a situation in
which each of two processes is waiting for the other to do something; thus, neither one can proceed.
For a deadlock to occur, the following four conditions must hold.
Mutual Exclusion: At least one resource must be held in a non-sharable way.
Hold and Wait: A process must be holding a resource and waiting for another.
No Preemption: No resource can be forcibly removed from a process holding it.
Circular Wait: A waits for B, B waits for C, C waits for A.
Deadlock can be prevented by ensuring that one of the above conditions does not hold. For example
using pre-emptive scheduling.
d. Starvation
Process states
Starvation is a situation where a task can never finish because it can never get a necessary resource
such as a large block of memory. The operating system should detect such tasks and do its best to
o New - The process is being created.
allocate the resources that they need.
o Ready - Process has all needed resources - waiting for CPU only.
o Running - Instructions are being executed.
1.2.3. CPU Scheduling
o Waiting - Process is waiting for some event to occur (human, hardware or another
CPU scheduling is the act of determining which process in the ready state should be moved to the
process)
running state. It decides which process in memory is to be executed by the CPU at any given
o Terminated - Process has finished execution
moment. Scheduling decisions may take place when a process:
1. Switches from running to waiting state
Definition: The turnaround time for a process is the amount of time between the time the process
2. Switches from running to ready state
arrives the ready state and the time it exits the running state for the last time.
3. Switches from waiting to ready
In other words, it is the length of time it takes to run a process from initialization to termination,
4. Switches from running to terminated
including all the waiting time.
Scheduling can be preemptive or non-preemptive.
Question: What is a scheduler?
Preemptive scheduling is scheduling in which the currently executing process is forced to
a. Process Control Block give up the CPU. Scheduling under (2) and (3) is preemptive.
The operating system manages a large amount of data about a process like the program counter
(PC), CPU registers, memory management information, I/O status, scheduling data and process Non preemptive scheduling is scheduling in which the currently executing process gives up
state. This data is stored in a data structure called a process control block (PCB) also called process the CPU voluntarily. Scheduling under (1) and (4) is non-preemptive.
descriptor or state vector. Every process has its PCB and each time a process is moved to the
c. VoiceRecognition Interface
1.2.4. Management of I/O Devices
A speech recognition interface allows the user to give verbal commands to the computer. The user
communicates with the computer through natural language. They are also called natural language
a. Interrupts
interface
5. Library Programs
6. Language Translators
A language translator is a computer program that translates program instructions from one
programming language to another. There are three types of language translators: compilers,
interpreters and assemblers.
Compilers translate instructions written in a high-level language into machine language
instructions.
Interpreters translate instructions written in a high-level language into machine language
instructions and execute them, one line at a time.
Assemblers translate instructions written in assembly language to machine language
instructions.
a. Bluetooth
Bluetooth is a low power, short-range wireless technology largely used to interconnect computing
Ring topology
devices into a personal area network. It is based on IEEE standard 802.15 which gives specifications
a. Advantage for Wireless Personal Area Network (WPAN).
No collision as a station needs the token to transmit
Each computer acts like a repeater so signals are not attenuated b. Wi-Fi
Wi-Fi stands for Wireless Fidelity. It is based on a set of wireless networking technologies known as
b. Disadvantage 802.11. These include 802.11b, 802.11a, 802.11g and 802.11n. The range of Wi-Fi network
If a node in the network fails, the entire network fails transmission is about 30-40m indoors and up to about 100m outdoors.
Network is disrupted when additional stations are added The table below shows the different 802.11 standards for wireless networking.
1.4. Network Technologies Specification Popular name Frequency Speed Compatible with
802.11a Wireless-A 5 GHz 54 Mbps
1.4.1. Ethernet Network
802.11b Wireless-B 2.4 GHz 11 Mbps Wireless-A
Ethernet (IEEE 802.3 standard) is the most common and widely used technology to establish a local
area network. An Ethernet network is formed by physically connecting the individual computer 802.11g Wireless-G 2.4 GHz 54 Mbps Wireless-B, -G
units to each other in a bus topology or a star topology. Ethernet’s media access policy is CSMA/CD 802.11n Wireless-N 2.4 GHz 100 Mbps Wireless-B, -G, -N
(Carrier Sense Multiple Access with Collision Detection).
CS: means that a station listens to (senses) the medium and transmits only if medium is idle c. WiMax
MA: means that any station can use (access) the medium WiMax stands for Worldwide Interoperability for Microwave Access. It is based on IEEE standard
CD: means that each station stops transmitting immediately it senses a collision 802.16 and facilitates high speed wireless network links to both fixed and mobile devices. The range
of a WiMax wireless connection is around 3-10km.WiMax service providers are now just entering
When a collision is detected, the two stations involved will retransmit after a random time wait the market, offering customers an alternative to a DSL Internet connection.
created by a backoff algorithm.
1.5. Network Architectures
1.4.2. Token Ring Network 1.5.1. Client/Server Architecture
Token ring (IEEE 802.5 standard) is a network technology developed by IBM in which computers Client/server is a network architecture in which a more powerful computer called server is
are connected together in a ring. Token ring’s media-access method is called token passing. A dedicated to serving less powerful computers called clients. Servers hold shared resources like files,
special message, called token, circulates along the ring from one computer to another and each programs and the network operating system. They provide access to network resources to all the
computer can transmit only while it is holding the token. Information flows in one direction along users of the network. There are many different kinds of servers, and one server can provide several
the ring from source to destination and back to source. When a station wishes to transmit, it waits functions. For example, there are file servers, print servers, mail servers, database servers and Web
for the empty token to pass by. It seizes it and inserts data into it and then releases it to the medium. servers. Users run applications on client workstations which rely on servers for resources such as
The token circulates until it gets to the destination computer that picks it and retrieves the data. files, devices and even processing power.
After retrieving the data, it regenerates the token and sends it back to the medium. Internet services are organized according to a client/server architecture. Client programs, such as
Web browsers and file transfer programs create connections to servers, such as Web and FTP
1.4.3. Fiber Distributed Data Interface servers. The clients make requests and the server responds to the requests by providing the
FDDI is a network technology that uses fiber-optic cables in a ring topology with dual rings on which services requested by the client.
information can travel in opposite directions. The media access method for FDDI is token passing.
The primary ring is used for data transmission, and the secondary ring remains idle. Because of this 1.5.2. Peer-to-Peer Architecture
double ring topology, if a station fails or a cable becomes damaged, the dual ring is automatically Peer-to-peer (P2P) is a network configuration in which all the workstations (computers) have equal
wrapped around itself, forming a single ring. This prevents downtime as a result of a failed machine capabilities and responsibilities. Each workstation acts both as a server and a client. This means that
or faulty wiring. any computer on the network can provide services to any other computer. Peer-2-peer is usually
implemented where strict security is not necessary. P2Pnetworks are generally simpler and less
expensive, but they usually do not offer the same performance under heavy loads.
1.6.2. Limitations
Purchasing the network cabling and file servers can be expensive.
Managing a large network is complicated. It requires training and a network manager
usually needs to be employed. Analogue signal
If the file server breaks down the files on the server become inaccessible. Email might still
work if it is on a separate server. The computers can still be used but are isolated. 2.1.2. Digital Signals
Viruses can easily spread to other computers throughout the network, if one computer is A digital signal is one in which information is represented as a sequence of binary values 0 and
infected.. 1.These two values represent two conditions, on or off, corresponding to two known levels of
There is a danger of hacking, particularly with wide area networks. Security procedures are voltage or current.
needed to prevent such abuse, eg a firewall. Digital signals do not continuously vary as analogue signals. Signals are transmitted within the
computer as digital signals. Systems that use digital technology are known as baseband systems.
2. Data Communication
Data communication refers to the exchange of data between two devices via some form of
communication channel. In data communication the following basic terms are frequently used:
Data: a collection of facts in raw form that becomes information after processing.
Signal: an electric or electromagnetic encoding of data.
Signaling: propagation of signals across a communication channel.
Transmission: sending of data from one place to another by means of signals.
Coaxial cable
To connect coaxial cable to devices, we need coaxial connectors. The most common type of
Optic fiber
connectors used today is the Bayone-Neill-Concelman, or BNC connector.
The light source can be LED (light emitting diode) or LD (laser diode)
b. Twisted Pair Cable
Twisted-pair cable is the most common type of cabling used in LAN networks today. It consists of a 2.5.2. Unguided Media
pair or pairs of insulated wires twisted together. Cable twisting helps reduce noise pickup from Unguided media do not use physical means to define the path to be taken. They provide a means for
outside sources and crosstalk on multi-pair cables. There are two types of twisted pair cables: transmitting electromagnetic waves but do not guide them. They are also called unbounded media.
shielded twisted pairs (STP) and unshielded twisted pairs (UTP). Examples of unguided media are infrared waves, radio waves and microwaves.
2.6.2. Checksum Definition: A protocol is a set of rules that govern how devices on a network communicate.
A checksum or hash sum is a count of the number of bits in a transmission unit that is included with
the unit for the purpose of detecting errors that may have been introduced during transmission. The Protocols allow different computers from different vendors and with different operating
checksum or hash sum may be computed according to the number of set or unset bits in the characteristics to ‘speak the same language’. They set the message formats and procedures that
message. On reception, the receiver applies the same checksum function/algorithm to the message. allow machines and application programs to exchange information. The same protocols must be
3 Network Layer
These layers can be recalled using the These layers can be recalled using the following mnemonics: All People Seem To Need Data
2 Data Link Layer following mnemonics: All People Seem To Processing. (Layers 7 - 1)
Need Data Processing. (Layers 7 - 1)
1 Physical Layer 3. The Internet
3.1. Brief History
OSI Reference Model Many years ago, the military of the United States of America desired to interconnect or link their
computers in order to better understand and manage information and communication with respect
Layer 7: Application to enemy attacks in times of crisis. In the year 1969 the Department of Defense (DoD) then
It provides network services directly to the user’s applications such as a web browser or e-mail developed an experimental network called the Advanced Research Project Agency Network
client. This layer is said to be “closest to the user”. Examples of protocols that operate at this layer (ARPANet)
are: TELNET, HTTP, FTP, SMTP and POP. In the year 1980, the National Science Foundation of the United States of America then developed
the technology of ARPANet to produce the National Science Foundation Network (NSFNet) which
Layer 6: Presentation now enabled universities and other school establishments in the USA to be interconnected. After a
The Presentation layer represents the data in a particular format to the Application layer. It defines great deal of work, a network which enabled the transfer of large amounts of information at very
encryption, compression, conversion and other coding functions. Examples of specifications defined high speed which is today called the Internet was developed.
at this layer are: GIF, JPEG, MPEG, MIME and ASCII. The Internet can be defined as a worldwide/global system of interconnected computer networks. It
is the network of networks in which users can view information on the World Wide Web, exchange
Layer 5: Session electronic mail, participate in electronic discussion forums (newsgroups), send files from any
It establishes, maintains and terminates end-to-end connections (session) between two applications computer to any other and even use each other’s computers directly if they have appropriate
on two network nodes. It controls the dialogue between the source and destination nodes, which passwords. Another name for the Internet is information superhighway.
node can send when and for how long. Examples of protocols that operate on this layer are: RPC,
NETBIOS and X.225
Definition: An IP address is a unique identifying number given to every single computer on a TCP/IP a. Hypertext Transfer Protocol
network. HTTP is a standard method of publishing information as hypertext in HTML format on the Internet.
It provides the ability to supply web pages between a browser and the server. HTTPS is a secure
Two versions of IP addresses are available: IPv4 that uses 32 bits and IPv6 that uses 128 bits. version of HTTP used for accessing secure web servers, whereby all data transferred are encrypted.
An IPv4 is made up of four sets of numbers separated by dots such as 123.23.168.22. This
notation is known as dotted decimal notation. Each of the four numbers separated by dots b. File Transfer Protocol
can be any number from 0 to 255, making for a total of 4.3 billion potential IPv4 addresses FTP is a standard for transferring files between a server and a client on a TCP/IP network. It
(i.e. 255×255×255×255). provides the ability to upload and download files between hosts on the network.
An IPv6 has eight sets of numbers separated by colons such as c. Simple Mail Transfer Protocol
3ffe:1900:4545:3:200:f8ff:fe21:67cf. SMTP is used for sending e-mails between servers on the Internet and other TCP/IP networks. It
governs the transmission of mail messages and attachments. SMTP is used in the case of outgoing
IP addresses are assigned manually by an administrator or automatically by DHCP (Dynamic Host messages.
Control Protocol) or APIPA (Automatic Private IP Addressing). An IP address is also known as a
logical address. d. Post Office Protocol
POP is a standard protocol for delivering e-mails to personal computers. There are different
b. Address Resolution Protocol versions of the post office protocol indicated by POPn where n = 1, 2, 3 or4.
ARP resolves IP addresses to MAC addresses. It is used to obtain the MAC address of a node on a
network when its IP address is known. e. Telnet
Telnet is a protocol that allows a computer on the network to be accessed remotely. It provides the
Assignment: Differentiate between an IP address and a MAC address. ability to login into a remote host and administer the machine. Using Telnet a computer can be used
as a terminal on another.
c. Internet Control Message Protocol
ICMP is responsible for diagnostics and error reporting. It is used to send control and error f. Wireless Application Protocol
messages to computers and servers. WAP is a protocol which runs on mobile phones and provides a universal open standard for
bringing Internet content to mobile phones and other wireless devices.
d. Internet Group Management Protocol
IGMP is responsible for management of group multicast. Assignment: Give the full meaning of the following protocols and state their functions.
i) IMAP (ii) RIP (iii) DNS
3.3.3. Transport Layer
The transport layer is responsible for sequencing and transmission of packets, acknowledgment of 3.4. TCP/IP Ports
receipts, recovery of packets and flow control. In essence, it engages in host-to-host transportation A computer has a single physical connection to the network. All data destined for a particular
of data packets and the delivery of them to the application layer. A transport layer PDU is called computer arrives through that connection. However, the data may be intended for different
segment. applications running on the computer. To identify the application for which the data is intended,
Core protocols at this layer are TCP and UDP. TCP requires port numbers on the host and destination for communication.
a. Transmission Control Protocol Definition: A communication port is a number (16-bits) that identifies an application on the Internet
TCP is a connection-oriented reliable protocol used in the accurate transmission of large amounts of or TCP/IP network.
data. Data packets are verified using checksums and retransmitted if they are missing or corrupted.
The application plays no part in validating the transfer. Popular Internet application protocols are associated with well-known ports assigned by the
Internet Assigned Number Authority (IANA). Sample TCP port numbers are:
b. User Datagram Protocol
UDP is a connectionless unreliable protocol used for the transmission of small amounts of data. Data
packets are sent without testing to verify whether they actually arrive at the destination, nor
whether they were corrupted in transit. It is up to the application to determine these factors and
request retransmissions. UDP is faster compared to TCP.
b. Business-to-Business
B2B describes commerce transactions between businesses, such as between a manufacturer and a
wholesaler, or between a wholesaler and a retailer. In this form, the buyers and sellers are both
business entities and do not involve an individual consumer.
c. Business-to-Government
B2G is a derivative of B2B marketing. B2G sites provide a platform for businesses to bid on
government opportunities which are presented as solicitations requests for proposal (RFPs) to
tender.
d. M-Commerce
M-commerce refers to the use of mobile devices for conducting transactions. The mobile device
holders can contact each other and can conduct the business. Even the web design and development
companies optimize the websites to be viewed correctly on mobile devices.
Some e-commerce websites are: www.bruneiair.com for airline ticket bookings, www.amazon.com
for sales of books and magazines, www.brumedia.com/shop for sales of computers, shirts, and
cameras
Length check o Divide the total by 11. If the remainder is 0, then the number has passed the validation
A length check ensures that an entered value is no longer than a certain number of characters. For check and so it is likely that it has been inputted correctly.
example, a phone number has 8 digits. Entering fewer or more digits makes a number invalid. 231 / 11 = 21 remainder 0
Presence check ii) Calculate the check digits to complete the ISBNs: 019276150-1 and 995640216-8.
A presence check ensures that an entry has been made in a particular field. If it has not, the system will
not allow the record to be saved or any entries to be made in later fields. Such fields called mandatory iii) Set up a spreadsheet which will calculate and check the validity of Modulo-11 weighted check
fields are indicated on some systems by the used of an asterisk. digits for any given ISBN.
At the tactical level, information is needed by middle managers to help them monitor and
control business activities. Tactical planning and decision-making takes place within the
guidelines set by the strategic plan.
The outcome of a feasibility analysis is a feasibility report which is presented to the user management 5.4. Construction
for approval. It may be accepted or accepted with modifications or rejected. Once the design of the system is complete, it has to be converted into a computer understandable form.
Development is the stage where the design is converted into a computer program.
Documenting System Analysis
The outcome of systems analysis is a system proposal or requirements specification document which Coding (programming)
describes what the new system should do without specifying how to do it. At the end of systems Coding is an important activity by which a programmer converts the systems specifications from the
analysis phase, the system analyst produces a system proposal that will be used as basis for the design design stage into computer instructions referred to as programs. It is generally felt that the programs
phase. must be modular in nature. This helps in fast development, maintenance and future change if required.
Two testing techniques that can be used are black-box testing and white-box testing. o Direct Conversion/Cutover: in which the old system is completely replaced by the new one.
Its disadvantage is that, if the new system fails, there is no back-up system, so data can be
o Black-box Testing lost.
Black-box testing is a test that relies on the input/output behavior of the system, without any
assumptions to what is happening within the system. It examines some fundamental aspects of a o Pilot Conversion: in which the new system is installed in one part of the business or
system with little regard for the internal logical structure of the system. Black-box tests are used to organization. This allows the new system to be fully developed and tested. Once the pilot
demonstrate that system functions are operational, that input is properly accepted and output is system is running successfully, the new system is introduced to all of the
correctly produced, while at the same time searching for errors in each function. business/organization.
- Its advantages are that, if something goes wrong with the new system, only a small part of
o White-box Testing the organization is affected, and the staff that were part of the pilot scheme can help train
White-box testing, also called glass-box testing, is a test that relies on information about how the other staff.
system has been designed and constructed. It requires knowledge of the internal structure or - As a disadvantage, there is no back-up system for the office/department doing the pilot, if
implementation of the system. White-box tests are conducted to ensure that internal operations are things go wrong.
performed according to specifications and all internal components have been adequately exercised.
o Parallel Conversion: in which old system and new system operate alongside each other (in
Documentation parallel) until new system is proven capable.
The job of the programmer does not end with the code or software instructions. The organization or - It is advantageous in that, if the new system fails, the old system will act as a back-up. Also,
users need to know how to get the best out of the system. This is done through documentation. System the outputs from the old and new systems can be compared to check that the new system
documentation ensures continuity of the system. is running correctly.
There are two types of documentation; user documentation and technical documentation. - Its disadvantage is that, entering data into two systems, and running two systems together,
takes a lot of extra time and effort.
o User Documentation
User documentation is a complete description of the system from the user’s point of view detailing o Phased Conversion: in which the new system is installed in phases (stages or steps)
how to use or operate the system. It could be a paper-based user manual or help incorporated into the gradually replacing parts of the old system until eventually, the new system takes over.
software that can be accessed when the software is installed. User documentation always covers the - Its advantages are that, it allows users to gradually get used to the new system, and
following: training of staff can be done in stages.
- A guide that describes what the system is supposed to do in non-technical terms - Its disadvantage is that, if a part of the new system fails, there is no back-up system, so
- Instructions for installing and running the program data can be lost
Preventive Maintenance
Preventive maintenance aims in retaining the system’s capabilities before the occurrence of any a. Initiation
problem (e.g. system failure). It locates weaknesses in the system and provides repairs in order to Project initiation determines the main objective of the project and forms a clear understanding about
avoid any eventual breakdown of the system. Making changes to prevent future system failures. the necessity and suitability of the project. This stage answers the questions “what?” and “why?”
Common activities at this stage are:
Corrective Maintenance Identification and initial analysis of the business needs.
Corrective maintenance aims in restoring a defective system to a required state. This implies that Determination of the main objective(s).
repairs are made after a breakdown of the system. (Making changes to repair system defects) Resource analysis (people, equipment, financial; needs and availability).
Composition of the project charter.
Perfective Maintenance (Project charter - document issued by the project initiator or sponsor that formally authorizes
Perfective maintenance refers to enhancements to the product in order to either add new capabilities the existence of a project, and provides the project manager with the authority to apply
or modify existing functions. Making changes to enhance the system and improve such things as organizational resources to project activities.)
processing performance and usability.
b. Planning
6. Project Management Project planning involves the project plan development and approval. It determines an optimal
A project is an endeavor to accomplish a specific objective through a unique set of interrelated tasks scheme/algorithm for project execution. This stage answers the question “how?” The main activities at
and the effective utilization of resources. A project has a definite start and finish time, well-defined this stage are:
outcomes or performance goals, and consumes scarce resources such as money, personnel, material, Needs analysis
and equipment. Description of the project (including determination of activities and necessary resources)
A project is considered constrained by three functions: Composition of project plan
Scope: what it is intended to accomplish. In other words, the customer’s requirements for Planning and performing necessary PR-activities.
the project. (PR is the practice of managing the spread of information between an individual or an
Time allocation: the time schedule for the project. organization and the public. Public relations activities include: launchings, media conferences,
Cost: the money, budget, and resources for a project. sales promotions, open day, product testing, websites, press release, newsletters.)
These three functions are called the Triple Constraint. The relationship between them is represented
using the Project Management Triangle. c. Execution
Project execution is the phase within which the deliverables are physically constructed and presented
to the customer for acceptance. It integrates people and other resources to carry out the project
Time
management plan for the project. The activities undertaken to construct each deliverable will vary
Cost
depending on the type of project being undertaken. Main activities are:
Starting up the execution.
Building the deliverables
Scope
Day-to-day management and reporting
The Project Management Triangle visualizes the fact that time, cost and scope of a project are
d. Monitoring and Control
interdependent; changing one of them causes changes in the other two. For example, if you want to
Project control measures and monitors progress to identify variances from the project management
shorten a schedule, you can hire more resources which would increase cost, or reduce customer
plan so that corrective action can be taken when necessary to meet project objectives. Control occurs
requirements which would affect quality. This simply means “you can have any two of quick, good or
throughout the duration of the project and has a range relatively similar to that of execution. While the
cheap, but not all three.”
A 7 0 0 0
B 2 0 5 5
C 15 0 12 12 b.
E 10 7 7 0
D 8 17 17 0
F 2 25 25 0
G 5 17 19 2
H 8 22 24 2
c.
I 2 27 27 0
J 3 29 29 0
Finish 32 32
Solution
a) 𝑡 = 246, 𝑇 = 246 and σT 2 = 25
246 − 246
𝑃(𝑡 ≥ 𝑇) = =0
25
1 Collect requirements 3
2 Analyze processes 2 1
3 Analyze data 2 2
4 Design processes 6 2
5 Design data 3 3
8 Program 5 6,7
10 Install 2 8,9
Exercise 2: At 4:30 pm one day CRTV news team hear of a Government Minister resigning. They
wish to prepare an item on the event for that evening’s 6 o’clock news. The table below list the jobs
needed to prepare this news item, the time each job takes and the constraints on when the job can
commence.
Time
Job Constraints
needed
A - Interview the
15 mins. Starts at 4:30 pm
resigning minister
B - Film the ministry 20 mins. None
C - Get reactions from Cannot start until A and B
25 mins.
regions are completed
D - Review possible Cannot start until B is
40 mins
replacements completed
The solution to these problems is to divide the data into logical groups and store the data in multiple StudID StudName School Subject Grade
tables, then connect (relate) the tables to each other. This results to a Relational database.
7023 Mary W. BGS Molyko Chem A
1.2. Relational Database Model
In a relational database, data is organized in two dimensional tables called relations, which are 7023 Mary W. BGS
BGSMolyko
Molyko Phy
Phy CC
linked. A relation has the following features:
Name: the name of the table 7023 Mary W. BGS Molyko Maths BB
Tuples: a tuple is a single row of a table, which contains a single record for that relation.
7140 Peter R. BGS Molyko Bio B
Attributes: an attribute is a single column in the table, which contains a fact about each
record in the relation.
7140 Peter E. BGS Molyko Chem C
To put the data model to 2NF, we have to ensure that every non-key attribute is functionally
dependent on the entire primary key. An attribute B is said to be functionally dependent on another An E-R diagram
attribute A if A determines B, and is written as AB.
The basic elements of an E-R diagram are entity sets, attributes and relationship types.
{StudID} {StudName}
{StudID} {School} 3.1. Entity Set
{StudID} {Grade} An entity is a person, place, concept or thing for which we intend to collect data. For example, a
{Subject} {StudName} customer, an employee, a book, an appointment.
{Subject} {School} A group of entities that share the same properties is an entity set. An entity is therefore a member or
{Subject} {Grade} an instance of an entity set. In an E-R diagram, an entity set is represented by a rectangle. In the
above E-R diagram, PERSON and HOUSE are entity sets
StudName is dependent on StudID but it is not dependent on subject, the other part of the key.
School is neither dependent on StudID nor Subject. 3.2. Attributes
Grade is dependent on Subject but to have the grade in a subject you need a StudID. Therefore, An attribute is a fact about an entity or a property that describes an entity. For example, a person’s
grade is dependent on both Subject and StudID. name, date of birth or gender, a vehicle’s model, color or brand. Attributes store the actual data we
want to keep about each entity within an entity set. An attribute is represented by an ellipse. In the
To solve these problems, we create separate tables for the fields that are not functionally dependent above E-R diagram, name and date of birth are attributes of the entity set PERSON while Number
on the entire key. The primary key for these tables is the part of the primary key on which they are and Street are attributes of the entity set HOUSE.
dependent. An attribute can be simple, composed, derived, single valued or multi-valued.
We now have, a. Simple attribute: simple attribute is an atomic value, which cannot be divided further.
For example, a person’s phone number is an atomic value of 9 digits.
STUDENT: (StudID, StudName)
SCHOOL: (SchoolID, SchoolName) b. Composite attribute: an attribute made of more than one simple attribute. For example,
SUBJECT: (SubjCode, SubjTitle) a person’s complete name may have FName, MName and LName.
STUDENT_SUBJECT: (StudID,SubjCode, Grade)
c. Derived attribute: an attribute which does not exist physically in the database, but its
2.3. Third Normal Form value is derived from other attributes present in the database. For example, a person’s
A relation is in third normal form (3NF) if and only if age can be derived from his date_of_birth.
It is in 2NF
There are no transitive dependencies. Transitive dependency is a situation where a non- d. Single-valued attribute: an attribute that contains one single value. For example ID car
key attribute depends on another non-key attribute. number.
3. Entity-Relationship Modeling e. Multi-valued attribute: an attribute than can contain more than one value for the same
When a relational database is to be designed, an entity-relationship model is drawn at an early stage entity. For example, a person can have more than one phone numbers or e-mail
and developed as the requirements of the database and its processing become better understood. addresses.
Definition: An E-R model is a diagram which uses basic graphic symbols to show the organization of 3.3. Relationship Type
and relationships between data in a database. A relationship type is a named association between entities. A person (entity) owns (relationship) a
house (entity), a teacher (entity) teaches (relationship) a subject (entity). Normally, individual
An E-R diagram serves as a schema diagram for the required database. A schema diagram is any entities have individual relationships of the type between them but in an E-R diagram, this is
diagram that attempts to show the structure of the data in a database. generalized to entity sets and relationship types. For example, the entity set PERSON is related to
the entity set HOUSE by the relationship type OWNS.A relationship type is represented by a
diamond.
A unary relationship type is one that involves entities from a single entity set. E.g. the (1,1) (1,1)
STUDENT Receives SLIP
relationship MANAGES between entities within the entity set EMPLOYEE.
Employee Manages
(1:1) relationship
In the relationship TEACHES between TEACHER and SUBJECT, a teacher teaches one or
many subjects. The cardinality of TEACHER is many and the optionality is one.
A binary relationship type is a relationship between entities from two different entity sets. A subject is taught by one or many teachers. The cardinality of SUBJECT in the inverse
An example is the relationship OWNS in the E-R diagram above. relationship IS_TAUGHT_BY, is many and the optionality is one. This relationship is
described as many-to-many (M:N).
A ternary relationship type is one that involves entities from three different entity sets. An (1,M) (1,N)
TEACHER Teaches SUBJECT
example is a LECTURER who teaches a certain COURSE in a DEPARTMENT.
An 𝑛-ary relationship type involves entities from 𝑛 different entity sets. (1,1) (1,N) (1,N) (1,1)
TEACHER TEACHES SUBJECT
3.3.2. Cardinality Ratio of a Relationship Type
Cardinality is the maximum number of entities within each entity set that can take part in a Normalized (M,N) relationship
relationship. For example, what is the maximum number of houses that a person can own? On the The primary key of the link entity is a composite key that consists of the primary keys of the entities
other hand, the minimum number of entities within each entity that can take part in the relationship TEACHER and SUBJECT.
is the Optionality. For example, what is the minimum number of houses that can be owned by a
person? The above representation of an E-R diagram is the Chen Convention. Another way of representing E-
The cardinality ratio is a ratio of the cardinalities of the entity sets involved in a relationship. It can R diagrams is the crow’s foot notation that uses three symbols to show cardinality ratios. Here, a
be one-to-one (1:1), one-to-many (1:N) or many-to-many (M:N). circle means zero, a line means one and a crow’s foot means many. The cardinality is shown next to
the entity type and the optionality (if shown at all) is shown behind it.
In the relationship OWNS between PERSON and HOUSE, a person can own zero or many
houses. Therefore, the cardinality of PERSON in the relationship OWNS is many while the
optionality is zero.
On the other hand, a house is owned by one person. The cardinality of HOUSE in the inverse
relationship IS_OWNED_BY, is one while the optionality is one. The relationship OWNS is
therefore described as a one-to-many (1:N) relationship.
(1,1) (0,N)
PERSON Owns HOUSE Where A and B are entity sets and R is the relationship type.
A field is a specific piece of data stored in a table. The above mentioned ‘BOOKS’ table has
fields ‘Title’, ‘Publisher’, ‘Year’ etc.
Each field in a database table is assigned a data type when the field is created. The data type
determines the kind and format of the information stored in the field. Example: the “Title”
field in the “BOOKS” table will store text that will vary with each book in the database, so the
data type in this case will be text or character type.
2) A database will be made to store information about patients in a hospital. On arrival, each
patient’s personal details (name, address, and telephone number) are recorded where a. Creating a New Table
possible, and they are given an admission number. They are then assigned to a particular To create a new table,
ward (Accident and Emergency, Cardiology, Oncology, etc.). In each ward there are a o Click the Create Tab
number of doctors and nurses. A patient will be treated by one doctor and several nurses o Select Table in the Tables group to create a new table in Datasheet view or Table
over the course of their stay, and each doctor and nurse may be involved with several Design to create a new table in Design view
patients at any given time.
b. Adding Fields in a Table
From the description, draw a corresponding E-R diagram showing all entity sets, To add a field to a table in Datasheet View,
attributes, relationship types and cardinality ratios. o Click the Add New Field column label.
o Click Rename in the Fields & Columns group.
4. Database Management Systems o Type the field name and press Enter. Access creates the field. Continue until you have
A database management system (DBMS) is a computer program that is used to create, manipulate created all of the fields in your table.
and access a database. Examples are MS Access, MySQL, Oracle, Sybase, dBase, Paradox, Objecstore o Press Enter without entering a field name to end your entries.
and O2.
A DBMS provides users with: To add a field to a table in Design View,
Data Definition Language (DDL): language which programs the structure (schema) of the o Select a cell in the Field Name column
database o Type a name for the first field in the table and press Enter
Data Manipulation Language (DML): language which changes the contents (instance) of the o Select a data type and press Enter
database o Type a description and press Enter
Data Control Language (DCL)
c. Naming and Saving a Table
4.1. Microsoft Access 2007 To name and save a table,
MS Access 2007 is made up of several components including: o Click the Save button on the Quick Access toolbar. The Save As dialog box appears.
Tables o Type the name you want to give your table.
Forms o Click OK. Access names your table.
Queries
Reports Tip: You can use the Rename option at any time to rename any column. For example, you can
rename the ID column Author_ID.
These components are called database objects. One or more of these components are formed when
a database is created. These components are stored in a single database file. d. Setting a Primary Key
A primary key is a field in a table that allows each entry in the table to be identified in a unique way.
4.1.1. Tables No two entries in the database can have the same primary key. For example your ID card number is
A table is an area of the database where information is stored. Tables organize data into columns unique. By default, Access sets the first field in the table as the Primary Key field.
(called fields) and rows (called records). Example: a database storing information about books and To set a Primary Key:
authors for a library could have a “BOOKS” table to store information about books (title, publisher, o Switch to Design View
For example: Let’s create a relation between the AUTHORS table and the BOOKS table. 4.1.5. Reports
A report is an effective way to analyze and present data in printable format using a specific layout.
4.1.3. Queries Reports are the primary method of retrieving and viewing information. Using queries, reports pull
A query is a command that tells the database what data the user wants to see. A query allows information the user has requested and either print that information or display it on screen. The
information to be found and retrieved from one or more tables based on a set of search conditions information that appears and the formatting and appearance of a report are set when the report is
you define. For example: a query can be written specifying that the database should retrieve all the created.
books from the “BOOKS” table written by William Shakespeare.
To create a Report using the Report Wizard:
To create a query, Click the Create tab on the Ribbon
o Click the Create tab on the Ribbon Click the Report Wizard command
o Click the Query Design command
Select the table or query upon which the report will be based
o Double-click Create Query in Design View
Select the fields that you want to include on the report by double clicking on them
o Select the table that you would like to base your Query on
Click Next
o Click Add
Select a style for the report
o Close the Show Table window
Click Next
Type a title for the report
In order to control which records are displayed, you must define criteria in a Query.
Click Finish
To define criteria for your query:
o Position your cursor in the criteria row in the field for which you wish to define the
4.2. Structured Query Language
criteria for
Structured query language (SQL)
o Enter the criteria
o Click the Run Query button
g. Container Example: Given the 2-dimensional array Tab[4][2] below, what are the elements given by the
A container is a data type used for storing images, video, sound or another type of ‘complex’ file. In references Tab[0][0], Tab[1][1], Tab[3][0] and Tab[2][1]?
some languages, binary large object (blob) is used rather than container.
Index [0] [1]
1.2. Data Structures
[0] 5 3
A data structure is a way of organizing and storing data in memory so that it can be used efficiently.
Any data structure is designed to organize data so that it can be accessed and worked with in [1] 1 4
appropriate ways. A well-designed data structure allows a variety of critical operations to be
performed, using as few resources, both execution time and memory space, as possible. Data [2] 3 1
structures include arrays, records, stacks, queues, trees, graphs and hash tables. [3] 2 8
Each individual element can be referenced by its row and column indices. For
ClassList[0].Gender == F; ClassList[4].DOB == 29 Feb 1995; ClassList[3].DOB.Month == Dec
example:
Tab[0][0] = 5 2.1.3. Stack
Tab[1][1] = 4 A stack is a linear list in which items are added and removed from the same end (head). Items being
Tab[3][0] = 2 added and removed from the same end means that the last item to be added will be the first to be
removed. As such stacks are also called last in, first out (LIFO) lists as they use the LIFO principle.
2.1.2. Record (FILO)
A record is a data structure which allows items of different types that define a particular structure Stack operations are:
or object, to be stored together. The elements of a record are usually called fields or members. Stack(S): creates an empty stack named S
Defining a record includes specifying the data type of each field and a name (label) by which the Push(S,x): inserts the element x to the top of the stack S. Inserting an element into a stack
field can be accessed. that is full leads to a situation known as overflow. (START == NULL)
For example, Pop(S): removes an element from the top of the stack S. Removing an element from an
empty stack leads to a situation known as underflow. (START == HEAD)
Student = RECORD struct Student
Date= RECORD IsEmpty(S): checks whether the stack S is empty. Returns true if it is empty and false
Name: String {
Day: Integer otherwise.
Gender: Character string Name
Month: String
DOB: Date char Gender
Year: Integer Application of stacks:
End RECORD Date DOB
End RECORD
}
a. Converting a Decimal Number to Binary
The above Date record has a numeric field Day, a text field Month and a numeric field Year. The Initially we push the binary digit formed into the stack, instead of printing it directly. After the
Student record has fields Name, Gender and DOB which is of type Date. The table below gives entire digit has been converted into the binary form, we pop one digit at a time from the stack and
examples of student records. print it. Therefore we get the decimal number converted into its proper binary form.
Stack[empty] a. Spooling
Output: [ ] It is a method used to place input and output on a fast access storage device, such as a disk, so that
Read A push it into stack stack[A] output: [𝐴 ] slow peripheral devices do not hold up the processor. For example, print spooler stores output to be
Read + stack[+] output: [𝐴 ] printed in a queue while waiting for the user’s program to finish creating the output. The spooler
Read ( stack[+(] output: [ ] then sends the stored output to the printer at the proper speed. If new output arrives for printing, it
Read ( stack[+((] output: [ ] is added to the queue.
Read B stack[+((] output: [ 𝐴𝐵 ]
Read * stack[+((*] output: [ 𝐴𝐵 ] b. Scheduling
Read C stack [+((*] output: [𝐴𝐵𝐶] It is the process of determining which of the jobs in memory will be executed by the CPU. When a
Read ) stack [+(] output: [𝐴𝐵𝐶 ×] pop until you meet an opening ) job is created, it is added to a queue, the ready queue. Any other job that arrives is added to the tail
Read / stack [+(/] output: [𝐴𝐵𝐶 ×] of the queue. A scheduling algorithm like round-robin is then used to allocate the jobs one by one, to
Read D stack [+(/] output: [𝐴𝐵𝐶 × 𝐷] the CPU for execution.
Read ) stack [+] output: [𝐴𝐵𝐶 × 𝐷/]
stack[ ] output: [𝐴𝐵𝐶 × 𝐷/+] Remark A queue in which elements can be added and removed from any end is known as a double
ended queue (Deque).
𝐴 + ((𝐵 × 𝐶)/𝐷) in postfix notation is 𝐴𝐵𝐶 × 𝐷/+
2.1.5. Linked Lists
Example 2: Let’s evaluate the expression 234 × 5 + − written in postfix notation. A linked list is a linear list in which each element contains a pointer to the next element in the list.
Read 2 stack [2] Each element in a linked list is known as a node and consists of two parts: the data item and the
Read 3 stack [2, 3] pointer to the next element.
Read 4 stack [2, 3, 4]
Read × stack [2, 3 × 4 = 12]= [2, 12] A C E
Read 5 stack [2, 12, 5]
Read + stack [2, 12 + 5 = 17] = [2, 17]
Read − stack [2 − 17 = −15] = [−15] Data Pointer
A linked list that stores characters
The result of the expression 234 × 5 + − is −15
Linked lists make it possible to insert items in the middle of the list without moving other items to
Exercise: Convert the following to postfix notation and evaluate them. make room.
i) 2−3×4+5 (34 × 2 − 5+)
ii) (2 − 3) × (4 + 5) (23 − 45 +×)
iii) 2 × 3/(2 − 1) + 5 × 3 (23x A B E
Jones, Stephen, Agbor, William, Bate, Peter, Terence A level order traversal of this tree gives: ABCDEGHFJKL
The names can be arranged into a binary tree by using the following two-step procedure: b. Depth First Traversal
1. Use the first name on the list as the root of the tree. In depth first traversal, the left subtree is traversed, the right subtree is traversed and the root is
2. To find where to put each subsequent name, start at the root of the tree. If the name you are visited. There are three different depth first traversal techniques; preorder, in order and post order
dealing with precedes the root name alphabetically, follow the left pointer; otherwise follow the traversals. What distinguishes them is the order in which the subtrees and the root are visited.
right pointer. Proceed in this way until you come to an empty pointer; attach the name to it.
Preorder Traversal:
Jones - Visit the root
- Traverse left subtree
- Traverse right subtree
Postorder Traversal:
Terence
- Traverse left subtree
- Traverse right subtree
- Visit the root
A binary tree that stores names
Index Element - should be unambiguous (i.e. no doubts about what to do/ only one way of interpreting the
instructions)
Null - should be effective (i.e. produce good results)
Key
- should be finite (i.e. have a definite stopping place)
25 Agbor
3.1. Representation of Algorithms
36 2 Kome There are different ways for representing algorithms such as pseudo code, flow chart and
structured English.
3 x.Eyong
24
3 3.1.1. Pseudo code
44 x Epie
A pseudo code is an outline of a computer program, written in a mixture of a programming language
. and English. Writing pseudo code is one of the best ways to represent an algorithm as it allows the
66 5
4 Null
programmer to concentrate on how the program works while ignoring the details of the language.
In a pseudo code, some terms are commonly used to represent the various actions. For example, for
6 Sama
inputting data the terms may be (INPUT, GET, READ), for outputting data (OUTPUT, PRINT,
DISPLAY), for calculations (COMPUTE, CALCULATE), for incrementing (INCREMENT), in addition
A hash table
words like ADD, SUBTRACT, INITIALIZE are used for addition, subtraction, and initialization,
The above hash table stores the names Agbor, Epie, Sama, Kome and Eyong using the hash function respectively.
h(k) = k mod tablesize, where k, the key of each string is the sum of its letters’ positions in the For example, here is a pseudo code for an algorithm that reads two numbers, computes and displays
alphabet. This means that if an element p has key k, then p will be stored at position h(k) in the table. their sum:
Keys:
Agbor = 1+7+2+15+18 = 43 Begin
Epie = 5+16+9+5 = 25 Get A
Sama = 19+1+13+1 = 34 Get B
Kome =11+15+13+5 = 44 Result = A + B
Eyong = 5+25+15+14+7 = 66 Print Result
End
Applying the function ℎ to each key we get:
Agbor = 43 mod 7 = 1 3.1.2. Flowchart
Epie = 25 mod 7 = 4 A flow chart is a diagram that uses graphic symbols to describe the nature and flow of steps in an
Sama = 34 mod 7 = 6 algorithm. Each step in a flowchart is followed by an arrow that indicates which step to go next. The
Kome = 44 mod 7 = 2 following symbols are used in flow charting:
Eyong = 66 mod 7 = 3
a. Elongated circle: indicates the beginning (start) or end (stop) of the algorithm
Hash table operations are:
o Search: compute ℎ(𝑘) and see if an element exists Start/Stop
o Insert: compute ℎ(𝑘) and place element in the resulting position
o Delete: compute ℎ(𝑘) and remove element in that position b. Rectangle: indicates instructions or actions
3. Algorithms
An algorithm is a well-defined set of step-by-step instructions for solving a problem in a finite
amount of time. A set of instructions is not an algorithm if there is no definite stopping place, or if d. Arrow: indicates the direction of flow
the instructions are too vague to be followed clearly.
A good algorithm:
- should be explicit (i.e. clear and obvious)
- should be precise (i.e. exact and accurate)
𝐶𝑜𝑚𝑚𝑎𝑛𝑑 𝑥 𝑦 𝑧
𝑥← 2 − −
Is y=0
𝑥←𝑥 + 1 − −
𝑦← 1 −
z = x/y Error 𝑧←𝑥 + 𝑦
𝑦←𝑧 + 𝑥
Explanation Condition is a Boolean expression meaning that it can take only one of two values
true or false. The condition is evaluated, if it is true, Action3 is executed. If it is false, Action 2 is 3.4.3. Repetition Control
executed. The repetition (iteration) control structure executes a statement or group of statements many times
Note that actions 2 and 3 could be a block statements. until a certain condition is reached. Repetition structures define the order of operations and the
number of repetitions. They are also called loops. Examples are, the WHILE, REPEAT and FOR loops.
E Get a, b
if (a = 0) then a. The WHILE Loop
Print “Error”
else Syntax: while condition do
Print b/a statement(s);
end while No
?
E Get n
c. The CASE Statement
x. i 1
while (i <= n) do
Syntax: case variable of
print “this is a while loop”
case 1: statement 1
ii + 1
case 2: statement 2
endwhile
…
case n: statement n
end case
Explanation The value of variable is evaluated, if it matches with case 1, instruction 1 is executed.
If it matches with case 2, instruction 2 is executed and so on. CASE is a multiple selection structure.
5) Write an algorithm that reads a person’s name and sex, and returns the message “good
Explanation The statement(s) is(are) executed and the condition is evaluated. If it evaluates to morning Mr. name” if the person is a man and “Good morning Mrs. Name” for a woman.
false, the statement or set statements is/are executed again. If condition evaluates to true, the
program exits the loop. 3.5. Recursion
Some problems are recursive in nature. This means that the solution to such problems involves the
repeated application of the solution to its own values until a certain condition is reached.
Get n
Algorithms for such problems are known as recursive algorithms.
i 1
A recursive algorithm is an algorithm that calls (invokes) itself during its execution. Examples are
repeat
the factorial function and the sum function.
print “This is a repeat loop”
Recursion can be defined as the calling of a procedure by itself, creating a new copy of the
i := i + 1
procedure.
until(i <= n)
Remark! The repeat loop must be executed at least once as the condition is evaluated only at the
end of the loop. a. Factorial Function
Factorial is defined as:
c. The FOR Loop 1! = 1
2! = 2 × 1 = 2
Syntax: for var low_limit to hi_limit do 3! = 3 × 2 × 1 = 6
statement(s); 4! = 4 × 3 × 2 × 1 = 24
end for 5! = 5 × 4 × 3 × 2 × 1 = 120
Or …
for var hi_limit downto low_limit do 𝑛! = 𝑛 × (𝑛 − 1) × (𝑛 − 2) × … × 2 × 1
statement(s);
end for By studying the above equations closely, we see that the factorial of any number 𝑛 can be calculated
by multiplying the number by the factorial of the preceding number.
Explanation var (variable) is given a value low_limit or hi_limit depending on the loop, which is We therefore have:
automatically incremented or decremented (by 1) after each iteration of the loop. The loop stops
when low_limit becomes greater than hi_limit. In both cases, if hi_limit is less than low_limit, the loop 1! = 1
body is not executed at all. 2! = 2 × 1!
E Get n 3! = 3 × 2!
x. For i 1 to n do 4! = 4 × 3!
print “this is a for loop” 5! = 5 × 4!
end For …
Or
Get n 𝑛! = 𝑛 × (𝑛 − 1)!
For i n downto 1 do
print “this is a for loop” Factorial is defined recursively as follows:
end For
Get n Get 𝑛
1 𝑖𝑓 𝑛 = 1 base case If𝑛 = 0or𝑛 = 1then 𝑓𝑖𝑏 0
𝑓𝑎𝑐𝑡 (𝑛) 𝑓𝑎𝑐𝑡1 if𝑛 = 0then
= 𝑛 × 𝑓𝑎𝑐𝑡(𝑛 − 1) 𝑖𝑓𝑛 > 1 else 𝑓𝑖𝑏 0
𝑓𝑎𝑐𝑡𝑛 × 𝑓𝑎𝑐𝑡(𝑛 − 1) else
return fact if𝑛 = 1then
𝑓𝑖𝑏 = 1
else
Remark 1! = 1 is known as the base case. Every recursive problem must always have some base 𝑓𝑖𝑏 fib(𝑛 − 1) + 𝑓𝑖𝑏(𝑛 − 2)
case which can be solved without recursion. For cases that are to be solved recursively, the return fib
recursive call must always make progress towards the base case.
Exercise! Exercise! Exercise!
b. The Sum Function Write a recursive algorithm to find the greatest common divisor (gcd) of two numbers.
The sum function is a function that calculates the sum of the first n integers. For example we want to
calculate the sum of the first 5 integers 1, 2, 3, 4 and 5. Their sum is calculated as follows: 3.6. Sort Algorithms
Sorting is a programming technique which is used to arrange a list of pre-stored data in an
Sum(5) = 1+2+3+4+5 ascending or descending order according to a preset criterion. There are lots of useful sorting
methods. For example: insertion sort, bubble sort, selection sort, quick sort, merge sort and heap
We can see that for any number n, the sum sum(n), is the number n plus the sum of the previous sort algorithms.
numbers.
The sum function can therefore be defined recursively as:
a. Bubble Sort
𝑠𝑢𝑚(1) = 1 Bubble sort algorithm arranges items in order as follows:
𝑠𝑢𝑚(2) = 2 + 𝑠𝑢𝑚(1) - First, examine the first two items in the list. If they are in order, leave them alone; if not,
𝑠𝑢𝑚(3) = 3 + 𝑠𝑢𝑚(2)
The base case is 𝑛 = 1 interchange them.
𝑠𝑢𝑚(4) = 4 + 𝑠𝑢𝑚(3) which gives 𝑠𝑢𝑚(1) = 1 - Do the same with the second and third items, then with the third and fourth items, until you
… have reached the last two. At this point you are guaranteed that the item that should come
𝑠𝑢𝑚(𝑛) = 𝑛 + 𝑠𝑢𝑚(𝑛 − 1) last in the list has indeed “bubbled” up to that position.
- Now repeat the whole process for the first (n-1) items in the list, then for (n-2) and so on until
the list is sorted.
getn
𝑠𝑢𝑚 0
begin
if𝑛 = 1then
for i = size downto 1 do
𝑠𝑢𝑚 1
for j 2 to i do
else
if (List[j-1] >List[j]) then
𝑠𝑢𝑚 n + 𝑠𝑢𝑚(𝑛 − 1)
temp List[j-1];
List[j-1] List[j];
return sum
List[j] temp;
end_if;
c. The Fibonacci Series end_for;
The Fibonacci series is a series in which each number is the sum of the two previous numbers in the end_for;
series. E.g. 0, 1, 1, 2, 3, 5, 8, 13, 21… end.
The Fibonacci series is defined as follows: Example: Sort the list [4, 3, 2, 1]
Definition: Compilation is the process of translating a program in one language (the source language) sum ident(sum)
into an equivalent program in another language (the object or target language).
:= assign_op
The process of compilation is split up into six phases: lexical analysis, syntactic analysis, semantic
analysis, intermediate code generation, code optimizing and code generation. x ident(x)
+ bin_op
2 integer
; semicolon
a. Class e. Inheritance
A class is a description of an object or a real life concept. Classes are templates for creating objects, Inheritance is the derivation of one class from another so that the attributes and methods of the
providing initial values for instance variables (attributes) and the bodies for methods. All objects derived class are part of the definition of the initial class. The initial class is often called the base
generated from the same class share the same methods, but contain separate copies of the instance class, parent class or super class while the derived class is often referred to as the child class or sub-
variables. New objects can be created from a class by applying the new operator to the name of the class. The subclass usually contains all the attributes and methods of the superclass plus some of its
class. own.
For example: the class Student inheriting from the class person will have all the attributes and
Class Person { methods of Person plus the following:
private:
char name[20]; Class Student extends Person {
char sex; private
date birthdate; int admNumber;
public: int level;
updateInfo(); public
returnAge(); changeLevel(int newLevel) {
}; level=newLevel;
}
The name of the class is person. It has four instance variables (attributes) name, sex and age, and }
three methods: updateInfo(),and returnAge(). These methods act on the instance variables when
invoked. Inheritance is usually represented using an inheritance diagram.
For example: if the classes Student and Teacher are derived from the superclass Person, this is
b. Object represented as:
An object is an instance of a class. An object consists of a collection of attributes, representing the
state of the object, and a collection of methods, representing the behavior that the object is capable Person Person
of performing. Attributes are sometimes referred to as the fields of an object. The methods are
routines that are capable of accessing and manipulating the values of the attributes of the object.
Objects interact with each other by sending messages. When a message is sent to an object, the
corresponding method of the object is executed. Student Teacher
There are two types of Inheritance: multiple inheritance and multilevel inheritance.
c. Abstraction
Abstraction is the process of representing important details and hiding away the implementation Multiple inheritance is when a derived class inherits features from more than one
details. Through abstraction unnecessary details are removed so that one can focus on only the superclass. It is illustrated as follows:
relevant parts of a problem in order to solve it. Abstraction is obtained by separating the interface
and the implementation. For example, functions use the concept of abstraction. Base class 1 Base class 2
Statements 1, 2, and 3 are each executed once. Statements 5, 6, and 7 are each executed n times. c. Quadratic Time or O(𝒏𝟐 )
Statement 4 (which controls the loop) is executed n + 1 times (one additional check is required), and An algorithm is said to run in quadratic time if its execution time is proportional to n squared. For
statement 8 is executed once. The running time T(n) of this algorithm is given as follows: example, if the computation involves comparing each item of input with all of the other items, it will
take 𝑛2 steps. Many sorting algorithms are O(𝑛2 ).
Number of
Statement
times executed
d. Polynomial Time or O(𝒏𝒌 )
1 1 An algorithm is said to run in polynomial time if its execution time is proportional to n raised to
2 1 some constant power. A program that contains k nested loops, each with a number of steps
3 1 proportional to n, will take time proportional to 𝑛𝑘 .
4 n+1
e. Exponential Time or O(𝒌𝒏 )
5 n An algorithm is said to run in exponential time if its execution time is proportional to some constant
6 n k raised to the nth power. Exponential-time computations are generally not practical.
7 n
f. Logarithmic Time or O(log n)
8 1
An algorithm is said to run in logarithmic time if its execution time is proportional to the logarithm
of the input size. An example is binary search.
𝑇(𝑛) = 1 + 1 + 1 + 𝑛 + 1 + 𝑛 + 𝑛 + 𝑛 + 1 = 4𝑛 + 5
2. Computability
Computability deals with whether a problem can be solved at all, regardless of the resources
required.