0% found this document useful (0 votes)
20 views62 pages

1 - Abstract-Note Version

The document provides information about a cloud storage website and account for online teaching materials. It discusses data structures and algorithms, including some examples like lists, trees, and graphs. It introduces concepts like abstract data types and algorithm complexity analysis. It also provides details about a data structures textbook and course requirements and grading.

Uploaded by

Rakibul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views62 pages

1 - Abstract-Note Version

The document provides information about a cloud storage website and account for online teaching materials. It discusses data structures and algorithms, including some examples like lists, trees, and graphs. It introduces concepts like abstract data types and algorithm complexity analysis. It also provides details about a data structures textbook and course requirements and grading.

Uploaded by

Rakibul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

• INFO3L3901 Data structures

• Cloud storage for online teaching

• Website:https://pan.baidu.com/

• User name:YNUteaching

• Password:EE12111211

• Just download!Don’t change the password!!!


• QQ group

• QQ vs Wechat(weixin)
•易

• Data structures & algorithm

• 算法
• 算:计算 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

• What to learn? What to study?


➢ Abstract
Requirement & suggestion
• Taking notes

• 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

• Abstract data type (ADT)

• How to estimate the time required for a program


➢ Algorithm complexity
• 1.1 history
• 1.2 basic structure
• 1.3 ADT
• 1.4 algorithm
Pioneer in data structure-Donald Ervin Knuth

• Born in 1938 US.


• Earnd a doctorate in 1963 from the
California Institute of Technology.
• <The art of computer programming>
• TeX,a document-prepation system
• Received many awards Turing Award
(1974)
Why do we need ‘structure’
• Relation between objective world and computer
➢Computer science:
Data representation
Data processing

Some model can NOT be compute/calculate


• 1.1 history
• 1.2 basic structure
• 1.3 ADT
• 1.4 algorithm
Example1:teaching system

List
Example2
• Example2 Man VS Machine
Tree

…….. ……..

…... …... …... …...


Man VS Machine

⚫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?

aggregattion: S=(D,R) Note:


D:data <a,b> a b
R:relation
(a,b) a b
例:our class G=(D,R)
D={ T,S1,S2,…,Sn}
R={<T,Si>|1<=i<=n}
• Describition
• for people: Logical structure
• for computer: storage structure/ Physical 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)

• Link password (your own account)

• Download player MP4


• 1.1 history
• 1.2 basic structure
• 1.3 ADT
• 1.4 algorithm
• An ADT is a set of operations.(P42, 3.1.)
• Abstract data type
• 抽象(chou xiang)
• 抽:拉(pull) more accurate careful ,take out extract
• 现象(phenomena)
• Abstract:keep the basic or the most important element
• ignore the details
• Same model /structure to solve many problems
What should be inclined in an ADT?
• We will begin the experiment part NEXT week.
• 1.1 history
• 1.2 basic structure
• 1.3 ADT
• 1.4 algorithm
• An algorithm is a clearly specified set of simple instructions to
solve a problem.
• Requirement:
➢finite(instruction & time)
➢readability 人看得懂的程序才是好程序
➢robustness
How to describe a algorithm?
• EX. Euclid’s algorithm for Gcd
• The greatest common divisor of two integers:the largest integer
that divides both.

• natural language/ human language



• 1.输入m和n;
• 2.求m除以n的余数r;
• 3.若r等于0,则n为最大公约数,算法结束;否则执行第4步;
• natural language • 4.将n的值放在m中,将r的值放在n中;
• 1.To input the integer M and N; • 5.重新执行第2步。

• 2.Find the remainder R of M divided by N;

• 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.

• Advantage: easy to understand


• Disadvantage: lengthy, different meanings
• Advantage: easy to understand
• Disadvantage: lengthy, different meanings
• HSK
• 中国队大胜美国队
• 中国队大败美国队

• This weekend 这周末


• That’s why you can’t program by human language!

• The final victory of artificial intelligence----


free talk between human and computer
• Pseudocode 伪代码 fake code
➢1.r=m%n;
Advantage: simple
➢2.loop until r=0;
➢ 2.1 m=n;
➢ 2.2 n=r;
➢ 2.3 r=m%n;
➢3.output n.
• Code (fig2.10)

• Pseudocode

• natural language/ human language


Analysis of algorithm

• The theoretical study of computer program performance and


resource usage.

• Time complexity
• Space complexity
Problem: sorting

• Input: sequence<a1,a2…an> of numbers


• Output: permutation <a1’,a2’…an’>
• Such that
• a1’ ≤ a2’ ≤ … ≤ an’
Insertion sort (A, n) // A[1,2…n]

• 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

➢It won’t run more than 3 seconds ➢upper bounds √


➢It goes at least 3 seconds 3 mins? 3 years? ➢lower bounds X
Kinds of analysis
• Worst case: (usually)
➢T(n)=max time on any input of size n.
➢It always does something rather than just sometimes dose something.

• Average case: (sometimes)


➢T(n)=expected time over all input of size n.
➢Time of every input times the probability.
➢Need assumption of statistical distribution
➢All inputs are equally likely—uniform distribution
Kinds of analysis
• Worst case: (usually)
• Average case: (sometimes)
• Best case:
➢bogus No good
➢it‘s not guarantee
Worst time calculation
• A simple example (2.4.1)

/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

• Asymptotic analysis • Asymptotic 渐近


➢Ignore machine dependent constant. ➢逐渐 gradually
➢Look at growth of T(n) as n →∞. ➢接近 approach

We need some notations to help us.


Asymptotic notation

• θ-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

• Sometimes the n0 is so large


• That‘s why we are interested in some of the slower algorithms.
The great thing about Asymptotic notation

• 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)

• /1/ sum=0; • /1/ 1 unit time constant time


• /2/ for(i=0;i<=N;i++) • /2/ 2N+2
• /3/ sum+=i*i*i; • /3/ four unit time(2*,+,=) executed N times 4N
• /4/ return sum; • /4/ 1 unit time
• Total: 6N+4
• We say that this function is O(N).
• In terms of asymptotic notation
• lots of shortcuts that can be taken without affecting the answer
• line 3 is also an O(1) statement (per execution)
• It is silly to count precisely whether it is 2, 3, or 4 units
• leads to several general rules
General rules
• Rule 1-for loops:
• The running time of a for loop is at most the running time of the statements
inside the for loop times the numbers of iteration.
General rules
• Rule 2-nested for loops:
• Analysis inside out
• Total running time-- the time of statement multiplied by the
product of the sizes of all the for loops.
• for(i=0; i<N; i++)
• for(j=0; j<N; j++)
• k++;
• Rule 3-consecutive statement:
• just add (the maximum is the one that counts)
• for(i=0; i<N; i++)
• A[i]=0;
• for(i=0; i<N; i++)
• for(j=0; j<N; j++)
• A[i]+=A[j]+i+j;
• Rule 4-if/else:
• If (condition)
• S1
• Else
• S2

• never more than the running time of the test plus the larger of the
running time of S1 and S2.
exercises

• Recursive procedures: • Textbooks end of Chapter 2


• n!(factorial) • 2.1
• 2.6 a. b.

• O(?)

You might also like