# Tough Apps: Pretty Good at Half the Speed

### Solutions

1. Why is the heuristic of doing the most expensive job first not optimal? Well, suppose that there are 5 jobs: 45 min, 40 min, 15 min, 11 min, 9 min and two machines. According to the heuristic, they should be scheduled this way m1: 45 min, 11 min m2: 40 min 15 min, 9 min But it would be better for m2 to do 11 and 9 when it's finished with the 40 minute job. Then all jobs would complete in 60 minutes rather than 64 minutes.

2. Order the items from longest to shortest. Put the trucks in a line. For each item, put it on the first truck on which it will fit. All trucks but one will be at least half full. Here is why: if any two trucks A and B are less than half full and A precedes B in line, then all the items on B would have gone on A or onto some other truck. So this is within a factor of two of the minimum possible number of trucks (possibly with one extra truck). In practice, it will usually be much better.

3. Go up and down the minimum spanning tree edges as shown in Figure 3. Since the minimum spanning tree costs no more than the optimal route, traversing every edge both ways cannot cost more than twice the optimal route. This can be improved by taking shortcuts as shown in Figure 4.

[Click image to view at full size]
Figure 3.

[Click image to view at full size]
Figure 4.

How to Solve It: Modern Heuristics by Z. Michaelewicz and D. Fogel, Springer Verlag, ISBN 3642061346.

Approximation Algorithms for NP-Hard Problems by Dorit Hochbaum, Brooks/Cole Pub Co; ISBN: 0534949681; 1st edition (July 26, 1996).

### More Insights

 To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.

# First C Compiler Now on Github

The earliest known C compiler by the legendary Dennis Ritchie has been published on the repository.

# HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

# Building Bare Metal ARM Systems with GNU

All you need to know to get up and running... and programming on ARM

# Amazon's Vogels Challenges IT: Rethink App Dev

Amazon Web Services CTO says promised land of cloud computing requires a new generation of applications that follow different principles.

# How to Select a PaaS Partner

Eventually, the vast majority of Web applications will run on a platform-as-a-service, or PaaS, vendor's infrastructure. To help sort out the options, we sent out a matrix with more than 70 decision points to a variety of PaaS providers.

More "Best of the Web" >>