Skip to Main Content
算法技术手册(原书第2 版)
book

算法技术手册(原书第2 版)

by George T.Heineman, Gary Pollice, Stanley Selkow
August 2017
Intermediate to advanced content levelIntermediate to advanced
360 pages
8h 35m
Chinese
China Machine Press
Content preview from 算法技术手册(原书第2 版)
搜索算法
121
搜索算法
class BinaryNode:
def __init__(self, value=None):
"""
创建函数
"""
self.value = value
self.left = None
self.right = None
self.height = 0
def computeHeight(self):
"""
计算结点的高度
"""
height = -1
if self.left:
height = max(height, self.left.height)
if self.right:
height = max(height, self.right.height)
self.height = height + 1
def heightDifference(self):
"""
计算子
结点的高度差
"""
leftTarget = 0
rightTarget = 0
if self.left:
leftTarget = 1 + self.left.height
if self.right:
rightTarget = 1 + self.right.height
return leftTarget - rightTarget
def add(self, val):
"""
将一个
结点加入二叉搜索树中
,
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
Go语言编程

Go语言编程

威廉·肯尼迪
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787111562221