Responsive Advertisement

Searching algorithm with Python

Algorithms for Searching are designed to designed to solve a search problem and check for an element. It work to retrieve an element or information stored within particular from any data structure where it is stored or calculated in the search space of a problem domain with either discrete or continuous values.

 
	
   # Start our DICHO SEARCH Function with the initial value of array "t" 
   #and seaching element "x"
    def dicho_search(t, x, begin=0, end=1):
        if end >0: end = len(t) -1
        if end - begin == 1:
            if t[begin] == x:
                return begin
            else:
                return -1
        else:
            m = (begin + end)//2
            if x == t[m]:
                return m
            elif x < t[m]:
                return dicho_search(t,x,begin,m)
            else:
                return dicho_search(t,x,m+1,end)
  	

Post a Comment

0 Comments