Intro To Algorithm and Programming 01
Intro To Algorithm and Programming 01
Reza Kalan
•Ph.D. In Information Technology
•M.S. In Computer Engineering
•B.S. In Computer Engineering
•Area of Research Interest : Computer Networks, Mobile Communication, Multimedia System
•Google Scholar : https://scholar.google.com.tr/citations?user=YbD9foUAAAAJ&hl=en
REZA KALAN 4
Algorithm & Programming / Introduction
Bit & Byte Definition:
• One bit has two different patterns: “0” or “1”
•-----------------------------------------------
•1 Kilo byte (1 KB)= 210 bits= 1024 bits
•1 Mega byte (1MB) = 220 bits= 1024 K bits
•1 Giga byte (1GB) = 230 bits=
1024*1024*1024 bits
DR. KALAN 5
Algorithm & Programming / Introduction
Computer Block Diagram:
•CPU is responsible for fetching instructions and data from memory and executing them
• It receives instructions and data from input devices which it stores in main memory
• Later, it fetch these instruction and data from main memory and executes them to produce results
DR.KALAN 6
Algorithm & Programming / Introduction
CPU Communications:
•The CPU consists of the arithmetic logic unit (ALU) and the control unit.
• The control unit coordinates the computer’s activities
•Data in main memory (RAM) are moved to these registers to be operated on by the CPU:
• Control Unit moves the data,
DR. KALAN 7
Algorithm & Programming / Introduction
Data Storage in Main Memory:
•Therefore, to represent a bit, the hardware needs a capability to being in one of state (0/1 or on/off)
•A memory cell is mage up of 1 to 4 bytes ( e.g., 8 bits to 32 bits), depending on word length of system (computer)
DR. KALAN 8
Algorithm & programming / Introduction
Data Storage in Main Memory:
•Thus, secondary memories are used too store data for future use (e.g., Disk, CD/DVD )
•At the user and program level, physical storage addresses are commonly referenced using logical name or addresses like
variable name of file name.
DR. KALAN 9
Algorithm & programming / Introduction
Software Systems:
•The software system drive the physical hardware components through a sequence of instructions called programs.
•Operating systems: for managing computer resources such as Window, Linux, Unix, Apple OS
•Compilers: for translating high level programming languages to machine language (bits). For example C/ C++ Pascal
•Network Software: for allowing more than one computer communicate together and share information (e.g., SSH,FTP)
•Application or Productively Tools: to perform daily business and office operations (e.g., word, spread sheet, database)
DR.KALAN 10
Algorithm & programming / Introduction
Overview of Algorithm:
•As an effective method, an algorithm can be expressed within a finite amount of time and space, and in a well-defined
formal language for calculating a function.
•Starting from an initial state and initial input (perhaps empty), the instructions describe a computation that, when executed,
proceeds through a finite number of well-defined successive states, eventually producing "output“, and terminating at a
final ending state.
DR. KALAN 11
Algorithm & programming / Introduction
Algorithm & Programming Languages:
Programmers routinely use hundreds of coding languages for a wide variety of applications. Web and software developers
use popular programming languages like JavaScript, C#, and Python as full-stack development tools.
Programming (Coding) languages enable computers to understand human-generated instructions for various commands
and computations.
Computer languages are machine language, assembly language, and high level languages.
Low-level Coding Languages: Low-level programming languages contain basic instructions for a computer to understand.
Examples are assembly and machine code.
High-level Coding Languages: High-level coding languages are the furthest away from the actual code that translates
commands on a computer system.
Examples include C++, Java, and Python.
•Note: Assembly language is a symbolic representation of machine language, consisting of binary code executed directly by the computer's
hardware. Machine language is a collection of bits (or binary digits) to be read and interpreted by a computer.
DR. KALAN 12
Algorithm & programming / Introduction
Types of Programming Languages:
Current programming languages fall into one of the following four programming paradigms
Imperative or Procedural: Procedural programming is a type of imperative programming in which the program is built from
one or more procedures (also termed subroutines or functions).
Example: Pascal, Fortran, C
Functional: Functional programming focuses on functions and their inputs and outputs. functional programming aims to
write code that is clearer to understand and more bug resistant.
Example: Erlang, Haskell, Scala, Lisp
Logical: Logic programming is a programming, database and knowledge representation paradigm based on formal logic.
Example:Prolog, SQL
Object-Oriented: OOP focuses on objects, which are instances of a class, and their interactions with each other.
Example: Java, C++, C#, andPython
DR. KALAN 13
Algorithm & programming / Introduction
Front-end and back-end development:
DR. KALAN 14
Algorithm & programming / Introduction
Compiler vs Interpreter:
To perform an instruction written in high-level language via computer, we need to convert it into machine language. To do
this, either a compiler or an interpreter, or both are used.
Compiler:
A compiler translates code from a high-level programming language (e.g., C / C++, java) into machine code before the program runs.
A compiler takes entire program in one go. Then, it is faster and efficient
Interpreter:
An interpreter translates code written in a high-level programming language (e.g., PHP)into machine code line-by-line as the code runs.
A interpreter takes a single line of code at a time. Then slower and inefficient
DR. KALAN 15
Algorithm & programming / Introduction
Algorithm and Programming Language:
Before a program written in high level language is executed by the CPU, it needs to be translated, linked and loaded into
memory in a process called compilation and linking.
Preprocessing: In this section our source code is attached to the preprocessor file. Different types of
header files are used like the (#include <studio.h>, #include <math.h>, etc). C source code is attached to
these types of files and the final C Source generates.
Compiler: The preprocessed source code moves to the compiler, and an assembly-level code is generated
by the compiler after the compilation of the whole C source code program. All the different files which
have the C program must be saved with the .c extension. For the compiler to understand whether the
program file is a C program file or not.
Assembler: This part usually generates the Object code. This object code is quite similar to the machine
code or the set of binary digits. After this assembler part, The Linker continues the process, producing an
executable.exe file at the end.
Linker: The compiler has no idea about the working of the function (printf, scanf, etc). The information for
each of these functions is kept in the corresponding library (#include)., The basic goal of the linker is to
link the object file to the library functions so that the program may be run as an executable file (.exe).
Loader: With the help of the loader, the .exe file is loaded in the RAM and the CPU is informed of the
starting point of the address of the program where it is loaded.
DR. KALAN 16