Skip to main content

BuildTest PyPi License Downloads PythonVersion

Library for Studying and Applying Tree Data Structure

Installation

pip install treekit

Sample Usage

>>> from treekit import binarytree
>>> bt1 = binarytree([13, 3, 14, 0, 4, None, None, None, 2, None, 7]) # data array in breadth-first order, see: https://en.wikipedia.org/wiki/Binary_tree#Arrays
>>> bt1.show() # this will create an output.html and open a tab in web browser to view it
>>> bt1.height
3
>>> bt1.inorder # bt.preorder # bt.postorder # bt.levelorder
[0, 2, 3, 4, 7, 13, 14]
>>> bt1.preorder
[13, 3, 0, 2, 4, 7, 14]
>>> bt1.diameter()
The sum of depths from the left and right subtrees of Node(3) is 4
4
>>> bt1.flatten(target="preorder", inplace=True)
>>> bt1.inorder
[13, 3, 0, 2, 4, 7, 14]
>>> bt1.preorder
[13, 3, 0, 2, 4, 7, 14]
>>> bt1.find_maximum_path_sum()
(43, Node(13))
>>> from treekit import binarytree
>>> bt2 = binarytree()
>>> bt2.compact_build([4, -7, -3, None, None, 8, -4, 9, -7, -4, None, 6, None, -1, -6, None, None, 0, 6, 7, None, 11, None, None, -1, -4, None, None, None, -2, None, -3])
>>> bt2.show() # this will create an output.html and open a tab in web browser to view it
>>> bt2.diameter()
The sum of depths from the left and right subtrees of Node(8) is 9
9
>>> from treekit import tree
>>> t1 = tree()
>>> t1.remove_invalid_parenthese('()())a)b()))')
['((ab()))', '((a)b())', '(()ab())', '(()a)b()', '(())ab()', '()(ab())', '()(a)b()', '()()ab()']
>>> t1.Fibonacci_numbers(n=5, a=[0, 1])
>>> t1.Fibonacci_numbers(n=5, a=[0, 1], distinct=True)
>>> t1.Lucas_numbers(n=5)
>>> t1.Tribonacci_numbers(n=8, distinct=True)
>>> t1.Fibonacci_numbers_generalized(n=15, a=[0]*7+[1], distinct=True)
>>> t1.word_break_DFS(s = "catsanddog", wordDict = ["cats", "dog", "sand", "and", "cat"])
>>> t1.word_break_BFS(s = "catsanddog", wordDict = ["cats", "dog", "sand", "and", "cat"])
>>> t1.climbing_stairs(n_steps = 8)
>>> t1.coin_change(coins = [3, 5], amount = 12)
>>> t1.coin_change(coins = [1, 2, 3], amount = 6)
>>> t1.decode_ways(s = "11106")
>>> from treekit import tree
>>> t2 = tree()
>>> t2.tree_traversals_summary()
>>> t2.validate_IP_address()
>>> from treekit import bst
>>> bst1 = bst(h=4)
>>> bst1.show()
>>> from treekit import heap # Max Heap
>>> from random import randint
>>> array = [randint(-100, 100) for x in range(30)]
>>> maxheap1 = heap(array)
>>> maxheap1.array
>>> maxheap1.show()

Screenshot 1: Binary Search Tree, height = 4

image1


Screenshot 2: DFS Search Space for Removing Invalid Parentheses

image2


Screenshot 3a: Computation Space for Fibonacci Numbers (n=5, order=2)

image3a


Screenshot 3b: Computation Space for Fibonacci Numbers Generalized (n=15, order=8)

image3b


Screenshot 4: DFS Search Space for Work Break

image4


Screenshot 5: Max Heap

image5

Metadata

Release files for treekit 0.0.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for treekit 0.0.22
File Interpreter ABI Platform Actions
treekit-0.0.22-py3-none-any.whl Python 3 none any Details for treekit-0.0.22-py3-none-any.whl

Release files / treekit-0.0.22-py3-none-any.whl

Download URL treekit-0.0.22-py3-none-any.whl
Size 798.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86b06dca70d44c308c09b098590a07a2ed1d89f2e244e7a9bf8217c9aaab24fa
BLAKE2b-256 checksum
How to use checksums
6d6b0cdad9ba89a1dbbac67c1ee0212a6eceab8f795c8ae6ab895d628c4f41ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.13

Security for treekit 0.0.22

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page