Download presentation
Presentation is loading. Please wait.
Published byHortense Shields Modified over 9 years ago
1
Unit 1. Sorting and Divide and Conquer
2
Lecture 1 Introduction to Algorithm and Sorting
3
What is an Algorithm? 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 Insertion Sort, Merge Sort e.g.,
6
Efficiency Running time from receiving the input to producing the output. Insert Sort Merge Sort Running time
9
Insertion Sort
11
key In the key outside of array.
12
How to calculate running time? Each “line” of pseudocode requires a constant time. (In RAM model)
13
This loop runs at most j-1 times and each time runs at most 3 lines. This loop runs n-1 times and each time runs at most 4+3(j-1) lines.
14
Remark on Running Time Running time is a function of input size. In Turing machine model, the input size of sorting is
15
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.
16
Merge Sort
17
Procedure
20
Example
22
Procedure
23
Symmetry
24
How to Solve Recurrences Substitution method. Recursion-tree method. Master method.
25
Substitution Method Guess the form of the solution. Use math induction to find the constants and also show the solution works.
29
Remark
30
Recursion Tree
31
Master Theorem
32
Relationship
33
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.