Skip to main content
Top

2014 | OriginalPaper | Chapter

7. Greed Is Good? Prove It!

Author : Magnus Lie Hetland

Published in: Python Algorithms

Publisher: Apress

Activate our intelligent search to find suitable subject content or patents.

search-config
loading …

Abstract

It’s not a question of enough, pal.

Dont have a licence yet? Then find out more about our products and how to get one now:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Footnotes
1
No, it’s not to run away and buy comic books.
 
2
The idea for this version of the problem comes from Michael Soltys (see references in Chapter 4).
 
3
To be on the safe side, just let me emphasize that this greedy solution would not work in general, with an arbitrary set of weights. The distinct powers of two are key here.
 
4
If we view each object individually, this is often called 0-1 knapsack because we can take 0 or 1 of each object.
 
5
Not only is it unimportant whether zero means left or right, it is also unimportant which subtrees are on the left and which are on the right. Shuffling them won’t matter to the optimality of the solution.
 
6
If a future version of the heapq library lets you use a key function, such as in list.sort, you’d no longer need this tuple wrapping at all, of course.
 
7
They might also have equal weights/frequencies; that doesn’t affect the argument.
 
8
By the way, did you know that the ZIP code of Huffman, Texas, is 77336?
 
9
You can, in fact, combine Borůvka’s algorithm with Prim’s to get a faster algorithm.
 
10
Do you see why the result cannot contain any cycles, as long as we assume positive edge weights?
 
11
Going back and forth between this representation and one where you have edges both ways isn’t really hard, but I’ll leave the details as an exercise for the reader.
 
12
We’re sorting m edges, but we also know that m is O(n 2), and (because the graph is connected), m is Ω(n). Because Θ(lg n 2) = Θ(2.lg n) = Θ(lg n), we get the result.
 
13
Actually, the difference is deceptive. Prim’s algorithm is based on traversal and heaps—concepts we’ve already dealt with—while Kruskal’s algorithm introduced a new disjoint set mechanism. In other words, the difference in simplicity is mostly a matter of perspective and abstraction.
 
14
As I mentioned when discussing Kruskal’s algorithm, adding and removing such redundant reverse edges is quite easy, if you need to do so.
 
15
Because the intervals don’t overlap, sorting by starting and finishing times is equivalent.
 
16
Versions of this problem can be found in Soltys’ book (see “References” in Chapter 4) and that of Cormen et al. (see “References” in Chapter 1). My proof closely follows Soltys’s, while Cormen et al. choose to prove that the problem forms a matroid, which means that a greedy algorithm will work on it.
 
Metadata
Title
Greed Is Good? Prove It!
Author
Magnus Lie Hetland
Copyright Year
2014
Publisher
Apress
DOI
https://doi.org/10.1007/978-1-4842-0055-1_7

Premium Partner