0% found this document useful (0 votes)
6 views10 pages

Introduction To Algorithms v1 23052022

The document provides an introduction to algorithms, defining them as finite sets of steps to solve specific problems and categorizing them into types such as search, sort, insert, update, and delete. It outlines the essential attributes of algorithms, including input, output, definiteness, finiteness, and effectiveness, and discusses algorithm complexity in terms of time and space factors. Additionally, it addresses the time-space trade-off, emphasizing the balance between memory usage and execution time when designing efficient algorithms.

Uploaded by

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

Introduction To Algorithms v1 23052022

The document provides an introduction to algorithms, defining them as finite sets of steps to solve specific problems and categorizing them into types such as search, sort, insert, update, and delete. It outlines the essential attributes of algorithms, including input, output, definiteness, finiteness, and effectiveness, and discusses algorithm complexity in terms of time and space factors. Additionally, it addresses the time-space trade-off, emphasizing the balance between memory usage and execution time when designing efficient algorithms.

Uploaded by

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

Introduction to

Algorithms
Ms. Divya Verma
Assistant Professor,IT
Contents

 Introduction to Algorithms- Attributes


 Design Techniques
 Algorithm Complexity
 Time Space Trade Off
Algorithms
 An algorithm is a finite set of steps defining the solution of a particular problem.
 can be defined as a finite set of instructions that, if followed, accomplishes a
particular task.
 are generally created independent of underlying languages, i.e. an algorithm can
be implemented in more than one programming language.
 From the data structure point of view, following are some important categories
of algorithms −
• Search − Algorithm to search an item in a data structure.
• Sort − Algorithm to sort items in a certain order.
• Insert − Algorithm to insert item in a data structure.
• Update − Algorithm to update an existing item in a data structure.
• Delete − Algorithm to delete an existing item from a data structure.
Attributes/Characteristics of an
Algorithm
 An algorithm must satisfy the following criteria:
 Input: An algorithm should have 0 or more well-defined inputs.
 Output: An algorithm should have 1 or more well-defined outputs, and
should match the desired output.
 Definiteness: Algorithm should be clear and unambiguous. Each of its steps
(or phases), and their inputs/outputs should be clear and must lead to only
one meaning.
 Finiteness: Must terminate after a finite number of steps
 Effectiveness: Must be basic enough to carried out in principle.
How to Write an Algorithm?
 There are no well-defined standards for writing algorithms. Rather, it
is problem and resource dependent. Algorithms are never written to
support a particular programming code.
 As we know that all programming languages share basic code
constructs like loops (do, for, while), flow-control (if-else), etc. These
common constructs can be used to write an algorithm.
 We write algorithms in a step-by-step manner, but it is not always the
case. Algorithm writing is a process and is executed after the problem
domain is well-defined. That is, we should know the problem domain,
for which we are designing a solution.
Example-
Problem − Design an algorithm to add two numbers and display the
result.

 Begin
 Read:a and b
 Set c= a+b
 Write: “addition result is ”,c
 End.
Algorithm Complexity
 Suppose X is an algorithm and n is the size of input data, the time
and space used by the algorithm X are the two main factors, which
decide the efficiency of X.
• Time Factor − Time is measured by counting the number of key
operations such as comparisons in the sorting algorithm.
• Space Factor − Space is measured by counting the maximum
memory space required by the algorithm.
 The complexity of an algorithm f(n) gives the running time and/or the
storage space required by the algorithm in terms of n as the size of
input data.
 An algorithm is said to be efficient and fast, if it takes less
time to execute and consumes less memory space.
Space Complexity
 The space complexity of an algorithm, hence program, is the amount of memory it
needs to run to completion.
 The space needed by a program consists of following operations:
1. Instruction Space-space needed to store the executable version of the program and is
fixed.
2. Data Space- space needed to store all constants, variable values.has three components
further:
i. Space needed by constants and simple variables. This space is fixed.
ii. Space needed by fixed sized structured variables, such as arrays and structures.
iii. Dynamically allocated space. This space usually varies.

3. Environment stack space- space needed to store the information needed to resume
the suspended(or partially completed) functions. Each time a function is invoked, the
following data is saved on stack:
3. Return address i.e. from where it has to resume after completion of the called function.
4. Values of all local variables and the values of formal parameters in the function being invoked.
Time Complexity
 Time complexity of an algorithm represents the amount of time
required by the algorithm to run to completion. Time requirements
can be defined as a numerical function T(n), where T(n) can be
measured as the number of steps, provided each step consumes
constant time.
 For example, addition of two n-bit integers takes n steps.
Consequently, the total computational time is T(n) = c ∗ n, where c is
the time taken for the addition of two bits. Here, we observe that T(n)
grows linearly as the input size increases.
Time-Space Trade-Off
 A tradeoff is a situation where one thing increases and another thing
decreases. It is a way to solve a problem in:
• Either in less time and by using more space, or
• In very little space by spending a long amount of time.

 The best Algorithm is that which helps to solve a problem that


requires less space in memory and also takes less time to generate
the output. But in general, it is not always possible to achieve both of
these conditions at the same time.

You might also like