Algorithms and Problem Solving
CSBP 119
Chapter 1
An Overview of Computers and Programming Languages
CIT, UAE University Fall 2020
In this chapter you will learn about:
Different types of computers and the history
of computing machines
Objectives The hardware components of a computer
The evolution of programming languages
Low and high-level programming languages
Compilers
CIT, UAEU. 2
History of
Computers
An Overview
CIT, UAEU. 3
The basic commands a computer performs:
Elements Input - The data provided to the computer
Output - Results of the processing that is
of a provided by the computer
Storage
Computer Processing – arithmetic and logical
System operations.
CIT, UAEU. 4
Hardware /
CPU
Control Unit (CU)
Arithmetic Logic Unit
(ALU)
Program Counter (PC)
Instruction Register (IR)
CIT, UAEU. 5
Ordered sequence of
cells (memory cells)
which are uniquely
addressed.
Hardware / Programs loaded into
Main main memory before
execution
Memory Volatile state i.e., when
power is turned off,
everything in main
memory is lost
Main Memory with 100 storage cells
CIT, UAEU. 6
7 Hardware / Secondary Storage
Provides permanent storage for information
Examples of secondary storage:
Hard Disks
Floppy Disks
Flash memory
CDs, DVDs
Tapes
CIT, UAEU.
Hardware / IO Devices
Input Devices
Feed data and programs into computers
Examples:
Keyboard
Mouse
Track Ball
Output Devices
Used by the computer to display results
Examples:
Printer
Monitor
So, what would a touchscreen interface of a smartphone be? Input or Output device?
CIT, UAEU. 8
9 Software
A computer needs to be given instructions or
commands to perform tasks
A set of instructions is called a program
A set of programs written to perform a specific
task is called a Software
The two types of software are:
System software: controls the computer, ex:
Microsoft Windows
Application software: Perform a specific user-
defined task, ex: Microsoft Word
What language does a computer understand?
CIT, UAEU.
Machine Language
Basic language of a computer
A sequence of 0s and 1s (off and on)
Programming Every computer understands its own
machine language
Languages
The 0 or 1 is called a Bit or Binary Digit
A Byte is a sequence of 8 bits
10101001
CIT, UAEU. 10
Binary Units
CIT, UAEU. 11
12 Evolution of Programming Languages
Machine Language
Early computers were programmed in
machine language (only using zero’s and
one’s)
Assembly Language
Programming is made easier.
An instruction is an easy-to-remember form
called a mnemonic
Assembler: a software that translates
assembly language instructions into machine
language
CIT, UAEU.
What programmer easily What Computer understands.
understands.
Assembly program Machine code
Assembler
Evolution of Programming Languages
CIT, UAEU. 13
14 Evolution of Programming Languages
High-Level Languages
Makes programming easier for users.
Closer to spoken language (English)
Examples
Java, Basic, Quick Basic, Visual Basic,
FORTRAN, COBOL, C/C++, etc.
Well-known language constructs
If-then-else
do-while
for
integer, String, char, etc.
CIT, UAEU.
15 Evolution of Programming Languages
High-level programs needs to be translated into machine code
Compiler: a program that translates a program written in
a high-level language into the equivalent machine
language
A compiler checks the syntax of all statements in the
program against the language rules.
In case there is a mistake, the compilation fails.
Java is a High-level programming language
Stop
Bugs/errors/mistakes
High level programing Machine code
language Compiler/Interpreter
CIT, UAEU.
Java Programing Language Java Virtual Machine (JVM): Java
hypothetical computer
developed to make Java Programming
Java is a machine-independent language
programs machine independent.
Language
Java program is written using the Java
syntax
•Syntax is the grammar for the
instructions/commands.
CIT, UAEU. 16
17 Java Programming Language
To run a Java program
① Java instructions need to be written: Java Code/Java Source
Program.
② The instructions must be translated/compiled into an
intermediate language called bytecode
If there is an error then the Java Code must be rewritten
③ Then the bytecode is loaded and interpreted into machine
language
④ The machine language is executed by the CPU and then the
result is displayed
Java Machine
program Bytecode Code
Java compiler Java Interpreter
CIT, UAEU.
Source program:
written in a high-level
language
Loader: transfers the
compiled code
Run a Java (bytecode) into main
memory
Program
Interpreter: reads
and translates each
bytecode instruction
into machine
language and then
executes it
CIT, UAEU. 18
Problem Solving
Problem-Analysis-Coding-Execution Cycle
Algorithm: a step-by-step problem-solving
process in which a solution is arrived at, in a
finite amount of time.
CIT, UAEU. 19
1 2 3
Analyze the problem Implement the Maintain the program
• Outline solution algorithm in a • Use and modify if the
requirements and design an programming language problem domain or
algorithm (Java) and verify if the requirement changes
algorithm works
Problem Solving
CIT, UAEU. 20