1 / 21

Data Structures

Data Structures. Instructor: Dr. Leah Epstein TA: Miri Priesler (This lecture)Text book: pages 1-15, 22-30, 54-64. General. Leah Epstein email: lea@idc.ac.il tel: 381 Reception hour: before/after class Text book: Cormen, Leiserson, Rivest Introduction to Algorithms Final grade:

Télécharger la présentation

Data Structures

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. Data Structures Instructor: Dr. Leah Epstein TA: Miri Priesler (This lecture)Text book: pages 1-15, 22-30, 54-64

  2. General • Leah Epstein • email: lea@idc.ac.il • tel: 381 • Reception hour: before/after class • Text book: • Cormen, Leiserson, Rivest Introduction to Algorithms • Final grade: • fg- final exam, mg- midterm exam, hw-homework

  3. Why “Intro” is not enough • Because: • not every problem has a computational solution • or at least no practically efficient solution • devising efficient algorithm is difficult • evaluating the efficiency of a computational solution • well known techniques that may improve efficiency • proving the correctness of the solution

  4. Why Study D.S ? • Because the efficiency of a computing solution often depends on the way the data is organized • for example searching in a pile of cards • unsorted • sorted ID 3459696 name- Hober Huchem Address: etc

  5. Unsorted For i=1 to n do if pile[i]=k then return true return false • Takes approximately 3n steps in the worst case

  6. Sorted (Binary Search) l=1, u=n while l<=u do m=(l+n)/2 if pile[m]=k then return true if pile[m]<k then l=m+1 else u=m-1 return false Takes approximately 6log2n steps

  7. Sorting • Specification • input- a sequence of numbers • output- a permutation of the sequence such that • Sorting by insertion • start with an empty pile and insert each number in its correct position

  8. Sorting • Insertion-Sort(A) for j=2 to length(A) do key = A[j] i = j-1 while i > 0 and A[i] > key do A[i+1]=A[i] i=i-1 A[i+1]=key

  9. Analysis • Algorithm analysis- trying to predict the resources the algorithm requires as a function of the input size • Resources- • time, space (memory), etc.. • Input size • number of items in the input, number of bits in a number.

  10. Running time for j=2 to length(A) do key = A[j] i = j-1 while i > 0 and A[i] > key do A[i+1]=A[i] i=i-1 A[i+1]=key

  11. Running Time • Best case (when?) • Worst case (when?) • Average case?

  12. Order of Growth • We are interested only in the order of growth of the running time (space) • best case • worst case • Most of the time, we are interested only in worst case analysis • and sometimes in average case analysis

  13. Order of Growth • Definition- asymptotic tight bound • Convention • usually stands for Example

  14. Order of Growth • Definition - asymptotic upper bound • Definition- asymptotic lower bound • Claim-

  15. Examples also

  16. Merge Sort • The idea: divide the array into 2 equal parts, sort each part separately and merge the two sorted parts into one array mergeSort(A, p, r) if (p<r) then q = (p+r)/2 mergeSort(A,p,q) mergeSort(A,q+1,r) merge(A, p, q, r)

  17. Time analysis • The time required for mergeSort: • How to solve recurrence equations? • Iterate and see...

  18. Recursion trees

  19. Master Theorem • Provides a cookbook for solving recurrences of the form: where and are constants • if for some constant then • if then • if for some constant and if for some constant and for sufficiently large then

  20. Using Master Theorem

More Related