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

学習アルゴリズム

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

第3章. より良いハッシングを通してより良い生活を

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

値をキーに関連付ける

単に値を格納するのではなく、特定のキーに値を関連付けるために、(キーと値)のペアのコレクションを格納する必要があるかもしれない。これはシンボル・テーブル・データ型として知られており、キーだけを指定して関連付けられた値を発見することができる。ハッシュは、(キーと値)のペアを見つけるために最初から最後まで手作業でコレクションを検索する効率的な代替手段を提供する。先に説明した検索アルゴリズムよりも優れている。シンボル・テーブルは、キー(とその値)の削除を許容しながらも効率的である。すべてのキーを特定の順序、たとえば昇順で取り出す機能は失うが、結果として得られるシンボル・テーブルは、個々のキーに関連する値を取り出したり格納したりするのに最適なパフォーマンスを提供する。

任意の月と年のカレンダーを印刷する関数print_month(month, year) を書きたいとしよう。例えば、print_month('February', 2024) は次のように出力する:

   February 2024
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29

どのような情報が必要だろうか?その年のその月の最初の日の平日が必要であり(上記では木曜日)、2月の日数が28日(2024年のようなうるう年では29日)であることを知る必要がある。その年の各月の長さを日単位で記録した値を持つ固定配列、month_length を使うことができる:

month_length = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

最初の月である1月は31日あるので、month_length[0] = 31となる。2月は次の月で28日あるので、リストの次の値は28である。1年の最後の月である12月は31日なので、month_length の最後の値は31である。

これまで本書で紹介してきたことを踏まえると、同じ長さのkey_array を保存しておき、その中から月を検索して、month_length に対応する値を割り出すという方法もある。次のコードは、February has 28 days ...

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