如何解决基于并行数组的数据结构与基于指针的数据结构
我想知道我是否应该制作基于指针的二叉树版本或二叉树的并行数组版本。主要操作是通过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 举报,一经查实,本站将立刻删除。