15 112 fundamentals of programming
play

15-112 Fundamentals of Programming Week 3 - Lecture 2: Intro to - PowerPoint PPT Presentation

15-112 Fundamentals of Programming Week 3 - Lecture 2: Intro to efficiency + Searching and sorting + Big O June 1, 2016 Principles of good programming Correctness Your program does what it is supposed to. Handles all cases (e.g. invalid user


  1. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Find the minimum element. Put it on the left. Repeat process on the remaining n-1 elements.

  2. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort

  3. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 4

  4. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 4

  5. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 4

  6. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 2

  7. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 2

  8. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 2

  9. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 2

  10. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 2

  11. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Current min: 0

  12. Selection Sort: Algorithm Sort a given list of integers (from small to large). 4 8 2 7 99 5 0 Selection Sort Swap current min with first element of the array

  13. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Swap current min with first element of the array

  14. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort

  15. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 8

  16. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 8

  17. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 2

  18. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 2

  19. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 2

  20. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 2

  21. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Current min: 2

  22. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 8 2 7 99 5 4 Selection Sort Swap current min with first element of unsorted part

  23. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Swap current min with first element of unsorted part

  24. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort

  25. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 8

  26. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 8

  27. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 7

  28. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 7

  29. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 7

  30. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 5

  31. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 5

  32. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Current min: 4

  33. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 8 7 99 5 4 Selection Sort Swap current min with first element of unsorted part

  34. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Swap current min with first element of unsorted part

  35. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort

  36. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Current min: 7

  37. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Current min: 7

  38. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Current min: 7

  39. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Current min: 5

  40. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Current min: 5

  41. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 7 99 5 8 Selection Sort Swap current min with first element of unsorted part

  42. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Swap current min with first element of unsorted part

  43. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort

  44. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Current min: 99

  45. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Current min: 99

  46. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Current min: 7

  47. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Current min: 7

  48. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 99 7 8 Selection Sort Swap current min with first element of unsorted part

  49. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort Swap current min with first element of unsorted part

  50. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort

  51. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort Current min: 99

  52. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort Current min: 99

  53. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort Current min: 8

  54. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 99 8 Selection Sort Swap current min with first element of unsorted part

  55. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 8 99 Selection Sort Swap current min with first element of unsorted part

  56. Selection Sort: Algorithm Sort a given list of integers (from small to large). 0 2 4 5 7 8 99 Selection Sort Done!

  57. Selection Sort: Running Time Sort a given list of integers (from small to large). 0 2 4 5 7 8 99 Selection Sort How many steps does this take (in the worst case)? = N 2 2 + N ∼ N + ( N − 1) + ( N − 2) + · · · + 1 2 (As N increases, small terms lose significance.) Running time is . O ( N 2 )

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend