27.10.2013 Views

Space/time tradeoffs; dynamic programming - Framingham State ...

Space/time tradeoffs; dynamic programming - Framingham State ...

Space/time tradeoffs; dynamic programming - Framingham State ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6. <strong>Space</strong>-<strong>time</strong> <strong>tradeoffs</strong> and <strong>dynamic</strong> <strong>programming</strong><br />

1. <strong>Space</strong>/<strong>time</strong> <strong>tradeoffs</strong><br />

• Time efficiency can some<strong>time</strong>s be<br />

gained by making use of storage space<br />

• Tables or larger tree nodes may be used<br />

to obtain improved running <strong>time</strong>s<br />

• Cases:<br />

– Sorting by counting<br />

– String matching<br />

– Hashing<br />

– B trees<br />

David Keil Analysis of Algorithms 1/11<br />

Sorting by counting<br />

• Suppose problem is to sort an array composed<br />

only of values in 1..m<br />

• Then a solution is to count the occurrences of<br />

each value in 1..m and store in a table T<br />

• Then write to the array T[1] 1’s,<br />

T[2] 2’s, etc.<br />

• RRunning i <strong>time</strong> ti O(n) O( )i is better b tt than th any comparison-based<br />

sort, provided that m ≤ O(n)<br />

• 2 5 1 2 8 7 5 1 5 ⇒ 1 1 2 2 5 5 7 8<br />

David Keil Analysis of Algorithms 1/11<br />

D. Keil Analysis of Algorithms 1/11<br />

3<br />

4

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!