Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:25:04+00:00 2026-06-04T20:25:04+00:00

This is slightly confusing to me. What should be my approach of solving a

  • 0

This is slightly confusing to me. What should be my approach of solving a given problem when the constraint is as follows:

1) Without using extra space:
For e.g.: If I want to sort a given array, I have few ways of doing it.
Bubble sort, which keeps on swapping ( just loops, no recursion). I believe this is said to be without using extra space.
What is the case if I use a recursion to sort the elements. Is it the same as “without using extra space”, or the stack used is counted in the Space complexity of the algorithm?

2) In O(1) space:
What is the meaning of O(1) space? Does it mean constant space. Now if it is constant space then please comment on the following cases:

a) If I am swapping in bubble sort with the help of the third variable. Isn’t it an extra space and it will not depend on the size of input so it is in constant space.

b) Moreover if I am using count sort being applied on natural numbers, where it doesn’t really require the amount of space proportional to the total numbers, do we consider it to be in constant space O(1).

Please explain the difference if any.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:25:05+00:00Added an answer on June 4, 2026 at 8:25 pm

    According to Fortnow & Homer (2003),

    The space complexity of the computation is […] taken to be the amount of space used on the work tapes.

    Sorting algorithm are all O(n) space in the least, since it needs the space to store all the inputs (no matter on memory or on disk). Therefore, even for bubble sort, the space complexity is still O(n).

    However, sometimes, we are not interested in the overall space complexity (esp. in the case above), but we want to know the additional space used by the algorithm. For bubble sort, we can say that it uses constant amount of additional space.

    Recursion is quite a special case where we have to consider stack. We are storing the state when we recurse, and we call the recursive function many times based on the input. As the number of recursion level depends on the input size, the space complexity must take into consideration the stack space usage.

    I’m not sure if O(1) space algorithm is common or not, but Cycle Finding algorithm is one of such example. The algorithm by itself only use space for exactly 2 “pointers”. Extra spaces used by the function whose cycle to be find should be counted separately.

    In case of counting sort, the space complexity depends on the size of the input n (the count) and the maximum input value k. The 2 parameters are independent of each other, hence
    the space complexity is O(n + k). The additional space used can be defined as O(k).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
This is a slightly original variation on a common problem. I have a fairly
I thought that there should have been a simple solution to this, given that
This might be slightly confusing, so please bear with me for a moment while
Well, sorry about the confusing title but I'm having a slightly annoying problem with
Apologies if this is a slightly noob question, but looking to clarify my thoughts
OK, this is a slightly weird question. We have a touch-screen application (i.e., no
This answer had me slightly confused. What is a 'select to a temp table'
I know that this is jumping the gun slightly as it is early days
I know this question has been done but I have a slightly different twist

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.