logo
Tags down

shadow

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 : facebook icon twitter icon

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;
    }
  }
}
Related Posts Related Posts :
  • How to solve a matrix reachability recursion problem efficiently?
  • Count number of subsets having cumulative XOR less than k
  • Find a Circle ((x,y,r)) that has maximum number of points 'on' it; given a set of points(x,y) in a 2D plane
  • Find Top K Frequent Words In A Big Word Stream
  • How to find Nth Armstrong number in less than O(n) time complexity?
  • Given a random int generator [0-5], generate [0-7]
  • How to Hash Value in Flutter Using SHA256?
  • Picking out exacly one value from each row and column of a matrix
  • Why is the given algorithm O(n^2)?
  • How can I determine if a list of ranges covers a given range?
  • Divide two strings to form palindrome
  • How to partition 2D-points into intervals (using only vertical lines)?
  • Algorithm to traverse k nodes of an undirected, weighted graph (and return to the origin) at the lowest cost
  • Arranging the number 1 in a 2d matrix
  • If a function is called more than million times in a second, print an error
  • Find missing permutation
  • What is the time complexity of the following method?
  • How to get the K smallest Products from pairs from two sorted Arrays?
  • divide and conquer algorithm for finding a 3-colored triangle in an undirected graph with the following properties?
  • Find the median in an unsorted read-only array
  • What is the most efficient integer nth root algorithm for small numbers?
  • How to detect an inconsistent pattern of coordinates?
  • What is the time complexity of the algorithm to check if a number is prime?
  • Algorithm to suggest correction for wrong input?
  • 2d path "shrink-wrap" algorithms
  • Complexity of multiple variables
  • Algorithm to produce number series
  • Buy Sell Stock with Transaction Fee?
  • How do I keep track of the shortest paths in the Dijkstra algorithm when using a min-priority queue?
  • Write method about 15-5-3 division rule
  • minimum number of operations to make two numbers equal
  • How to do unspecific number of nested loop using only loops
  • How do I calculate mathematically this algorithm's time complexity?
  • Special Perfect Maze Generation Algorithm
  • Algorithm to find the points closest to a given set of 3D lines
  • Finding second largest element in sliding window
  • What algorithm theory would I use for searching one full record in one big file which contains 100 millions records?
  • What does the extra 0 added to the LSB in Modified Booth Algorithm do?
  • How to calculate angle of rotation of a rectangle, given its 4 points
  • What is a data structure suited for representing railways with turnouts?
  • How to efficiently move the decimal point in a number until reaching some threshold
  • Can I check whether a bounded list contains duplicates, in linear time?
  • confused about a nested loop having linear complexity(Big-Oh = O(n)) but I worked it to be logarithmic
  • Merging two binary strings and separating them
  • What is the "Problem size" for bubble sort and distribution sort algorithm?
  • Algorithm to find all possible solutions for x1² + x2² + ... + xn² = 1
  • How to solve this minimum steps needed to reach end of matrix problem?
  • Last remaining number
  • Special Pairs till N
  • The point that minimizes the sum of euclidean distances to a set of n points
  • Efficient algorithm for computing a compositional square root
  • Join (sum) two adjacent elements of an array into one element until its size is K and GCD of new elements is maximum pos
  • Algorithm | Solving O(N^2) complexity to something lesser?
  • No. of triplets
  • Sum of very very large numbers
  • Time Complexity and Big O Notation
  • How to sort all polygon points by clockwise/ anticlockwise direction?
  • Algorithm to distribute a jackpot between winners
  • An effective way to perform a prefix search on ranked (sorted) list?
  • Algorithm to find correct index
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk