My Notes

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 33

Chapter 1

Algorithm

An algorithm is a precise method for solving a problem. An algorithm is a


step-by-step procedure for solving a problem or carrying out a task.

Algorithm and Programs

An algorithm is a detailed design for a solution.

A program is when the design is implemented.

Successful Algorithm

Accuracy - expected outcome

Consistency – same result

Efficiency – shortest possible time, as few computer resources as possible

Written Descriptions

A written description is the simplest way of expressing an algorithm.

Flowcharts

Flowchart is a diagram that is used to show an algorithm. It provides a


more visual display.
Terminal Proces Decision/ Input/ Line/ Logical
s Selection Output flow

Pseudocode

A pseudocode is a structured, code-like language that can be used to


describe an algorithm.

Similar to programming languages

Cannot be understood by computers

Variable

A variable is a container that is used to store data. The data stored in a


variable is not fixed.

Constant

A constant is a container that holds a value that never changes.

Identifier

An identifier is a unique name given to a variable or a constant.


firstName Or FirstName  Camel case

first_name, second_name  Snake case

Chapter 2
Selection

A selection is a construct that allows a choice to be made between


different alternatives.

Iteration

An iteration is a construct that means a process is repeated. An action is


repeated until a condition is met or a particular outcome is reached. It is often
referred to as a loop.

Condition

A condition is something that must happen before something else happen.

Chapter 3
Bubble Sort

Start at the beginning of the list.


Compare the value in position 1 and position 2 in the list – if they are not in
ascending order then swap them.

Compare the value in position 2 and position 3 in the list and swap if necessary.

Continue to the end of the list.

If there have been any swaps, repeat steps 1 to 4.

Merge Sort

Merge Sort is a sorting algorithm that breaks a list into its component parts
and then builds it up again with them in the correct order.

Brute force

Brute force is an algorithm design that does not include any techniques to
improve performance, but instead relies on the computing power to try all
possibilities until the solution to a problem is found.

Divide and Conquer

Divide and conquer is an algorithm design that works by dividing a problem


into smaller and smaller sub-problems, until they are easy to solve. These
solutions are then combined to give a solution to the complete problem.

Linear Search
Linear search starts at the beginning of the list and goes through it, item by
item, until it finds the item it is looking for or reaches the end of the list without
finding it.

Binary Search

A binary search compares the search item with the median item in a list,
repeatedly splitting the list in half until the item is found or there are no more
items left to search.

The list must have been sorted into ascending or descending order. It will not
work on an unsorted list.

Chapter 4
Decomposition

Decomposition is breaking down a problem into smaller parts, which are


easier to solve.

Abstraction

Abstraction is the process of removing or hiding unnecessary detail so that


only the important points remain.
Subprogram

A subprogram is a self-contained module of code that performs a specific


task. It can be called by the main program when it is needed.

Chapter 5
Why are variables needed?

Variables are needed to control the number of time a loop is executed, to


determine which branches of an IF statement is taken, to keep running and to
hold user input.

Program

A program is an algorithm that has been converted into program code so


that it can be executed by a computer.

Data Types

Integer whole number

fractions or decimals(sometimes called floating


Real or Float
points)

Boolean Only has two possible values: True or False

Character A single letter, a symbol, a number or a space

String A set of characters


Assignment statement

The SET…TO command is used to initialize variables or change its values


in pseudocode.

Type Coercion

Type Coercion is the process of converting the value stored in a variable


from one data type to another.

Implicit casting – automatic data type conversions

Selection

A selection construct is used to create a branch in a program.

Nested IF

A nested IF statement consist of one or more IF statements inside each


other. A nested IF is used where there are more than two possible courses of
action.

Relational Operators

Relational operators are the operators that test the relationship between
two entities. Relational Operators are used to compare two values.

Equal to ==

Greater than >

Greater than or equal to >=


Less than <

Less than or equal to <=

Not equal to !=

Logical Operators

And

The two conditions must both be true for the whole statement to be true.

Or

Either one condition must be true for the whole sentence to be true.

Not

The NOT operators reverse the logic of the AND and OR statements.

Iteration

Iteration is used to make a computer repeat a set of instructions more than


once. There are two types of iteration: definite and indefinite.

Definite Iteration

A definite iteration is used when we know in advance how often the


instructions in the body of the loop are to be repeated. E.g. For loop

Indefinite Iteration
An indefinite iteration is used when the number of times a loop will need to
be repeated is not known in advance. Indefinite loops are repeated until a
specified condition is reached. E.g. While loop

Nested Loops

A nested loop is made of a loop within a loop.

Random Numbers

random number between 1 to 10

Chapter 6
Why it is important to make your code easy to read?

Programming is not a solo activity. Programmers usually work in teams


with each programmer developing a different part of the program. Therefore our
codes need to be understood easily by every programmer.

Four techniques that a programmer should use

Comments
To explain what each part of the program does

Descriptive names
To make the purposes of variables and constants clear
Indentation
Wrong indentation will result in unexpected outcomes.

White space
Blank lines between different blocks of code makes them stand out.

Chapter 7
String

A string is a data type that is used to represent a sequence of characters,


which are treated as if they were text. They are useful when receiving user input
or displaying the output.

Length of strings

len(variable name)

String traversal

Finding a character with a particular index

variable[index]
This will output “m”.

Changing all characters to lower case

variable.lower

This will output “computer science”.

Changing all characters to upper case

This will output “COMPUTER SCIENCE”.

*Don’t forget to add brackets after .upper and .lower.

Extracting a phrase in the string

variable[phrase index]

This will output “Com”.


Checking a phrase in the string
“string” in variable

This will output “True”.

Concatenation

Concatenation involves joining two or more items of information together. It is


very useful when displaying text on screen.

“string” + variable

This will output “Hello Thurein”.

Chapter 8
Data structure

A data structure is an organized collection of related elements.

Array

An array is an organized collection of related value with a single shared


identifier. All the elements in an array are the same data type.
List

A list is very similar to an array but lists are dynamic. They do not have a
fixed size and can grow as new elements are added.

Declaring a list
variable = [ ]

Adding items to the list


variable.append(item)

Multidimensional arrays

A multidimensional array is an “array of arrays”; each item at an index is


another array.

Records

A record is a data structure that store a set of related values of different


data types. A record consists of a collection of fields.

Chapter 9
Validation

Validation is checking if the data entered by a user meets specified


requirements. It cannot guarantee that the data is correct, only that is
reasonable.

Range check

A range check is used to ensure that the data entered is withing a


specified range.
Presence check

Presence check ensures that a value has been entered, preventing the
user from leaving an input blank.

Look-up check

A look-up check is used to test that a value is one of a predefined set of


acceptable values.

Length check

It checks that the length of a value entered falls within a specified range.
Testing validation rules

Normal data
This is within the limit of what should be accepted by the program.

Boundary data
This is the data that is at the outer limits of what should be accepted by a
program.

Erroneous data
This is the data that should not be accepted by the program.

Working with text files


Two-dimensional array

Chapter 10
Subprogram

A subprogram is a self-containing module of code that performs a specific


task.
Local variable

A local variable is a variable that only exists within the function.

Global variable

A global variable is a variable that can be used anywhere within the main
program.

Procedure

A procedure is similar to a function but it does not return a value.

Arguments
Arguments are the data that are passed from the main program to the
function.

Parameter

Parameter are the variables that are used to store the data passed from
the main program as arguments.

Benefits of using subprograms

 Subprograms are written once and can be called when necessary.


 Short development time of a program
 Less memory space is required to run.
 Easier to read, find errors, debug and change

Bulit-in functions

 Used for common tasks (print, random number, length)


 save the programmer time.

Chapter 11
Logic errors

Logic error is an error that result in incorrect or unexpected behavior. Logic


errors occur when the thinking behind an algorithm is incorrect.

Trace table
Trave table is a technique used to identify any logic errors in algorithm.
Each column represents a variable and each row a value of that variable.

Syntax errors

Syntax errors occur when the grammar rules of a programming language


are not followed. e.g. missing out a bracket, missing out quotation marks

Runtime errors

A runtime error is an error that occur when the computer tries to run code
that it cannot execute. They are the most difficult to predict and spot.

Integrated development environment (IDE)

IDE is a package that helps programmers to develop code. Its features are
syntax highlighting, code auto complete, auto indent and debugger, which
detects errors in the code.

SyntaxError: invalid syntax

IdentationError: expected an indented block

TypeError: Can’t convert ‘int’ object to str implicitly

ZeroDivisionError: integer division or modulo by zero

NameError: variable name is not defined.

The test plan


Test Test Expected Actual Action
Purpose of the test
No. data result result needed/Comment

To check correct conversion


of valid data
To check correct conversion
of boundary data

To check response to
erroneous data

Evaluating programs

Usability – easy to use?

Efficiency – loops and subprograms?

Code readability – meaningful identifiers, comments and white space?

Validation – appropriate validation?

Requirements –

Chapter 14
1 byte = 8 bits

1nibble = 4 bits

Compression
Compression is changing the format of a data file so that the size of the file
becomes smaller.

Bandwidth

Bandwidth is the amount of data that can be carried on a network in a


given period of time.

Benefits of data compression

 Users don’t waste time while their data is being transferred or saved.
 Providers can store data in as little space as possible.
 Compressed files use less network bandwidth to upload and download.
 There is less internet congestion and it makes possible the streaming of
video and audio files.

Loseless compression

Loseless compression is compressing a file so that it can be


decompressed without any loss of data. When loseless compression is used, no
data is lost and the original file can be restored. Loseless compression is
essential for text.

Lossy compression

Lossy compression is a compression where some of the data is removed.


The original file cannot be restored when the lossy file is decompressed.

Run-Length Encoding (RLE)

RLE is used to reduce the size of a string of repeated items.

The string of repeated items is called a run and is represented by two bytes.
ccc  string of repeating items

3c

3  number of times of the item of information

c  item of information

Chapter 16
The input-process-output model

A computer is a machine that takes some kind of input from its


surrounding, processes the input according to given rules and provides some
kind of output.

Sequential model

In the sequential model the instructions are in the algorithm are processed
step by step, in order, from start to finish.

Parallel model

In a parallel model, computer processes are distributed between two or


more processers in a computer with two or more processors installed. It requires
an operating system and software programs capable of supporting two or more
processors.

Multi-agent model

In the multi-agent model, separate tasks or algorithms are processed by


different systems (agent) to perform a particular function. Each agent is
autonomous.
Chapter 20
Instruction set

Instruction set is the list of all possible commands a particular CPU knows
how to carry out.

Machine code

The binary codes representing each of the instructions in the instruction


set are called machine code.

Translator

A translator is a program that converts source code into machine code.

Source code

The text of the program that a programmer writes is called source code.

Assembler

An assembler translates the mnemonics of assembly language programs


into machine language instructions for the microprocessor to carry out.

Assembly language

Assembly language is a low-level language written using mnemonics.

Low-level programming language


A low-level programming language is a programming language that is
closely related to the CPU’s machine code.

Mnemonic

A short, memorable keyword that represents each of the instructions in


CPU’s instruction set is called mnemonic.

Compiler

A compiler is a translator that converts high-level language source code


into object code all at once and saved to be executed later.

Interpreter

An interpreter is a translator that converts high-level language source code


into object code one line at a time and executed.

Chapter 21
Network

A network is a collection of two or more devices that are connected


together for the purpose of sharing resources and data. A network can support
multiple users accessing multiple services at the same time.

Server

A server is a powerful computer that provides the network with services.

Network services
 provide extra storage
 back-up facility
 accessing shard files
 download data or updates
 shared printer
 access to the internet
 communication

Local area network (LAN)

A local area network (LAN) is a network that covers a relatively small


geographical area. In a wireless local area network, devices use high-frequency
radio waves to communicate.

Wide area network (WAN)

A wide area network (WAN) is a network that covers a large geographical


area. It connects two or more LANs together under shared ownership.

Personal area network (PAN)

A personal area network is a network used for data transmission over short
distances by computer devices. The devices usually communicate wirelessly
over distances of up to 10 meters by radio waves using Bluetooth.

Bluetooth

Bluetooth is a protocol for the short-range wireless interconnection of


electronic devices.

Client-server network
A client-server network is a network that has at least one server to provide
services to the client computers.

The process of accessing data from a server

1. A client will make a connection to the server using its address.


2. Once the connection has been made, the client will make a service request
to the server. (The client sometimes needs authentication.)
3. If the request is valid, the server will send the requested data to the client
using the address identified in step 1.

Peer-to-peer network

A peer-to-peer network is a network that doesn’t have any dedicated


servers. Each computer in a network can act as both a client and a server.

Network topology

The arrangement of the connections between networked devices is


referred to as the network topology. The four main network topologies are bus,
ring, star and mesh.

Bus

single cable, electronic signal,

terminator – absorbs signal and prevent them from bouncing back

Only one message can be sent at any one time.

Carrier Sense Multiple Access with Collision Detection (CSMA/CD) is used to


deal with messages sent at the same time.
CSMA/CD algorithm
1. Check if bus is busy.
2. If not busy then send message, else go to step 1.
3. Listen to see if message received correctly.
4. If message not received correctly then go to step 5, else go back to
listening for messages.
5. Wait any amount of time, go to step 1 retry sending message.

Advantages – Cheap to install, easy to add extra network devices

Disadvantages – If the cable is cut, the whole network will fail.

Difficult to identify where a fault is on the cable

The more devices that are added to the network, the slower
it runs.

Data sent is received by all the computers on the network.


(security risk)

Ring

Closed loop, In and out connection

In the same direction, No collision

Advantages – Easy to add extra network devices

Adding extra devices does not affect the network performances

Disadvantages – Whole network will fail when either the cable or a device fail

The network is shut down temporarily when adding a device


Difficult to identify where a fault is

More expensive to install than a bus network

Star

Central point(a switch or a hub), a lot of cabling

Advantages – Easy to add extra network devices

A damaged cable will not stop the whole network

If a switch is used, the messages are only sent to intended


recipients.

Easy to identify faults

Disadvantages – If the hub or switch is failed, the whole network will fail

Expensive to install

Mesh

Fully connected and partially connected

Wired or wireless

Advantages – Very fault tolerant

Very high performances

In a wireless mesh network, each node extends the range of the


network.

Disadvantages – Difficult and expensive to install


Difficult to manage

Chapter 22
Confidentiality

 Ensuring only authorized users can access the parts of a network and its
resources
 Stopping misuse
 Encrypting data

Correctness

Stored data must not be changed without authorization.

Availability

Protection should be put in place to prevent failure caused by viruses and denial
of services (DoS) attacks.

DoS attacks can

 slow down network performance or stop it working altogether


 delete data
 allow data to be stolen or eavesdropped
 alter data or program code

Reasons why security is important

The data stored on the network could be:


 required for the running of the organization
 private and confidential
 financially valuable

Authentication

Authentication is the process of checking the identity of a user of a


computer system or network.

 Username and passwords


 PINs
 Fingerprint

Access control

Access control is the method that controls whether a particular user will
gain access to a particular file.

 Read-only access
 read and write access (modify access)
 full control – permission to delete a file

Access controls are set up by an organization’s system administrators according


to the management’s requirements.

Firewall

A firewall is a network security system that monitors and controls data that
is moving from one network to another. Firewall sits between the internet and the
LAN and inspects the incoming and outgoing data. It uses a set of rules which
can be customized by the organization that owns the firewall.

Rules can:
 stop certain protocols (e.g. FTP)
 block data coming from and going to certain network addresses
 stop hacking by disallowing data that matches the pattern an attacker
would use.

Firewall can be software or hardware based. Individual computers have software


firewall installed with default rules. Hardware-based firewalls are used by
businesses and can have much more flexibility.

Physical security

Physical security can ensure that critical parts of the network can only be
physically accessed by authorized people, such as network technicians or a
system administrator. It involves installing a burglar alarm, security tagging and
physically locking down equipment, etc. By using an electronic lock system,
entry/exist times can be recorded, and individual cards/fobs can be deactivated if
lost.

Cloude storage and security

Advantages of cloud storage:

 The amount of storage can easily be changed as and when required.


 Data is protected from loss due to fire, theft of computers/servers,
electrical failure, and so on.
 Many cloud storage systems also manages the back-up of your data.

Disadvantages of cloud storage:

 You are relying on a third-party storage provider to keep your organisation


running.
 Data stored anywhere accessible via the internet carries the risk of other
people gaining access to it.
 Access to cloud storage is dependent on having a reliable, high-speed
internet connection.

However, you can encrypt your data to reduce some of these risks.

Network-attached storage (NAS)

NAS is a hardware device that is connected to a network to provide file


storage for any device connected to that network. NAS devices often allow
access over the internet. They are designed for ease of use rather than being
secure. Home users often make mistakes such as:

 not changing a device’s default password


 not updating the software

Therefore, in order to minimize the security risks, users must use a complex
password, remove any default passwords and ensure that all software updates
are applied.

USB

USB flash drives are easy to transport, relatively cheap for the amount of storage
available and very convenient to use.

The disadvantage is that the small drive can easily be lost. But encrypted USB
flash drives are available.

Cyber attack

A cyber attack is any kind of electronic attack on a computer system,


server, network or other IT device.
Social Engineering

Attacks that rely on exploiting human behavior are often referred to as


social engineering. Three common forms of social engineering are phishing,
shoulder surfing and pharming.

Phishing

A phishing attack is an attempt to get sensitive, confidential information from the


user of a computer system or service.

Shoulder surfing

Shoulder surfing means gaining access to confidential information by directly


observing a user.

You might also like