Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Python Search

The document discusses and compares several sorting and searching algorithms: - Linear search sequentially checks each element of a list to find a target value. It is slower than binary search. - Binary search works on a sorted list, comparing the target to the middle element to determine which half to search. - Bubble sort compares adjacent elements and swaps them into order, repeating until the list is fully sorted. - Insertion sort places each unsorted element into its correct position by shifting larger values to the right.

Uploaded by

IT Dept GMIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Python Search

The document discusses and compares several sorting and searching algorithms: - Linear search sequentially checks each element of a list to find a target value. It is slower than binary search. - Binary search works on a sorted list, comparing the target to the middle element to determine which half to search. - Bubble sort compares adjacent elements and swaps them into order, repeating until the list is fully sorted. - Insertion sort places each unsorted element into its correct position by shifting larger values to the right.

Uploaded by

IT Dept GMIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

COMPUTATIONAL THINKING AND

PROBLEM-SOLVING

With Python
LINEAR SEARCH

• Sequential searching algorithm


• Checks every element in the list – till the desired element is found
• Little slow as compared to binary search
• Let’s say I am trying to find 9
8 4 2 7 9

• Loop will continue till the required element is found


• At the end we will have the following output

9
• AT Index 4
BINARY SEARCH

• Algorithm to find an item in the list.


• Prerequisite is that the list should be sorted – Ascending or Descending.

8 4 2 7 9

2 4 7 8 9

L M U
• M = (L+U)/2
• (0+5)/2 = 2
• Mid Index now become L

2 4 7 8 9

L M U
BUBBLE SORT
• Sorting algorithm that compares two adjacent elements
• Swaps the elements to put them in desired order.

8 4 2 7 9 i=0

4 8 2 7 9 i=1

4 2 8 7 9 i=2

4 2 7 8 9 i=3
• This iteration will continue till the list is sorted
• At the end of the iteration our output will be

2 4 7 8 9
INSERTION SORT
• This sort uses an algorithm to place an unsorted element at its suitable place.
• Lets assume that we have the following list to sort.

0 1 2 3 4 Index no
10 4 25 1 5 Element

• 1st element will be assumed as the sorted element which is Index 0 and element 10
• Current = 4 Sorted 10
• If current is less than sorted = True; swap the places
0 1 2 3 4 • Same process will be repeated and this time 25 will be compared
with 10. Now, current is 25 and sorted is 10
4 10 25 1 5
• If current is < sorted = false; do not swap
0 1 2 3 4 • Now, current is 1 and sorted is 25
4 10 25 1 5 • Above process will be repeated to compare the current with sorted
• If true it will keep swapping the places.

You might also like