Untitled Document-2 2
Untitled Document-2 2
Data Representation
● The two fundamental characteristics of any number system are:
○ A base: The number of different digits that a system can use to
represent numbers
○ Place value: The specific-value of a digit based on its position within
a number
● Denary - Base 10
● Binary Systems - Base 2
○ Possible bits (binary digits): 0 and 1
○ All data and characters are represented in binary
128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0
Only the English alphabet ASCII’s extension - Also Superset for ASCII &
can be represented includes most European extended ASCII - recognized
languages’ alphabets by various global languages
Each character encoding ASCII extended to 8 bits, It has an excellent range of
takes up 7 bits, hence 128 hence 256 possible characters, using 2 or 4
possible characters characters bytes per character
n
○ colours per pixel (e.g., a 16-color bitmap has 4 bits per pixel because 2
4
○
4
○ = 16)
○ Effect: Increasing color depth improves color quality but also increases file
size.
○ File Size Calculation:
■ File Size = Number of Pixels × Color Depth
■ Convert bits to bytes by dividing by eight if necessary.
○ Applications: Scanned images and general computer usage, where small
file sizes and easy manipulation are beneficial.
● Vector Graphics
○ Definition: Made up of drawing objects.
○ Drawing Objects: Mathematically defined constructs (e.g., rectangles,
lines, circles).
○ Drawing List: A set of commands defining the vector.
○ Properties: Basic geometric data that determine the shape and
appearance of each object.
○ Encoding: Data is encoded using mathematical formulas to generate
properties for drawing lines and curves to create the image.
○ Scalability: Objects can be resized without losing quality, unlike bitmaps.
○ Applications: Company logos and other graphics that require scaling.
● Sound
○ Analogue vs Digital:
■ Analogue data consists of continuous electrical signals.
■ Digital data consists of discrete electrical signals.
○ Sound Signals: Vibrations through a medium, inherently analogue due to
infinite detail.
○ Conversion:
■ Analogue signals are converted to digital signals by sampling.
■ The sound wave’s amplitude is sampled at set time intervals.
■ These samples are encoded as a binary number sequence,
providing a digital representation of the sound wave
● Sampling Rate
○ Definition: Number of samples taken per unit of time.
○ Effect: Increasing the sampling rate improves the accuracy of the digitized
sound wave representation but increases file size.
● Sampling Resolution
○ Definition: Number of bits used to encode each sample.
○ Effect: Increasing sampling resolution improves the accuracy of digitized
sound waves but increases file size.
● Bit Rate
○ Definition: Number of bits used to store 1 second of sound.
○ Calculation:
○ Bit Rate=Sampling Rate∗Sampling Resolution
○ Bit Rate=Sampling Rate∗Sampling Resolution
○ Length of Sound: Measured in seconds.
Compression
● Definition: Compression is the process of reducing file size without significant
loss in quality, resulting in:
○ Reduced time needed to search for data.
○ Faster transfer of compressed files, using less bandwidth than
uncompressed files.
● Lossless Compression
○ Definition: A type of compression that allows original data to be perfectly
reconstructed from a compressed file by utilizing some form of
replacement.
○ Examples: Bitmap (.bmp), vector graphic (.svg), .png images, text file
compression, database records.
○ Run-Length Encoding (RLE):
■ Definition: A form of lossless compression used for compressing text
files and bitmap images.
■ Mechanism: Reduces file size by encoding sequences of adjacent,
identical elements (characters in text files and pixels in bitmap
images) into two values: run count and run value.
■ Example: RLE of a bitmap image.
● Lossy Compression
○ Definition: A type of compression that irreversibly eliminates unnecessary
data.
○ Effect: File accuracy/quality is lower than with lossless compression, but
file size is significantly reduced (often to about 10% of the lossless size).
○ Examples: Sound files (.mp3), .jpeg images.
○ Mechanism in Sound Files:
■ Perceptual Coding: Removes parts of the sound that are less audible
or discernible to human hearing, as used in .mp3 compression.
Networks, including the Internet
LAN WAN
Only provides input and receives output; Thick client processes most of
processing is done by the server. the application locally.
Client-Server Peer-to-Peer
Files & resources centralized in Lesser network traffic: Each peer can
server: Prevents illegal resource simultaneously receive data from
usage. different sources.
Improved security: Files are stored on It can work even if a device goes
a central server, which would be down, but the client-server model
regularly scanned for malware. can’t work if the server goes down.
Benefits Drawbacks
Copp Less expensive and easier to install. Flexible. Doesn’t perform well
er Easier to make terminations. with small charges.
Cable Affected by
electromagnetism.
● Wired Networks
○ Use copper (twisted-pair cable or coaxial cable) or fiber-optic cables.
○ Cables are connected to an Ethernet port on the network router.
Benefits Drawbacks
Radio Can travel over large distances Low frequency means less
waves with a wide range of wavelengths. data can be transmitted at one
Relatively inexpensive. Used for time. Affected by interference
TV signals and mobile phone from radio stations with similar
communications. frequencies.
Microwa Larger bandwidth allows more Expensive to build emitting
ves data transfer. towers. Physical obstacles can
interfere with signals.
● Wireless Networks
○ Use radio waves (including WiFi), microwaves, and satellites to
connect devices to networks without cables.
Real-time On-demand
The event is captured live via a video Existing digital files are converted to
camera that is connected to a encoded bit-streaming format for
computer. broadcasting on the internet by
uploading to a dedicated server.
Encoded video signal uploaded from The data is streamed to a buffer in the
computer to a dedicated streaming user’s computer, and the buffer stops
server via cables or high-speed the video from being paused as the
wireless internet connection. bits are streamed.
The server then sends live images to As the buffer is emptied, it’s filled
all users requesting them as a again, thus providing continuous
real-time video. viewing.
It cannot be paused, fast-forwarded, Can be paused, fast-forwarded, etc.
etc.
● Ethernet
○ The most common wired medium for data transmission in LANs or
WANs.
○ Typically used in bus topology; data collisions are managed by the
CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
method.
○ CSMA/CD Process:
■ Device checks if the channel is busy before transmitting.
■ If busy, the device waits a random time before retrying.
■ During transmission, the device listens for other
transmissions.
■ If a collision occurs, transmission is aborted, and both devices
wait random times before retrying.
● Bit Streaming
○ Sequence of digital signals (bits) transferred over a communication
path at high speeds, requiring a fast broadband connection and
buffers.
○ Bit Streaming Types:
■ Real-time: Live events captured and transmitted directly.
■ On-demand: Pre-existing files are converted and streamed as
requested.
○ Importance of High Broadband Speed/Bit-Rate
■ The user has to download and display bits at the same time.
■ Higher quality media requires faster speeds due to larger data
frames as well.
■ Real-time streaming needs higher speeds due to simultaneous
data requests coming from multiple different users.
● Cloud Computing
○ On-demand provision of computing services over the internet,
including infrastructure, and platforms.
■ Infrastructure: Storage capacity and higher processing power.
■ Platform: Software, testing & debugging resources.
Public cloud vs. Private cloud
Benefits Drawback
Flexibility to scale with Poor data privacy, since there may be data
organization’s growth leakage in the multi-tenant architecture (public
mindset. clouds).
● LAN-Supporting Hardware:
○ Switch:
■ Connected to all devices in a LAN.
■ Can simultaneously broadcast information to all devices.
○ Server:
■ Device/software that provides specific functions for computers
in the network.
○ Network Interface Card (NIC):
■ Provides each device (end-system) in the wired LAN with a
unique MAC address to uniquely identify it on the network.
■ Allows each device to connect to the network.
○ Wireless Network Interface Card (WNIC):
■ Provides each end-system of a wireless (WiFi) LAN a unique
network address to identify it.
○ Wireless Access Points (WAP):
■ Allows devices to connect to the LAN via WiFi instead of using
a cable.
■ Usually built into the router.
○ Cables:
■ A wired transmission medium that allows communication in
wired networks.
○ Bridge:
■ Connects two LANs which work using the same protocol,
which can be two segments of the same network.
■ Stores network addresses for all devices (end-systems)
between the two networks.
■ Looks for the receiving device before it sends the message.
○ Repeater:
■ Connects two cables.
■ Regenerates the sent data signal over the same network
before the signal weakens (attenuation) to prevent it from
being corrupted.
● Internet-Supporting Hardware:
○ Modems:
■ Allows a device to connect to the Internet via a telephone line.
■ Function: A transmitter uses a modem to convert digital
signals (from the transmitting device) to analogue signals sent
down the telephone line. A receiver uses a modem on the
other end to convert the analogue signals to digital signals so
the receiving device can understand the data.
○ PSTN (Public Switched Telephone Network):
■ Refers to all telephone networks.
■ Channel: Used between two endpoints for the call duration via
circuit switching.
■ Resilience: Lines are active even during a power outage.
■ Communication: Bi-directional.
○ Dedicated Lines:
■ Telecommunication path between endpoints.
■ Not shared with multiple users; it’s bought/leased.
■ Function: Able to host websites as well as carry phone calls.
Allows continuous, uninterrupted access to the Web.
○ Cell Phone Network:
■ Wireless networks spread over land areas divided into
(hexagonal) cells.
■ Base Stations: Each cell is served by at least one base station
(transceiver), which uses a different frequency range
compared to adjacent cells to transmit data.
■ Capacity: Larger capacity is possible since the same
frequencies can be used in non-adjacent cells.
■ Transmission: Radio waves are usually used for transmission.
Can be broadcast in all directions over a wide area.
■ Portable Transceivers: Devices like mobile phones can
communicate and access the internet via base stations.
IPv4 IPv6
32-bit address, The 128-bit address is divided into eight 16-bit blocks by
split into 4 blocks “:”
by “.”
Each block could Each block can have 4 hex values ranging from 0000 to
have a value FFFF.
between 0 and 255
(00 to FF in hex).
Static Dynamic
Benefits Drawbacks
Reliable since there are no moving Difficult to program functions since there is no
parts interface
Require less power Expensive expert help is needed for the repair
Cheap to mass-produce
Principle Operations of Hardware Devices
Laser printer:
● A laser beam and rotating mirrors are used to draw an image of the page on a
photosensitive drum
○ The image is converted into an electric charge, which attracts charged
toner such that it sticks to the image
● Electrostatic-charged paper rolled against the drum
● Charge pulls toner away from drum and onto paper
● Heat applied in the fuser to fuse toner to the paper
● The electrical charge was removed from the drum, and excess toner was
collected
3D Printer:
● The process starts with a saved digital file that holds the blueprint of the object to
be printed
● The object is then built by sequentially adding layers of a material (e.g. polymer
resin) until the object created
● The object is then cured (e.g. resin-made objects are hardened by UV light)
Microphone:
● Incoming sound waves enter the screen and cause vibrations in the diaphragm
● Vibrations cause the coil to move past a magnetic core
● Electrical current is generated, which is then digitized
Speaker:
● Takes electrical signals and translates them into physical vibrations to create
sound waves
● The electric current in the voice coil generates an electromagnetic field
● Change in digital audio signal causes current direction to change, which changes
field polarity
● Electromagnet is either attracted or repelled to a permanent magnet, causing a
diaphragm that is attached to the coil to vibrate
● Vibration transmitted to air in front of the speaker
● The degree of vibration determines the amplitude and frequency of the sound
wave produced
Magnetic Hard Disk:
● Hard disks have platters whose surfaces are covered with a magnetisable
material.
● Platters are mounted on a central spindle and rotated at high speed
● The surface of platters is divided into concentric tracks & sectors, where data is
encoded as magnetic patterns
● Each surface is accessed by read/write heads
● When writing, current variation in the head causes magnetic field variation on the
disk
● When reading, magnetic field variation from the disk produces current variation in
the read head
Solid State (Flash) Memory:
Pressure causes plates to touch, completing the When touched, the charge is
circuit transferred to the finger
RAM ROM
Volatile memory: loses content when Non-volatile memory: does not lose content
power is turned off when power is turned off
SRAM DRAM
Doesn’t need to refresh; hence, it uses Has to be refreshed; it has slower access
less power and faster access time times and needs higher power
More complex circuitry, hence more Only a single transistor & capacitor,
expensive hence less expensive to purchase
Data cannot be Chip has to be removed for Can update data without
erased or deleted reprogramming removing the chip.
A B Output
0 0 0
0 1 0
1 0 0
1 1 1
A B Output
0 0 0
0 1 1
1 0 1
1 1 1
A Output
1 0
0 1
● NAND gate: (A•B)
A B Output
0 0 1
0 1 1
1 0 1
1 1 0
0 0 1
0 1 0
1 0 0
1 1 0
A B Output
0 0 0
0 1 1
1 0 1
1 1 0
Fundamentals
Central Processing Unit (CPU)
Architecture
Von Neumann model
● Von Neumann realized data & programs are indistinguishable and can, therefore,
use the same memory.
● Von Neumann's architecture uses a single processor.
● It follows a linear sequence of fetch–decode–execute operations for the set of
instructions, i.e. the program.
● To do this, the processor uses registers.
Registers
● Arithmetic and Logic Unit (ALU): part of the processor that processes instructions
which require some form of arithmetic or logical operation
● Control Unit (CU): part of the CPU that fetches instructions from memory,
decodes them & synchronizes operations before sending signals to the
computer’s memory, ALU and I/O devices to direct how to respond to instructions
sent to the processor
● Immediate Access Store (IAS): memory unit that the processor can directly
access
● System Clock: a timing device connected to a processor that synchronises all
components.
Buses
● Set of parallel wires that allow the transfer of data between components in a
computer system
○ Data bus: bidirectional bus that carries data instructions between
processor, memory, and I/O devices.
○ Address bus: unidirectional bus that carries the address of the main
memory location or input/output device about to be used, from processor
to memory address register (MAR)
● Control bus
○ Bidirectional
○ used to transmit control signals from the control unit to ensure access/use
of data & address buses by components of the system does not lead to
conflict
Performance of Computer System Factors
● Clock Speed
○ Number of pulses the clock sends out in a given time interval, which
determines the number of cycles (processes) the CPU executes in a given
time interval
○ Usually measured in Gigahertz (GHz)
○ If the clock speed is increased, then the execution time for instructions
decreases. Hence, more cycles per unit time, which increases
performance.
○ However, there is a limit on clock speed since the heat generated by
higher clock speeds cannot be removed fast enough, which leads to
overheating.
● Bus Width
○ Determines the number of bits that can be simultaneously transferred
○ Refers to the number of lines in a bus
○ Increasing bus width increases the number of bits transferred
simultaneously, increasing processing speed and performance.
● Cache Memory
○ Commonly used instructions are stored in the cache memory area of the
CPU.
○ If the cache memory size is increased, more commonly executed
instructions can be stored, and the need for the CPU to wait for
instructions to be loaded reduces. Hence, the CPU executes more cycles
per unit of time, thus improving performance.
● Number of Cores
○ Most CPU chips are multi-core — have more than one core (essentially a
processor)
○ Each core simultaneously processes different instructions through
multithreading, improving computer performance.
Ports
● Hardware which provides a physical interface between a device with CPU and a
peripheral device
● Peripheral (I/O) devices cannot be directly connected to the CPU, hence
connected through ports.
● Universal Serial Bus (USB): Can connect both input and output devices to the
processor through a USB port.
● High Definition Multimedia Interface (HDMI)
○ Can only connect output devices (e.g. LCD) to the processor through a
HDMI port
○ HDMI cables transmit high-bandwidth and high-resolution video & audio
streams through HDMI ports
● Video Graphics Array (VGA)
○ Can only connect output devices (e.g. second monitor/display) to the
processor through a VGA port
○ VGA ports allow only the transmission of video streams but not audio
components
Fetch-Execute (F-E) cycle
● Fetch stage
○ PC holds the address of the next instruction to be fetched
○ The address on the PC is copied to MAR
○ PC is incremented
○ Instruction loaded to MDR from the address held in MAR
○ Instruction from MDR loaded to CIR
● Decode stage: The opcode and operand parts of instruction are identified
● Execute stage: Instructions executed by the control unit sending control signals
● Register Transfer Notation (RTN)
○ MAR ← [PC]
○ PC ← [PC] + 1
○ MDR ← [[MAR]]
○ CIR ← [MDR]
○ Decode
○ Execute
○ Return to start
○ Square brackets: value currently in that register
○ Double square brackets: CPU is getting value stored at the address in the
register
Interrupts
Assembly Language
● Assembly language: low-level programming language with instructions made up
of an op code and an operand
● Machine code: code written in binary that uses the processor’s basic machine
operations
● Relationship between machine and assembly language: every assembly
language instruction (source code) translates into exactly one machine code
instruction (object code)
● Symbolic addressing
○ Symbols used to represent operation codes
○ Labels can be used for addresses
● Absolute addressing: a fixed address in memory
● Assembler
○ Software that changes assembly language into machine code for the
processor to understand
○ The assembler replaces all mnemonics and labels with their respective
binary values (that are predefined before by the assembler software)
● One pass assembler
○ Assembler converts mnemonic source code into machine code in one
sweep of program
○ Cannot handle code that involves forward referencing
● Two pass assembler: software makes 2 passes thru code
○ On the first pass:
■ Symbol table created to enter symbolic addresses and labels into
specific addresses
■ All errors are suppressed
○ On the second pass:
■ Jump instructions access memory addresses via table
■ Whole source code translates into machine code
○ Error reported if they exist
● Grouping the Processor’s Instruction Set
Addressing
Data Movement
STO Store contents of ACC into address
Arithmetic
Operations
Comparing
Conditional Jumps
Unconditional
Jumps
JMP Jump to given address
I/O Data
Ending
B denotes a binary number, e.g. B01001010 & denotes a hexadecimal number, e.g.
&4A
● Modes of Addressing
○ Direct Addressing: loads contents at address into ACC
○ Indirect Addressing: The address to be used is at given address. Load
contents of this second address to ACC
○ Indexed addressing: form the address to be used as + the contents of the
IR (Index Register)
○ Relative addressing: next instruction to be carried out is an offset number
of locations away, relative to address of current instruction held in PC;
allows for relocatable code
○ Conditional jump: has a condition that will be checked (like using an IF
statements)
○ Unconditional jump: no condition to be followed, simply jump to the next
instruction as specified
Bit Manipulation
● Binary numbers can be multiplied or divided by shifting
● Left shift (LSL #n)
○ Bits are shifted to the left to multiply
○ E.g. to multiply by four, all digits shift two places to left
● Right shift (LSR #n)
○ Bits are shifted to the right to divide
○ E.g. to divide by four, all digits shift two places to right
● Logical shift: zeros replace the vacated bit position
● Arithmetic shift: Used to carry out multiplication and division of signed integers
represented by bits in the accumulator by ensuring that the sign-bit (usually the
MSB) is the same after the shift.
● Cyclic shift: the bit that is removed from one end by the shift is added to the other
end.
Bit Masking
● Disk Formatter
○ Prepares a hard disk to allow data to be stored on it
○ Deletes any existing data on disk
○ Performs formatting, process where computer ‘draws lines’ on disk
surface to split it into small areas
● Virus checker
○ Checks for and then removes any viruses found
○ Constantly checks all incoming and outgoing files
● Defragmentation Software
○ Files can be big so have to be stored in multiple sectors, which can result
in fragmentation (contents of file scattered across >2 non-contiguous
sectors)
○ Fragmentation slows down disk access and thus the performance of the
entire computer.
○ Defragmenting software works by physically reorganizing disk contents
(files) such that they are stored in contiguous sectors.
○ This defragmentation reduces number of movements of the read/write
heads require to access the disk contents, hence increasing computer
performance
○ The defragmentation also creates larger contiguous free space regions
● Disk contents analysis/disk repair software
○ Software utility for visualization of disk space usage
○ Gets size for each folder and files, and generates a graphical chart
showing disk usage distribution according to folders or other user defined
criteria.
○ Allows disk to report errors (e.g. “bad sector”)
○ Software will attempt to offer a solution
● File Compression
○ Reduces file size by removing redundant data in files
○ Causes improvements in the computer’s performance by reducing the
data that needs to be stored
● Back-up Software
○ Makes copy of files on another storage medium in the event of a hard
drive failure, user error, disaster or accident.
○ Should be a regular process
○ Can provide synchronization between devices
Program Libraries
● Pre-written code that can be linked to a software under development without any
amendments
● Can perform common or complex tasks
● Takes the form of classes
● Benefits:
○ Saves time: less code needs to be written
○ Smaller testing time: pre-tested and used by others
○ Library file is a complex algorithm which the user does not need to
understand to use it
● Dynamic Link Library (DLL) files
○ Shared library file that contains code and data
○ Code saved separately from the main .EXE file, reducing the .EXE file’s
size
○ Code only loaded to main memory when required
○ DDL file can be made available to several applications simultaneously,
thus reducing strain on memory
○ DLL files act as modules in more complex programs, making it easier to
install and run updates
Language Translators
● Assembler
○ Software that translates assembly language statements into machine code
(binary) for execution
○ The mnemonics used translates into machine opcodes
○ Process simple because assembly language has a one-to-one relationship
with machine code.
● Compiler and Interpreter
Compiler Interpreter
Once compiled, .exe file does not Execution very slow – translated each time
need to be compiled again, resulting program run.
in faster execution.
Only be produced when all errors are Can run program any time, even before code
fixed. finished.
● Two-step translation
○ Java and some other high level language programs may require two-step
translation, i.e., they will be partially compiled and partially interpreted
○ Java code first translated to bytecode by Java compiler
○ Bytecode finally interpreted by the Java Virtual Machine to produce
machine code
● Integrated Development Environment (IDE) features
○ Coding
■ Context-sensitive prompts: Displays choice of keywords and
available identifiers appropriate at current insertion point and
provides choices in alphabetical order
■ Highlights undeclared/unassigned variable identifiers
○ Initial Error Detection
■ Dynamic syntax checks: Automatic checking and highlighting of
syntax errors, as soon as line typed
■ Type checking & parameter checking
○ Presentation
■ Prettyprint: Automatic indentation and color-coding of keywords
■ Expand and Collapse code blocks: Saves excessive scrolling if
collapsed, and easy to see global variable declarations and main
program body when collapsed
○ Debugging
■ Single stepping: Executes program line-by-line to see the effect of
each statement on variables
■ Breakpoints: Pauses program at a specific line to ensure program
operates correctly up to that line
■ Variables/expressions Report Window: Monitors variables for
comparing values.
, Privacy and Data
Integrity
Data Security
● Data Security: ensuring data is protected against loss and unauthorized access.
● Data Integrity: making sure that data is valid and does not corrupt after
transmission
● Data Privacy: ability to determine what data is shared with a third party
● Data Security and Computer System Security
● Malware
○ software intentionally designed to damage a computer or computer
network
○ Includes Virus & Spyware
○ Virus: Software that replicates itself by inserting a copy of itself into
another piece of software, which may cause the computer to crash and
can lead to deletion or corruption of data
○ Spyware: software that gathers information about users' online and offline
activity, including accessed sites, applications, and downloaded files.
○ Risk restriction: Ensure anti-virus and anti-spyware software is installed,
regularly updated and run.
● Hacking
○ illegal access to a computer system
○ Hackers can obtain user’s confidential data which can cause identity theft
○ Can lead to the deletion or corruption of data
○ Risk restriction: Use strong passwords and ensure firewall
● Phishing
○ Attempt through emails to obtain user’s confidential data which can cause
identity theft
○ Risk restriction: Ignore suspicious mails and ensure firewall criteria include
SPAM filters, blacklist, etc.
● Pharming
○ Redirects user to a fake website that appears legitimate to gain
confidential data
○ Risk restriction: use a reliable ISP; check that links are genuine and
ensure https is present in the URL
Computer System Security Measures
Data Integrity
● Data validation and data verification help protect the integrity of data by checking
whether the data entered is sensible and accurate, respectively.
● Data Validation: checks if data entered is valid, but not its accuracy
● Data Validation Methods
○ Range check: data must be between a set of values
○ Format check: data must follow correct pattern/order
○ Length check: data must have exact no. of characters
○ Presence check: checks if some data has been entered
○ Existence check: data entered must exist
○ Limit check: checks whether a value entered is within acceptable minimum
and maximum values.
○ Check digit: A digit is used as the answer to an arithmetic operation of
other digits in data. If not matched, then data entered incorrectly
● Data Verification: checks data entered is accurate during data entry and data
transfer
● Data Entry Verification Methods
○ Visual Check: Person manually compares original data with that entered to
check if correct
○ Double Entry: Enter data into computer twice and compares.
○ If differences found, go back to raw data to fix error
Data Transfer Verification Methods
Normalization
1st Normal Form (1NF): contains no repeating attribute or groups of attributes.
dependent on the primary; all the incomplete dependencies have been removed.
Example:
3rd Normal Form (3NF): it is in 1NF and 2NF and all non-key elements are fully
becomes:
Data Definition Language (DDL)
● Creation/modification of the database structure using this language
○ written in SQL
● Creating a database:
CREATE DATABASE <database-name>
● Creating a table:
CREATE TABLE <table-name> (…)
● Changing a table:
ALTER TABLE <table-name>
● Example:
CREATE DATABASE ‘Personnel.gdb’
CREATE TABLE Training
(EmpID INT NOT NULL,
CourseTitle VARCHAR(30) NOT NULL,
CourseDate Date NOT NULL,
PRIMARY KEY (EmpID, CourseDate),
FOREIGN KEY (EmpID) REFERENCES Employee(EmpID))
Creating a query:
SELECT <field-name>
FROM <table-name>
WHERE <search-condition>
●
● SQL Operators:
= Equals to
● Deleting a record:
DELETE FROM <table-name>
WHERE <condition>
Identifier Table
● Identifier: name given to a variable in order to call it
● An identifier table depicts information about the variable, e.g.
number of iterations required, and a WHILE or REPEAT loop if you do not know the
Stepwise Refinement
● Process of developing a modular design by splitting a problem into smaller
sub-tasks, which themselves are repeatedly split into even smaller sub-tasks until
each is just one element of the final program.
Program Modules
● This refers to a modular program design
● Subroutines: self-contained section of code, performing a specific task; part of
the main program
● Procedures: performs a specific task, no value returned to part of code where
called
● Functions: performs a specific task, returns a value to part of code where called
Logic Statements
Operator Meaning
>= Greater/equal
= Equal to
ASCII Code
● Uses 1 byte to store a character
● 7 bits available to store data and 8th bit is a check digit
● 27 = 128, therefore 128 different values
● ASCII values can take many forms: numbers, letters (capitals and lower case are
separate), punctuation, non-printing commands (enter, escape, F1)
Unicode
● ASCII allows few number of characters; it is good for English
● Unicode allows others, too: Chinese, Greek, Arabic, etc.
● Different types of Unicode:
○ UTF-8: compatible with ASCII, variable-width encoding can expand to 16,
24, 32, 40, 48
○ UTF-16: 16-bit, variable-width encoding can expand to 32 bits
○ UTF-32: 32-bit, fixed-width encoding, each character exactly 32 bits
Arrays
● 1-Dimensional (1D) Array: declared using a single index, can be represented as
a list
● Pseudocode:
○ 1-D Array: array = []
○ 2-D Array: array = [[], [], [], …]
● Python:
○ Declaring an array: names = []
○ Adding to an array: names.append(‘ZNotes’)
○ Length of array, i.e. number of elements: len(names)
○ Printing an element in a 1D array: print(names[element position])
○ Printing element in a 2D array: print (a[row][column])
○ Printing row in a 2D array: names[row] = [new row]
○ Printing column: Use it for loop, add 1 to the row, and keep the column the
same.
Bubble Sort
Linear Search
File Handling
● Files are needed to import contents (from a file) saved in secondary memory into
the program, or to save the output of a program (in a file) into secondary memory,
so that it is available for future use
Pseudocode:
Mod Description
e
r Opens file for reading only. Pointer placed at the beginning of the file.
w Opens a file for writing only. Overwrites file if file exists or creates new file if it
doesn’t
a Opens a file for appending. Pointer at end of file if it exists or creates a new
file if not
● Reading a file:
○ Read all characters: variable.read()
○ Read each line and store as list: variable.readlines()
● Writing to a file:
○ Write a fixed a sequence of characters to file: variable.write(“Text”)
○ Write a list of string to file: variable.write(‘ ‘.join(‘Z’, ‘Notes’))
Abstract Data
Types (ADT)
An Abstract Data Type (ADT) is a collection of data with associated operations. There
● Stack: an ordered collection of items where the addition of new items and
removal of existing items always takes place at the same end.
● Queue: a linear structure which follows the First In First Out (FIFO) mechanism.
Items are added at one end (called the rear) and removed from the other end
(called the front)
● Linked List: a linear collection of data elements whose order is not given by
physical placements in memory (non-contiguous). Each element points to the
next.
PROGRAMING
● Programming is a transferable skill
● Transferable skill: skills developed in one situation which can be transferred to
another situation.
Variables
● Declaring a variable:
○ Pseudocode: ‘’’DECLARE : ‘’’
○ Python: no need to declare however must write above as a comment
(‘’’python #...‘’’)
● Assigning variables:
‘’’python ← ‘’’ or ‘’’python ‘’’
Selections
● “IF” Statement
○ Pseudocode: IF…THEN…ELSE…ENDIF
○ Python: if (expression): (statements) else: (statements)
● “CASE” Statement
○ Pseudocode: CASE OF variable: … … … OTHERWISE: … ENDCASE
○ Python: if (expression): (statement) elif (expression): statement) … else: (statement)
Iterations
Count-controlled Loop
<statement(s)>
ENDFOR
statement(s)
Pre-condition Loop
WHILE <condition> while expression:
<statement(s)> statement(s)
ENDWHILE
Built-in Functions
String/character manipulation:
Procedure
Procedure: subroutine that performs a specific task without returning a value
● Procedure without parameters:
● When a procedure has a parameter, the function can either pass it by either
reference or value
● Pass by value: data copied into procedure so variable not changed outside
procedure
PROCEDURE <identifier> (BYVALUE <param>: <datatype>)
<statement(s)>
ENDPROCEDURE
def identifier(param):
statement(s)
<statement(s)>
ENDPROCEDURE
● Calling a procedure:
CALL () Identifier()
Function
Function: subroutine that performs a specific task and returns a value
Functions are best used to avoid having repeating blocks of code in a program, as well
<statement(s)>
ENDFUNCTION
def identifier(param):
statement(s)
return expressioN
Development
Program Development Cycle
● Analyze problem: define problem, record program
specifications and recognize inputs, process, output & UI
● Design program: develop logic plan, write algorithm in e.g.
pseudocode or flowchart and test solution
● Code program: translate algorithm into high level language
with comments/remarks and produce user interface with
executable processes
● Test and debug program: test program using test data, find
and correct any errors and ensure results are correct
● Formalize solution: review program code, revise internal
documentation and create end-user documentation
● Maintain program: provide education and support to
end-user, correct any bugs and modify if user requests
There are three different development life cycles:
Integrated Development
Environment
● A software application that allows the creation of a
program e.g. Python
● Consists of a source code editor, build automation tools, a
debugger
Coding:
● The IDE executes the code & initial error detection carried
out by compiler/interpreter doing the following:
○ Syntax/Logic Error: before program is run, an error
message warns the user about this
○ Runtime Error: run of the program ends in an error
Debugging:
Structure Charts
● Purpose: used in structured programming to arrange program
modules, each module represented by a box
● Tree structure visualizes relationships between modules,
showing data transfer between modules using arrows.
● Example of a top-down design where a problem (program) is
broken into its components.
Rules:
● Process: Represents a programming module e.g. a calculation
Example:
Types of Errors
Syntax errors:
Corrective Maintenance
● Corrective Maintenance is correcting identified errors
● White-Box testing: making sample data and running it
through a trace table
● Trace table: technique used to test algorithms; make sure
that no logical errors occur e.g.
Adaptive Maintenance
● Making amendments to:
○ Parameters: due to changes in specification
○ Logic: to enhance functionality or more faster or both
○ Design: to make it more user friendly
Testing Strategies
Black box testing: