1 / 21

Searching & Sorting

Searching & Sorting. Linear Search. I'm thinking of a number between 1 and 100 You try to guess it I'll give too low/too high hints. Linear Search. I'm thinking of a number between 1 and 100 You try to guess it I'll give too low/too high hints Method #1 – Linear Search 1, 2, 3….

neron
Download Presentation

Searching & Sorting

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. Searching & Sorting

  2. Linear Search • I'm thinking of a number between 1 and 100 • You try to guess it • I'll give too low/too high hints

  3. Linear Search • I'm thinking of a number between 1 and 100 • You try to guess it • I'll give too low/too high hints • Method #1 – Linear Search • 1, 2, 3….

  4. Binary Search • Method #2 – Binary Search • Pick middle of remaining search space • Too high? Eliminate middle and above • Too low? Eliminate middle and below

  5. Algorithm

  6. Binary Search Searching for 5:

  7. Binary Search Searching for 5:

  8. Binary Search Searching for 5:

  9. Binary Search Searching for 5:

  10. Binary Search Searching for 5:

  11. Binary Search Searching for 5:

  12. Binary Search Searching for 6:

  13. Binary Search Searching for 6:

  14. Binary Search Searching for 6:

  15. Binary Search Searching for 6:

  16. Binary Search Searching for 6:

  17. Binary Search Searching for 6:

  18. Basic Sorts

  19. Simple Sort • Get a list of unsorted numbers • Make a new empty list • Repeat steps these steps until the unsorted list is empty • Select the smallest unsorted number • Move this number to the sorted list

  20. Insertion Sort • Get a list of unsorted numbers • Set a marker for the sorted section after the first number in the list • Repeat steps until the unsorted section is empty • Select the first unsorted number • Swap this number to the left until it arrives at the correct sorted position • Advance the sorted marker to the right one position

  21. Selection Sort • Get a list of unsorted numbers • Set a marker for the sorted section at the front of the list • Repeat steps until one number remains in the unsorted section • Find smallest number in the unsorted section • Swap this number with the first number in the unsorted section • Advance the marker to the right one position

More Related