Question

1. what conditions does counting sort run in a linear line 2. which has the best...

1. what conditions does counting sort run in a linear line

2. which has the best running time. assume we sort n #s in range 0 to n^2 using radix sort(counting sort to sort each digit)

- all n numbers in decimal form(radix-10)

- all n numbers are represented in radix-n

Homework Answers

Answer #1

1. Time complexity of counting sort is O(n). Count sort runs on a condition that it will initially generates a new array based on the maximum element. Then by iterating through the entire array, it will count how many times each element occurs using for loop. Based on this condition counting sort run in a linear line.

2. Radix sort has a best running time when it comes to run in the range of 0 to n2 .

Radix sort is a specific type of sorting technique which starts with the top n-bit or n-digits and may sort those buckets using a radix sort etc, until every entry is sorted.

Counting sort is like using radix sort except you are using the whole value. Instead of recording each object, it has a bucket for each object and it just counts the number of occurrences. This works well when you have a limited number of possible keys and you have many duplicates.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary...
Write a program that reads a binary string (string of 0’s and 1’s) converting the binary value into decimal. Allow the user to type in as many numbers as they want (one at a time) and end the program when they type in “0”. Use Horner’s method (given in step 3, below) to convert from binary to decimal. Sample Run Binary to Decimal Conversion Enter a binary string: 1101 1101 = 13 decimal Enter a binary string: 10011001 10011001 =...
If you run summary() command on a result of linear model fitting returned by lm(), you...
If you run summary() command on a result of linear model fitting returned by lm(), you will see a column Pr(>t). You could guess that it is a result of some t-test. How does it apply here? So far we have seen t-tests in the settings of testing sample locations. The ingredients were: 1) null hypothesis: in earlier cases we looked into the null that stated that two samples came from the distribution(s) with the same mean(s); 2) test statistic:...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number...
1. Given an n-element array A, Algorithm X executes an O(n)-time computation for each even number in A and an O(log n)-time computation for each odd number in A. What is the best-case running time of Algorithm X? What is the worst-case running time of Algorithm X? 2. Given an array, A, of n integers, give an O(n)-time algorithm that finds the longest subarray of A such that all the numbers in that subarray are in sorted order. Your algorithm...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
a) Determine all x-values where the function has a horizontal tangent line. y=ln(1+sinx) b) The position...
a) Determine all x-values where the function has a horizontal tangent line. y=ln(1+sinx) b) The position of a particle is given by s(t)+2e^t/t . What is the particle's acceleration at t=1?  Round to 2 decimal places. c)Determine the limit using L'Hospital's rule. Before applying the rule, first verify that the function is a simplified indeterminate form. The rule may need to be used more than once. lim x->0 x^2/1-cosx
Use the following linear regression equation to answer the questions. x1 = 1.1 + 3.0x2 –...
Use the following linear regression equation to answer the questions. x1 = 1.1 + 3.0x2 – 8.4x3 + 2.3x4 (a) Which variable is the response variable? x3 x1      x2 x4 Which variables are the explanatory variables? (Select all that apply.) x1 x2 x3 x4 (b) Which number is the constant term? List the coefficients with their corresponding explanatory variables. constant = x2 coefficient= x3 coefficient= x4 coefficient= (c) If x2 = 4, x3 = 10, and x4 = 6, what...
C program fractions.c that does the following: 1. The program starts by making the user enter...
C program fractions.c that does the following: 1. The program starts by making the user enter a non-negative integer number a, called the first numerator. If the user enters a negative number, the program repeats the entry. 2. The program then makes the user enter a positive integer number b, called the first denominator. If the user enters a non-positive number, the program repeats the entry. 3. The program then makes the user enter a non-negative integer number c, called...
Use the following linear regression equation to answer the questions. x1 = 1.5 + 3.5x2 –...
Use the following linear regression equation to answer the questions. x1 = 1.5 + 3.5x2 – 8.2x3 + 2.1x4 (a) Which variable is the response variable? A. x3 B. x1     C. x2 D. x4 (b) Which variables are the explanatory variables? (Select all that apply.) A. x4 B. x1 C. x3 D. x2 (c) Which number is the constant term? List the coefficients with their corresponding explanatory variables. constant ____________ x2 coefficient_________ x3 coefficient_________ x4 coefficient_________ (d) If x2 =...
There are two ways to write loops: (1) iterative, like the for-loops we're used to using,...
There are two ways to write loops: (1) iterative, like the for-loops we're used to using, and (2) recursive. Your prerequisite preparation for this course should have exposed you to both, although your working knowledge of recursive loops may not be as strong as that of iterative loops. Consider the following iterative function that prints an array of characters backward: #include <iostream> #include <cstring> // print an array backwards, where 'first' is the first index // of the array, and...
Lab 6- Linear Kinetics 1. Place a pencil or pen on a flat surface. Using your...
Lab 6- Linear Kinetics 1. Place a pencil or pen on a flat surface. Using your finger, push on the side of the pencil in the middle. What happens? Now, reset the pencil and push again, using the same amount of force, but this time about midway between the center and the end of the pencil What happens this time? Considering the two trials you just completed, what do you think is the "take home message" about the application of...