Skip to Content
学習アルゴリズム
book

学習アルゴリズム

by George Heineman
March 2025
Intermediate to advanced
280 pages
4h 16m
Japanese
O'Reilly Media, Inc.
Content preview from 学習アルゴリズム

第6章 バイナリーツリー手のひらの中の無限大

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

はじめに

リンクされたリストと配列は、直線的な配置で情報を格納する。この章では、コンピューターサイエンスの分野で最も重要な概念の一つであるバイナリーツリー再帰的データ構造を紹介する。第5章では、関数が自分自身を呼び出す再帰の概念について学んだ。この章では、バイナリーツリーが再帰的データ構造であること、つまり他のバイナリーツリー構造を参照することを学ぶ。再帰的データ構造の概念を紹介するために、すでに見たリンクリストのデータ構造をもう一度見てみよう。

リンクリストは再帰的データ構造の一例であり、各ノードはサブリストの最初のノードへの参照(next )を持つ。リンクリストは、N個の値の集合の動的な成長と縮小をサポートすることで、固定長配列を改良している。リスト6-1に示すsum_list() 再帰関数は、リンクリストを処理してその和を返す。この実装を、従来の反復処理と比較してみよう。

リスト6-1. リンクリストの値を合計する再帰的関数と反復関数
class Node:
  def __init__(self, val, rest=None):
    self.value = val
    self.next = rest

def sum_iterative(n):
  total = 0                         1
  while n:
    total += n.value                2
    n = n.next                      3
  return ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

データサイエンスのための実践線形代数

データサイエンスのための実践線形代数

Mike X Cohen
データ分析によるネットワークセキュリティ

データ分析によるネットワークセキュリティ

Michael Collins, 中田 秀基, 木下 哲也

Publisher Resources

ISBN: 9798341626317