1 / 36

Introduction to Algorithms and Sorting: Efficiency and Running Time Calculation

Learn about algorithms, sorting techniques, running time calculation, divide and conquer approach, and solving recurrences in this introductory lecture.

lisahicks
Download Presentation

Introduction to Algorithms and Sorting: Efficiency and Running Time Calculation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unit 1.Sorting and Divide and Conquer

  2. Lecture 1 Introduction to Algorithm and Sorting

  3. What is anAlgorithm? • An algorithm is a computational procedure that takes some value, or a set of values, as input and produces some values, or a set of values, as output. • So, it is a sequence of computational steps that transform the input into the output. • Correction: sequence -> combination

  4. Sequential and Parallel • In sequential computation, an algorithm is a sequence of computational steps. • However, it is not true in parallel computation. • In this course, we study only algorithms in sequential computation.

  5. Algorithms for Sorting e.g., Insertion Sort, Merge Sort

  6. Efficiency • Running time from receiving the input to producing the output. Running time Insert Sort Merge Sort

  7. Insertion Sort

  8. key In the key outside of array.

  9. How to calculate running time? • Each “line” of pseudocode requires a constant time. (In RAM model)

  10. This loop runs n-1 times and each time runs at most 4+3(j-1) lines. This loop runs at most j-1 times and each time runs at most 3 lines.

  11. Remark on Running Time • Running time is a function of input size. • In Turing machine model, the input size of sorting is

  12. Divide and Conquer • Divide the problem into subproblems. • Conquer the subproblems by solving them recursively. • Combine the solutions to subproblems into the solution for original problem.

  13. Merge Sort

  14. Procedure

  15. 5,2,7,4,6,8,1,3 5,2,7,4 6,8,1,3 1,3 5,2 7,4 6,8 6 4 8 1 5 2 3 7 2,5 4,7 1,3 6,8 1,3,6,8 2,4,5,7 1,2,3,4,5,6,7,8

  16. Example

  17. Procedure

  18. Symmetry

  19. How to Solve Recurrences • Recursion-tree method. (give reasonable estimate) • Substitution method. (mathematical induction and find correct constant) • Master method. (already proved results)

  20. Recursion Tree

  21. Substitution Method • Guess the form of the solution (e.g., use recursive tree). • Use math induction to find the constants and also show the solution works.

  22. Conclusion

  23. Master Theorem

  24. Relationship

  25. Summary

  26. What we learnt in this lecture? • How to calculate running time. • How to solve recurrences. • Insertion sort and Merge sort. • Divide and conquer • Lecture Notes give you key points in each lecture. • You must read textbook after lectures in order to study well.

  27. We start to work from here.

  28. Where it comes from?

  29. Where comes from?

More Related