• 大小: 66KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: Python
  • 标签: python  算法  

资源简介

python版 算法基础第五版 Foundation Of Algorithms 各章节代码,以及课后习题代码 各章节(1-11章)的代码基本上都有。习题只有写代码的有参考答案。证明没有,个人做的。如有错误欢迎纠正。本书图灵出版社翻译的错误不少,建议对照原英文版观看。

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
“““
Created on Thu Jan  3 22:47:27 2019

@author: lenovo
“““
‘‘‘
def wen(ab):
    c=1
    def shi(de):
        jie = c
        print(jie)
        c+=1
        print(jie)
    shi(44)
wen(33)
‘‘‘
import itertools
import numpy as np
# 算法 3.11
# 1 生成不包含v1的集合


def make_set(v):  # 输入不包含v1的矩阵
    long_v = len(v)
    subset = []
    for i in range(1 long_v+1):
        subset.extend(itertools.combinations(v i))
    return [list(i) for i in subset]


def k_subset(k n s):  # 包含k个顶点的所有子集
    return s[bin2(nk-1):bin2(n k)]


def edge(w):  # 给一个无向连通矩阵返回非递减的边信息
    n = np.shape(w)[0]
    edge_list = []
    for i in range(n-1):
        for j in range(1 n-1):
            if i+j < n:
                edge_list.append((w[i][i+j] i+1 i+j+1))
    edge_list.sort()
    return edge_list

s = [1 3 2 4]


def merges(low mid high):
    q = [0]*(high - low + 1)
    i j k = low mid+1 0
    while (i <= mid) & (j <= high):
        if s[i] < s[j]:
            q[k] = s[i]
            i += 1
        else:
            q[k] = s[j]
            j += 1
        k += 1
    if i == mid+1:
        q[k:] = s[j:high+1]
    else:
        q[k:] = s[i:mid+1]
    s[low:high+1] = q
    return s


if __name__ == ‘__main__‘:
    v = [2 3 4 5]
    # print(make_set(v))
    # w = np.array([[0 1 3 20 20] [1 0 3 6 20] [3 3 0 4 2] [20 6 4 0 5] [20 20 2 5 0]])
    # print(edge(w))
    print(merges(013))

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-01-19 13:46  Foundations_Of_Algorithms\
     目录           0  2019-01-19 13:46  Foundations_Of_Algorithms\.idea\
     目录           0  2019-01-08 18:57  Foundations_Of_Algorithms\.idea\dictionaries\
     文件         151  2019-01-08 18:57  Foundations_Of_Algorithms\.idea\dictionaries\lenovo.xml
     文件         764  2019-01-15 16:56  Foundations_Of_Algorithms\.idea\Foundations_Of_Algorithms.iml
     目录           0  2019-01-01 16:16  Foundations_Of_Algorithms\.idea\inspectionProfiles\
     文件         294  2019-01-01 16:04  Foundations_Of_Algorithms\.idea\misc.xml
     文件         309  2019-01-01 16:04  Foundations_Of_Algorithms\.idea\modules.xml
     文件         239  2019-01-13 19:24  Foundations_Of_Algorithms\.idea\other.xml
     文件       54437  2019-01-19 13:46  Foundations_Of_Algorithms\.idea\workspace.xml
     目录           0  2019-01-19 13:40  Foundations_Of_Algorithms\bin_search_tree\
     文件        4793  2019-01-16 20:49  Foundations_Of_Algorithms\bin_search_tree\bin_search_tree.py
     文件        9155  2019-01-19 13:40  Foundations_Of_Algorithms\bin_search_tree\B_tree.py
     文件          79  2019-01-16 16:20  Foundations_Of_Algorithms\bin_search_tree\__init__.py
     目录           0  2019-01-17 15:17  Foundations_Of_Algorithms\bin_search_tree\__pycache__\
     文件        2805  2019-01-17 15:17  Foundations_Of_Algorithms\bin_search_tree\__pycache__\bin_search_tree.cpython-36.pyc
     文件         195  2019-01-16 18:52  Foundations_Of_Algorithms\bin_search_tree\__pycache__\__init__.cpython-36.pyc
     文件        1609  2019-01-14 16:09  Foundations_Of_Algorithms\ceshi.py
     目录           0  2019-01-11 18:34  Foundations_Of_Algorithms\chapter1\
     目录           0  2019-01-17 21:50  Foundations_Of_Algorithms\chapter10\
     文件           0  2019-01-17 21:50  Foundations_Of_Algorithms\chapter10\nothing
     目录           0  2019-01-18 10:50  Foundations_Of_Algorithms\chapter11\
     文件        1364  2019-01-18 10:05  Foundations_Of_Algorithms\chapter11\chapter11.py
     文件         313  2019-01-18 10:50  Foundations_Of_Algorithms\chapter11\work11.py
     文件        3272  2018-12-28 00:19  Foundations_Of_Algorithms\chapter1\chapter1.py
     文件        6828  2019-01-02 14:07  Foundations_Of_Algorithms\chapter1\work1.py
     目录           0  2019-01-11 18:39  Foundations_Of_Algorithms\chapter2\
     文件        5564  2019-01-02 14:13  Foundations_Of_Algorithms\chapter2\chapter2.py
     文件       15992  2019-01-04 20:47  Foundations_Of_Algorithms\chapter2\work2.py
     目录           0  2019-01-16 20:31  Foundations_Of_Algorithms\chapter3\
     文件        3160  2019-01-16 20:31  Foundations_Of_Algorithms\chapter3\binary_search_tree.py
............此处省略30个文件信息

评论

共有 条评论