Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

1

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

Q1. Define algorithm. Also explain its phases.

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain


order to get the desired output. Algorithms are generally created independent of underlying languages,
i.e. an algorithm can be implemented in more than one programming language.

Q2. List out and explain different properties of algorithm.

Output: The algorithm must specify the output and how it is related to the input. Definiteness: The steps
in the algorithm must be clearly defined and detailed. Effectiveness: The steps in the algorithm must be
doable and effective. Finiteness: The algorithm must come to an end after a specific number of steps.

Q3.Write an algorithm to find area of a rectangle

Therefore, with the help of the formula of area of a rectangle, that is, length × breadth, area of a
rectangle can be found.

Q4. What is flowchart? Explain its various symbols with its usage.

A flowchart is simply a graphical representation of steps. It shows steps in sequential order and is widely
used in presenting the flow of algorithms, workflow or processes. Typically, a flowchart shows the steps
as boxes of various kinds, and their order by connecting them with arrows.

Q5. Why does preparation of algorithm and flowchart important before developing

the code of a problem?

It is a diagrammatic representation of the solution to a given problem but, more importantly, it provides
a breakdown of the essential steps to solving the problem. When designing and planning a process,
flowcharts can help you identify its essential steps and simultaneously offer the bigger picture of the
process.

Q3

Language Processors: Assembler, Compiler and Interpreter

Language Processors –

Compilers, interpreters, translate programs written in high-level languages into machine code that a
computer understands. And assemblers translate programs written in low-level or assembly language
into machine code. In the compilation process, there are several stages. To help programmers write
error-free code, tools are available.
Assembly language is machine-dependent, yet mnemonics used to represent instructions in it are not
directly understandable by machine and high-Level language is machine-independent. A computer
understands instructions in machine code, i.e. in the form of 0s and 1s. It is a tedious task to write a
computer program directly in machine code. The programs are written mostly in high-level languages
like Java, C++, Python etc. and are called source code. These source code cannot be executed directly by
the computer and must be converted into machine language to be executed. Hence, a special translator
system software is used to translate the program written in a high-level language into machine code is
called Language Processor and the program after translated into machine code (object program/object
code).

The language processors can be any of the following three types:

GEEKSFORGEEKS

Language Processors: Assembler, Compiler and Interpreter

Language Processors –

Compilers, interpreters, translate programs written in high-level languages into machine code that a
computer understands. And assemblers translate programs written in low-level or assembly language
into machine code. In the compilation process, there are several stages. To help programmers write
error-free code, tools are available.

Assembly language is machine-dependent, yet mnemonics used to represent instructions in it are not
directly understandable by machine and high-Level language is machine-independent. A computer
understands instructions in machine code, i.e. in the form of 0s and 1s. It is a tedious task to write a
computer program directly in machine code. The programs are written mostly in high-level languages
like Java, C++, Python etc. and are called source code. These source code cannot be executed directly by
the computer and must be converted into machine language to be executed. Hence, a special translator
system software is used to translate the program written in a high-level language into machine code is
called Language Processor and the program after translated into machine code (object program/object
code).

The language processors can be any of the following three types:

1. Compiler :
The language processor that reads the complete source program written in high-level language as a
whole in one go and translates it into an equivalent program in machine language is called a Compiler.
Example: C, C++, C#, Java.

In a compiler, the source code is translated to object code successfully if it is free of errors. The compiler
specifies the errors at the end of the compilation with line numbers when there are any errors in the
source code. The errors must be removed before the compiler can successfully recompile the source
code again

2. Assembler :

The Assembler is used to translate the program written in Assembly language into machine code. The
source program is an input of an assembler that contains assembly language instructions. The output
generated by the assembler is the object code or machine code understandable by the computer.
Assembler is basically the 1st interface that is able to communicate humans with the machine. We need
an Assembler to fill the gap between human and machine so that they can communicate with each
other. code written in assembly language is some sort of mnemonics(instructions) like ADD, MUL, MUX,
SUB, DIV, MOV and so on. and the assembler is basically able to convert these mnemonics in Binary
code. Here, these mnemonics also depend upon the architecture of the machine.

For example, the architecture of intel 8085 and intel 8086 are different.

3. Interpreter :

The translation of a single statement of the source program into machine code is done by a language
processor and executes immediately before moving on to the next line is called an interpreter. If there is
an error in the statement, the interpreter terminates its translating process at that statement and
displays an error message. The interpreter moves on to the next line for execution only after the
removal of the error. An Interpreter directly executes instructions written in a programming or scripting
language without previously converting them to an object code or machine code.

Example: Perl, Python and Matlab.


Difference between Compiler and Interpreter –

Compiler

A compiler is a program that converts the entire source code of a programming language into
executable machine code for a CPU.

Compiler Interpreter

A compiler is a program that converts the entire An interpreter takes a source program and runs it
source code of a programming language into line by line, translating each line as it comes to it
executable machine code for a CPU.

The compiler takes a large amount of time to


analyze the entire source code but the overall An interpreter takes less amount of time to
execution time of the program is comparatively analyze the source code but the overall execution
faster. time of the program is slower.

The compiler generates the error message only


after scanning the whole program, so debugging is Its Debugging is easier as it continues translating
comparatively hard as the error can be present the program until the error is met.
anywhere in the program.

The compiler requires a lot of memory for


generating object codes. It requires less memory than a compiler because
no object code is generated.

Generates intermediate object code.


No intermediate object code is generated.

For Security purpose compiler is more useful.


The interpreter is a little vulnerable in case of
security.
Examples: C, C++, Java Examples: Python, Perl, JavaScript,

You might also like