![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
杂谈
文章平均质量分 68
hyperbolechi
这个作者很懒,什么都没留下…
展开
-
Tripadvisor 面经解答 -持续更新ing
2. Binary Search Tree Insertclass Node: def __init__(self,val): self.left=None self.right=None self.val=val def insertBST(root,node): if root==None:原创 2015-02-04 07:29:51 · 940 阅读 · 0 评论 -
python 先序遍历非递归
最近看面经,基本只要考了递归一定会follow up一道非递归的算法。所以我写了一下。主要思想是构造一个栈一直将左子树压栈,并每次读取一个 node 出栈,直到没有左子树 再看右边,依次循环 直到结束。先看递归的方法。def preorder(root): if root: print root.val preorder(root.left)原创 2015-01-20 08:06:22 · 1746 阅读 · 0 评论 -
sortings in python
这篇主要写几种sort的方法,后面还会持续更新。1. heapsortheap sort uses an array as a full tree to sort. time complexity is nlogn space is O(1) because it sorts in place.it requires random access so we use array原创 2015-01-31 00:34:56 · 600 阅读 · 0 评论 -
Matrix Chain Multiplication-geeksforgeeks
(ABC)D = (AB)(CD) = A(BCD) calculate the least calculation.第一种方法穷举发,willl take np time.def matrixp(p,i,j): if i==j: return 0 k=i minval=10000000 while k<j: result=m原创 2015-02-18 22:15:18 · 424 阅读 · 0 评论 -
insertion mergesort bubble sort 复习 python
最近重新开始复习算法那本书,整理了一下关于insertion mergesort以及 divide and conquer的思路insertion sort is O(n^2) best case when it is already sorted it will be O(n) worse case is the array is reversed sorted.the mai原创 2015-01-23 00:45:11 · 495 阅读 · 0 评论 -
select largest K number from unsorted array Python
heap:take klog(n) timecode is as follow"def siftdown(A, start, end): root = start child = 2 * root + 1 while child <= end: if child + 1 <= end and A[child] < A[child + 1]: child原创 2015-03-26 02:16:52 · 921 阅读 · 0 评论 -
topological sort python recursive and iterative
Define a DAG we need to find a path so that we can follow the path and get the result.graph={'A':['B','C'],'B':['D','E'],'C':['B','F'],'D':[],'E':[],'F':[]}def dfs(graph): stack=[graph.keys()[原创 2015-03-20 03:34:16 · 1297 阅读 · 0 评论