GATE CSE
First time here? Checkout the FAQ!
x
0 votes
108 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 | 108 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.4k 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)   | 23 views
0 votes
0 answers
3
asked in Algorithms by vaishali jhalani Boss (6k points)   | 71 views


Top Users Mar 2017
  1. rude

    4018 Points

  2. sh!va

    2994 Points

  3. Rahul Jain25

    2804 Points

  4. Kapil

    2608 Points

  5. Debashish Deka

    2104 Points

  6. 2018

    1414 Points

  7. Vignesh Sekar

    1336 Points

  8. Bikram

    1218 Points

  9. Akriti sood

    1186 Points

  10. Sanjay Sharma

    1016 Points

Monthly Topper: Rs. 500 gift card

21,445 questions
26,757 answers
60,936 comments
22,954 users