Algorithms - searching and sorting

 

Sequential search 
starting with the first element of the list, the order of the search until they find. 

Binary Search 
from the ordered list of the candidate region data [0: n] started, by comparing the value of the intermediate value candidate regions lookup treated, the candidate region can be reduced by half. 
Li = [. 1, 2,. 3,. 4,. 5,. 6,. 7,. 8,. 9 ] 

Val =. 5 DEF Search (Li, Val): 
    Low = 0 
    High = len (Li) -. 1
     the while Low <= High: 
        MID = (High + Low) // 2
         IF Val == Li [MID]:
             return MID
         elif Val < Li [MID]: 
            High = MID +. 1
         the else : 
            Low = MID -. 1
    


return 'no'

print(search(li, val))
Sort low B trio: 
Bubble sort 
Selection Sort 
Insertion Sort 
Sort NB trio: 
quick sort 
heap sort 
merge sort 
no one with a sort: 
radix sort 
Shell sort 
bucket sort

 

Guess you like

Origin www.cnblogs.com/ls1997/p/10931790.html