My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to prepare for, and for each subject, his score is determined only by the time he spend on learning. It's not surprising that Leo found out he actually spent zero time on preparing before. At least he knows when he can start learning all of these subjects. For each subject i, there is a start time, si when he can get all materials ready to start learning. And there is also a ending time ei for each subject, when his learning materials expire and he can't learn anymore. We know that si and ei are integers, and Leo can only dedicate to a single subject within each time phase. Universtiy of Southern Algorithmville (USA), a student's total grade is the minimum grade among all subjects. Leo wants you to help him find out the best outcome. Given N subjects and their time intervals (si; ei ), design an algorithm to find out the maximum time possible for the least prepared subject. Prove the correctness of your algorithm. (Hint: It's not enough to use the network ow algorithm alone to determine the answer.)

Answers

Answer 1
Answer:

Answer:

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.

If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that problem as the Greedy algorithms are in general more efficient than other techniques like Dynamic Programming. But Greedy algorithms cannot always be applied. For example, the Fractional Knapsack problem (See this) can be solved using Greedy, but 0-1 Knapsack cannot be solved using Greedy.

The following are some standard algorithms that are Greedy algorithms.

1) Kruskal’s Minimum Spanning Tree (MST): In Kruskal’s algorithm, we create an MST by picking edges one by one. The Greedy Choice is to pick the smallest weight edge that doesn’t cause a cycle in the MST constructed so far.

2) Prim’s Minimum Spanning Tree: In Prim’s algorithm also, we create an MST by picking edges one by one. We maintain two sets: a set of the vertices already included in MST and the set of the vertices not yet included. The Greedy Choice is to pick the smallest weight edge that connects the two sets.

3) Dijkstra’s Shortest Path: Dijkstra’s algorithm is very similar to Prim’s algorithm. The shortest-path tree is built up, edge by edge. We maintain two sets: a set of the vertices already included in the tree and the set of the vertices not yet included. The Greedy Choice is to pick the edge that connects the two sets and is on the smallest weight path from source to the set that contains not yet included vertices.

4) Huffman Coding: Huffman Coding is a loss-less compression technique. It assigns variable-length bit codes to different characters. The Greedy Choice is to assign the least bit length code to the most frequent character. The greedy algorithms are sometimes also used to get an approximation for Hard optimization problems. For example, the Traveling Salesman Problem is an NP-Hard problem. A Greedy choice for this problem is to pick the nearest unvisited city from the current city at every step. These solutions don’t always produce the best optimal solution but can be used to get an approximately optimal solution.


Related Questions

Implement a java program to find the smallest distance between two neighbouring numbers in an array.
When law enforcement becomes involved, the need may arise to freeze systems as part of the evidence. There is also the likelihood that the incident will become known publicly. Do you think these issues play a significant part in the decision to involve law enforcement? Why or why not? Can you name some situations in which you believe that large organizations have decided not to involve law enforcement?
When people receive benefits just because they belong to a particular identity group, this is called
A _____, or spider, is a search engine program that automatically searches the web to find new websites and update information about old websites. ​a. ​crabb. web ​robotc. ​databased. ​runner
If you pay a subscription fee to use an application via the internet rather than purchasing the software outright, the app is called a/an -- application.

in C, Print the two strings, firstString and secondString, in alphabetical order. Assume the strings are lowercase. End with newline. Sample output: capes rabbits

Answers

Answer:

View Images.

Image1  = the code

Image2 = testcase 1

Image3 = testcase 2

Image4 = testcase 3

create a Java program that prompt the user to enter a number of hours, wages, over time factor, then your program should calculate the employee total wages. Make sure your program can calculate the over time and regular wages if number of hours are great than 40 hours. Use 1.5 for over time factor. Make sure your Java code has comments showing declarations and description of your variables.

Answers

Answer:

The program to the given question as follows:

Program:

import java.util.*; //import package for user input.

public class Main //defining class Main

{

public static void main(String[] as) //defining main method

{

final double over_time_factor = 1.5; //define final variable

double number_Of_hours,wages,total_Wages=0; //defining variables  

System.out.println("Enter hours and wages rate:"); //print message

Scanner obc = new Scanner(System.in); //creating Scanner class object for user input

number_Of_hours = obc.nextDouble(); //taking input

wages = obc.nextDouble(); //taking input

if(number_Of_hours>40) //check condition if number_Of_hours greter then 40

{

total_Wages=40*wages+(number_Of_hours-40)*wages*over_time_factor; //calculate value

}

else //else part

{

total_Wages = number_Of_hours*wages; //calculate total_Wages

}

System.out.println("Total Wages: $"+total_Wages); //print value

}

}

Output:

Enter hours and wages rate:

12

3

Total Wages: $36.0

Explanation:

In the above java program, the package is first imported into the user input and then the class is defined and inside this, the main method is defined, that defines a double type final variable "over_time_factor" is defined that holds a value "1.5", Then double type variable is defined that are " number_Of_hours, wages, and total_Wages", in which first two variables are used for taking input from the user and the third variable is used to calculate their values. After taken input from the user, the conditional statement is used that can be defined as follows:

  • The if block, checks the variable "number_Of_hours" value is greater than 40 it will calculate over_time_factor value that is held by total_Wages variable.  
  • In else block, it will multiply the user input value that is store in total_Wages variable.  
  • At the end of the conditional statement, the print function is used that prints total_Wages variable value.  

What does I/O mean in computing​

Answers

Explanation:

I/O (input/output)" describes any operation, program, or device that transfers data to or from a computer

How does an Index Organized table differ from a standard table and a typical index?

Answers

The thing is that an Index organized table, also known as IOT, is a type of table that stores data in a B tree index structure, which is used by Oracle. Normal relational tables, called heap-organized tables, store rows in any order and  primary key indexes store only the columns included in its definition.

In an e-credit card transaction the clearinghouse plays the following role:A. validates and verifies the sellers payment information

B. initiates the transfer of money

C. transfers funds between the sellers bank and the buyers bank

D. all of the above

Answers

Answer:

validates and verifies the seller's payment information- A.

Answer:

Hi Samantha, i have a work with you.

Make a program that asks for input from the user, apply eval to this input, and print out the type of the resulting object and its value. Test the program by providing five types of input: an integer, a real number, a complex number, a list, and a tuple.

Answers

Answer:

x = input("Input a number ")

print(eval("x"))

print ("Type is:",type(x))

#Taking an float input

y = input("Input a number ")

print(eval("y"))

print ("Type is:",type(y))

#Taking an complex input

z = complex(input("Input a number "))

print(eval("z"))

print ("Type is:",type(z))

#Taking an List input

L_num = raw_input().split(",")

print(eval("L_num"))

print ("Type is:",type(L_num))

#Taking an tuple input.

T_num = raw_input().split(",")

print(eval("T_num"))

print ("Type is:",type(T_num))

Explanation: