Find the fastest algorithm

Find the fastest algorithm

Postby Guest » Wed Nov 22, 2023 4:03 pm

**Problem:** A metal worker can cut a metal rod of length x into two smaller pieces in [tex]x[/tex] minutes. One day, a customer comes to the metalsmith's shop with an order for n metal bars. The client specifies the length [tex]z_k[/tex]of each bar k. The metalworker must cut a metal rod of total length to fulfill the customer's order. **Question:** What is the fastest algorithm for the metallurgist to cut the metal bars and fulfill the customer's order? Prove that your algorithm is the fastest.
Guest
 

Re: Find the fastest algorithm

Postby Guest » Thu Nov 23, 2023 2:08 am

Sort the lengths of the metal bars ([tex]z_k[/tex]) in decreasing order.

Initialize a list of remaining lengths starting with a single rod of length 0.

For each metal bar length in decreasing order:
Try to fit the current bar length into the remaining lengths:

Start from the beginning of the list.
If a segment is found where the bar length fits, cut it from that segment.
If no suitable segment is found, add a new segment of the current bar length.

The number of cuts made during this process is the minimum number required to fulfill the customer's order.
Guest
 


Return to Java



Who is online

Users browsing this forum: No registered users and 1 guest

cron