Skip to content

Commit

Permalink
update readme and dp
Browse files Browse the repository at this point in the history
  • Loading branch information
keon committed Dec 1, 2016
1 parent 9980417 commit 30b3f32
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,70 @@

Minimal and clean examples of data structures and algorithms.

List of Implementations:

```
.
├── array
│   ├── house_robber.py
│   └── longest_increasing_subsequence.py
├── builtins
│   ├── dictionary.py
│   ├── list.py
│   ├── set.py
│   └── tuple.py
├── dynamic_programming
│   └── max_subarray.py
├── graph
│   ├── find_path.py
│   ├── graph.py
│   └── traversal.py
├── hashtable
│   └── hashtable.py
├── linkedlist
│   ├── first_cyclic_node.py
│   ├── kth_to_last.py
│   ├── linkedlist.py
│   └── remove_duplicates.py
├── matrix
│   └── matrix_rotation.txt
├── output.txt
├── queue
│   └── queue.py
├── search
│   ├── binary_search.py
│   ├── count_elem.py
│   ├── first_occurance.py
│   └── last_occurance.py
├── sorting
│   ├── insertion_sort.py
│   ├── merge_sort.py
│   ├── quick_sort.py
│   └── selection_sort.py
├── stack
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── stack.py
│   └── stack.pyc
├── string
│   ├── license_number.py
│   ├── reverse_string.py
│   ├── reverse_vowel.py
│   └── reverse_words.py
├── testStack.py
└── tree
├── bintree2list.py
├── deepest_left.py
├── invert_tree.py
├── longest_abs_path.py
├── max_height.py
├── predecessor.py
├── same_tree.py
├── successor.py
├── tree.py
└── trie.py
```

11 changes: 11 additions & 0 deletions array/house_robber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def house_robber(houses):
last, now = 0, 0
for house in houses:
tmp = now
now = max(last + house, now)
last = tmp
return now

houses = [1, 2, 16, 3, 15, 3, 12, 1]

print(house_robber(houses))
11 changes: 11 additions & 0 deletions dynamic_programming/max_subarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

def max_subarray(array):
max_so_far = max_now = array[0]
for i in range(1, len(array)):
max_now = max(array[i], max_now + array[i])
max_so_far = max(max_so_far, max_now)
return max_so_far

a = [1, 2, -3, 4, 5, -7, 23]
print(a)
print(max_subarray(a))
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 30b3f32

Please sign in to comment.