All Questions
Tagged with tree python-3.x
48 questions
5
votes
2
answers
445
views
Weakly-Referencing Tree Structure in Python
For another project of mine, I decided that it would be handy to have a tree structure to dictate hierarchy between pieces of data, but I didn't want to unnecessarily keep that data alive if it would ...
4
votes
1
answer
169
views
AutoComplete-Esque Tree
I've written a tree data structure that takes in input from the user, and stores the each letter based on the previous letter in the text. I'm not sure what this is called, but the closest I can find ...
2
votes
1
answer
206
views
Implementation of binary tree traversal
Based on what i understood of Binary Tree, queue and recursion I implemented this Breadth First Search algorithm as follows.
Do you have any suggestions to improve (in term of readability, good ...
8
votes
1
answer
2k
views
Red-Black Tree Implementation in Python
I'm wondering if there are better practices, and optimizations I could make on my code, to do things easier/faster.
I have added comments, in many places in the code, to make understanding easier.
<...
3
votes
0
answers
293
views
Noughts and Crosses Terminal Game with AI
I created a game which can play tic-tac-toe with: 0 players (AI vs AI), 1 player (human vs AI) or 2 player (human vs human).
Here is the AI function which wraps around my innermost function. This ...
5
votes
1
answer
151
views
AVL Tree implementation Based on VisualGo
I have tried implementing an AVL Tree on my own, based on visualising it. But i'm unsure how many testcases it work with, and how efficient it is. Are there any ways to make it efficient, and compact?
...
2
votes
0
answers
95
views
Max Heap Implementation in Python
I decided to challenge myself to code this data structure by just seeing how it looks visually and this is what I got. I can change this easily to minheap by changing some greater than (>) operators. ...
4
votes
2
answers
317
views
Suffix Tree in Python
I was wondering why the following implementation of a Suffix Tree is 2000 times slower than using a similar data structure in C++ (I tested it using python3, pypy3 and pypy2). I know the bottleneck is ...
2
votes
2
answers
407
views
Iterative “post order” tree traversal [closed]
I wanted to get feedback on the correctness and efficiency of this post order traversal routine that my wife and I find really easy to grasp.
...
2
votes
1
answer
740
views
Python Fenwick Tree
I am trying to solve this question: https://open.kattis.com/problems/fenwick
A Fenwick Tree (also known as a Binary Indexed Tree) is a data
structure on an array which enables fast (𝑂(log𝑛)) ...
3
votes
2
answers
2k
views
Ternary search tree implementation in python 3
I have implemented a Ternary search tree. It works well. But if you think something needs to be improved, say it. This code was tested in Python 3.7.4.
...
3
votes
2
answers
361
views
Binary Search Tree implementation in Python 3
Please review my BST Code
1. Class node
class Node:
2. Constructor
...
6
votes
3
answers
169
views
Symmetric Tree Check in Python
Inspired by This LeetCode Question.
Instead of checking if every layer is symmetric, it instead checks if any aren't. This allows the program to leave early is an early layer fails the test. I'm ...
-1
votes
1
answer
1k
views
Python 3 code for a binary search tree [closed]
I am working on a python3.6.5 question about BST:
Binary search tree (BST) is a binary tree where the value of each node is larger or equal to the values in all the nodes in that node's left subtree ...
1
vote
1
answer
519
views
leetcode 987. Vertical Order Traversal of a Binary Tree
anyone can provide some suggestion about my answer for the questions
987. Vertical Order Traversal of a Binary Tree
Given a binary tree, return the vertical order traversal of its nodes values. For ...