Space complexity-DAA.pptx

SPACE COMPLEXITY
NAME: MOUNIKA
PIN: 21BQ5A0514
Introduction to Space complexity
Calculation of Space Complexity
for an Algorithm
Example of Space Complexity for
an Algorithm
INTRODUCTION TO SPACE COMPLEXITY
 Space complexity refers to the amount of memory or storage
space required by an algorithm to solve a problem.
 Space complexity is usually measured in terms of the number of
bits or bytes required to store the data used by the algorithm.
This includes both the input data and any additional memory
used by the algorithm during its execution.
CALCULATION OF SPACE COMPLEXITY FOR AN ALGORITHM
 Space complexity of an algorithm is sum of space required for fixed part of algorithm and space
required for variable part of algorithm.
 Space Complexity = Space required for fixed part +Space required for
variable part
Space Complexity = Space required for fixed part + Space required for variable
part
To estimate the memory requirement we need to focus on two parts:
(1) A fixed part: It is independent of the input size. It includes memory for instructions
(code), constants, variables, etc.
(2) A variable part: It is dependent on the input size. It includes memory for recursion stack,
referenced variables, etc.
Under fixed part, the space for the following is considered
1) Codeofalgorithm
2) Simplevariablesorlocalvariables
3) Definedconstants
Under variable part, the space for the following is considered
1) Variableswhosesizevariesfromoneinstanceoftheproblemtoanotherinstance(arrays,structuresandsoon)
2) Globalorreferencedvariables
3) Recursionstack
Recursion stack space is considered only for recursive algorithms. For each call of recursive
algorithm, the following information is stored in recursion stack
1) Valuesofformalparameters
2) Valuesoflocalvariables
3) Returnvalue
Example: Calculate space complexity of the following algorithm
Algorithm Add(a, b)
{
c := a + b;
write c;
}
Space complexity=space for fixed part + space for variable part
Space for fixed part:
Space for code=c words
Space for simple variables=3 (a, b, c) words
Space for defined constants=0 words
Space for variable part:
Space for arrays=0 words
Space for global variables=0 words
Space for recursion stack=0 words
Space complexity=c+3 +0+0+0+0=(c+3) words
Example : calculate space complexity for the following recursive algorithm
Algorithm Rsum(a, n)
// a is an array of size
{
if n = 0 then
return 0;
else
return a[n] + Rsum(a, n-1);
}
Space for fixed part:
Space for code=c words
Space for simple variables=1 (n) word
Space for defined constants=0 words
Space for variable part:
Space for arrays=n words
Space for global variables=0 words Space for recursion
stack=3(n+1) words
For each call of the algorithm, three values are stored in recursion stack (formal parameters: n,
starting address of array and return value). The algorithm is called for n+1 times. Total space
required by the recursion stack is (n+1)*3 words.
Space complexity = c+1+0+n+0+(n+1)3=(c+4n+4) words
Space complexity-DAA.pptx
1 de 10

Recomendados

Space complexity por
Space complexitySpace complexity
Space complexityBhanusree Koduru
2.7K vistas8 diapositivas
Complexity of Algorithm por
Complexity of AlgorithmComplexity of Algorithm
Complexity of AlgorithmMuhammad Muzammal
30.5K vistas14 diapositivas
Data Structure: Algorithm and analysis por
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysisDr. Rajdeep Chatterjee
4.4K vistas22 diapositivas
Complexity analysis in Algorithms por
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in AlgorithmsDaffodil International University
3.2K vistas20 diapositivas
Data Structures- Part5 recursion por
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
9.4K vistas28 diapositivas
Data Structure and Algorithms por
Data Structure and Algorithms Data Structure and Algorithms
Data Structure and Algorithms ManishPrajapati78
2.6K vistas40 diapositivas

Más contenido relacionado

La actualidad más candente

SEARCHING AND SORTING ALGORITHMS por
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
4.6K vistas27 diapositivas
Mathematical Analysis of Recursive Algorithm. por
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.mohanrathod18
5K vistas8 diapositivas
Algorithms Lecture 4: Sorting Algorithms I por
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IBenha University
11.2K vistas92 diapositivas
Asymptotic Notations por
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
11.6K vistas23 diapositivas
Insertion sort por
Insertion sort Insertion sort
Insertion sort Monalisa Patel
2K vistas11 diapositivas
Binary search por
Binary searchBinary search
Binary searchAparnaKumari31
2.4K vistas11 diapositivas

La actualidad más candente(20)

SEARCHING AND SORTING ALGORITHMS por Gokul Hari
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari4.6K vistas
Mathematical Analysis of Recursive Algorithm. por mohanrathod18
Mathematical Analysis of Recursive Algorithm.Mathematical Analysis of Recursive Algorithm.
Mathematical Analysis of Recursive Algorithm.
mohanrathod185K vistas
Algorithms Lecture 4: Sorting Algorithms I por Benha University
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Benha University11.2K vistas
Asymptotic Notations por Rishabh Soni
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni11.6K vistas
Stack organization por chauhankapil
Stack organizationStack organization
Stack organization
chauhankapil14.9K vistas
General register organization (computer organization) por rishi ram khanal
General register organization  (computer organization)General register organization  (computer organization)
General register organization (computer organization)
rishi ram khanal2.8K vistas
linked list in data structure por shameen khan
linked list in data structure linked list in data structure
linked list in data structure
shameen khan39.2K vistas
Hash table por Vu Tran
Hash tableHash table
Hash table
Vu Tran335 vistas
Analysis of algorithms por Ganesh Solanke
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
Ganesh Solanke15.9K vistas
Predictive parser por Jothi Lakshmi
Predictive parserPredictive parser
Predictive parser
Jothi Lakshmi12.9K vistas
Asymptotic notations por Nikhil Sharma
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma38.4K vistas

Similar a Space complexity-DAA.pptx

Performance analysis and randamized agoritham por
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agorithamlilyMalar1
258 vistas19 diapositivas
VCE Unit 01 (2).pptx por
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
383 vistas28 diapositivas
VCE Unit 01 (1).pptx por
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptxskilljiolms
370 vistas26 diapositivas
Buffer overflow attack por
Buffer overflow attackBuffer overflow attack
Buffer overflow attackPrithiviraj Prithiviraj
154 vistas28 diapositivas
Process of algorithm evaluation por
Process of algorithm evaluationProcess of algorithm evaluation
Process of algorithm evaluationAshish Ranjan
398 vistas14 diapositivas
Unit i basic concepts of algorithms por
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithmssangeetha s
3.7K vistas32 diapositivas

Similar a Space complexity-DAA.pptx(20)

Performance analysis and randamized agoritham por lilyMalar1
Performance analysis and randamized agorithamPerformance analysis and randamized agoritham
Performance analysis and randamized agoritham
lilyMalar1258 vistas
VCE Unit 01 (2).pptx por skilljiolms
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
skilljiolms383 vistas
VCE Unit 01 (1).pptx por skilljiolms
VCE Unit 01 (1).pptxVCE Unit 01 (1).pptx
VCE Unit 01 (1).pptx
skilljiolms370 vistas
Process of algorithm evaluation por Ashish Ranjan
Process of algorithm evaluationProcess of algorithm evaluation
Process of algorithm evaluation
Ashish Ranjan398 vistas
Unit i basic concepts of algorithms por sangeetha s
Unit i basic concepts of algorithmsUnit i basic concepts of algorithms
Unit i basic concepts of algorithms
sangeetha s3.7K vistas
Lec2&3 data structure por Saad Gabr
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Saad Gabr514 vistas
Functions, Strings ,Storage classes in C por arshpreetkaur07
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
arshpreetkaur0757 vistas
Programming in C sesion 2 por Prerna Sharma
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
Prerna Sharma974 vistas
E04612529 por IOSR-JEN
E04612529E04612529
E04612529
IOSR-JEN253 vistas
Ashish garg research paper 660_CamReady por Ashish Garg
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
Ashish Garg208 vistas
Data structure and algorithm por Trupti Agrawal
Data structure and algorithmData structure and algorithm
Data structure and algorithm
Trupti Agrawal979 vistas
C language por spatidar0
C languageC language
C language
spatidar0860 vistas
Ijmsr 2016-05 por ijmsr
Ijmsr 2016-05Ijmsr 2016-05
Ijmsr 2016-05
ijmsr55 vistas

Más de mounikanarra3

unit-2.pdf por
unit-2.pdfunit-2.pdf
unit-2.pdfmounikanarra3
3 vistas23 diapositivas
Unit - 4.pptx por
Unit - 4.pptxUnit - 4.pptx
Unit - 4.pptxmounikanarra3
4 vistas91 diapositivas
UNIT-1 (4).pdf por
UNIT-1 (4).pdfUNIT-1 (4).pdf
UNIT-1 (4).pdfmounikanarra3
2 vistas55 diapositivas
functionsinc-130108032745-phpapp01.pdf por
functionsinc-130108032745-phpapp01.pdffunctionsinc-130108032745-phpapp01.pdf
functionsinc-130108032745-phpapp01.pdfmounikanarra3
1 vista14 diapositivas
travelingsalesmanproblem-170122053648.pdf por
travelingsalesmanproblem-170122053648.pdftravelingsalesmanproblem-170122053648.pdf
travelingsalesmanproblem-170122053648.pdfmounikanarra3
7 vistas17 diapositivas
EEM MID2.PPT.pptx por
EEM MID2.PPT.pptxEEM MID2.PPT.pptx
EEM MID2.PPT.pptxmounikanarra3
10 vistas14 diapositivas

Último

MSA Website Slideshow (16).pdf por
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdfmsaucla
92 vistas8 diapositivas
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth por
BCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for GrowthBCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for Growth
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for GrowthInnomantra
6 vistas4 diapositivas
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... por
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...csegroupvn
5 vistas210 diapositivas
SPICE PARK DEC2023 (6,625 SPICE Models) por
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models) Tsuyoshi Horigome
33 vistas218 diapositivas
Ansari: Practical experiences with an LLM-based Islamic Assistant por
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic AssistantM Waleed Kadous
5 vistas29 diapositivas
Final Year Presentation por
Final Year PresentationFinal Year Presentation
Final Year PresentationComsat Universal Islamabad Wah Campus
11 vistas29 diapositivas

Último(20)

MSA Website Slideshow (16).pdf por msaucla
MSA Website Slideshow (16).pdfMSA Website Slideshow (16).pdf
MSA Website Slideshow (16).pdf
msaucla92 vistas
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth por Innomantra
BCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for GrowthBCIC - Manufacturing Conclave -  Technology-Driven Manufacturing for Growth
BCIC - Manufacturing Conclave - Technology-Driven Manufacturing for Growth
Innomantra 6 vistas
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc... por csegroupvn
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
Design of Structures and Foundations for Vibrating Machines, Arya-ONeill-Pinc...
csegroupvn5 vistas
SPICE PARK DEC2023 (6,625 SPICE Models) por Tsuyoshi Horigome
SPICE PARK DEC2023 (6,625 SPICE Models) SPICE PARK DEC2023 (6,625 SPICE Models)
SPICE PARK DEC2023 (6,625 SPICE Models)
Tsuyoshi Horigome33 vistas
Ansari: Practical experiences with an LLM-based Islamic Assistant por M Waleed Kadous
Ansari: Practical experiences with an LLM-based Islamic AssistantAnsari: Practical experiences with an LLM-based Islamic Assistant
Ansari: Practical experiences with an LLM-based Islamic Assistant
M Waleed Kadous5 vistas
SUMIT SQL PROJECT SUPERSTORE 1.pptx por Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 18 vistas
Proposal Presentation.pptx por keytonallamon
Proposal Presentation.pptxProposal Presentation.pptx
Proposal Presentation.pptx
keytonallamon52 vistas
GDSC Mikroskil Members Onboarding 2023.pdf por gdscmikroskil
GDSC Mikroskil Members Onboarding 2023.pdfGDSC Mikroskil Members Onboarding 2023.pdf
GDSC Mikroskil Members Onboarding 2023.pdf
gdscmikroskil58 vistas
Update 42 models(Diode/General ) in SPICE PARK(DEC2023) por Tsuyoshi Horigome
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Update 42 models(Diode/General ) in SPICE PARK(DEC2023)
Tsuyoshi Horigome38 vistas
_MAKRIADI-FOTEINI_diploma thesis.pptx por fotinimakriadi
_MAKRIADI-FOTEINI_diploma thesis.pptx_MAKRIADI-FOTEINI_diploma thesis.pptx
_MAKRIADI-FOTEINI_diploma thesis.pptx
fotinimakriadi8 vistas
Generative AI Models & Their Applications por SN
Generative AI Models & Their ApplicationsGenerative AI Models & Their Applications
Generative AI Models & Their Applications
SN10 vistas
Effect of deep chemical mixing columns on properties of surrounding soft clay... por AltinKaradagli
Effect of deep chemical mixing columns on properties of surrounding soft clay...Effect of deep chemical mixing columns on properties of surrounding soft clay...
Effect of deep chemical mixing columns on properties of surrounding soft clay...
AltinKaradagli10 vistas
DevOps-ITverse-2023-IIT-DU.pptx por Anowar Hossain
DevOps-ITverse-2023-IIT-DU.pptxDevOps-ITverse-2023-IIT-DU.pptx
DevOps-ITverse-2023-IIT-DU.pptx
Anowar Hossain12 vistas

Space complexity-DAA.pptx

  • 2. Introduction to Space complexity Calculation of Space Complexity for an Algorithm Example of Space Complexity for an Algorithm
  • 3. INTRODUCTION TO SPACE COMPLEXITY  Space complexity refers to the amount of memory or storage space required by an algorithm to solve a problem.  Space complexity is usually measured in terms of the number of bits or bytes required to store the data used by the algorithm. This includes both the input data and any additional memory used by the algorithm during its execution.
  • 4. CALCULATION OF SPACE COMPLEXITY FOR AN ALGORITHM  Space complexity of an algorithm is sum of space required for fixed part of algorithm and space required for variable part of algorithm.  Space Complexity = Space required for fixed part +Space required for variable part Space Complexity = Space required for fixed part + Space required for variable part To estimate the memory requirement we need to focus on two parts: (1) A fixed part: It is independent of the input size. It includes memory for instructions (code), constants, variables, etc. (2) A variable part: It is dependent on the input size. It includes memory for recursion stack, referenced variables, etc.
  • 5. Under fixed part, the space for the following is considered 1) Codeofalgorithm 2) Simplevariablesorlocalvariables 3) Definedconstants Under variable part, the space for the following is considered 1) Variableswhosesizevariesfromoneinstanceoftheproblemtoanotherinstance(arrays,structuresandsoon) 2) Globalorreferencedvariables 3) Recursionstack Recursion stack space is considered only for recursive algorithms. For each call of recursive algorithm, the following information is stored in recursion stack 1) Valuesofformalparameters 2) Valuesoflocalvariables 3) Returnvalue
  • 6. Example: Calculate space complexity of the following algorithm Algorithm Add(a, b) { c := a + b; write c; } Space complexity=space for fixed part + space for variable part Space for fixed part: Space for code=c words Space for simple variables=3 (a, b, c) words Space for defined constants=0 words
  • 7. Space for variable part: Space for arrays=0 words Space for global variables=0 words Space for recursion stack=0 words Space complexity=c+3 +0+0+0+0=(c+3) words
  • 8. Example : calculate space complexity for the following recursive algorithm Algorithm Rsum(a, n) // a is an array of size { if n = 0 then return 0; else return a[n] + Rsum(a, n-1); } Space for fixed part: Space for code=c words Space for simple variables=1 (n) word Space for defined constants=0 words
  • 9. Space for variable part: Space for arrays=n words Space for global variables=0 words Space for recursion stack=3(n+1) words For each call of the algorithm, three values are stored in recursion stack (formal parameters: n, starting address of array and return value). The algorithm is called for n+1 times. Total space required by the recursion stack is (n+1)*3 words. Space complexity = c+1+0+n+0+(n+1)3=(c+4n+4) words