1 / 12

Algorithms and Data Structures الخوارزميات و تراكيب البيانات CS 211 Lecture 6:

Algorithms and Data Structures الخوارزميات و تراكيب البيانات CS 211 Lecture 6: Searching & Sorting Algorithms. Sorting Algorithms. Bubble Sort Algorithm Selection Sort Algorithm Insertion Sort Algorithm.

shannonv
Download Presentation

Algorithms and Data Structures الخوارزميات و تراكيب البيانات CS 211 Lecture 6:

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. Algorithms and Data Structuresالخوارزميات و تراكيب البياناتCS 211 Lecture 6: Searching & Sorting Algorithms

  2. Sorting Algorithms • Bubble Sort Algorithm • Selection Sort Algorithm • Insertion Sort Algorithm

  3. Bubble Sort AlgorithmItis a sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted.

  4. Selection Sort Algorithm • The list is divided into two parts, the sorted part at the left and the unsorted part at the right. • Initially, the sorted part is empty and the unsorted part is the entire list. • In every iteration of selection sort, the smallest element (considering ascending order) is selected from the unsorted array and swapped with the leftmost element, and that element becomes a part of the sorted array.

  5. Selection Sort Algorithm

  6. Insertion Sort Algorithm At each iteration, insertion sort algorithm removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

  7. Insertion Sort Algorithm

  8. Searching Algorithms • Sequential (Linear) Search Algorithm • Binary Search Algorithm

  9. Sequential Search Algorithm • In this algorithm, a sequential search is made over items one by one. • It sequentially checks each element of the list until a match is found or the whole list has been searched.

  10. Sequential Search Algorithm Wanted = 80 == ؟ == ؟ == ؟ ...... ....... 0 1 2 3 4 5 7 8 9 10 11 13 6 12 array 66 29 34 3 56 8 19 80 20 5 18 10 90 47

  11. Binary Search Algorithm • Search a SORTED list by repeatedly dividing the search interval in half. • Begin with an interval covering the whole list . • Binary search compares the target value to the middle element of the interval. If they are equal, this element is returned. • If the target value is less than the middle element of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. • Repeatedly check until the target value is found or the interval is empty.

  12. Binary Search Algorithm

More Related