I Introduction to programming languages
Types of programming languages – high level – assembly language - low level
language – Compilers and interpreters. Problem solving concepts– flow charts
and algorithms.
Programming languages are categorized based on their level of abstraction from
machine code and human readability.
1. Low-Level Languages:
These languages are very close to the computer's native language (binary machine
code).
They provide direct control over hardware and memory.
They are highly machine-dependent, meaning code written for one type of processor
may not run on another without modification.
Machine Language: This is the most fundamental low-level language, consisting of
binary instructions (0s and 1s) directly executable by the CPU.
Assembly Language: This is a symbolic representation of machine language, using
mnemonics (short, English-like abbreviations) for instructions and registers. It
requires an assembler to translate it into machine code.
2. High-Level Languages:
These languages are designed to be more human-readable and easier to write and
understand than low-level languages.
They use syntax and structures closer to natural human language, often employing
keywords and phrases.
They offer a higher level of abstraction, simplifying complex operations and reducing
the need for direct hardware manipulation.
They are generally more portable, meaning code can often be run on different systems
with minimal changes.
Examples include Python, Java, C++, JavaScript, C#, and many others.
High-level languages require a compiler or interpreter to translate them into machine
code before execution.
Compiler and Interpreter
The Compiler and Interpreter, both have similar works to perform.
Interpreters and Compilers convert the Source Code (HLL) to Machine Code
(understandable by Computer). In general, computer programs exist in High-
Level Language that a human being can easily understand. But computers cannot
understand the same high-level language, so for computers, we have to convert
them into machine language and make them readable. In this article, we are going
to see the differences between them.
Compiler
The Compiler is a translator that takes input i.e., High-Level Language,
and produces an output of low-level language i.e. machine or assembly language.
The work of a Compiler is to transform the codes written in the programming
language into machine code (format of 0s and 1s) so that computers can
understand.
A compiler is more intelligent than an assembler it checks all kinds of
limits, ranges, errors, etc.
But its program run time is longer and occupies a larger part of
memory. It has a slow speed because a compiler goes through the entire
program and then translates the entire program into machine codes.
Role of a Compiler
For Converting the code written in a high-level language into machine-level
language so that computers can easily understand, we use a compiler. Converts
basically convert high-level language to intermediate assembly language by a
compiler and then assembled into machine code by an assembler.
Advantages of Compiler
Compiled code runs faster in comparison to Interpreted code.
Compilers help improve the security of Applications.
Compilers give Debugging tools, which help in fixing errors easily.
Disadvantages of Compiler
The compiler can catch only syntax errors and some semantic errors .
Compilation can take more time in the case of bulky code.
Interpreter
An Interpreter is a program that translates a programming language into a
comprehensible language. The interpreter converts high-level language to an
intermediate language. It contains pre-compiled code, source code, etc.
It translates only one statement of the program at a time.
Interpreters, more often than not are smaller than compilers.
Role of an Interpreter
The simple role of an interpreter is to translate the material into a target language.
An Interpreter works line by line on a code. It also converts high-level language
to machine language .
Advantages of Interpreter
Programs written in an Interpreted language are easier to debug.
Interpreters allow the management of memory automatically, which
reduces memory error risks.
Interpreted Language is more flexible than a Compiled language.
Disadvantages of Interpreter
The interpreter can run only the corresponding Interpreted program.
Interpreted code runs slower in comparison to Compiled code.
FLOWCHART
The flowchart is a diagram which visually presents the flow of data through
processing systems. This means by seeing a flow chart one can know the operations
performed and the sequence of these operations in a system. Algorithms are nothing but
sequence of steps for solving problems. So a flow chart can be used for representing an
algorithm.
A flowchart, will describe the operations (and in what sequence) are required to solve a given
problem. You can see a flow chart as a blueprint of a design you have made for solving a
problem.
Flowchart Symbols
There are 6 basic symbols commonly used in flowcharting of assembly language
Programs:
Terminal,
Process,
input/output,
Decision,
Connector and
Predefined Process.
ALGORITHM:
The word “algorithm” relates to the name of the mathematician Al-khowarizmi, which
means a procedure or a technique. Software Engineer commonly uses an algorithm for
planning and solving the problems. An algorithm is a sequence of steps to solve a particular
problem or algorithm is an ordered set of unambiguous steps that produces a result and
terminates in a finite time.
Algorithm has the following characteristics
• Input: An algorithm may or may not require input
• Output: Each algorithm is expected to produce at least one result
• Definiteness: Each instruction must be clear and unambiguous.
• Finiteness: If the instructions of an algorithm are executed, the algorithm
should terminate after finite number of steps
The algorithm and flowchart include following three types of control structures.
1. Sequence: In the sequence structure, statements are placed one after the other and the
execution takes place starting from up to down.
2. Branching (Selection): In branch control, there is a condition and according to a condition,
a decision of either TRUE or FALSE is achieved. In the case of TRUE, one of the two
branches is explored; but in the case of FALSE condition, the other alternative is taken.
Generally, the ‘IF-THEN’ is used to represent branch control.
3. Loop (Repetition): The Loop or Repetition allows a statement(s) to be executed repeatedly
based on certain loop condition e.g. WHILE, FOR loops.
Advantages of algorithm
• It is a step-wise representation of a solution to a given problem, which makes it easy to
understand.
• An algorithm uses a definite procedure.
• It is not dependent on any programming language, so it is easy to understand for anyone
even without programming knowledge.
• Every step in an algorithm has its own logical sequence so it is easy to debug.
HOW TO WRITE ALGORITHMS
Step 1 Define your algorithms input: Many algorithms take in data to be processed, e.g. to
calculate the area of rectangle input may be the rectangle height and rectangle width.
Step 2 Define the variables: Algorithm's variables allow you to use it for more than one
place. We can define two variables for rectangle height and rectangle width as HEIGHT and
WIDTH (or H & W). We should use meaningful variable name e.g. instead of using H & W
use HEIGHT and WIDTH as variable name.
Step 3 Outline the algorithm's operations: Use input variable for computation purpose,
e.g. to find area of rectangle multiply the HEIGHT and WIDTH variable and store the value
in new variable (say) AREA. An algorithm's operations can take the form of multiple steps
and even branch, depending on the value of the input variables.
Step 4 :Output the results of your algorithm's operations: In case of area of rectangle
output will be the value stored in variable AREA. if the input variables described a rectangle
with a HEIGHT of 2 and a WIDTH of 3, the algorithm would output the value of 6.