Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itsmunim/bongotest
Some simple enough algorithmic code test problems
https://github.com/itsmunim/bongotest
algorithm problem-solving python
Last synced: about 4 hours ago
JSON representation
Some simple enough algorithmic code test problems
- Host: GitHub
- URL: https://github.com/itsmunim/bongotest
- Owner: itsmunim
- Created: 2019-01-24T17:50:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-27T17:51:11.000Z (almost 6 years ago)
- Last Synced: 2024-02-23T09:43:03.803Z (9 months ago)
- Topics: algorithm, problem-solving, python
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
Awesome Lists containing this project
README
#### Setup
- `mkvirtualenv `
- `pip install -r requirements.txt`
- `python setup.py install` <-- Important, otherwise module won't be found by `py.test`#### Running Test
- `pytest -vv`
#### Testing in iPython or Python Console
##### Testing Depth of Object Keys (Problem 1 & 2)
```python
from bongotest.depthcheck import get_depths, print_depth
# A list of depth tuple(unordered), read the method docstring to know more
get_depths({'a': 1, 'b': 2, 'c': {'d': 10, 'e': {'f': 11}}})# Prints the solution you expect from an object properly
print_depth({'a': 1, 'b': 2, 'c': {'d': 10, 'e': {'f': 11}}})
```##### Testing Least Common Ancestor (Problem 3)
```python
from bongotest.datastructure import create_bst, get_node
from bongotest.lca import lca# Create a bst first
bst = create_bst()# Test lca for different nodes
print lca(bst[2], bst[4]).value```
#### Complexity of the LCA Algorithm
##### Runtime:
If we consider the height of the tree is `h`, then the time complexity is `O(h)`. Considering number
of node to be `n`, this is more optimal than `O(n)`. This was possible because of the data structure as
in every node has pointer to it's parent.##### Space:
The space complexity is constant `O(1)`; the reason being we don't store any path or info while running the
algorithm. The algorithm works based on calculating depth of two nodes and based on that deciding if
it should go back upto the node where both has a convergence and hence the LCA is obtained.