问题描述
我想知道我是否应该制作基于指针的二叉树版本或二叉树的并行数组版本。主要操作是通过fisher yates shuffle进行插入和随机遍历。
"""
Operations and Fequency:
Insertion (Very Frequent)
Random Ordering (Each key,value once in a random order) (Very Frequent)
Set item with key (Somewhat frequent)
Get item with key (Somewhat frequent)
The random ordering has to visit every node and be exactly once
I kNow I can make a pointer based data structure which can share nodes (space efficency)
Also,I kNow I can make a data structure from parallel arrays (is this more efficent?)
"""
from typing import Generics
from typing import TypeVar
K = TypeVar('K')
V= TypeVar('T')
#Psudeo Code Ideas:
class PointerBasedTree:
__key: K
__val: V
__length: int
__is_head: bool #Alllows part of one tree to share nodes with another
#allows immutable data to be "deleted",insertion function can just early return to enforce deletions
__is_removed: bool
__left_tree: PointerBasedTree = self #self is sententail node
__right_tree: PointerBasedTree = self #self is sententail node
__ordering: List[PointerBasedTree] #can NOT have senentail nodes since self is a possible order for an entry (do NOT yield None)
class ArrayBasedTree:
__keys: List[K]
__vals: List[V]
__is_removed: List[bool] #lazy delete to insert to array element in middle of list
__left_keys: List[int] #int is row of left key (left tree val is same row)
__right_keys: List[int] #int is row of right key (right tree val is same row)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)