Algorithms and Data Structures: Concepts and
Applications
(アルゴリズムとデータ構造の概要と応用)
Data Structures and Algorithms
(データ構造とアルゴリズム)
1st lecture, September 21, 2016
http://www.sw.it.aoyama.ac.jp/2017/DA/lecture1.html
Martin J. Dürst
(テュールスト
マーティン ヤコブ)
duerst@it.aoyama.ac.jp
Building O, Room 529
© 2008-17 Martin
J. Dürst Aoyama Gakuin
University
Today's Schedule
- About this course
- Data Structures: Concept and Example
- Algorithms: Concept and Example
- Course Schedule
自己紹介
Teaching Assistant: Soichiro Yashiki (矢舗 宗一郎、M1)
授業の位置づけ
- 情報テクノロジー学科: 2年後期、必修
- 経営システム工学科:
- 2012年入学生まで: 2年後期、選択必修、第一科目群
(▲)
- 2013年入学生から: 他学科科目 (自由選択科目)
- 機械創造工学科: 3年後期、選択必修、第一科目群
(△)
This is a JE course (理工学国際プログラム JE 科目): The
explanations are in Japanese, the materials (mostly) in English
授業の進め方
- 資料の配布とウェブ公開
- 配布資料への書き込みが不可欠
- ミニテストはアナウンスなし
- 出席は前提 (文科省); 遅延や未出席は大損
- 宿題、復習、予習は授業時間の二倍程度 (文科省)
- 質問はいつでも大歓迎
- 約束事 1: 私語禁止、脱帽、飲食禁止、通路解放
- 約束事 2: 書き込み、宿題を必ずやること
Glossary
- Each lecture handout comes with a glossary at the end
- The glossary contains:
- technical terms for this lecture (e.g. data
structure/データ構造) ⇐ part of examination
- technical terms for computer science (e.g.
compiler/コンパイラ)
- technical terms from other fields (e.g. topology/位相幾何学)
- selected general terms/expressions (e.g. technical
term/専門用語)
- Please report missing terms
成績評価方法
おおよその割合:
- 授業中のミニテスト: ~20%
- 演習課題: ~30%
- 期末試験: ~50%
総合的な評価
Why Algorithms and Data Structures?
Example of what happens without
data structures and algorithms:
- Don't know how to solve a problem at all
- Long program, difficult to maintain
- Slow program, especially when number of data items increases
One More Example
(from Computer Practice I, problem 1503, Finding Strings in Fibonacci
Words)
// fibonacci and pattern are very long strings
n=0;
for (i=0; i<strlen(fibonacci); i++) {
match = 0;
for (j=0; j<strlen(pattern); j++)
if (fibonacci[i+j] == pattern[j])
match++;
if (match==strlen(pattern))
match++;
}
Where is the Problem?
(from Computer Practice I, problem 1503, Finding Strings
in Fibonacci Words)
// fibonacci and pattern are very long strings
n=0;
for (i=0; i<strlen(fibonacci); i++) {
match = 0;
for (j=0; j<strlen(pattern); j++)
if (fibonacci[i+j] == pattern[j])
match++;
if (match==strlen(pattern))
match++;
}
strlen
takes more time for longer
strings!
Solution
(from Computer Practice I, problem 1503, Finding Strings
in Fibonacci Words)
// fibonacci and pattern are very long strings
n=0;
p_length = strlen(pattern);
for (i=0; i<strlen(fibonacci); i++) {
match = 0;
for (j=0; j<p_length; j++)
if (fibonacci[i+j] == pattern[j])
match++;
if (match==p_length)
match++;
}
The Fascination of Algorithms and Data Structures
Lecture Goal
Understand
- Way of thinking for algorithms and data structures
- Design of algorithms and data structures
- Well-known algorithms and data structures
Example of Data Structure: Linked List
Data Structure: Concept
A data structure consists of:
- A number of data items
Examples: Numbers, student data, ...
- Relationships (connections) between the data items
The term data structure is used mostly for structures inside
computer (main) memory.
There are two different views of data structures:
- Internal view (implementation): Construction out of arrays, structures,
pointers, ...
- External view (functionality provided): Abstract data type
(ADT)
Algorithm Examples
Problem: Searching a word (target) in a (real!) dictionary
- Linear search:
- Starting with page 1, proceed page by page until the end
- For each page, search columns from left to right and entries from top
to bottom
- Binary search:
- Start with whole dictionary
- Repeatedly split dictionary in half
- Check the word in the middle
- If the target is larger than the word in the middle, keep the
second half of the pages/words
- If the target is smaller than the word in the middle, keep the
first half of the pages/words
- If the target is equal to the word in the middle, then return the
target
- If you only have one word left, return failure
Algorithm: Concept
An algorithm is a clear set of instructions for how to solve a
well-defined problem in finite time.
Requirements:
- Clear definition of problem and result (well-defined problem)
- Detailled and precise step-by-step instructions (similar to a program;
clear set of instructions)
- Termination in a finite number of steps (finite time)
Counterexamples
- "Let's create world peace!"
Problem: Result unclear.
- "Just look it up in the dictionary!"
Problem: Precise instructions are missing.
- Random dictionary search: Open the dictionary at random locations, stop
if you find the word you searched for.
Problem: May take infinite number of steps.
Difference between Algorithms and Programs
- Algorithms cannot be executed directly,
they have to be implemented as programs in order to be executed.
- The same algorithm can be implemented in many different programming
languages, and in many different ways in the same program language
- Programs concentrate on details, algorithms are
concepts (ideas)
History of Algorithms
- Land area calculations in ancient Egypt
- Abstraction in ancient Greece (example: Euclid's algorithm for the
greatest common denominator)
- Origin of the name algorithm: Persian Mathematician Muhammad ibn
Mūsā al-Khwārizmī
(الخوارزمي, ca. 800 A.D.)
- In the 1930ies: Establishing the Mathematical base of algorithms (Gödel, Turing ...)
- From the 1950ies: Used in practice with computers, dramatic increase in
numbers
- From the 1990ies: Increased economic importance
Relationship between Data Structures and Algorithms
- Data structures represent state (static aspect of a computation)
algorithms represent processing (dynamic aspect of a computation)
- Some algorithms use more than one data structure
- More than one algorithm may use the same data structure
Summary of this Lecture
- Data Structures and Algorithms are core concepts of Computer
Science.
- A data structure describes a number of data items with their
relationships.
- An algorithm is a clear set of instruction for how to solve a
well-defined problem in finite time.
- Algorithms are not programs: Algorithms are abstract ideas, programs can
be executed.
- Algorithms are more than 2000 years old, but have been gaining enormous
economic importance recently.
Lecture Schedule
Data Structures and Algorithms: Schedule
参考書 (Strongly recommended to buy one book
and read it in parallel to the lecture /
どれか一冊を買って、授業の内容に合わせて読むことは強く推奨)
Homework 1: Huge Amounts of Data
Submission: Deadline: September 27 (next Wednesday), 19:00; Place: Box in
front of room O-529; Format: One page, A4 (both sides okay)
(for each subproblem, give the reasons for you assumptions, and cite
references. When citing Wikipedia,..., use IRIs, not URIs, e.g.
http://ja.wikipedia.org/wiki/情報, not http://ja.wikipedia.org/wiki/%E6%83%85%E5%A0%B1.)
- For exchanges in the First Section of the Tokyo Stock Exchange, calculate
the total of data items (counting one trade as one data item) during 2017.
Assume that during operating hours, each stock is traded once every 10
seconds.
- Imagine and explain some kind of data where the number of data items is
much higher than in subproblem 1, and where the data may be used in actual
calculations on a computer (there will be a deduction if different students
submit simmilar solutions)。
宿題 1: 膨大なデータ
提出: 来週の水曜日 (9月27日) 19:00時締切; O 棟
529号室の前の箱に提出; A4 一枚 (両面可) 厳守
(それぞれの問題で、想定の根拠となる理由、参考にした文献など必ず明記のこと。Wikipedia
などへの参照の場合、URI のではなく IRI を使用のこと (例:
http://ja.wikipedia.org/wiki/%E6%83%85%E5%A0%B1
のではなく http://ja.wikipedia.org/wiki/情報))
- 東京証券取引所の第一部の取引で、一つの株式会社の株が営業時間内に平均で
10秒で一回売買されていると想定して、合計で2017年に
(一売買行為を一つの項目と考えるとき)
何項目のデータが集まるかを、計算しなさい。
- 問題 1
の結果よりもデータ項目数がもっと多くて、実際に計算機で扱えそうな問題を考え、説明しなさい
(他人と同じものの場合には減点対象)。
Homework 2: Representation of Algorithms
Examine the algorithm representations on the additional handout, and think
about each representation's advantages and disadvantages.
(no need to submit)
Homework 3: Help Ms. Noda
Design an efficient (=fast) algorithm for Ms. Noda's problem.
Hint: Can you use an algorithm that you already know?
(no need to submit)
Homework 4: Install Ruby
Install Ruby on your notebook computer (and/or on your computer at home)
Main installation methods (choose one):
How to check: Open a Cygwin Terminal
or start Command
Prompt with Ruby
and execute ruby -v
Important: If you have problems with installing Ruby, come to my lab to fix
it before the next lecture.
Preparation for the Next Lecture
- Submit Homework 1 (deadline: September 27, 18:30)
- Complete Homework 2 (no need to submit)
- Complete Homework 3 (no need to submit)
- Review today's lecture's content
- Complete Homework 4
- Bring your notebook computer (with Ruby installed) with you next time
Glossary
- job search
- 就職活動
- data structure
- データ構造
- linked list
- 連続リスト
- data item
- データ項目
- abstract data type (ADT)
- 抽象データ型
- algorithm
- アルゴリズム
- linear search
- 線形探索
- binary search
- 二分探索
- implement(ation)
- 実装 (する)
- land area calculations
- 土地面積の計算
- ancient Egypt
- 古代エジプト
- Euclid
- ユークリッド
- greatest common denominator (GCD)
- 最大公約数
- Mathematician
- 数学者
- ancient Greece
- 古代ギリシャ
- state
- 状態
- static aspect
- 静的側面
- dynamic aspect
- 動的側面
- economic
- 経済的