1 / 11

ITEC 2620M Introduction to Data Structures

ITEC 2620M Introduction to Data Structures. Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: DB 3049. Sorting. Key Points. Recursive sorting algorithms Achieving leverage Quicksort Mergesort. Review.

ericdbrown
Download Presentation

ITEC 2620M Introduction to 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. ITEC 2620MIntroduction to Data Structures Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: DB 3049

  2. Sorting

  3. Key Points • Recursive sorting algorithms • Achieving leverage • Quicksort • Mergesort

  4. Review • Previous sorting algorithms were O(n2) on average. • What if we could get O(nlogn) • Where have we seen O(logn) before? • Binary search • How did binary search work? • first query explores 1 element • second query explores 2 elements • third query explores 4 elements

  5. Recursive Sorting • Split the elements into smaller sub-groups • Partially sort each sub-group • Trust recursion to put everything back together

  6. Quicksort Algorithm • Pick an element • partially sort them • move all larger elements on one side, and smaller elements on the other • have to look at all elements to get one element in position • Pick one element in each sub-division (2) • partially sort them • move all elements as before (twice) • have to look at half of the elements to get each new element into position • Pick one element in each sub-division (4) • partially sort them • move all elements as before (four times)

  7. Quicksort Algorithm (Cont’d) • Each sub-division is being sorted by the same algorithm as the overall set • recursion • base case is 0 or 1 elements – already sorted • Work to sort each element is cut in half each level down • Get twice as much done for our effort • How many times can we cut something in half? • O(logn) • Pseudocode

  8. Mergesort Algorithm • Divide what you have to do into two halves • sort each half • merge the two halves into a fully sorted set • Each half will be sorted by the same algorithm as the overall set • recursion • base case is 0 or 1 elements – already sorted • Each upward merge sorts twice as much • How many times can we cut something in half? • O(logn) • Pseudocode

  9. Binary Search Trees

  10. Key Points • Inserting and Deleting into Linked Structures • Linked lists • Basic BST operations • Deleting from BSTs

  11. Codes • Inserting into a Linked List • Deleting from a Linked List • Inserting into a BST • insertion always happens at the bottom of the tree • new node will be a leaf node • Deleting from a BST – target node has less than two children • Deleting from a BST – target node has two children • Deleting from a BST – a better way

More Related