LT 03 - Juan Lopes - Complexidade algoritmos

1,946 views
1,889 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,946
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

LT 03 - Juan Lopes - Complexidade algoritmos

  1. 1. Juan Lopesgithub.comtwitter.com /juanplopes
  2. 2. for(int i = 0; i < 30000; i++) s += “whatever”;
  3. 3. var builder = new StringBuilder();for(int i = 0; i < 30000; i++) builder.Append(“whatever”);s = builder.ToString();
  4. 4. var builder = new StringBuilder();builder.Append(“whatever”);builder.Append(“whatever”);s = builder.ToString();
  5. 5. n tempo 5 175 10 700 15 1575 20 2800 25 4375 30 6300 35 8575 50 17500 tempo 20000 15000 10000 tempo 5000 0 5 10 15 20 25 30 35 50
  6. 6. nfor(int i = 0; i < ; i++) s += “whatever”; O(n)?
  7. 7. for(int i = 0; i < ; i++) n s += “whatever”; i len(s) custo 0 0 L 1 L 2*L 2 2*L 3*L … n n*L (n+1)*L n²  n L Total: 2
  8. 8. nfor(int i = 0; i < ; i++) s += “whatever”; O(n²L)!
  9. 9. Dr. Donald E. Knuth“Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.”
  10. 10. VilfredoPareto 20% Alguma coisa Outra coisa80%

×