Académique Documents
Professionnel Documents
Culture Documents
• Computer Architecture
• The Concept of Algorithm
• Complexity and Order
• NP-complete Problems
Self Introduction
Name: Takeaki Uno
Affiliation: NII, Sokendai
Age, status: 44, professor
Research Area: algorithm, data mining, bioinformatics, operations
research
• e-mail: uno@nii.ac.jp
Homepage : http://research.nii.ac.jp/~uno/index-j.html
(the slides are uploaded)
Contents of the Lecture
Architecture of computer, and the program
CPU, memory, OS, memory management, instruction, register
Data structure (efficient ways of recording/using the data)
stack, queue, heap, binary tree, hash
Graph Algorithms
matching, shortest paths,…
Connection to Latest Researches
• Algorithms are connected to the many latest researches
(algorithms are studied in the areas, in which algorithm are
related)
• Especially, having simple mathematical models and criteria, with
huge data or complicated data
+ Bioinformatics
Human genome is of 3 billion letters. They have only 4 kinds of
letters ATGC, thus computers have advantages. Genes and variations
often have some implicit rules
+ Chemoinformatics
Chemical compounds are networks of atoms, so tractable for
computers. However, the stereographical structures are difficult
Connection to Latest Researches
+ Astronomy
Computer systems of observatories generates huge amount of data,
and those data is accumulated to integrated databases
+ Social science
recently, there have been progresses on understanding systems of
societies by simulations with including micro activities
Connection to Latest Researches
+ architecture
other than structural calculations to evaluate the strength of the
buildings, material optimizations and structure optimizations reduce
the costs
+ literature
large amount of literatures allows as to find interesting knowledge
by computer operations
+ other
development of simulation science, that is to understand the real
world phenomenon and mechanisms by simulations
Latest Researches in Japan
• Japanese algorithmic researches are of high levels in the world
+ interior point methods for optimization problems
+ discrete mathematics and combinatorial optimizations
+ compression and succinct indexes
+ database search and database construction
+ data mining
+ computational geometry
…
CPU memory
Interfaces
• Monitor, keyboard, mouse etc. are connected to CPU, and
controlled/managed by signals given by CPU
CPU memory
Execution of Program
• CPU executes instructions written in the program, sequentially
CPU memory
プログラミング言語
• CPU の命令は数値。しかも、1つ1つの処理は非常に単純(これ
をマシン語、あるいは機械語という)
• これを組合せてプログラムを作るのは、かなり大変
• そこで、通常はもう少し抽象化して、人間に見やすくした「高級
言語」とよばれるものを使う
( C , JAVA , Perl, Basic, シェルスクリプトなど)
8: ...
• 2-4のように局所的に繰り返して実行される部分をループ
という
CPU メモリ
メモリのアクセス
• メモリは 1 バイトずつ数値が記憶されている
• メモリには、記憶場所に 0 から始まる番号がついていて、好き
な場所のデータに一手でアクセス(書き込み/読み出し)でき
る
• このように、好きな場所に一手でアクセスできるメモリをランダ
ムアクセスメモリという
• ランダムアクセスでない記憶装置は、例えば CD とかハード
ディスクとか、テープ
1 0 1 1 0 1 0 1
数値の表現(バイト)
• メモリは数値を覚えられるが、実は 0 と 1 しか覚えられな
い (ビットという)
• しかし、大量に 01 の数値を記憶できる
• 実際は、 01 しか記憶できないのでは用をなさないので、 01
の数値を 8 個セットにして、それを 2 進数とみなす。( 0-
255 が表現できる)
- これを 1バイトという
• 足す引くかけるの算術演算の結果、 2 進数 9 桁目に繰り
上がったとき、あるいはマイナスになったときは、その部分
は無視して計算する
1 0 1 1 0 1 0 1 128+32+16+4+1 = 181
16 進数
• コンピュータに記憶された数を扱うときは、当然、2進数で話
をしたほうがわかりやすい
(例えば、 1 バイトに入る数の最大は 11111111 とか。直感的
になる)
• 01 だけで表記すると場所をとる、桁が大きくなる
• つまり、「何のデータはどこに書いた」ということを決めておく。プ
ログラムでは、データの計算をする際には、場所を決めて書く
• 常に 0 か 1 の値が書いてあるので、「書き込まれていない」とい
うことも検出できない
点数
点数
20点数
20 1 0 1 1 0 1 0 1
20
整数小数文字
- 整数: 01 の数値をいくつかセットにして、それを 2 進数とみな
す。通常、 32 ビット = 4 バイト。 (0-40 億くらい )
- 文字: 文字と整数値を対応させたコード表があり、それを使っ
て整数値として記憶する
1 0 1 1 0 1 0 1 128+32+16+4+1 = 181
• 歴史的な事情で、いくつかのコードがある
- JIS コード
- shift JIS コード
- EUC コード
- unicode
JIS コード
• 英語は 0-127 しか定められていないので、 128-255 の部分にか
なと記号が入っている
JIS 漢字コード
• 漢字については、制御コードという、特別の文字 2 つが入った
ら、日本語のモードになる。漢字は、 2 バイト 1 文字。もう一度
制御コードが来たら、以後は英数字に戻る
0 1 2 3 4 5 6 7 8 9 A B C D E F
9 亜
A 唖 娃 阿 哀 愛 挨 姶 逢 葵 茜 穐 悪 握 渥 旭 葦
B 芦 鯵 梓 圧 斡 扱 宛 姐 虻 飴 絢 綾 鮎 或 粟 袷
C 安 庵 按 暗 案 闇 鞍 杏 以 伊 位 依 偉 囲 夷 委
D 威 尉 惟 意 慰 易 椅 為 畏 異 移 維 緯 胃 萎 衣
E 謂 違 遺 医 井 亥 域 育 郁 磯 一 壱 溢 逸 稲 茨
Shift-JIS コード
• Windows で使われているコード
• 制御文字を使わず、 2 バイトの文字をあらわしている
• 1 文字目が記号だと、次の
1 バイトとあわせて記号だと
みなすので、記号が使えな
くなる
• 2 バイト目は、改行コード
など、通常の文字になること
もあるので、日本語対応して
いないソフトで見ると、
ぐちゃぐちゃになる
EUC コード
• 主に UNIX で使われているコード
• 制御文字を使わず、 2 バイトの文字をあらわしている
• 1 文字目が記号、かななら、
2 文字目とあわせて、
漢字コードとみなす
• 2 文字目も、かな記号なの
で、漢字の一部ならかな記号、
と判断できる
• 記号、かなが出せない
UNICODE
• 世界の全ての言語の文字を1つのコードで表す、というもの
• 2 バイト 1 文字を使わず、 2 バイトの文字をあらわしている
• 漢字など、地域で字体が
違うものも1つとして扱うため
事実上はその国固有の
フォントが必要
• 最近は 4 バイトで表すようだ
キャッシュメモリ
• コンピュータのメモリのアクセス速度は、演算速度よりかなり遅
い( 10 倍以上)
• そのため、メモリを読み出すときは、しばらく演算をとめて待つこ
とになる。次の命令を読むときもそう。
• そこで、メモリを読むときはまとめてたくさん読む
• 読んだメモリは、 CPU に直結した速いメモリにしばらく取っておく
(この操作をキャッシュ、キャッシュに使うメモリをキャッシュメ
モリという)
キャッシュ
CPU メモリ ディスク
メモリ
キャッシュによる高速化
• メモリアクセスが、キャッシュに入っている場所ばかりだと計算は
大幅に速くなる
キャッシュの効率を高めるような保存法が重要
引き続いて、キャッシュの中を見ることが多い計算をさせる
と、高速化できる
• ディスクのアクセスにも、同じようにキャッシュを使う
CPU 直結メモリの代わりに、通常のメモリを使う。メモリのほうが
ディスクよりアクセス速度が速いので、高速化できる
• 高級言語では、数値を記憶する際に変数というものを使う
• 変数には、何か値が1つ入る
• コンパイルして実行するときに、各変数にメモリの場所が割当て
られる。以後、変数をアクセスするときには、その場所にアクセ
スするようになる
配列
• 大量のデータを扱う場合、全てのデータに直接変数を割当てる
のは、大変。プログラムを書くのも大変
• そこで、配列を使う
• 配列を使うと、変数+添え字、という形でデータにアクセスでき
る。添え字のところは変数を入れられるので、例えば、 100 個
の変数を 0 にする、といった作業も、ループを使って楽にできる
1 0 1 1 0 1 0 1
OS
• コンピュータは、機種によって、入出力の方法が違う
• ディスプレイに文字を書くためには、文字の形になるよう、デー
タを書き込まなければいけない
• こういった、ハードウェアによる違いを吸収する、低レベルの処
理を行う、実行するプログラムの管理、などをするプログラムが
ある
• メモリの管理も OS が行う
メモリの確保
• 普通、コンピュータでは、複数のプログラムが同時に実行されて
いる(含むデバイスドライバ)
• そのため、メモリの適当な場所に適当に数値を書き込むと、他
のプログラムの実行を阻害する(下手をすると動きが止まる)
• そのため、メモリを使いたいときには、 OS にお願いして、必要な
分だけ使える場所をあてがってもらう(これをメモリを確保する
という)
Complexity and Order
Ways to Solve
Algorithm:
set (order) of instructions to do a specified task
Usually, algorithm is that for computers
Algorithm can be considered as a theory of designing the way of
computing, or theory of efficient programs
• How simple
simplicity of programs
• Efficiency (speed, place, cost,…)
speed and memory usage (electric power consumption)
• A Turing machine can read/write data, move the tape, and change
the internal state of the execution unit
A Model for Computation Time
size of million
size of 100
2-3 times
10,000
times
Evaluation of Memory Usage
+ sorting
examine all possible orders, and output the one which is
increasing order
+ sorting
computation time is O(n n!) ≒ O(n2n logn)
+ sorting
scan the sequence and swap the pairs of neighboring numbers
with the reverse ordering; repeat this n times
computation time is O(n2)
“Good” Algorithms
+ if size > 3, prepare a slack for each literal, and joint them by using
slack literals
(a∨b∨c∨d∨e∨f) (a∨b∨x)∧ ( ¬ x∨c∨y)∧ ( ¬ y∨d∨z)∧ ( ¬ z∨e∨f)
SAT k-Clique
x4
• When a literal of clause Ci is chosen
Ci is disabled Ci x1
¬ x3
• When no literal of Ci is chosen
Ci is disabled
Ci x1
Ci ¬ x3
How Much Can We Do Better?
• Exponential time can be reduced to polynomial time, by deriving
good algorithm
low degree polynomials are better
• Fundamentals of algorithm
a sequence of operations with conditional branches
• Definition of order
ignoring constant factors and small degrees, to capture the global
increase by the problem sizes
• Fundamentals of complexity:
polynomiality, NP-complete, lower bounds