Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.

Similar presentations


Presentation on theme: "Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement."— Presentation transcript:

1 Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement the binary search algorithm

2 List Processing List: a set of values of the same type Basic operations performed on a list: –Search list for given item –Sort list –Insert item in list –Delete item from list

3 Search Necessary components to search a list: –Array containing the list –Length of the list –Item for which you are searching After search completed: –If item found, report “success”, return location in array –If item not found, report “failure”

4 Search

5 Sorting a List Selection sort –Sorting algorithm –List is sorted by selecting list element and moving it to its proper position –Algorithm finds position of smallest element and moves it to top of unsorted portion of list –Repeats process above until entire list is sorted

6 Selection Sort

7 Sequential Ordered Search

8 Binary Search Can only be performed on a sorted list Uses divide and conquer technique to search list If L is a sorted list of size n, to determine whether an element is in L, the binary search makes at most 2 * log2n + 2 key comparisons –(Faster than a sequential search)

9 Binary Search Algorithm Search item is compared with middle element of list If search item < middle element of list, search is restricted to first half of the list If search item > middle element of list, search second half of the list If search item = middle element, search is complete

10 Binary Search


Download ppt "Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement."

Similar presentations


Ads by Google