记一组面试题

1.是否了解线程的同步和异步?

2.是否了解网络的同步和异步?

3.一个数组存放10个数[8,5,3,0,7,1,2,6,4,9] 编程实现这10个数有小到大的排序,找出效率最好的方式

"""
我当时用的是Python的内置函数,现在想想应该自己实现一个堆排序的,这个才是最好的排序方式
堆排序里面的存储结构是数组  逻辑结构是二叉树
"""
def HeapSortMax(lst, n):
    # 找出最大值登顶对顶
    # n = len(lst)
    if n <= 1:
        return lst
    depth = n // 2 - 1  # 这个深度是0~depth
    # 下面开始调整堆 从最后一个非终端节点开始调整
    for i in range(depth, -1, -1):
        topmax = i
        leftchild = 2 * i + 1
        rightchild = 2 * i + 2  # 左右孩子节点
        # 从这三个节点里面选出最大值 还要不能越界才得行
        if leftchild <= n - 1 and lst[leftchild] > lst[topmax]:
            topmax = leftchild
        if rightchild <= n - 1 and lst[rightchild] > lst[topmax]:
            topmax = rightchild
        if i != topmax:
            lst[topmax], lst[i] = lst[i], lst[topmax]
    return lst
def HeapSort(lst):
    n = len(lst)
    for i in range(n):
        lastmesslen = n - i
        # 每次登顶了数组长度就少了一个了
        HeapSortMax(lst, lastmesslen)
        # print(lst)
        if i < n:
            lst[0], lst[lastmesslen - 1] = lst[lastmesslen - 1], lst[0]
            # 这个位置为什么是lastmesslen-1呢?道理很简单
            # 最后一个元素本来就是lastmesslen-1,lastmesslen已经越界了
        # print("ex", lst)
    return lst
if __name__ == "__main__":
    lst = [3, 1, 5, 4, 7, 6, 8, 0]
    # lst = HeapSortMax(lst)
    lst = HeapSort(lst)
    print(lst)

4.找出字符串里面出现最多的字符

def func(str):
    dic = {}
    for el in str:
        if dic.get(el):
            dic[el] = dic[el] + 1
        else:
            dic[el] = 1
    key, value = "", 0 
    for item in dic.items():
        if item[1] > value:
            value = item[1]
            key = item[0]
    return key, value

数据库的相关知识 就是crud

还有一个动态规划的问题 说真的 我一直觉得动态规划是最最最牛逼的算法 我一定要把每一个类型都搞得清清楚楚明明白白透透彻彻。

原文地址:https://www.cnblogs.com/d9e84208/p/11064028.html