Unit 1 sorting and divide and conquer
Download
Sponsored Links
This presentation is the property of its rightful owner.
1 / 33

Unit 1. Sorting and Divide and Conquer PowerPoint PPT Presentation


  • 83 Views
  • Uploaded on
  • Presentation posted in: General

Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting. 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 .

Download Presentation

Unit 1. Sorting and Divide and Conquer

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Unit 1 sorting and divide and conquer

Unit 1.Sorting and Divide and Conquer


Lecture 1 introduction to algorithm and sorting

Lecture 1 Introduction to Algorithm and Sorting


What is an algorithm

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


Sequential and parallel

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.


Algorithms for sorting

Algorithms for Sorting

e.g.,

Insertion Sort, Merge Sort


Efficiency

Efficiency

  • Running time from receiving the input to producing the output.

Running time

Insert Sort

Merge Sort


Unit 1 sorting and divide and conquer

Insertion Sort


Unit 1 sorting and divide and conquer

key

In the key outside of array.


How to calculate running time

How to calculate running time?

  • Each “line” of pseudocode requires a constant time. (In RAM model)


Unit 1 sorting and divide and conquer

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.


Remark on running time

Remark on Running Time

  • Running time is a function of input size.

  • In Turing machine model, the input size of sorting is


Divide and conquer

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.


Merge sort

Merge Sort


Procedure

Procedure


Unit 1 sorting and divide and conquer

Example


Procedure1

Procedure


Unit 1 sorting and divide and conquer

Symmetry


How to solve recurrences

How to Solve Recurrences

  • Substitution method.

  • Recursion-tree method.

  • Master method.


Substitution method

Substitution Method

  • Guess the form of the solution.

  • Use math induction to find the constants and also show the solution works.


Remark

Remark


Recursion tree

Recursion Tree


Master theorem

Master Theorem


Unit 1 sorting and divide and conquer

Relationship


What we learnt in this lecture

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.


  • Login