Tags
 IOS SQL HTML C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6

# Can we make the counting sort algorithm for n element with O(n) space complexity?

By : A Patel
Date : October 17 2020, 06:10 PM
Hope this helps If we use an array for counting in counting sort then it requires space equal to the difference between the maximum and minimum key values. We can use hash-table, then we can reduce space complexity to linear relative to the number of elements in the input. But in this case, hidden constant might be too big and performance might deteriorate.
code :

Share :

## Space complexity of bubble sort algorithm

By : Vikram Rihal
Date : March 29 2020, 07:55 AM
it helps some times The space complexity is a measure of how much extra memory your algorithm requires.
If you were to allocate an extra array of size n (when n is the variable size of the input array), the space complexity would be O(n).

## How to find exact Time complexity and Space Complexity for below new Quick sort algorithm

By : NoodTug
Date : March 29 2020, 07:55 AM
I wish this helpful for you Time complexity for the above algorithm seems to be O(n^2).
As you can see there are 2 nested for loops. external one runs from x = 0, y = n to x < y, and in each step it reduces x++ and y--. While the other inner loop goes from x to y.

## Confused about complexity of counting sort algorithm

By : Ferdian Nasruddin
Date : March 29 2020, 07:55 AM
wish helps you To answer 1:
Let there be three 'for' loops that each works in O(n) therefore the overall complexity is of:
code :
``````for(i = 0; str[i]; ++i) // O(n)

for (i = 1; i <= RANGE; ++i) // O(k)

for (i = 0; str[i]; ++i) // O(n)

for (i = 0; str[i]; ++i) // O(n)
``````

## Which sorting algorithm is best in terms of space complexity - Quick Sort or Insertion Sort?

By : Craig68x
Date : March 29 2020, 07:55 AM
seems to work fine Quick Sort and Insertion Sort both are in-place and comparison-based sorting algorithms.
None of the above two sorting algorithms demand extra space from you but the space complexity of Insertion Sort is O(1) because it uses few temporary variables during swapping.

## What is the most efficient algorithm to find repeated elements in an array in time complexity O(n) and space complexity

By : suzan
Date : September 27 2020, 04:00 PM
this will help If the elements in an array with size n are in a range of 0 ~ n-1 ( or 1 ~ n).
We can try to sort the array by putting a[i] to index i for every a[i] != i, and if we find that there is already an a[i] at index i, it means that there is another element with value a[i].
code :
``````for (int i = 0; i < a.length; i++){
while (a[i] != i) {
if (a[i] == a[a[i]]) {
System.out.print(a[i]);
break;
} else {
int temp = a[i];  // Putting a[i] to index i by swapping them
a[i] = a[a[i]];
a[temp] = temp;
}
}
}
``````