1 - Abstract-Note Version
1 - Abstract-Note Version
• Website:https://pan.baidu.com/
• User name:YNUteaching
• Password:EE12111211
• QQ vs Wechat(weixin)
•易
• 算法
• 算:计算 calculate
• 法:方法 method way
• Simplified character
• Traditional Chinese character/ complex form of Chinese character
• 简化字
• 繁体字
•灵
•靈
• Textbook
• <Data Structures and algorithm analysis in C>
• Mark Allen Weiss
• Second edition
• ISBN 978-0-201-49840-0
• What?!Why do we need to learn programming again?
➢ Relation between the data structures & programming
• Follow my ‘translation’
• Asking question
• Grading
• 20 pts performance attendance
• 20 pts small test
• 20 pts midterm
• 40 pts final
Introduction
• Aims and goals for this text
List
Example2
• Example2 Man VS Machine
Tree
…….. ……..
⚫Kasparov
VS
Deepblue
⚫Deepmind
⚫AlphaGo
• Example3:traffic lights
Graph
C
AB AC AD D
B
BA BC BD
E
DA DB DC A
EA EB EC ED
• Solve problem by computer:
➢Question-model-solution
➢Question(numerical value; NON numerical value)
numerical value Mathematical equation
NON numerical value Data structure
• Solve problem by computer:
➢Question-model-solution
➢Question(numerical value; NON numerical value)
numerical value Mathematical equation
NON numerical value Data structure
• How to describe/define one structure?
• Advance:
• Keep stable
List——1 VS 1
Logical structure Tree——1 VS n
Graph——n VS n
• Describition
• for people: Logical structure
• for computer: storage structure/ Physical structure
• application
• Log in by the account (baidunetdisk)
• 3. If R is equal to 0, then n is the greatest common divisor, and the algorithm ends;
otherwise, step 4 is executed;
• 4. Put the value of N in M, and the value of R in N;
• 5.Repeat step 2.
• Pseudocode
• Time complexity
• Space complexity
Problem: sorting
• A: • exercise:
key • Try to describe this insertion sort
alg. in pseudocode
• EX. 8 2 4 9 3 6
Running time
• Depends on input • already sorted VS. reverse sorted
• Depends on input size • 6 elem VS. 6*106
• Want upper bounds • a guarantee to user
/1/ sum=0;
/2/ for(i=0;i<=N; i++)
/3/ sum+=i*i*i;
/4/ return sum;
• Depend on computer (supercomputer、laptop、watch?)
• How to analysis worst time without talking about hardware?
• We need other BIG idea !!!
Big idea
• θ-notation:
• Drop low order terms and ignore leading constants.
• 3n3+99n2-6n+4068=? θ(n3 )
Asymptotic notation
• T(n1)=9999n2+8888n+7777, T(n2)=n3
• as n approach infinity
• Θ(n2) alg. always beats eventually Θ(n3) alg.
• As n gets bigger, it doesn’t matter what the low order terms/ leading constant
• Even if you ran the Θ(n2) alg. on a slow computer and Θ(n3) on a fast
• It satisfies our issue of being able to compare both relative and absolute
speed.
• Combination of Mathematics and Engineering
• How about the upper bound we want ?
Asymptotic notation
• O-notation:
• T(N)=O(f(N)) if there are positive constants c and n0 such that
T(N)≤cf(N) when N≥ n0.
• Ω-notation:lower bound
• read section 2.1 about Ω part
• very bad style to include constant or low-order terms in side a
BIG O
• Do NOT say T(N)=O(2N2) or T(N)=O(N2+N)
• The correct form is T(N)=O(N2)
• Rules:
• If T1(N)=O(f(N)) and T2(N)=O(g(N)), then
➢ T1(N)+T2(N)= Max(O(f(N)) , O(g(N)), )
➢ T1(N)*T2(N)= O(f(N))*O(g(N))
• Typical growth rates
• O(1)<O(log2n) <O(n) <O(n log2n) <O(n2) <O(n3)<O(2n) <O(n!)
The running time table (billion operations per second)
• the same simple example (2.4.1)
• never more than the running time of the test plus the larger of the
running time of S1 and S2.
exercises
• O(?)