CSC 101 Compiled by SISTER IZA ???
CSC 101 Compiled by SISTER IZA ???
(CSC 101)
CSC 101 Objective
• This course is to prepare the students on the Fundamentals of
Computer science and Computing.
• It teaches the basics concepts, Data representation, Computer
Organization & Architecture, Problem Solving with Algorithm,
Computer Networks and the Internet and programming in
Visual Basics.
• The course will feature activities like teaching, demonstration,
laboratory activities, chatting, assignment and group discussion.
• Course evaluation will be based on class attendance, online
activities, quizzes, lab work and examination.
• Go to moodle learning system to see the course outline
lms.ui.edu.ng
How to get maximum benefits from the Lecture
• Attend class regularly
• Read the related chapters in the textbook
• Visit Moodle regularly
• Visit lecturer whenever you have questions
• Use your IT gadget to foster understanding of
the course by checking up new concepts online.
Go to U-tube and download lecture videos on
topics you don’t understand
• Attend Discussion Groups after studying
• Think more!
Lesson Objectives
• To Introduce Computer science through an
understanding of what computer scientists do
• To examine COMPUTER SCIENCE AS A DISCIPLINE
• To present an understanding of the nature of
computational tools and theories.
• To explain the Founding Traditions of Computer Sc
• QUALITIES OF A GOOD COMPUTER SCIENTIST
• To introduce six major criteria that computation tools
must be built to satisfy.
i.E correctness, efficiency, security, fault-tolerance,
user-friendliness and intelligence
Understanding Computer science
• Computer Scientists have been in increasing
demand since the advent of the modern
computer.
• The pervasiveness of the modern computer
has accentuated the need to train more
people in the discipline.
• These people must be able to meet the need
of the society in helping to achieve the
effective use of computers.
What Computer Scientists do
• In order to understand the discipline, it is
important to answer the question: what do
computer scientists do?
• They create and manage tools that support
and enhance the use of the modern
computer(computation tools for short).
• In order to create effective computation tools
it is important to create models of these tools
before they are built.
What Computer Scientists do
• Most of the models created are mathematical
in nature.
• Models need to be built around discrete
mathematical structures(e.g. sets, lists,
orderings etc.)
• Computer scientists use these existing
structures to create mathematical theories
• A theory is a body of knowledge that
facilitates the creation of models.
• Tools are built based on these theories
Definitions of Computer Science
• The systematic study of algorithmic processes
that describe and transform information:
their theory, analysis, design, efficiency,
implementation and application. (automation)
• Computer Science is about building computers
and writing computer programs, how we use
computational tools, and what we find out
when we do
• Computer Science is also about problem
solving. Solving problem computationally
involves the followings:
Steps in Computational Problem Solving
• ABSTRACTION
• AUTOMATION
• IMPLEMENTATION
Medicine Science
Entertainment Business
Computer Science
Engineering
Humanities
Art
What Computer Scientists do...
Application
Programmers
and System
Programmers
Foundational Basis of CSC
As a discipline computer science brings together ideas from
different traditions i.e The Founding Traditions of Computer Sc
• Mathematics: gives the discipline much of its theory.
– Theory has to do with building of conceptual frameworks and notations
for understanding relationships among objects in a domain. A theory
clearly defines a kind of structure. The theory clearly defines its
properties. The properties must be clearly and precisely defined. The
usual vehicle for the precise description of properties is Logic or
algebra.
– The structures that a theory defines allows a computer scientist to
capture the essence of a tool to be developed.
– This essence is the model of the system to be built.
– Using the theory it is possible to reason about the behaviour of the
system to be built through the model.
– This kind of reasoning can help avoid disastrous consequences.
Foundational Basis of CSC
Knowledge from
Experimental Science
Tools Processes
SERVICE TO
HUMANITY
Information Processing
• Computation is thought of as the process of
transforming(processing) information.
• Information is “acquired facts”.. “about a
specific subject”. (Encarta)
• “I have five cows”. “Maigida has given me two
more”, “I sold one to Mr. Bako today”.
• It takes a little bit of information processing to
know how many cows I have left.
Tools
• A computational tool is a product of a creative
activity.
• It might be a piece of software or hardware.
• There are two categories of tools.
– Those tools support the creation of other tools
• E.g Programming languages
– end-user tool supports a specific task in the
human domain (and not the creation of other
tools).
• Word processing application
What can be automated?
• Automation refers to our ability to make a
computer solve a problem.
• Usually, automation consist of
• Generating software that will solve the problem
on a general purpose computer. OR
• Generating hardware that will do so.
• That software/hardware is a computational
tool.
What can be automated? How?
• Computer Scientists build and study tools based
on one or any combination of the followings set
of performance goals.
• Correctness
• Efficiency
• Security
• User-friendliness
• Fault-tolerance
• Intelligence
Each of the above represent possible objectives
that a tool may be engineered to meet.
Correctness
• A tool is said to be correct if it works according to
a pre-defined specification.
• The pre-defined specification must be clearly and
unambiguously stated – for correctness to be
assessed.
• The specification answers the question of what
tool are we expected to build.
• A correct tool conforms completely with the
specification ……..A little story will drive home the
point:
Efficiency
• The efficiency of a tool is a measure of its
ability to make judicious use of resources.
• The most important resource for tools is time.
• Another important group of resources is
machine resources (especially space).
• A tool is more efficient w. r. t. time if it uses
less time to a solve problem than another.
• A tool is more efficient w. r. t. space if it uses
less space to a solve problem than another.
Security
• A tool is secure if its functions will not be
hampered by malicious attacks or other
compromising situation.
• There are different ways in which a tool can be
compromised.
• One way is if information is intercepted during
transmission.(This happened a lot during
WW2).
Security(2)
• Another possible source of security
compromise is unauthorized use of a tool.
• Data Interception can be prevented by data
encryption.
• Data encryption is the process of transforming
data into an unintelligible form(encrypted
data) prior to transmission.
• The transformation is undone at the point of
reception (decryption).
User-Friendliness
• User-friendliness reflects the ease with which
a tool can be used by a human user.
• Factors ranging from culture, ergonomics to
personal preferences may affect user-
friendliness.
• As such user-friendliness may be context-
dependent.
Fault-tolerance
• Fault-tolerance is the ability of a tool to cope
in the presence of faults.
• A tool is fault-tolerant if every possible fault
does not lead to a failure.
• The level of fault-tolerance is measured by
mean time between failure (MTBF).
• This is a measure of the time between two
failure incidents in the use of a tool.
Intelligence
• Intelligence is the ability of a tool to mimic
human intelligence.
• Tools can mimic intelligence in a number of
ways:
– Reasoning
– Language understanding
– Learning
– Game playing
Example- Game Playing
• In 1997, IBM’s chess playing computer ‘Deep
Blue’ defeated the then world champion Garry
Kasparov under tournament conditions.
• That was a landmark in the history of game
playing machines.
• The success of game playing machines has
been attributed to their ability to ‘see’ many
moves ahead in a game.
QUALITIES OF A GOOD COMPUTER SCIENTIST
Qualities of a good computer scientist include:
• Passion for finding elegant solutions
• Ability to use mathematical analysis and logical rigor to evaluate such
solutions
• Creativity in modeling complex problems through the use of abstractions
• Attention to details and hidden assumptions
• Ability to recognize variants of the same problem in different settings
• Ability to retarget known efficient solutions to problems in new settings
i.e. reusability.
• If you like to solve puzzles, then computer science is for you!
CAREERS IN COMPUTER SCIENCE
• Many students graduate to rewarding computer-related careers in:
– Software engineering,
– System administration and management
– Research and development in industrial and governmental
laboratories etc
•
RELATIONSHIP BETWEEN COMPUTER SCIENCE AND OTHER DISCIPLINES
(Chinese) Abacus
Used for performing arithmetic operations
AL’KHOWARIZMI AND THE
ALGORITHM
12th Century Tashkent Cleric
Developed the concept of a
written process for doing
something
Published a book on the
process of algorithms
The basis of software
EARLY COMPUTATIONAL DEVICES
John Napier
1550-1617
PHILOSOPHER FOREFATHERS OF
MODERN COMPUTING
1600-1700 Von Leibniz developed
Blaise Pascal – binary arithmetic and a
developed the hand cranked
Pascaline. calculator.
Calculator was able to
Desk top calculator
add, subtract, multiply
worked lik an
and divide.
odometer.
BLAISE PASCAL
Blaise Pascal
1623-1662
EARLY COMPUTATIONAL DEVICES
Slide Calculators
William Oughtred
1574-1660
GOTTFRIED WILHELM VON LEIBNIZ
0001
0010
0011
0100
0101
0110
0111
1000
MODERN COMPUTERS USE BINARY
Why?
Much simpler circuits needed for performing
arithmetic
EARLY COMPUTATIONAL DEVICES
Difference engine
Designed to compute values of polynomial
functions automatically
No multiplication was needed because he used the
method of finite differences
He never built one
Analytical Engine
Could be programmed using punch cards – totally
revolutionary idea
Sequential control / branching / looping
Turing complete
The analytical engine
of Charles Babbage
LADY ADA BYRON – WORLD’S FIRST
PROGRAMMER
Countess of Lovelace,
daughter of Lord Byron.
One of the first women
mathematicians in England
Documented Babbage’s
work.
Wrote an account of the
difference engine.
Wrote a program for the
difference engine for
computing Bernoulli numbers
HERMAN HOLLERITH
Hollerith developed an electromechanical punched-card
tabulator to tabulate the data for 1890 U.S. census. Data
was entered on punched cards and could be sorted
according to the census requirements. The machine was
powered by electricity. He formed the Tabulating Machine
Company which became International Business Machines
(IBM). IBM is currently the largest computer manufacturer,
employing in excess of 300,000 people.
HERMAN HOLLERITH PUNCH CARD
TABULATING MACHINE
1890 CENSUS
HOLLERITH TABLES AND THE CENSUS
Improved the
speed of the
census
Reduced cost by
$5 million
Greater accuracy
of data collected
Hollerith –
unemployed after
the census
KONRAD ZUSE - FIRST CALCULATOR 1938
THE WAR YEARS 1939-1945
TWO PRIMARY USES
Artillery Tables
Hand calculation replaced by machine calculation
Department of the Navy
Cryptologist :
Cryptography
The art or process of writing in or deciphering secret writing
Bletchley House
The Enigma Codes – U23
THE BRITISH EFFORT
HISTORY OF COMPUTERS
Alan Turing was a British mathematician who also made significant
contributions to the early development of computing, especially to the
theory of computation.
He developed an abstract theoretical model of a computer called a
Turing machine which is used to capture the notion of computable i.e.
what problems can and what problems cannot be computed.
Not all problems can be solved on a computer.
Note: A Turing machine is an abstract model and not a physical
computer
ALAN TURING
MISUNDERSTOOD GENIUS
1936
Published a paper “On
Computable Numbers”
Turing’s machine -
hypothetical computer
that could perform any
computation or logical
operation a human
could devise.
TURINGS HERITAGE
51 feet long
3,304 electro mechanical
switches
Add or subtract 23 digit
numbers in 3/10 of a
second.
Instructions (software)
loaded by paper tape.
The infamous “Bug”
ENIAC - THE NEXT JUMP FORWARD -
1946
1st electronic digital computer
Operated with vacuum tubes
rather electro-mechanical
switches
1000 times faster than Mark I
No program storage - wired
into circuitry.
This was still based on the
decimal numbering system.
“programmed” by switches
and cords
ENIAC
THE ADVENT OF THE
SEMICONDUCTOR - 1947
Developed at Bell Labs
by Shockley & Bardeen –
Nobel Prize
Point Contact Transistor
replaced power hungry,
hot and short lived
vacuum tubes
HISTORY OF COMPUTERS
Von Neumann was a scientific genius and was a consultant on the
ENIAC project. He formulated plans with Mauchly and Eckert for a new
computer (EDVAC) which was to store programs as well as data.
This is called the stored program concept and Von Neumann is credited
with it. Almost all modern computers are based on this idea and are
referred to as Von Neumann machines.
He also concluded that the binary system was more suitable for
computers since switches have only two values. He went on to design
his own computer at Princeton which was a general purpose machine.
COMPUTER GENERATIONS
st1 generation computers
Vacuum tube, 1946-1957, 40K operations/sec
2nd generation computers
Transistor, 1958-1964, 200 K operations/sec
Smaller, cheaper, less heat dissipation
William Shockley et al. in 1947 at Bell Labs
The Cray
Parallel processing power
Speed 100 million
arithmetical functions per
second
Sensitive to heat - cooled with
liquid nitrogen
Very expensive
FOURTH GENERATION
VLSI allowed the equivalent of tens of thousand of
transistors to be incorporated on a single chip. This led to
the development of the microprocessor a processor on a
chip.
Intel produced the 4004 which was followed by the
8008,8080, 8088 and 8086 etc. Other companies
developing microprocessors included Motorolla (6800,
68000), Texas Instruments and Zilog.
FOURTH GENERATION
Personal computers were developed and IBM launched
the IBM PC based on the 8088 and 8086
microprocessors.
Mainframe computers have grown in power.
Memory chips are in the megabit range.
VLSI chips had enough transistors to build 20 ENIACs.
Secondary storage has also evolved at fantastic rates with
storage devices holding gigabytes (1000Mb = 1 Gb) of
data.
FOURTH GENERATION
On the software side, more powerful operating systems
are available such as Unix.
Applications software has become cheaper and easier to
use.
Software development techniques have vastly improved.
Fourth generation languages 4GLs make the development
process much easier and faster.
FOURTH GENERATION
Languages are also classified according to generations
from machine language (1GL), assembly language (2GL),
high level languages (3GL) to 4GLs.
Software is often developed as application packages.
VisiCalc a spreadsheet program, was the pioneering
application package and the original killer application.
Killer application: A piece of software that is so useful that
people will buy a computer to use that application.
THE ALTAIR FROM A VOYAGE TO ALTAIR -
STAR TREK -1975
THE BIRTH OF THE MICRO
COMPUTER 1975
Jobs and Wozniac develop
the Apple II
Commodore PET, programs
stored on a cassette
Tandy-Radio Shack TRS-80
5 1/2 inch floppy disk
becomes the standard for
software
FINALLY, THE COMPUTER AS MAN OF THE
YEAR - 1982
REVENGE OF THE NERDS
Bill Gates
Microsoft, 1978
Processor
power supply drive bays
Memory
Adapter cards
Sound card processor
Video card
Ports ports memory
Drive bays
Power supply
sound card
video card
The System Unit
What is the motherboard?
Main circuit
board in system
unit
Contains adapter
cards, processor
chips, and
memory chips
Also called
system board
The CPU
– manipulates raw data into more useful form and controls
the other parts of the computer system.
Primary storage
– temporarily stores data and program instructions during
processing.
Secondary storage
– devices store data and programs when they are not being
used in processing.
Input devices
– convert data and instructions into electronic form for input
into the computer.
Output devices
– convert electronic data produced by the computer system
and display them in a form that people can understand.
Communication devices
– provide connections between the computer and
communications networks.
Buses
– are circuitry paths for transmitting data and signals
among the parts of the computer system.
The CPU and Primary Storage
The CPU is the part of the computer system where
the manipulation of symbols, numbers, and letters
occurs, and it controls the other parts of the
computer system.
The CPU
Processor
What is the central processing unit (CPU)?
computer
Arithmetic logic unit
Input Output
Devices
Data Memory Information
Devices
(ALU) performs
arithmetic, comparison,
Instructions
and logical operations Data
Information
Also called the processor
Storage
Devices
Processor
What is a machine cycle?
Four operations of the CPU comprise a machine cycle
Step 1. Fetch
Obtain program instruction
or data item from memory
Memory
Step 2.
Step 4. Store Decode
Write result to memory Translate
instruction into
Processor commands
ALU Control Unit
Step 3. Execute
Carry out command
The CPU and Primary Storage
Central Processing Unit (CPU) Primary Storage
Data Bus
Address
Bus
Control
Bus
Three kinds of busses linked between the CPU,
primary storage and the other devices in the
computer system:
– Data bus
• Pass information in bi-directional.
– Address bus
• Transmits signals for locating a given address in primary
storage, indicating where data should be placed.
– Control bus
• Transmits signal specifying whether to read or write data to or
from primary storage address, input device or output device.
The characteristics of the CPU and primary
storage are very important in determining a
computer’s speed and capabilities
The Arithmetic-Logic Unit and
Control Unit
An arithmetic logic unit (ALU) and control unit
is one of the core components of all central
processing units.
The ALU performs the computer’s principal
logical and arithmetic operations.
It adds, subtracts, multiples, and divides,
determining whether a number is positive,
negative, or zero.
ALU must be able to determine when one quantity
is greater than or less than another and when two
quantities are equal.
The control unit coordinates and controls the other
parts of the computer system.
It reads a stored program, one instruction at a time
and directs other components of the computer
system to perform the program’s required tasks.
Processor
Which processor should you select?
The faster the processor, the more expensive the computer
Intel Processor Desired Clock Speed
Up to 2.4 GHz
Do not have to
Most
be re-energized
common
as often as
type
DRAM
Static
RAM
Dynamic Faster and
Must be (SRAM)
RAM more reliable
re-energized (DRAM) than DRAM
constantly
chips
– High-capacity storage
– Consists of several
inflexible, circular
platters that store items
electronically
– Components enclosed in
airtight, sealed case for
protection
Magnetic Disks
What are tracks and
sectors?
Track Sector
is narrow stores up to
recording 512 bytes
band of data
that forms
full
circle on
disk
Step 3.
When software requests a
disk access, read/write
heads determine current
Step 2. or new location of data.
Small motor spins
platters while
computer is running.
Step 4.
Head actuator positions
read/write head arms over
Step 1. correct location on platters
Circuit board controls to read or write data.
movement of head actuator
and a small motor.
Optical Disk
disc label
Typically stored in
single track
Track divided
into evenly
sized sectors
that store
items
single track
spirals to edge
of disc
disc sectors
WORM (write once/read memory) or CD-R
(compact disk-recordable) optical disk systems
allow users to record data only once on an optical
disk.
New CD-RW (CD-Rewritable) technology has
been developed to allow users to create rewritable
optical disks.
Digital-video disks (DVDs) also called digital
versatile disks are optical disks the same size as
CD-ROMs but of even higher capacity (minimum
of 4.7 gigabytes of data).
Optical Discs
What is a CD-ROM?
Compact disc read-only memory
Cannot erase or modify contents
Typically holds 650 MB to 1 GB
Commonly used to distribute multimedia and complex software
Optical Discs
What are CD-Rs and CD-RWs?
Must have
CD recorder
or CD-R drive
CD-R (compact disc-recordable)
— disc you can write on once
c
Cannot erase
disc’s contents
CD-RW (compact disc-rewritable)
— erasable disc you can write on
ce
What is a PC Card?
Adds capabilities to computer
Credit-card-sized device commonly
used in notebook computers
Input and Output Devices
Input devices
– Input devices gather data and convert them into electronic
form for use by the computer.
– Keyboard
• The principal method of data entry for entering text and numerical
data into a computer
– Pointing Devices
• A computer mouse is handheld device with point-and-click
capabilities that is usually connected to the computer by a cable.
• Touch screens allows users to enter limited amounts of data by
touching the surface of a sensitized video display monitor with
finger or a pointer.
Source Data Automation
– Captures data in computer-readable form at the time
and place they are created.
– Optical Character Recognition (OCR) devices
translate specially designed mark, characters, and codes
into digital form.
– Magnetic ink character recognition (MICR)
technology is used primarily in check processing for the
banking industry, which the bottom of typical check
contains characters identifying the bank, checking
account, and check number that are preprinted using a
special magnetic ink.
– A MICR reader translates these characters into digital form
for the computer.
– Handwriting-recognition devices such as pen-based
tablets, notebooks, and notepad are promising new input
technologies.
– These pen-based input devices convert the motion made by
an electronic stylus pressing on a touch-sensitive tablet
screen into digital form.
– Digital scanners translate image such as pictures or
documents into digital form.
– Voice input devices convert spoken words into digital form
for processing by the computer.
– Sensors are devices collect data directly from the
environment for input into a computer system.
What Is Input?
What is input?
Data or instructions entered into memory of computer
Input device is any hardware component that
allows users to enter data and instructions
What Is Input?
What are the two types of input?
Data
Unprocessed text,
numbers, images,
audio, and video
Instructions
Programs
Commands
User responses
The Keyboard
How is the keyboard
divided?
Typing area
Numeric keypad
Function keys, special
keys that issue
commands
Pointing Devices
What is a mouse?
Pointing device that fits under palm of hand
Pointing device controls mouse buttons
wheel
movement of pointer, also button
called mouse pointer
Mechanical mouse
ball
has rubber or metal
ball on underside
mouse pad
Other Pointing Devices
What is a trackball?
Stationary pointing device
with a ball on its top or side
To move pointer, rotate ball
with thumb, fingers, or palm
of hand
Other Pointing Devices
What are a touchpad and a
pointing stick?
Joystick is vertical
lever mounted
on a base
Wheel is
steering-wheel-type
input device
Pedal simulates
car brakes and
accelerator
Other Pointing Devices
What is a light pen?
Handheld input device
that can detect light
Press light pen against
screen surface and then
press button on pen
Other Pointing Devices
What is a touch screen?
10010111010110101100001101
What is a scanner?
graphics
Used for image processing,
converting paper documents Sheet-fed
Drum
Scanners and Reading Devices
How does a flatbed
scanner work?
Step 1. Document to be scanned is
placed face down on the glass window.
Step 2. Bright light moves underneath
scanned document.
Step 3. Image of the document is
reflected into a series of mirrors.
Step 4. Light is
converted to analog
electrical current that
is converted to
digital signal by an
analog-to-digital
Step 6. Users can print image,
converter (ADC).
e-mail it, include it in a document,
or place it on a Web page.
Step 5. Digital information is sent to
memory in the computer to be used by
illustration, desktop publishing, or
other software; or it is stored on disk.
Scanners and Reading Devices
What is an optical reader?
p. 302
CRT Monitors
What is a CRT monitor?
Contains cathode-ray
tube (CRT)
Screen coated with tiny
dots of phosphor material
Each dot consists of a red,
blue, and green phosphor
Common sizes are 15, 17,
19, 21, and 22 inches
Viewable size is diagonal
measurement of actual
viewing area
CRT Monitors
How does video travel from the processor to a CRT
monitor?
Video card (also called a graphics card) converts digital
output from computer into analog video signal
Step 5. Electron guns
Step 1. The fire the three color signals
processor sends Step 3. The to the front of the CRT.
digital video data analog signal is
to the video card. sent through a
cable to the CRT Step 4. The
monitor. CRT monitor
separates the
analog signal
into red, green,
and blue signals.
Step 6. An image is
displayed on the screen when
the electrons hit phosphor
Step 2. The video card’s dots on the back of the screen.
digital-to-analog converter
(DAC) converts the digital
Printers
What is a printer? portrait
IBM OS/2
Macintosh OS
SCO Unix
Linux
Other Proprietary OS
4. 99
Application Software
– programs that are developed to solve some specific
problems.
– A set of instructions designed to perform a specific task
such as word processing, accounting, cataloguing, library
management, animation, etc.
– There are two types of application software:
– application program to solve special classes of problems
– Application programs that you can write to solve your own
problems.
– Examples of application software:
– word processing
– database programs
– spreadsheets
– graphic programs
General purpose office software
Word processing: Example, MS Word
Spreadsheets: Example, Excel
Database management systems: Example,
MS Access, Oracle
Presentation/Graphics: Example, Power
Point, Corel
4. 101
special purpose software
1
Data and Computers
Data compression
Reduction in the amount of space needed to store a
piece of data
Compression ratio
The size of the compressed data divided by the size
of the original data
A data compression techniques can be
lossless, which means the data can be retrieved without
any loss of the original information
lossy, which means some information may be lost in the
process of compaction
2
Analog and Digital Information
Computers are finite!
How do we represent an infinite world?
3
Analog and Digital Information
Information can be represented in one of two ways:
analog or digital
Analog data
A continuous representation, analogous to the actual
information it represents
Digital data
A discrete representation, breaking the information up
into separate elements
4
Analog and Digital Information
Thermometer
is an
analog device
A mercury
thermometer
continually
rises in
direct
proportion to
the
temperature
5
Analog and Digital Information
Computers cannot work well with analog data, so we
digitize the data
Digitize
Breaking data into pieces and representing those
pieces separately
6
Electronic Signals
Important facts about electronic signals
An analog signal continually fluctuates in voltage
up and down
A digital signal has only a high or low state,
corresponding to the two binary digits
All electronic signals (both analog and digital)
degrade as they move down a line
The voltage of the signal fluctuates due to
environmental effects
7
Electronic Signals (Cont’d)
Periodically, a digital signal is reclocked to regain its
original shape
9
Binary Representations Counting with
binary bits
10
Binary Representations
How many things can bits represent?
Why?
11
Representing Negative Values
Signed-magnitude number representation
The sign represents the ordering, and the digits
represent the magnitude of the number
12
Representing Negative Values
There is a problem with the sign-magnitude
representation: Can you guess why?
Solution:
Keep all numbers as integer values, with half of
them representing negative numbers
13
Representing Negative Values
Using two decimal digits,
let 1 through 49 represent 1 through 49
let 50 through 99 represent -50 through -1
14
Representing Negative Values
To perform addition, add the numbers and discard any
carry
Now you try it
48 (signed-magnitude)
-1
47
15
Representing Negative Values
A-B=A+(-B)
Add the negative of the second to the first
Try
4 -4 -4
-3 +3 + -3
16
Representing Negative Values
Formula to compute the negative representation of a
number
17
Representing Negative Values
Two’s Complement
(Vertical line is easier to read)
18
Representing Negative Values
Addition and subtraction are the same as in 10’s
complement arithmetic
-127 10000001
+ 1 00000001
-126 10000010
Do you notice something interesting about the left-most
bit?
19
Number Overflow
What happen if the computed value won't fit?
Overflow
If each value is stored using eight bits, adding 127 to
3 overflows
1111111
+ 0000011
10000010
21
Representing Real Numbers
Same rules apply in binary as in decimal
Decimal point is actually the radix point
Positions to the right of the radix point in binary are
2-1 (one half),
2-2 (one quarter),
2-3 (one eighth)
…
22
Representing Real Numbers
A real value in base 10 can be defined by the following
formula
23
Representing Real Numbers
25
Representing Text
What must be provided to represent text?
Character set
A list of characters and the codes used to represent
each one
26
The ASCII Character Set
ASCII stands for American Standard Code for
Information Interchange
ASCII originally used seven bits to represent each
character, allowing for 128 unique characters
Later extended ASCII evolved so that all eight bits were
used
How many characters could be represented?
27
The ASCII Character Set
28
The ASCII Character Set
The first 32 characters in the ASCII character
chart do not have a simple character
representation to print to the screen
29
The Unicode Character Set
Extended ASCII is not enough for international use
Unicode uses 16 bits per character
How many characters can UNICODE represent?
Unicode is a superset of ASCII
The first 256 characters correspond exactly to the
extended ASCII character set
30
The Unicode Character Set
32
Keyword Encoding
Replace frequently used words with a single character
33
Keyword Encoding
Given the following paragraph,
We hold these truths to be self-evident, that all men are
created equal, that they are endowed by their Creator
with certain unalienable Rights, that among these are
Life, Liberty and the pursuit of Happiness. ム That to
secure these rights, Governments are instituted among
Men, deriving their just powers from the consent of the
governed, ム That whenever any Form of Government
becomes destructive of these ends, it is the Right of the
People to alter or to abolish it, and to institute new
Government, laying its foundation on such principles
and organizing its powers in such form, as to them shall
seem most likely to effect their Safety and Happiness.
34
Keyword Encoding
The encoded paragraph is
We hold # truths to be self-evident, $ all men are created
equal, $ ~y are endowed by ~ir Creator with certain
unalienable Rights, $ among # are Life, Liberty + ~
pursuit of Happiness. — $ to secure # rights,
Governments are instituted among Men, deriving ~ir
just powers from ~ consent of ~ governed, — $ whenever
any Form of Government becomes destructive of # ends,
it is ~ Right of ~ People to alter or to abolish it, + to
institute new Government, laying its foundation on such
principles + organizing its powers in such form, ^ to ~m
shall seem most likely to effect ~ir Safety + Happiness.
35
Keyword Encoding
What did we save?
Original paragraph
656 characters
Encoded paragraph
596 characters
Characters saved
60 characters
Compression ratio
596/656 = 0.9085
Could we use this substitution chart for all text?
36
Run-Length Encoding
A single character may be repeated over and over again
in a long sequence
Replace a repeated sequence with
a flag character
repeated character
number of repetitions
*n8
* is the flag character
n is the repeated character
8 is the number of times n is repeated
37
Run-Length Encoding
Original text
bbbbbbbbjjjkllqqqqqq+++++
Encoded text
*b8jjjkll*q6*+5 (Why isn't l encoded? J?)
The compression ratio is 15/25 or .6
Encoded text
*x4*p4l*k7
Original text
xxxxpppplkkkkkkk
This type of repetition doesn’t occur in English text; can you think of a
situation where it might occur?
38
Huffman Encoding
Why should the character “X" and "z" take up the same
number of bits as "e" or " "?
39
Huffman Encoding
ballboard would be
1010001001001010110001111011
compression ratio
28/56
Encode roadbed
40
Huffman Encoding
In Huffman encoding no character's bit string is the
prefix of any other character's bit string
To decode
look for match left to right, bit by bit
record letter when a match is found
begin where you left off,going left to right
41
Huffman
Try it! Encoding
Decode
1011111001010
42
Huffman Encoding
Technique for determining codes guarantees the prefix
property of the codes
43
Representing Audio
Information
44
Representing Audio
Information
46
Representing Audio Information
A CD player reading
binary information
47
Representing Audio Information
Some data
is lost, but a
reasonable
sound is
reproduced
49
Audio Formats
Audio Formats
WAV, AU, AIFF, VQF, and MP3
50
Representing Images and
Graphics
Color
Perception of the frequencies of light that reach the
retinas of our eyes
51
Representing Images and
Graphics
Color is expressed as an RGB (red-green-blue) value--
three numbers that indicate the relative contribution
of each of these three primary colors
52
Number Systems
Number Systems
Number categories
– Many categories: natural, negative, rational, irrational and many
others important to mathematics but irrelevant to the understanding
of computing
Number – unit belonging to an abstract mathematical
system and subject to specified laws of succession,
addition and multiplication
– Natural number is the number 0 or any other number obtained
adding repeatedly 1 to this number.
– A negative number is less than 0 and it is opposite in sign to a
positive number.
– An integer is any of positive or negative natural numbers
– A rational number is an integer or the quotient of any two integer
numbers
• is a value that can be expressed as a fraction
Number Systems …
The base of number system represents the number
of digits that are used in the system. The digits
always begin with 0 and continue through one less
than the base
Examples:
– There are two digits in base two (0 and 1)
– There are eight digits in base 8 (0 through 7)
– There are 10 digits in base 10 (0 through 9)
The base determines also what the position of the
digits mean
Positional Notation
It is a system of expressing numbers in which the digits are arranged in
succession and, the position of each digit has a place value and the number is
equal to the sum of the products of each digit by its place value
Example:
– Consider the number 954:
• 9 * 102 + 5 * 101 + 4 * 100 = 954
– Polynomial representation - formal way of representing numbers, where X is the
base of the number:
• 9 * X2 + 5 * X1 + 4 * X0
Formal representation – consider that the base of representation is B and the
number has n digits, where di represents the digit in the ith position.
– dn * Bn-1 + dn-1 * Bn-2 + …+ d2B +d1
– 642 is:
63 * 102 + 42 * 10 + 21 * 10 0
Other bases
What if 642 has the base of 13?
6 x 8² = 6 x 64 = 384
+ 4 x 8¹ = 4 x 8 = 32
+ 2 x 8º = 2 x 1 = 2
= 418 in base 10
12
0202
1010
-0111
0011
You can check if the result is correct by converting the
operands in decimal and making the calculus.
Review Question 4
Add 4 bit number 0100 with 0111. The answer is:
A. 1001
B. 1011
C. 1110
D. I don’t know …
Review Question 5
Subtract 4 bit number 0100 from 1111. The
answer is:
A. 1001
B. 1011
C. 1110
D. I don’t know …
Power of two Number Systems
Binary and octal numbers
have a very special relation Binary Octal Decimal
between them: given a binary 000 0 0
number, can be read in octal 001 1 1
and given an octal number 010 2 2
can be read in binary (i.e. 011 3 3
have 753 in octal, in binary 100 4 4
you have 111 101 011 by 101 5 5
replacing each digit by its 110 6 6
binary representation) 111 7 7
1000 10 8
Table represents counting in
1001 11 9
binary with octal and decimal
1010 12 10
representation
Converting Binary to Octal
Start at the rightmost binary digit and mark the digits in groups of
three
Convert each group individually
3567 16
32 D E F
36 222 16
32 16
47 62 13
32 48
15 14
Review Question 6
Convert number 11001111 to hexadecimal. The
answer is:
A. CF
B. BF
C. FC
D. I don’t know …
Review Question 7
Convert decimal number 375 to its octal
representation. The answer is
A. 567
B. 765
C. 556
D. I don’t know …
Review Question 8
Convert decimal number 37 to its binary
representation. The answer is:
A. 101001
B. 100101
C. 111000
D. I don’t know …
Fractions
Representation and conversion of fractional numbers is
more difficult because there is not necessarily an exact
relationship between fractional numbers in different
number bases.
Fractional numbers that can be represented exactly in one
number base, may be impossible to represent exactly in
another
Example:
– The decimal fraction 1/3 is not represent-able as a decimal value in
base 10: 0.333333310…; this can be represented exactly in base 3
as 0.13
– The decimal fraction 1/10 (or 0.110) cannot be represented exactly
in binary form. The binary equivalent begins: 0.0001100110012…
Fractions …
The strength of each digit is B times the strength of its right neighbor
(where B is the base for a given number).
If we move the number point to the right, the value of the number will
be multiplied by the base:
– 139010 is 10 times as large as 139.010
– The 1002 is twice as big as 102
The opposite is also true – if we move the number point to the left one
place, then the value is divided by the base
A given number .D1D2D3 …Dn will be represented as:
– D1 * B-1 + D2 * B-2 + D3 * B-3 + .. + DnB-n
– 0.2589 = 2 * (1/10) + 5 * (1/100) + 8 * (1/1000) + 9 * (1/10000)
– 0.1010112 = (½) + (1/8) + (1/32) + (1/64)
Fractional Conversion Methods
The intuitive method:
– Determine the appropriate weights for each digit, multiply each digit
by its weight and then add the values
• Example:
• convert 0.122013 to base 10 = (1/3) + 2 * (1/9) + 2 * (1/27) + (1/243) =
0.63374
– Convert the number in a natural number (and record what was the
multiplier) and then divide the result by the multiplier
• Example:
• convert 0.1100112 to base 10 – shifting the binary point six places to the
right and converting, we have: 32 + 16 +2 +1 = 51; shifting the point back
is the equivalent of 26 or 64, so we can obtain the final number by
dividing 51 to 64 = 0.796875
Variation of the division method shown earlier: we multiply
the fraction by the base value, repeatedly, and record, then
drop the values that move to the left of the point.
– This is repeated until the level of accuracy is obtained or until the
value being multiplied is zero
Fractions Base Conversion
0.828125 *
2 0.110101
1.656250 *
The 1 is saved as 2
result then dropped 1.312500 *
and the process 2
repeated 0.625000 *
2
1.250000 *
2
0.500000 *
2
1.000000
Fraction Conversions between Bases
power of two
The conversion between bases where one base is
an integer power of the other can be performed for
fractions by grouping the digits in the smaller base
as before
For fractions, the grouping must be done from the
left to right; the method is otherwise identical
Example:
– Convert 0.101112 to base 8: 0.101_110 = 0.568
– Convert 0.1110101 to base 16: 0.1110_1010 = 0.EA16
Review Question 9
Convert binary number 0.11 to its decimal value.
The answer is:
A. 0.1
B. 0.5
C. 0.75
D. I don’t know …
Review Question 10
Convert decimal number 0.33 in it binary
representation. Use maximum 8 bit precision after
the point. The result is:
A. 0.01010100
B. 0.11001100
C. 0.11111111
D. I don’t know …
Review Question 11
Consider binary number 0.01010100. Compute its
decimal value. The answer is:
A. 0.33
B. 0.328125
C. 0.5
D. I don’t know …
Boolean Algebra
1
What is an Algebra?
What is an Algebra? (e.g. algebra of integers)
set of elements (e.g. 0,1,2,..)
set of operations (e.g. +, -, *,..)
postulates/axioms (e.g. 0 + x = x,..)
2
Boolean Algebra Introduction
Boolean algebra forms the basis of logic circuit design.
Consider very simple but common example: if (A is true)
and (B is false) then print “the solution is found”. In this
case, two Boolean expressions (A is true) and (B is false)
are related by a connective „and‟. How do we define
these?
3
Boolean operators
Events : true or false
Connectives : a OR b; a AND b, NOT a
The operators used most often are AND and OR.
– The AND operation
• if and only if all inputs are on, the output will be on.
• The output will be off if any of the inputs are off.
– The OR operation
• If any input is on, the output will be on.
• Example: Either “it has rained” OR “someone splashed
water”, “must be tall” AND “good vision”.
• It's easy to see all of the combinations by using what are
called truth tables
4
Truth Tables
Truth tables show the result of combining boolean expressions of a logic
function by listing all possible values the function can attain
a b a AND b a b a OR b a NOT a
F F F F F F F T
F T F F T T T F
T F F T F T
T T T T T T
5
Truth Table: The AND operations
• the output will be on (or 1) if and only if all inputs are on (or 1).
• The output will be off (or 0) if any of the inputs are off (or 0)
TRUTH TABLE
The AND Gate
AND OPERATIONS
A B C=A.B A
0 0 0 C=A.B
B
0 1 0
1 0 0
1 1 1
6
Truth Table: The OR operations
• the output will be on (or 1) if ANY of inputs are on (or 1).
• The output will be off (or 0) if ALL inputs are off (or 0)
TRUTH TABLE
The OR Gate
OR OPERATIONS
A B C=A+B A
0 0 0 C=A.B
B
0 1 1
1 0 1
1 1 1
7
Truth Table: the inverter or NOT operation
• has only one input and one output
• The output will be in opposite state to the input
• If input is 0, output is 1; If input is 1, output is 0;
TRUTH TABLE
The NOT Gate
The NOT
Operations
A C= A A C= A
0 1
1 0
8
Truth Table: The NAND operations
• Has the same logic as AND operation, but with an inverted output.
• the output will be OFF (or 0) if and only if all inputs are ON (or 1),.
• The output will be ON (or 1) if any of the inputs are OFF (or 0)
TRUTH TABLE
The NAND Gate
NAND OPERATIONS
A B C= A.B A
C= A.B
0 0 1 B
0 1 1
1 0 1
1 1 0
9
Truth Table: The NOR operation
• Inverts the OR operation
• if any input is ON (or 1), the output will be OFF (or 0)
TRUTH TABLE
The NOR Gate
NOR OPERATIONS
A B C=A+B A
C= A+B
0 0 1 B
0 1 0
1 0 0
1 1 0
10
Summary of 2-input logic gates
11
Truth Table: The Exclusive-OR or XOR operation
TRUTH TABLE
The XOR Gate
XOR OPERATIONS
A B C=A + B A
C= A + B
0 0 0 B
0 1 1
1 0 1
1 1 0
12
common logic functions and their
equivalent Boolean notation.
A.B + A.B or A + B
13
Example
For all possible combinations of A and B, draw the truth table for
C = A.B + A
A B A.B A A.B+A
0 0 0 1 1
0 1 0 1 1
1 0 0 0 0
1 1 1 0 1
14
Overview of
Communication Systems
and Networks
instant
e-mail chat rooms
messaging
T1
lines
Physical Transmission Media
A tangible media
Examples: Twisted-pair cable, coaxial cable, Fiber-optics,
etc.
Twisted-pair cable:
One or more twisted wires bundled together (why?)
Made of copper
Coax-Cable:
Consists of single copper wire surrounded by three layers of
insulating and metal materials
Typically used for cable TV
Fiber-optics:
Strands of glass or plastic used to transmit light
Very high capacity, low noise, small size, less suitable to
natural disturbances
Physical Transmission Media
optical fiber
core
glass cladding
protective
coating
Wireless Transmission Media
Broadcast Radio
Distribute signals through the air
over long distance
Uses an antenna
Typically for stationary locations
Can be short range
Cellular Radio
A form of broadcast radio used for
mobile communication
High frequency radio waves to
transmit voice or data
Utilizes frequency-reuse
Wireless Transmission Media
Microwaves
Radio waves providing high speed
transmission
They are point-to-point (can’t be
obstructed)
Used for satellite communication
Infrared (IR)
Wireless transmission media that sends
signals using infrared light- waves - Such
as?
Physical Transmission Media
Which is bigger:
10,000 Mbps, 0.01Tbps or 10Gbps?
Networks
Examples:
Internet P2P: Networks with the same network software can be
connected together (Napster)
LAN v.s WAN
LAN - Local Area Network a group of
computers connected within a building
or a campus (Example of LAN may
consist of computers located on a
single floor or a building or it might link
all the computers in a small company.
Network Topology
The network topology
defines the way in
which computers,
printers, and other
devices are
connected. A network
topology describes
the layout of the wire
and devices as well
as the paths used by
data transmissions.
Network Topologies
BUS networks: Single central cable connected a number of
devices
Easy and cheap
Popular for LANs
RING networks: a number of computers are connected on a
closed loop
Covers large distances
Primarily used for LANs and WANs
STAR networks: connecting all devices to a central unit
All computers are connected to a central device called hub
All data must pass through the hub
What is the problem with this?
Susceptible to failure
Introduction to Computer Networks
Bus Topology
Commonly referred to
as a linear bus, all the
devices on a bus
topology are
connected by one
single cable.
Introduction to Computer Networks
Ring Topology
A frame travels around the ring,
stopping at each node. If a node
wants to transmit data, it adds the
data as well as the destination
address to the frame.
The frame then continues around
the ring until it finds the
destination node, which takes the
data out of the frame.
Single ring – All the devices on
the network share a single cable
Dual ring – The dual ring topology
allows data to be sent in both
directions.
Introduction to Computer Networks
Mesh Topology
The mesh topology
connects all devices
(nodes) to each other
for redundancy and
fault tolerance.
It is used in WANs to
interconnect LANs and
for mission critical
networks like those
used by banks and
financial institutions.
Implementing the mesh
topology is expensive
and difficult.
Network Topologies
personal personal personal
computer computer computer
personal personal
computer computer
personal computer
personal computer
personal computer
host
personal computer computer
printer
file server
Network Architecture
Refers to how the computer or devices are designed in a network
Basic types:
Centralized – using mainframes
Peer-2-Peer:
Each computer (peer) has equal responsibilities, capacities, sharing
hardware, data, with the other computers on the peer-to-peer network
Good for small businesses and home networks
Client/Server:
All clients must request service from the server
Different servers perform different tasks: File server, network server, etc.
laser serv
printer er
P2P vs Client-Server
Peers make a portion of their resources, such
as processing power, disk storage or network
bandwidth, directly available to other network
participants, without the need for central
coordination by servers or stable hosts
Peer-to-Peer
Examples
Introduction to Computer Networks
Project
RTP: Real-time Transport Protocol Topic
Network Technologies
Zigbee
High level communication protocols using small, low-power digital radios based on
the IEEE 802.15.4
Wireless mesh networking proprietary standard
Bluetooth
Uses radio frequency
Typically used for close distances (short range- 33 feet or so)
Transmits at 1Mbps
Used for handheld computers to communicate with the desktop
IrDA
Infrared (IR) light waves
Transfers at a rate of 115 Kbps to 4 Mbps
Requires light-of-sight transmission
RFID
Radio frequency identification
Uses tags which are places in items
Example: merchandises, toll-tags, courtesy calls, sensors!
WAP
Wireless application protocol
Data rate of 9.6-153 kbps depending on the service type
Used for smart phones and PDAs to access the Internet (email, web, etc)
Project
Topic
Network Example:
Telephone Networks
Called the Public Switched Telephone Network (PSTN)
World-wide and voice oriented (handles voice and data)
Data/voice can be transferred within the PSTN using different technologies (data
transfer rate bps)
Dial-up lines:
Analog signals passing through telephone lines Switching Technologies:
Requires modems (56 kbps transfer rate) Technologies:
ISDN lines: •Circuit Switching
Integrated Services Digital Network
Digital transmission over the telephone lines
•Packet Switching
Can carry (multiplex) several signals on a single line •Message Switching
DSL •Burst Switching
Digital subscribe line
ADSL (asymmetric DSL)
receiver operated at 8.4 Mbps, transmit at 640 kbps
T-Carrier lines: carries several signals over a single line: T1,T3
Frame Relay
ATM:
Asynchronous Transfer Mode
Fast and high capacity transmitting technology
Packet technology
Project
Topic
Network Example:
Optical Networks
Fiber-to-the-x
Broadband network architecture
that uses optical fiber to replace
copper
Used for last mile
telecommunications
Examples: Fiber-to-the-home
(FTTH); Fiber-to-the-building
(FTTB); Fiber-to-the premises
(FTTP)
Fiber Distribution Network (reaching
different customers)
Active optical networks (AONs)
Passive optical networks (PONs)
Project
Topic
Network Example
Smart Grid
Delivering electricity from suppliers to
consumers using digital technology to
save energy
Storage Area Networks
Computational Grid Networks
Project
http://rekuwait.wordpress.com/2009/06/18/smart-electric-grid/ Topic
Network Example:
Telephone Networks
Network Examples
Cellular Network Examples
0G
Single, powerful base station covering a wide area,
and each telephone would effectively monopolize a
channel over that whole area while in use (developed
in 40’s)
No frequency use or handoff (basis of modern cell
phone technology)
1G
Fully automatic cellular networks
introduced in the early to mid 1980s
2G
Introduced in 1991 in Finland on the GSM standard
Offered the first data service with person-to-person
SMS text messaging
Cellular Network Examples
3G:
Faster than PCS; Used for multimedia and
graphics
Compared to 2G and 2.5G services, 3G
allows simultaneous use of speech and
data services and higher data rates (up to
14.4 Mbit/s on the downlink and 5.8 Mbit/s.
4G:
Fourth generation of cellular wireless;
providing a comprehensive and secure IP
based service to users "Anytime,
Anywhere" at high data rates
Applications of Network
E-mail
Searchable Data (Web Sites)
E-Commerce
News Groups
Internet Telephony (VoIP)
Video Conferencing
Chat Groups
Instant Messengers
Internet Radio
Introduction to the Internet
and Web
What is Internet ?
• It is the largest network in the world that connects hundreds of
thousands of individual networks all over the world.
• The popular term for the Internet is the “information highway”.
• It is a Global network of computers, (servers or clients) to
exchange information.
• It is a "network of networks" that includes millions of private
and public, academic, business, and government networks
(local or Global), linked by copper wires, wireless
connections, and other technologies.
• Rather than moving through geographical space, it moves your
ideas and information through cyberspace – the space of
electronic movement of ideas and information.
The Internet: Then and Now
• The Internet was created by the Advanced Research
Projects Agency (ARPA) and the U.S. Department of
Defense for scientific and military communications.
• The Internet is a network of interconnected networks.
Even if part of its infrastructure was destroyed, data
could flow through the remaining networks.
• The Internet uses high-speed data lines, called
backbones, to carry data. Smaller networks connect to
the backbone, enabling any user on any network to
exchange data with any other user.
• ARPANET, NSFnet, Internet
• Internetworking: the process of connecting separate
networks
Some Common Terms
• The Internet is a network of computers spanning the
globe. It is also called the World Wide Web.
• Internal
It can be imposed by Public Key Security & Encryption
Key.
• External
Through Firewall.
What is Firewall ?
• Security device located between firm‟s internal network
(intranet) & external network (internet).
Request
The Web page
WWW server
Internet
Browser app (TCP/IP)
• com (commercial)
• edu (educational institution)
• gov (government)
• net (network)
• org (organization)
• You might also see addresses that add a country code as the
last part of the address such as:
• ca (Canada)
• uk (United Kingdom)
• fr (France)
• us (United States of America)
• au (Australia)
Uniform Resource Locator (URL)
• URL is the standard for specifying the whereabouts of a resource
(such as a web page) on the Internet
• A URL has four parts:
protocol pathname
http://www.ui.edu.ng/computerscience/index.htm
Implementation
Documentation
CONTINUE..
What is problem solving?
Problem solving is the process of transforming
the description of a problem into a solution of
that problem by using our knowledge of the
problem domain and by relying on our ability to
select and use appropriate problem-solving
strategies, techniques and tools.
START
Step 1: Input M1,M2,M3,M4
Step 2: GRADE (M1+M2+M3+M4)/4
Input
M1,M2,M3,M4
Step 3: if (GRADE <50) then
Print “FAIL”
else
GRADE(M1+M2+M3+M4)/4 Print “PASS”
endif
N IS Y
GRADE<5
0
PRINT PRINT
“PASS” “FAIL”
STOP
EXAMPLE 2
Write an algorithm and draw a flowchart to
convert the length in feet to centimeter.
Pseudocode:
Input the length in feet (Lft)
Calculate the length in cm (Lcm) by multiplying
LFT with 30
Print length in cm (LCM)
EXAMPLE 2
Algorithm Flowchart
Step 1: Input Lft
START
Step 2: Lcm Lft x 30
Step 3: Print Lcm Input
Lft
Lcm Lft x 30
Print
Lcm
STOP
EXAMPLE 3
Write an algorithm and draw a
flowchart that will read the two sides
of a rectangle and calculate its area.
Pseudocode
Input the width (W) and Length (L) of a
rectangle
Calculate the area (A) by multiplying L
with W
Print A
EXAMPLE 3
Algorithm START
Step 1: Input W,L
Step 2: AL x W Input
W, L
Step 3: Print A
ALxW
Print
A
STOP
EXAMPLE 4
Write an algorithm and draw a flowchart
that will calculate the roots of a quadratic
equation ax2 bx c 0
Algorithm:
Input
Step 1: Input a, b, c a, b, c
Step 2: d sqrt ( b b 4 a c )
Step 3: x1 (–b + d) / (2 x a) d sqrt(b x b – 4 x a x c)
Print
x1 ,x2
STOP
CONTROL STRUCTURE
In order to tackle a problem, we need
a correct algorithm
to apply the algorithm at the 'good' moment
to decide which algorithm to apply (sometimes there are
more than one, depending on conditions)
to know if a certain operation must be repeated
Y N
is
A>B
Print Print
A B
SELECTION CONSTRUCT
CONTINUED
THEN
Compute Overtime Compute Compute
©
Pay Overtime Regular
Cop
yrig
ELSE ht
2000
Compute Regular Pay by
the
ENDIF Tru
stee
s of
Indi
ITERATION CONSTRUCT
The logic pattern in programming in which
certain actions are repeated whenever a specified
condition occurs.
©
Cop
yrig
ht
2000
by
the
Tru
stee
s of
Indi
REPETITION/ITERATION STRUCTURE
Specifies a block of one or more statements that
are repeatedly executed until a condition is
satisfied.
The keyword used is while.
Format:
while condition
loop-body Example 1: print statements “hello
world “ 2 times
end_while
Begin
set number equal to 1
while number is less than 3
print hello world
add 1 to number
end_while
end
IMPLEMENTATION
The process of implementing an algorithm by
writing a computer program using a
programming language (for example, using
Python language)
The output of the program must be the solution
of the intended problem
The program must not do anything that it is not
supposed to do
(Think of those many viruses, buffer overflows,
trojan horses, etc. that we experience almost daily. All
these result from programs doing more than they were
intended to do)
CONTINUE..
Testing and verification
Program verification
Is the process of ensuring that a program meets user
requirements
o Program testing
• Is the process of executing a program to demonstrate its
correctness
Documentation
Document what the program do
Do the rest :
EXERCISE 2 – SEQUENCE STRUCTURE
Problem
An employee earns N 500.00 per hour for the
first 40 hours and N800.00 per hour for each
hour over 40. Design a program to calculate the
daily wage of this employee
EXERCISE 3 – REPETITION STRUCTURE
Problem
Design a program that can print the statement “ I
love programming “ 5 times.
EXERCISE 4-SEQUENCE AND REPETITION
Problem
Design a program that reads 5 numbers and
computes and outputs their arithmetic average.