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
what is the molarity of a solution prepared by dissolving 15.0g of sodium hydroxide in enough water to make a total of 225 ml of
Reptile [31]

Answer:

1.6666 g/mol = 1 \frac{2}{3} g/mol

Explanation:

Molar mass of NaOH= 23+16+1 =40g/mol

Mols in 15g = 15/40 mol

If this was dissolved in 225ml of water molarity of the solution is

\frac{15}{40} ÷ 225 x 1000 = 1.6666 g/mol = 1 \frac{2}{3} g/mol

5 0
3 years ago
What is the differnce between ''P4 and 4P''
34kurt
The number and letter are switched. This question needs more context to get a accurate answer.
5 0
3 years ago
Read 2 more answers
Which of the following is not a legal identifier?
Paraphin [41]

Answer:

321Go

Explanation:

The identifiers in C, C++, C#, Java and other programming languages are a combination of letters, numbers and the underscore symbol.  The laters versions of C and C++ allows you to use almost all Unicode characters. In Java, you can use also the dollar sign.

From that you have to be careful to follow these rules:

-Don't use keywords.

-Don't include white spaces.

-Don't use operators.

-Don't repeat identifiers.

-Don't start your identifier with a number.

-Don't use two consecutive underscores.

So app_234, happyTimesAhead, and cis22B are follo wing these rules but 321Go starts with a number.

4 0
3 years ago
A potential customer wants to find out how blockchain can benefit their company and why they should use Accenture’s Multi-party
grandymaker [24]

Answer:

maybe blockchain can help them in term of security

6 0
3 years ago
A user needs to use her laptop to give a presentation using a video projector. she called asking you how to switch the display t
Doss [256]

<span>I would advise her to press the fn keyboard key along with the function key with a monitor connected on it. She should ensure that she has the correct cable to connect the laptop to the projector. Most laptops require a manual switch by pressing these combination keys but for some, they will automatically detect the external display and switch to video output</span>

 

4 0
3 years ago
Other questions:
  • When you declare an array, _____________________ You always reserve memory for it in the same statement You might reserve memory
    9·1 answer
  • Which of the following are techniques that companies use to influence consumers demand for their goods and services
    7·2 answers
  • Load the titanic sample dataset from the Seaborn library into Python using a Pandas dataframe, and visualize the dataset. Create
    10·1 answer
  • Betrand Meyer developed the ______ programming language which is not type-safe because it violates the law of contravariance.
    9·1 answer
  • What is the difference between amplifier and the repeater?
    11·1 answer
  • Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integer
    12·2 answers
  • Write a program to generate a square wave with 80% duty cycle on bit P2.7 Microprocessor.​
    7·1 answer
  • You attempt to telnet to system 192.168.1.240. You receive the following message: "Connecting To 192.168.1.240...Could not open
    5·1 answer
  • How do you give brianliest
    13·1 answer
  • Can development and conservation of environment go hand-in-hand? Explain your point of view
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!