Motivations of Data Structures and Algorithms
Hsuan-Tien Lin
Dept. of CSIE, NTU
March 3, 2020
Introduction of Algorithms
Introduction of Algorithms
What is Algorithm?
descriptions to get something done
correctly/efficiently by computer
Introduction of Algorithms
Five Criteria of Algorithm
input, output, definiteness, finiteness, effectiveness
H.-T. Lin (NTU CSIE) Motivations of DSA 3/24
Introduction of Algorithms
getMinIndex with Sequential Search Algorithm
returns index to minimum element within array
Introduction of Algorithms
Correctness Proof of Algorithm
e.g. loop invariance by mathematical induction
—discrete math helps!
H.-T. Lin (NTU CSIE) Motivations of DSA 5/24
Introduction of Algorithms
Efficiency of Algorithm
knockout tournament for getMinIndex: not much faster overall,
but possibly faster if done in parallel
Expressing Algorithms with Pseudo Code
Expressing Algorithms with Pseudo Code
Pseudo Code for getMinIndex
pseudo code: “spoken language” of programming
Expressing Algorithms with Pseudo Code
Bad Pseudo Code: Too Detailed
goal of pseudo code: communicate efficiently
H.-T. Lin (NTU CSIE) Motivations of DSA 9/24
Expressing Algorithms with Pseudo Code
Bad Pseudo Code: Too Mysterious
goal of pseudo code: communicate correctly
Expressing Algorithms with Pseudo Code
Bad Pseudo Code: Too Abstract
goal of pseudo code: communicate effectively
H.-T. Lin (NTU CSIE) Motivations of DSA 11/24
Expressing Algorithms with Pseudo Code
Good Pseudo Code of SelSort
no “formal definition” and depends on the speaker/listener
Introduction of Data Structures
Introduction of Data Structures
What is Data Structure?
scheme of organizing data
within computer
Introduction of Data Structures
How to Organize 200 Exam Sheets?
different use cases
=⇒ different organization scheme (data structure)
H.-T. Lin (NTU CSIE) Motivations of DSA 15/24
Introduction of Data Structures
Good Algorithm Needs Proper Data Structure
if having data structure such that getMinIndex faster,
=⇒ SelSort also faster (we will see)
algorithm :: data structure ∼ recipe :: kitchen structure
Introduction of Data Structures
Good Data Structure Needs Proper Accessing Algorithms: get, insert
rule of thumb for speed: often-get ⇔ “nearby”
H.-T. Lin (NTU CSIE) Motivations of DSA 17/24
Introduction of Data Structures
Good Data Structure Needs Proper Maintenance Algorithms: construct, update, remove
hidden “cost” of data structure: maintenance effort
Why Data Structures and Algorithms?
Why Data Structures and Algorithms?
Why Data Structures and Algorithms?
use storage/computation resources properly =⇒ good program
Why Data Structures and Algorithms?
Proper Use: Tradeoff of Different Factors
understand tradeoff =⇒ good program
H.-T. Lin (NTU CSIE) Motivations of DSA 21/24
Why Data Structures and Algorithms?
Different Tradeoff on Different Platforms
important to learn other CS subjects
Why Data Structures and Algorithms?
Programming 6= Coding
programming :: building house ∼ coding :: construction work
H.-T. Lin (NTU CSIE) Motivations of DSA 23/24
Why Data Structures and Algorithms?