Representation and Evaluation of Algorithms

(アルゴリズムの表現と評価)

Data Structures and Algorithms

2nd lecture, September 29, 2022

https://www.sw.it.aoyama.ac.jp/2022/DA/lecture2.html

Martin J. Dürst

AGU

© 2009-22 Martin J. Dürst Aoyama Gakuin University

 

Today's Schedule

Introduce TA

Teaching Assistant (TA): YU JINSONG (于 津松、M1)

Covid Precautions

About Moodle

 

Summary of Last Lecture

 

Solution to Homework 1, Question 1

[都合により削除]

 

Tokyo Stock Exchange: Actual system capacity

(source: The Japan News, 2015/9/22, p. 6)

old system new system
used until 2015/9/18 from 2015/9/24
Orders per day (max) 137 million 270 million
Orders per second (max) 30'000~40'000 >50'000
Time to process orders 0.001s 0.0005s

 

Last Week's 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?

[都合により削除]

 

Last Week's 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)

 

Methods for Representing Algorithms

 

Text

Principle: Describe the algorithm in a natural language

Advantages: Possible to write and understand for non-experts

Disadvantages:

 

Diagrams

Examples: Flowchart, ...

Advantages: Visual expression

Disadvantages:

(structured programming: replacing goto (jump to an arbitrary location in a program) with structured branches (if/switch/...) and loops (for/while/...) only)

 

What is Pseudocode

 

(Dis)Advantages of Pseudocode

Advantages:

Disadvantages:

 

Programing Language

Advantages:

Disadvantages:

 

The Programming Language Ruby

 

Ruby for Algorithm Representation

 

Last Week's Homework 4: Install Ruby

Install Ruby on your notebook computer (and/or on your computer at home)

Main installation methods (choose at least 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, contact me before the next lecture.

 

Reading and Writing Ruby

 

First Ruby Example

Linear search and binary search: 2search.rb

How to execute:

 

Basics of Ruby Syntax

 

Overview of Algorithm Evaluation

Main evaluation criteria:

  1. Execution time (computational (time) complexity)
    (this is the main focus of this lecture, and of research on algorithms)
  2. Amout of memory used (space complexity)
    (in general, the difference between different algorithms or data structures for the same problem is small)
  3. Ease of implementation
    (this is highly subjective, but in general, faster algorithms may be more difficult to implement)

Contextual information used for evaluation:

 

Comparing the Execution Time of Algorithms

Example: Comparing linear search and binary search

 

Comparing the Execution Time of Algorithms

Example: Comparing linear search and binary search

Possible question:

 

Comparing the Execution Time of Algorithms

Example: Comparing linear search and binary search

Possible questions:

 

Comparing the Execution Time of Algorithms

Example: Comparing linear search and binary search

Possible questions:

Problem: These questions do not have a single, clear answer.

 

Comparing the Execution Time of Algorithms

Example: Comparing linear search and binary search

Possible questions:

Problem: These questions do not have a single, clear answer.

When we compare algorithms, we want a single, clear answer.

Our answer will be: Linear search is O(n), binary search is O(log n).

We will arrive at this answer, and understand it, in the next two weeks.

 

Comparing Execution Times: From Concrete to Abstract

Very concrete

Very abstract

 

Measuring Execution Time

⇒ We need a better method to compare algorithms, not implemenations and not hardware

 

Comparing Execution Times: From Concrete to Abstract

Very concrete

Very abstract

 

Counting Operation Steps

⇒ We need a more abstract way to compare algorithms

 

Homework 1: Example for Asymptotic Growth of Number of Steps

Use 2search.rb to fill in the following table. Set the COUNT variable to n.

number of steps (counting additions and divisions)
n (number of data items)       1      8     64    512   4'096  32'768 262'144
linear search
binary search

 

Homework 2: Calculate Function Values

Fill in the following table
(use engineering notation (e.g. 1.5E+20) if the numbers get big;
round liberally, the magnitude of the number is more important than the exact value)

n      1     10    100   1'000  10'000 100'000
5n
n1.2
n2
n log2 n
1.01n

 

Homework 3: Compare Function Growth

Which function of each pair (left/right column) grows larger if n increases more and more? And why?

left column right column column with larger growth reason
100n n2
1.1n n20
5 log2 n 10 log4 n
20n n!
100·2n 2.1n

 

Homework 4: Logarithms and Limits

Review logarithms (ln, log10, log2,...) and limits (limn→∞,...) based on high school books/notes and Web resources

 

Summary of Today's Lecture

 

This Week's Homework

(提出不要。ただし、記入した表は次回に持参すること。)

  1. Ruby を使って探索アルゴリズムのステップ数を調べ、テーブルを完成
    (散布図を作成してもよい)
  2. n の増加の場合、複数の関数の値を計算
  3. 関数の増加の比較で、どちらの関数が「最終的に勝つ」か、そしてその理由を調査
  4. 高校の教科書やウェブなどで対数 (ln, log10, log2 など) と極限 (limn→∞など) について調査・再確認

 

Glossary

representation
表現
evaluation
評価
pseudocode
疑似コード
non-expert
素人
ambiguity
曖昧さ
natural language
自然言語 (すなわち、人間が話す言語)
flowchart
流れ図
structured progamming
構造化プログラミング
obfuscation
ごまかし
object-oriented (programming language)
オブジェクト指向 ((プログラム) 言語)
scripting language
スクリプト言語
criterion (複数 criteria)
基準
execution time
実行時間
computational complexity
計算量
worst case
最悪の場合
asymptotic
漸近
round
四捨五入する、概数で表す
logarithm
対数
limit
極限