0 0 votes 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. Algorithms space-complexity breadth-first-search + – Shyam Singh 1 1.2k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 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 . Tendua answered Oct 12, 2016 Tendua comment Share Follow See all 3 Comments 3 3 Comments reply Arjun commented Oct 12, 2016 reply Follow flag By theory input space is included in space complexity. But usually in question they say extra/auxiliary space complexity to exclude it. 2 2 replyShare cse23 commented Oct 14, 2016 reply Follow flag 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) 0 0 replyShare reena_kandari commented Jan 31, 2017 reply Follow flag 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 0 0 replyShare Please log in or register to add a comment.