1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Vikentia [17]
2 years ago
6

Write an algorithm (pseudo-code) that takes an unsorted list of n integers and outputs a sorted list of all duplicate integers.

There must be no duplicates in the output list, also the output list should be a sorted list. The algorithm must run in O(n) time. Show your analysis of the running time. Note: Assume that inputs are integer values from 0 to 255. (Hint: use the concept that being used in the separate chaining)
Computers and Technology
1 answer:
nexus9112 [7]2 years ago
7 0

Answer:

brainliest if it did help you

Explanation:

Given array : A[0...n-1]Now, create a count array Cnt[0...n-1]then, initialize Cnt to zero

for(i=0...n-1)

Cnt[i]=0 ---------O(n) time

Linearly traverse the list and increment the count of respected number in count array.

for(i=0...n-1)

Cnt[A[i]]++; ---------O(n) time

Check in the count array if duplicates exist.

for(i=0...n-1){

if(C[i]>1)

output (i); -----------O(n) time

}

analysis of the above algorithm:

Algorithm takes = O(1 + n + n + n)

                           = O(n)          

//java code

public class SortIntegers {

  public static void sort(int[] arr) {

    int min = arr[0];

    int max = arr[0];

    for (int i = 0; i < arr.length; ++i) {

      if (arr[i] > max) {

        max = arr[i];

      }

      if (arr[i] < min) {

        min = arr[i];

      }

    }

    int counts[] = new int[max - min + 1];

    for (int i = 0; i < arr.length; ++i) {

      counts[arr[i] - min]++;

    }

    for (int i = 0; i < counts.length; ++i) {

      if (counts[i] > 1) {

        System.out.print((i + min) + " ");

      }

    }

    

    System.out.println();

  }

  public static void main(String[] args) {

    sort(new int[] { 5, 4, 10, 2, 4, 10, 5, 3, 1 });

  }

}

You might be interested in
Directory services store information in a heirarchical structure. Which statements about Organizational Units (OUs) of a directo
NeX [460]

Answer:B

Explanation:

Specific files within an OUs or container are called object.

5 0
3 years ago
Nina is trying to learn more about how computers work. She has repeatedly read that the motherboard is the "brain” of the comput
Lady bird [3.3K]

Its

Processes the data on the computer .

5 0
2 years ago
Read 2 more answers
PLS HELP!! 50 Points! Will mark correct answer brainliest!!
Illusion [34]

Answer: C

Explanation:

That way she can have slides for her advance class and leave out slides that her normal class doesn’t need

5 0
3 years ago
Read 2 more answers
python Which data type is the best choice to store the number of wins associated with each basketball team in the NBA
Sveta_85 [38]

Answer:

integer

Explanation:

this data type must be  a number, but it will always be  a whole number, so boolean is not appropriate. This means that it will be integer data type

4 0
3 years ago
Read 2 more answers
A browser is an example of a<br>​
Inessa [10]

Answer:

User Interface, Website

3 0
2 years ago
Other questions:
  • Mia is attending a team meeting to discuss how to prevent accidents. One of her teammates suggests pushing all the desks against
    15·2 answers
  • PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where lastName = ?"; ps.setStrin
    5·1 answer
  • I'm looking for a new laptop for school. Which laptop would be the best. Right now I have a chromebook and it is broken. 
    12·2 answers
  • i need to also do a algorithm where if the total is a even number 10 points are added to the score and if the total is odd then
    11·1 answer
  • Assume that strikeCounter has already been declared to be a "pointer to int". Assume further that strikeCounter has been initial
    5·1 answer
  • Paths describe the location of folders and files on your computer. If you have saved your work to c:\documents, then your work h
    12·1 answer
  • How can you stretch or skew an object in paint
    12·2 answers
  • Is the most important characteristic of a hard drive.​
    7·2 answers
  • Computer science - algorithms - flowcharts
    11·1 answer
  • Which feature is not in ms PowerPoint​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!