二叉树搜索 - 如何查找奇数值 [英] binary tree search - how to find odd values

查看:115
本文介绍了二叉树搜索 - 如何查找奇数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家好!



我正在编写一个代码,其目的是打印普通二叉树中的所有节点,

,它们的值是一个奇数。



如果我按顺序旅行树的节点,运行时间将为0(n ),(其中n是树中总节点的数量..)



我的问题是:如果我为此目的使用二叉搜索树,在运行时间会有什么不同吗?



谢谢!

解决方案

如果你正在迭代所有的树然后只是创建一个值的列表,然后检查它并得到奇数值O(n)。


hey everybody!

i''m working on a code which its purpose is to print all the nodes in an ordinary binary tree, ,
which their value is an odd number.

if i will travel the tree''s nodes by an Inorder , the running time will be 0(n) ,(where n is the number of the total nodes in the tree..)

my question is : if i was using a binary search tree for this purpose, would that make any different on the running time?

thanks!

解决方案

If you are iterating over all the tree then just create a list of the values and go over that and get the odd values O(n).


这篇关于二叉树搜索 - 如何查找奇数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆