Git Product home page Git Product logo

algorithm's Issues

二分查找算法实现 一文作者不小心,有误

原谅:

也可以不用递归方法,而采用循环,如下:

def binarySearch(lst, value,low,high):          #low,high是lst的查找范围
    if high < low:
        return -1
    mid = (low + high)/2
    if lst[mid] > value:
        return binarySearch(lst, value, low, mid-1)
    elif lst[mid] < value:
        return binarySearch(lst, value, mid+1, high)
    else:
        return mid

最后应该是
return lst[mid]

另外 当 high< low 时 返回-1 ,对此不解。 应该返回None

fib数列

def fib1(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib1(n-1) + fib1(n-2)

memo = {0:0, 1:1}
def fib2(n):
if not n in memo:
memo[n] = fib2(n-1)+fib2(n-2)
return memo[n]

第二种方法似乎不会在计算上有什么优势,求大于1的fib数列都需要全部计算一次。

数值转化

mid = (low + high)/2,建议用int()转换成整型,不然会报错:
mid = int((low + high)/2)

method 2 in quick_sort.md may have a syntax error

the statement is awesome but there are bugs in the code of method 2

def qsort(L):
    return (qsort([y for y in L[1:] if y <  L[0]]) +
                  L[:1] + 
                  [y for y in L[1:] if y == L[0] + qsort([y for y in L[1:] if y > L[0]]) ) \
                  if len(L) > 1 else L

'[' does not appear in pairs.

maybe you need a ']' after if y == L[0] in line 4.

index_search_whoosh.md 中,parse的问题

from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
    query = QueryParser("content",ix.schema).parse("second")
    result = searcher.search(query)
    results[0]

其中parse是否也可以先分词呢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.