【问题标题】:Plotting Uniform and Non-Uniform Binary Search Tree Graphs绘制均匀和非均匀二叉搜索树图
【发布时间】:2016-10-29 21:00:03
【问题描述】:

我需要创建两个二叉搜索树图,显示 radix-2 和 radix

为此,我决定使用 python igraph 库并发现了 Fruchterman-Reingold 力导向函数,例如:

from igraph import *;

pl=Plot();

g = Graph.Tree(16, 2);
layout = g.layout("rt", 1); # Reingold-Tilford tree layout, useful for (almost) tree-like graphs

pl.add(g, layout=layout);
pl._windows_hacks=True;
pl.show();

不幸的是,这会生成一个分支不是二进制的树,即我在根节点之后得到三个节点。我还需要一个平衡树,这个函数似乎没有提供(树枝不平衡):

我在 igraph 库中使用了 Bipartite 类方法,但我不确定我是否走在正确的道路上。

如果在 igraph 和树可视化方面更有经验的人可以帮我解决这个问题,我会很高兴。

【问题讨论】:

    标签: python algorithm binary-search-tree


    【解决方案1】:

    我对这个情节也有同样的问题。我通过像这样指定布局的根来解决它:

    layout = g.layout("rt", root=(0,0))
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      相关资源
      最近更新 更多