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
A(n _______________ is a pre-written formula that is built into excel
nevsk [136]
<span>A function is a pre-written formula that is built into excel.
There are many functions which are pre-written into excel.
Some examples are the SUM function which adds the values in a given range. The AVERAGE function takes the average of values in a given range, etc.
</span>
8 0
3 years ago
If your computer has a ________, someone else can gain access to it undetected.
irinina [24]
<span>If your computer has a rootkit, someone else can gain access to it undetected.
</span>The term rootkit denotes a set of software tools <span>typically malicious.
 The purpose of this software is to enable access to a computer or areas of its software that is not otherwise allowed.
</span><span>It is one of the most difficult types of malware to find and remove.</span>
3 0
3 years ago
Consider the following class definitions.
Serggg [28]

Answer:

The correct answer is option A

Explanation:

Solution

Recall that:

From the question stated,the following segments of code that should be used in replacing the /* missing code */ so that the value 20 will be printed is given below:

Android a = new Android(x);

a.setServoCount(y);

System.out.println(a.getServoCount());

The right option to be used here is A.

4 0
3 years ago
The first graphical browser application for using the web was netscape. <br> a. True <br> b. False
Mamont248 [21]
Hello <span>Jcece6710 
</span>

Question: <span>The first graphical browser application for using the web was netscape. True or False


Answer: True

Hope that helps
-Chris</span>
5 0
3 years ago
What tool is used to find and organize files on a mac
Margaret [11]

Answer:

the tool is literally called <u><em>The Finder.</em></u>

Explanation:

hope this helps

4 0
2 years ago
Other questions:
  • A. When executing System.out.println(a1), the toString() method in the Object class is invoked.
    14·1 answer
  • Write a program which:
    10·1 answer
  • Why did Hunter gatherers moved into the<br>America's?​
    8·1 answer
  • In which of the following situations will a macro make your work more efficient?
    9·1 answer
  • If an author is creating a reference list and wants the second and succeeding lines indented for a reference, they should select
    13·2 answers
  • All 24-point fonts take up the same amount of space on a slide. True False
    7·2 answers
  • Kathy created a video presentation of her company, which will be shown on a television show as an advertisement. Her company wan
    11·1 answer
  • Help me!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!​
    9·1 answer
  • Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contai
    14·1 answer
  • Pls say correct guyz pls pls pls
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!