Class SomePlumbers
java.lang.Object
topics.greedy.SomePlumbers
GREEDY ALGORITHM PROBLEM: SOME DILIGENT PLUMBERS
It has an optimal solution
- Author:
- vicegd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassignTasksToPlumbersBADWAY(int[][] plumbers, int[] tasks) Assigns tasks to plumbersvoidassignTasksToPlumbersBESTWAY(int[][] plumbers, int[] tasks) Assigns tasks to the less busy plumberintgetTotalTimeOfWait(int[][] plumbers) Calculates the total waiting time of customersvoidorderInWhichTasksAreHandledBADWAY(int[] tasks, int[] times) Sorts the tasks in a random order.voidorderInWhichTasksAreHandledBESTWAY(int[] tasks, int[] times) Sorts the tasks from smallest to biggest O(n) + O(nlogn) - O(nlogn)
-
Constructor Details
-
SomePlumbers
public SomePlumbers()
-
-
Method Details
-
getTotalTimeOfWait
public int getTotalTimeOfWait(int[][] plumbers) Calculates the total waiting time of customers- Parameters:
plumbers- Information about the tasks that any plumber performs- Returns:
- Total waiting time
-
orderInWhichTasksAreHandledBADWAY
public void orderInWhichTasksAreHandledBADWAY(int[] tasks, int[] times) Sorts the tasks in a random order. In fact, it does not change anything O(n)- Parameters:
tasks- Final order in which the different tasks are going to be donetimes- Times for the different tasks to be done
-
assignTasksToPlumbersBADWAY
public void assignTasksToPlumbersBADWAY(int[][] plumbers, int[] tasks) Assigns tasks to plumbers- Parameters:
plumbers- To save the tasks that any of the plumbers are going to performtasks- Final order in which the different tasks are going to be done
-
orderInWhichTasksAreHandledBESTWAY
public void orderInWhichTasksAreHandledBESTWAY(int[] tasks, int[] times) Sorts the tasks from smallest to biggest O(n) + O(nlogn) - O(nlogn)- Parameters:
tasks- Final order in which the different tasks are going to be donetimes- Times for the different tasks to be done
-
assignTasksToPlumbersBESTWAY
public void assignTasksToPlumbersBESTWAY(int[][] plumbers, int[] tasks) Assigns tasks to the less busy plumber- Parameters:
plumbers- To save the tasks that any of the plumbers are going to performtasks- Final order in which the different tasks are going to be done
-