GATE CSE
First time here? Checkout the FAQ!
x
0 votes
113 views

1. Does space complexity includes both input space and extra space needed for algorithm or only extra space?

2.What will be Space complexity for BFS algorithm with adjacency matrix representation? Please reply with supporting references.

asked in Algorithms by Active (1.4k points)  
edited by | 113 views

1 Answer

0 votes
The space complexity is the extra amount of space excluding the input array or space. We are comparing the nature of algorithm in different situations. So we does not take input space into consideration as all the algorithm will be needing that as compulsary.

the extra space for bfs will be n as the queue may be maximum size of all the nodes .
answered by Veteran (13.6k points)  
By theory input space is included in space complexity. But usually in question they say extra/auxiliary space complexity to exclude it.
for example

let us take an example of insertion sort

here input is an array of n elements but while calculation space complexity we take O(1)

but in merge sort it is O(n) because of extra space occupied by another array(auxillary space)

So in case of adjacency matrix space complexity of BFS should be O(n) but in wiki it is given O(n2)?

https://en.wikipedia.org/wiki/Breadth-first_search

Related questions

0 votes
0 answers
2
asked in Algorithms by thor Boss (8.6k points)   | 25 views
0 votes
0 answers
3
asked in Algorithms by vaishali jhalani Boss (6k points)   | 97 views


Top Users May 2017
  1. akash.dinkar12

    3302 Points

  2. pawan kumarln

    1776 Points

  3. Bikram

    1646 Points

  4. sh!va

    1640 Points

  5. Arjun

    1396 Points

  6. Devshree Dubey

    1272 Points

  7. Debashish Deka

    1142 Points

  8. Angkit

    1044 Points

  9. LeenSharma

    1000 Points

  10. Arunav Khare

    754 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 May 22 - 28
  1. Bikram

    732 Points

  2. Arnab Bhadra

    402 Points

  3. pawan kumarln

    402 Points

  4. bharti

    304 Points

  5. LeenSharma

    238 Points


22,823 questions
29,142 answers
65,209 comments
27,666 users