第 14 页 - Python笔记

Python解析树ParseTree

python ''' 构造一棵解析树 需要调用之前写过的Stack文件和BinaryTree文件 ''' from Stack import Stack from BinaryTree import BinaryTree import...

Python归并排序

python def mergeSort(alist): if len(alist) 1: mid = len(alist)//2 lefthalf = alist[:mid] righthalf = alist[mid:] merg...

Python插入排序

python def insertionSort(alist): for key, item in enumerate(alist): index = key while index 0 and alist[index-1] item...

Python Hash及常见操作

python 用Python实现hash表 hash的查找操作时间复杂度O(1) hash每个位置被称为slot槽。可以使用list实现hash,每个slot对应一个key,存放元素 按照正常的字母在ASCII中的顺序mod tabl...

Python几个小的动态规划问题

python 解决动态规划中的找零问题 输入需要找零的金额和货币的币值向量 输出满足找零条件的最少的硬币个数 def ChangeMaking(coinVal, change): alist = [0] (change+1) for ...

python 英语单词拼写检查算法

python 网传鹅厂面试题,英语单词拼写检查算法 比如输入hello, 却错误的输入了hellu, 找出出错的字母 感谢知乎知友@Lee Shellay 对词典中的每个词, 逐刺逐字母拓展Trie, 单词完结处结点用END符号标识 ...

Python 实现冒泡排序

python Python 实现冒泡排序 def bubbleSort(alist): for passnum in range(len(alist)-1, 0, -1): for i in range(passnum): if al...

python二叉树

python class BinaryTree: def init (self, rootObj): self.key = rootObj self.leftChild = None self.rightChild = None de...

python二分查找

python 实现一个二分查找 输入:一个顺序list 输出: 待查找的元素的位置 def binarySearch(alist, item): first = 0 last = len(alist) - 1 while first

python构建堆

python 构建树实现堆 class BinHeap: def init (self): self.heapList = [0] self.currentSize = 0 #插入新结点后必要时交换子节点和父节点的位置保持堆的性质 d...

python二叉查找树

python 构建二叉查找树(非平衡) class TreeNode: def init (self, key, val, left = None, right = None, parent = None): self.key = k...

python三种方法检测变位词Anagram

python class AnagramDetection: # 先对两个字符串进行list化 # 对字符串对应的两个list进行排序 # 依次比较字符是否匹配 def anagramSolution1(self, s1, s2): ...

python平衡查找树AVL

python 构建二叉查找树(非平衡) class TreeNode: def init (self, key, val, left = None, right = None, parent = None): self.key = k...

python链表及常见操作

python class Node: def init (self, initdata): self.data = initdata self.next = None def getData(self): return self.da...

Python实现欧几里得算法

欧几里得算法的目标是找到两个数的最大公约数。 计算两个非负整数p和q的最大公约数:若q是0,则最大公约数为p。否则,将p除以q得到余数r,p和q的最大公约数即为q和r的最大公约数。 python def euclid(p, q): i...

Python解析 算数表达式求值 栈的使用

使用Python实现一种算数表达式求值的算法,模拟这种使用栈的方式,这是由E.W.Dijkstra在20世纪60年代发明的一种非常简单的算法。代码模拟仅仅表现一种编程思想,代码的逻辑并不完全