There are two direction for us to solve this problem. (1) Recursion Recursive step: T[0] conbines with findsubsets(T[1:]) Final step: if len(T)==0: return [[]] Code: #Recursive method def findsubsets(T): if len(T)==0: return [[]] answer=[] for sets i…
Sort a linked list using insertion sort. 链表的插入排序实现原理很简单,就是一个元素一个元素的从原链表中取出来,然后按顺序插入到新链表中,时间复杂度为O(n2),是一种效率并不是很高的算法,但是空间复杂度为O(1),以高时间复杂度换取了低空间复杂度.代码如下: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNod…
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis of Algorithms_Second Edition>> _ Anany Levitin Note that throughout the paper, we assume that inputs to algorithms fall within their specified range…
About Cache Eviction Algorithms A cache eviction algorithm is a way of deciding which element to evict when the cache is full. In Ehcache , the memory store and the off-heap store might be limited in size. When these stores get full, elements are evi…
(referrence: GeeksforGeeks, Kth Largest Element in Array) This is a common algorithm problem appearing in interviews. There are four basic solutions. Solution 1 -- Sort First A Simple Solution is to sort the given array using a O(n log n) sorting alg…
本博客的代码的思想和图片参考:好大学慕课浙江大学陈越老师.何钦铭老师的<数据结构> 代码的测试工具PTA File Transfer 1 Question 2 Explain First, we will put N elements in a array,the elements is from 1 to N.The element in the array stand for the number  of computer. C1 stand for a computer and C2 s…
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (red) is removed from the input data and inserted in…
Sort a linked list using insertion sort. A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element (red) is removed from the input data and inserted in…
stl 中迭代器能够理解为面向对象版本号的广义指针,提供了对容器中的对象的訪问方法,能够遍历容器全部元素.也能够訪问随意元素.stl 迭代器有下面五种: Input iterators   仅仅读,输入迭代器,支持如:istream Output iterators  仅仅写,输出迭代器.支持如:ostream.inserter Forward iterators 读写,前向迭代器.仅仅能前向移动 Bidirectional iterators 读写,双向迭代器,可以双向移动.支持如: list…
Majority Number 原题链接:http://lintcode.com/en/problem/majority-number/# Given an array of integers, the majority number is the number that occurs more than half of the size of the array. Find it. Example For [1, 1, 1, 1, 2, 2, 2], return 1 Challenge O(…