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
astraxan [27]
3 years ago
10

Assume you have a sorting algorithm that you can use as a black box. Use the sorting algorithm to sort the input list. Now write

an algorithm to count the number of duplicates again. Analyze the time complexity of your algorithm in the worst-case (ignore the time complexity of sorting). Could you improve the worst-case time complexity of your algorithm compared to the previous question
Computers and Technology
1 answer:
Ber [7]3 years ago
7 0

Answer:

Algorithm explained below

Explanation:

Algorithm to check duplicate when list of element is sorted:

CheckDuplicate( Sorted list )

    initialize count = 0

    Repeat untill we reach on end of list :

            if next is not end of list and current element is equal to next element

                    count = count+1

                    increase the pointer to next untill a different element is found

end CheckDuplicate

Worst Case Time Complexity will be O(n). Because there is only one iteration over the list will be performed.

Yes We have improved the worst case time complexity compared to previous question.

Actually after applying sorting all the similar element to will be next to each other.Then we will start iterating one by one from one side and check which is similar to next.If a different element will be find then we will check whether it's next is similar to it or not.

eg. 1 1 1 2 2 2 4 4 4 we can check duplicate in one iteration.

You might be interested in
Which of the following best describes compounds.
Lemur [1.5K]
A. They can only be separate chemically
4 0
3 years ago
_____ is responsible for packet forwarding. a. Transmission Control Protocol b. User Datagram Protocol c. Extensible Authenticat
Mazyrski [523]

Answer:

d. Internet Protocol

Explanation:

Internet Protocols suite  are used to transport packets from the host network across other networks. This task is usually performed by optimizing the size of each available packet, which are then forwarded through the internet protocol (IP) address.

Therefore, Internet Protocol is responsible for packet forwarding.

6 0
3 years ago
What is wrong with this?
nalin [4]

Answer:

missing bracket

Explanation:

Notice that the "body" block has an opening bracket, but no closing bracket. Instead, the "p" block starts before the "body" block has closed. The "body" block is missing a bracket.

3 0
2 years ago
Explain why a network interface that has promiscuous mode turned off would prevent a sniffer running on the host from capturing
Sidana [21]

Answer:

In-network promiscuous mode is off then it stops or not allows the network to access or read the network packets.

Explanation:

In  promiscuous mode is enabled the allows the network  to  access or read network packet.  In this mode sometimes allows the sniffer to access the host and capture network packets. It is dangerous.

In LAN promiscuous mode can ready the network packets by network adapters when data transmitted in the network traffic.

promiscuous mode is normally supported by network adapters as an input and output device by the /operating systems.

3 0
3 years ago
Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee
AlexFokin [52]

Answer:

import java.util.Scanner;

public class Payroll {

   //set variable field

   private String name;

   private int idNumber;

   private double hourlyRate;

   private int hoursWorked;

   private double grossPay;

   //methods to get values of private class variables

   public String getName()

    {

        return name;

    }

   public int getIdNumber()

   {

      return idNumber;

   }

   public double getHourlyRate()

   {

       return hourlyRate;

   }

   public int getHoursWorked()

   {

       return hoursWorked;

   }

   public double getGrossPay()

   {

      return hoursWorked * hourlyRate;

   }

   //methods to initialize or change the private class values.

   public void setName( String nameGiven)

   {

       name = nameGiven;

   }

   public void setIdNumber(int idNumberGiven)

   {

       idNumber = idNumberGiven;

   }

   public void setHourlyRate(double rateGiven)

   {

       hourlyRate = rateGiven;

   }

   public void setHoursWorked(int hoursGiven)

   {

      hoursWorked = hoursGiven;

   }

   //Constructors

   public Payroll(String nameGiven, int idNumberGiven, double rateGiven, int hoursGiven)

   {

       name = nameGiven;

       idNumber = idNumberGiven;

       hourlyRate = rateGiven;

        hoursWorked = hoursGiven;

   }

 

   public static void main(String[] args)

   {

       double userGrossPay;

       String userEmplName;

       int userIdNum;

       double userRate;

       int userHours;

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter employee's name:");

       userEmplName = scanner.nextLine();

      System.out.print("Enter employee's ID number:");

       userIdNum = scanner.nextInt();

       System.out.print("Enter hourly rate:");

       userRate = scanner.nextDouble();

       System.out.print("Enter number of hours worked:");

       userHours = scanner.nextInt();

        Payroll payroll1 = new Payroll(userEmplName, userIdNum, userRate, userHours);

 

      payroll1.setName(userEmplName);

       payroll1.setIdNumber(userIdNum);

       payroll1.setHourlyRate(userRate);

       payroll1.setHoursWorked(userHours);

 

       System.out.printf(userEmplName + ", employee number " + userIdNum + ", made $%.2f in gross pay.\n", payroll1.getGrossPay());

}

}

Explanation:

The class "Payroll" is used to hold data of employees to be paid. the main function creates an instance of the class "payroll1", sets the name, id-number, hourly rate, and hours worked by the employee, then prints on screen the details of the payroll1 object.

8 0
2 years ago
Other questions:
  • Which is a feature of a strong thesis statement?
    8·1 answer
  • What is daemontools pakage in qmail?
    14·1 answer
  • All of the following are search operators EXCEPT _______________. a. AND b. OR c. NOT d. GET
    12·2 answers
  • Which of the following statements is true about scalability? Choose 3 options.
    9·2 answers
  • Swiping up with three fingers on mac os x launches what?
    8·1 answer
  • Which of the following kinds of software is a sophisticated type of application software that assists a professional user in cre
    5·1 answer
  • Convert 15 from decimal to binary. Show your work.
    14·1 answer
  • Complete the program segment below to write the numbers 1 through 50 to the numbers.txt file.
    5·1 answer
  • Allows a user to control the<br>volume of the computer​
    8·1 answer
  • A keyboard, mouse, and microphone are examples of ________.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!