1 / 9

Sorting and Searching

Sorting and Searching. Cristian Hill. The Need for Searching and Sorting (2.1.7). Because computers are constructed to solve data- processing problems, updating databases is a common operation.

gaetan
Télécharger la présentation

Sorting and Searching

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. Sorting and Searching Cristian Hill

  2. The Need for Searching and Sorting(2.1.7) • Because computers are constructed to solve data- processing problems, updating databases is a common operation. • For example, adding, deleting, and modifying require that the database be searched for a specific index • Sorting is needed because Searching is made easier when there is order to the database

  3. What you need to know • Two types of sorting and searching. • Ability to compare for efficiency and applicability

  4. Types of Searching Linear(Sequential) Binary • Each object is examined in turn • Ends when item is found or end is reached • Does not need to be sorted • Checks midpoint, if value is greater than midpoint, then midpoint equals first value, recalculate midpoint, repeat • Continues until item is found or found not to be present • Requires that array(or similar) is sorted • Comparable to looking through a dictionary or telephone book Examples are on next slide

  5. Example of Process • Linear(Sequential) • Searching for “1” • Binary • Searching for 4 Not equal to one, move to next number Equal to one stop and return index Mid point is 6, 3 < 6 , so 6 becomes new max 4 is the new midpoint, 4=search parameter

  6. Efficiency of Searching Algorithms

  7. Efficiency of Searching Algorithms(Time) All numbers are completely arbitrary, but is what is given by the IB approved book

  8. Bubble Sorting • Starts with the first pair of numbers at index 0 and 1 • The values are then swapped if necessary, and the next 2 indexes are compared(1 and 2) • This process is repeated until all the end of the array is reached • After the first pass it is repeated over and over until no changes are made.

  9. Selection Sort • Sorts by finding the largest element in array and moving it to the 1st index, then continues with the second largest and so on. • This is done by splitting the list into 2 parts(sorted and unsorted) • Unsorted elements are searched for the largest value and this is then moved to first element of the unsorted list. The boundary of the sorted list is then increased

More Related