0% found this document useful (0 votes)
20 views

Unit Ii

Uploaded by

Aashi Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Unit Ii

Uploaded by

Aashi Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

UNIT II

Introduction to Algorithms,
An algorithm is a method for solving a computational problem. A formula or set of steps for solving a
problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point.
Algorithms can be expressed in any language, from natural languages like English or French to
programming languages like FORTRAN.

For example, we might be able to say that our algorithm indeed correctly solves the problem in question and
runs in time at most f(n) on any input of size n.

Definition. An algorithm is a finite set of instructions for performing a computation or solving a problem.
Types of Algorithms Considered. In this course, we will concentrate on several different types of relatively
simple algorithms, namely:
Selection -- Finding a value in a list, counting numbers;
Sorting -- Arranging numbers in order of increasing or decreasing value; and
Comparison -- Matching a test pattern with patterns in a database.

Properties of Algorithms. It is useful for an algorithm to have the following properties:

Input -- Values that are accepted by the algorithm is called input or arguments.
Output -- The result produced by the algorithm is the solution to the problem that the algorithm is designed
to address.
Definiteness -- The steps in each algorithm must be well defined.
Correctness -- The algorithm must perform the task it is designed to perform, for all input combinations.
Finiteness -- Output is produced by the algorithm after a finite number of computational steps.
Effectiveness -- Each step of the algorithm must be performed exactly, infinite time.
Generality -- The procedure inherent in a specific algorithm should be applicable to all algorithms of the
same general form, with minor modifications permitted.

Procedure. Analysis of algorithmic complexity generally proceeds as follows:


Step 1. Decompose the algorithm into steps and operations.
Step 2. For each step or operation, determine the desired complexity measures, typically using Big-Oh
notation, or other types of complexity bounds discussed below.
Step 3. Compose the component measures obtained in Step 2 via theorems presented below, to obtain the
complexity estimate(s) for the entire algorithm.

Complexities of Algorithm:
Algorithmic complexity is concerned about how fast or slow algorithm performs.
Space S(n) -- How much storage (memory or disk) is required for an algorithm to produce a specified
output given n inputs?
Time T(n) -- How long does it take to compute the algorithm (with n inputs) on a given architecture?
Cost C(n) = T(n) · S(n) -- Sometimes called the space-time bandwidth product, this measure tells a system
designer what expenditure of aggregate computational resources is required to compute a given algorithm
with n inputs.

FLOWCHART
1. The flowchart is a type of diagram (graphical or symbolic) that represents an algorithm or process.
2. Each step in the process is represented by a different symbol and contains a short description of the
process step.
3. The flowchart symbols are linked together with arrows showing the process flow direction.
4. A flowchart typically shows the flow of data in a process.
5. Flowcharts are used in analyzing, designing, documenting or managing a process or program in
various fields.
6. Flowcharts are generally drawn in the early stages of formulating computer solutions.
7. Flowcharts often facilitate communication between programmers and business people.
Example: - Draw a flowchart to find the largest among three different numbers entered by the
user.

Advantages of Using Flowcharts


1. Communication: a better way of logical communicating.
3
2. Effective analysis: the problem can be analyzed in more effective way.
3. Proper documentation.
4. Efficient Coding: a guide or blueprint during the systems analysis and program development
phase.Proper Debugging: helps in debugging process.
5. Efficient Program Maintenance: easy with the help of flowchart.

Limitations of Using Flowcharts


1. Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart
becomescomplex and clumsy.
2. Alterations and Modifications: If alterations are required the flowchart may require
redrawing completely.
3. Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart
becomes aproblem.

Flowchart Symbols
1. Terminator: “Start” or “End”
2. Process
3. Decision: Yes/No question or True/False
4. Connector: jump in the process flow
5. Data: data input or output (I/O)
6. Delay
7. Arrow: flow of control in a process.

Symbol Purpose Description

Used to indicate the flow of logic by connecting


Flowline
symbols.

Terminal(Stop/Start) Used to represent start and end of the flowchart.

Input/output Used for input and output operation.

Used for arithmetic operations and data-


Processing
manipulations.

Used to represent the operation in which there are two


Decision
alternatives, true and false.

On-page Connector Used to join different flowline

Off-page Connector Used to connect flowchart portion on a different page.

Symbol Purpose Description


Used to represent a group of statements performing one
Predefined Process/Function processing task.

Introduction to Programming

An organized list of instructions that, when executed, causes the computer to behave in a predetermined
manner. Without programs, computers are useless.

A program is like a recipe. It contains a list of ingredients (called variables) and a list of directions
(called statements) that tell the computer what to do with the variables. The variables can represent
numeric data, text, or graphical images.

There are many programming languages -- C, C++, Pascal, BASIC, FORTRAN, COBOL, and LISP are
just a few. These are all high-level languages. One can also write programs in low-level languages
called assembly languages, although this is more difficult. Low-level languages are closer to the
language used by a computer, while high-level languages are closer to human languages.

Characteristics of Programming language

The following are the characteristics of a programming language

1. Readability: A good high-level language will allow programs to be written in some ways that
resemble a quite-English description of the underlying algorithms. If care is taken, the coding may be
done in a way that is essentially self-documenting.
2. Portability: High-level languages, being essentially machine independent, should be able to
develop portable software.
3. Generality: Most high-level languages allow the writing of a wide variety of programs, thus
relieving the programmer of the need to become an expert in many diverse languages.
4. Brevity: Language should have the ability to implement the algorithm with less amount of
code. Programs expressed in high-level languages are often considerably shorter than their low-
level equivalents.
5. Error checking: Being human, a programmer is likely to make many mistakes in the development of
a computer program. Many high-level languages enforce a great deal of error checking both at compile-
time and at run-time.
6. Cost: The ultimate cost of a programming language is a function of many of its characteristics.
7. Familiar notation: A language should have a familiar notation, so it can be understood by most of
the programmers.
8. Quick translation: It should admit quick translation.
9. Efficiency: It should permit the generation of efficient object code.
10. Modularity: It is desirable that programs can be developed in the language as a collection of
separately compiled modules, with appropriate mechanisms for ensuring self-consistency between these
modules.
11. Widely available: Language should be widely available and it should be possible to provide
translators for all the major machines and for all the major operating systems.
Difference between Procedure Oriented Programming (POP) & Object-Oriented Programming (OOP)

Object-Oriented Programming Procedure Oriented Points


Programming
In OOP, the program is divided into parts called objects. In POP, the program is Divided Into
divided into small parts
called functions.
In OOP, Importance is given to the data rather than In POP, Importance is not Importance
procedures or functions because it works as a real given to data but to
world. functions as well as the
sequence of actions to be
done.
OOP follows Bottom Up approach. POP follows Top-Down Approach
approach.
OOP has access specifiers named Public, Private, POP does not have any Access
Protected, etc. access specifier. Specifiers
In OOP, objects can move and communicate with each In POP, Data can move Data
other through member functions. freely from function to Moving
function in the system.
OOP provides an easy way to add new data and To add new data and Expansion
function. function in POP is not so
easy.
In OOP, data cannot move easily from function to In POP, the most function Data Access
function, it can be kept public or private so we can uses Global data for sharing
control the access of data. that can be accessed freely
from function to function in
the system.
OOP provides Data Hiding so provides more security. POP does not have any Data Hiding
proper way for hiding data
so it is less secure.
In OOP, overloading is possible in the form of Function In POP, Overloading is not Overloading
Overloading and Operator Overloading. possible.

You might also like