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)

Answers

Answer 1

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 });

  }

}


Related Questions

Taran is concerned with the security of his macros in a database. Which security option could he use to provide protection?

digital signatures
hide database objects
start-up options
secure VBA code

Answers

Answer:security VBA code

Explanation:

Two character strings may have many common substrings. Substrings are required to be contiguous in the original string. For example, photograph and tomography have several common substrings of length one (i.e., single letters), and common substrings ph, to, and ograph as well as all the substrings of ograph. The maximum common substring length is 6. Let X = X122 . Im and Y = yıy2 - - • Yn be two character strings. Using dynamic programming, design an algorithm to find the maximum common substring length for X and Y using dynamic programming. Please follow the general steps for designing a dynamic programming solution as in Q1 (other than the actual programming part).

Answers

Answer:

Explanation:

The following function is written in Java. It takes two strings as parameters and calculates the longest substring between both of them and returns that substring length.

import java.util.*;

class Test

{

   public static void main(String[] args)

   {

       String X = "photograph";

       String Y = "tomography";

       System.out.println(X + '\n' + Y);

       System.out.println("Longest common substring length: " + longestSub(X, Y));

   }

   static int longestSub(String X, String Y)

   {

       char[] word1 = X.toCharArray();

       char[] word2 = Y.toCharArray();

       

       int length1 = X.length();

       int length2 = Y.length();

       int substringArray[][] = new int[length1 + 1][length2 + 1];

       int longestSubstringLength = 0;

       

       for (int i = 0; i <= length1; i++)

       {

           for (int j = 0; j <= length2; j++)

           {

               if (i == 0 || j == 0)

                   substringArray[i][j] = 0;

               else if (word1[i - 1] == word2[j - 1])

               {

                   substringArray[i][j]

                           = substringArray[i - 1][j - 1] + 1;

                   longestSubstringLength = Integer.max(longestSubstringLength,

                           substringArray[i][j]);

               }

               else

                   substringArray[i][j] = 0;

           }

       }

       return longestSubstringLength;

   }

}

The variable strFirst's scope is _____.

Answers

pretty sure it’s d, hope this helps

Answer:

- the usernameMaker function

Explanation:

When you look at the code, you can see it's located alongside the usernameMaker. It it only utilized then, therefore being it's scope. For reassurance, it's also correct on Edge.

I hope this helped!

Good luck <3

Explain the five generations of computer

Answers

Answer:

1 First Generation

The period of first generation: 1946-1959. Vacuum tube based.

2 Second Generation

The period of second generation: 1959-1965. Transistor based.

3 Third Generation

The period of third generation: 1965-1971. Integrated Circuit based.

4 Fourth Generation

The period of fourth generation: 1971-1980. VLSI microprocessor based.

5 Fifth Generation

The period of fifth generation: 1980-onwards. ULSI microprocessor based.

The phrase "generation" refers to a shift in the technology that a computer is/was using. The term "generation" was initially used to describe different hardware advancements. These days, a computer system's generation involves both hardware and software.

Who invented the 5th generation of computers?

The Japan Ministry of International Trade and Industry (MITI) launched the Fifth Generation Computer Systems (FGCS) initiative in 1982 with the goal of developing computers that use massively parallel computing and logic programming.

The generation of computers is determined by when significant technological advancements, such as the use of vacuum tubes, transistors, and microprocessors, take place inside the computer. There will be five computer generations between now and 2020, with the first one starting around 1940.

Earlier models of computers (1940-1956)Computers of the Second Generation (1956-1963)Computers of the Third Generation (1964-1971)Computers of the fourth generation (1971-Present)Computers of the fifth generation

Learn more about generations of computers here:

https://brainly.com/question/9354047

#SPJ2

Other Questions
9)Find the average rate of change for f(x)= x to the second power+ 7x+10 from x= 0 to x= 2. If i have 22 more questions to go out of 42 what question am i on? 100 points Choose the different ways that a graph can be misleading.The y-axis starts at zero and uses consistent intervals.Different bar heights are used on the same graph.The y-axis doesn't start at zero.The intervals on the y-axis are too large.Different bar widths are used on the same graph.The y-axis starts at zero but has different intervals. I need help with this Where did fighting take place in the Far West? PLEASE HELP2. Tiene Anita mis anteojos de sol?S,tiene.O losO lasO lalo anyone know the answer to this????? Does a triangle with these side lengths exist?28, 41, 13 The table shows home runs for 2 baseball players over 5 games. Which statement is true? Input a list of positive numbers, terminated by 0, into an array Numbers[]. Then display the array and the largest and smallest number in it. How many solutions does the equation 2 + 6(2 - 4) = 3x 18 + 3x have?A infinite B 0 C 1 D 2 What is the total resistance of the circuit shown below? WILL MAKE BRAINLIEST!!find the slope of each line 4.2+7/20=420/100+BLANK/100 PLEASE HURRY Why did the Anti-Federalists urge the addition of a bill of rights to the Constitution?O to check the power of state governmentsto lower the costs of governmentO to protect individual libertiesO to abolish slavery The value of which of these expressions is closest to e ? Find the median, mean, and range.68, 82, 43, 39, 83 How does the author MAINLY explain what segregation is?(A) by giving examples of what happened to Freedom Ride buses(B) by describing different court decisions about bus seating(C) by describing who rode on the Freedom Ride buses(D) by giving examples of separate facilities for whites and blacks Genetic mutation which can lead to diversity between organisms can be caused by What combination of transformations is shown below?