[CS112] Data Structure Recitation (Section 02, 05) 1 st week - - PowerPoint PPT Presentation
[CS112] Data Structure Recitation (Section 02, 05) 1 st week - - PowerPoint PPT Presentation
[CS112] Data Structure Recitation (Section 02, 05) 1 st week Changkyu Song cs1080@cs.rutgers.edu Office Hours: Tue 12:00a.m. ~ 2:00 p.m. @ Hill 206 [CS112] Recitation - Changkyu Announcement Changkyu Song cs1080@cs.rutgers.edu Office
Section 4, 15
[CS112] Recitation - Changkyu
Announcement
Changkyu Song cs1080@cs.rutgers.edu Office Hours: Tue 12:00 ~ 2:00 p.m. @ Hill 206 Class Web Site: http://paul.rutgers.edu/~cs1080/courses/cs112
Section 4, 15
[CS112] Recitation - Changkyu
Intro.
- Programming
Section 4, 15
[CS112] Recitation - Changkyu
Intro.
- Programming
Section 4, 15
[CS112] Recitation - Changkyu
Intro.
- Programming
Section 4, 15
[CS112] Recitation - Changkyu
Intro.
- Programming
Section 4, 15
[CS112] Recitation - Changkyu
Intro.
- Programming Language
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- Good Programming
- Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- Good Programming
- Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- How to represent the speed of algorithm (program)
- Which algorithm is the faster?
– A takes 10 sec on my desktop. – B takes 0.001 sec on the super computer of NASA 10 sec 0.001 sec
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- The speed of algorithm is related with complexity of algorithm.
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- The speed of algorithm is related with complexity of algorithm.
- The order of Complexity
– represents the complexity of functions in terms of input size N
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- The speed of algorithm is related with complexity of algorithm.
- The order of Complexity
– represents the complexity of functions in terms of input size N
- Big O notation
( ) ( ) ( ) ( ) ( )
k n g k n f n g O n f constant positive a for , ⋅ ≤ ⇔ =
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- The speed of algorithm is related with complexity of algorithm.
- The order of Complexity
– represents the complexity of functions in terms of input size N
- Big O notation
( ) ( ) ( ) ( ) ( )
k n g k n f n g O n f constant positive a for , ⋅ ≤ ⇔ =
Upper bound Coefficient ignored Smaller terms ignored
Section 4, 15
[CS112] Recitation - Changkyu
Problem Set 1 – Big O
- Big O notation
1) Define the Unit Operation (ex> comparison, +, -, x, /, assign) 2) Count the # of unit operations in terms of input size N 3) Represent it as Big O notation
( ) ( ) ( ) ( ) ( )
k n g k n f n g O n f constant positive a for , ⋅ ≤ ⇔ =
Upper bound Coefficient ignored Smaller terms ignored
Section 4, 15
[CS112] Recitation - Changkyu
#1 Exercise E3.10, page 117
Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Joseph 68 35 … 53 Liam 89 22 … 77 Anthony 70 30 … 84 Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … Average
r students c exams
Section 4, 15
[CS112] Recitation - Changkyu
#1 Exercise E3.10, page 117
Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Joseph 68 35 … 53 Liam 89 22 … 77 Anthony 70 30 … 84 Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … Average
Total Score = 89 + 22 + … + 77 Average = (100 + 100 + 98 + … + 3) / r
r students c exams
Section 4, 15
[CS112] Recitation - Changkyu
#1 Exercise E3.10, page 117
Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Joseph 68 35 … 53 Liam 89 22 … 77 Anthony 70 30 … 84 Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … Average
Total Score = 89 + 22 + … + 77 Average = (100 + 100 + 98 + … + 3) / r
r students c exams
) (rc O
( ) ( )
) ( ) 1 ( rc O c rc O r c O = + = + ×
c times of + for r students for c exams, r times of + and one /
Section 4, 15
[CS112] Recitation - Changkyu
#1 Exercise E3.10, page 117
Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Joseph 68 35 … 53 Liam 89 22 … 77 Anthony 70 30 … 84 Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … Average
Total Score = 89 + 22 + … + 77 Average = (100 + 100 + 98 + … + 3) / r
r students c exams
) (rc O
( ) ( )
) ( ) 1 ( rc O c rc O r c O = + = + ×
c times of + for r students for c exams, r times of + and one /
Note: The Input Size is rc, and the running time is O(rc). >> Linear (Not quadratic)
Section 4, 15
[CS112] Recitation - Changkyu
Exercise 3.14, page 118
Image Reference: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/deck-of-cards.html
Section 4, 15
[CS112] Recitation - Changkyu
Exercise 3.14, page 118
Image Reference: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/deck-of-cards.html
) 1 ( O
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free
n m
Break Free Rather Be Bang Bang A sky full of stars … Turn Down For What
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free
Worst Case
n m
Summer Rather Be Latch A sky full of stars … Turn Down For What
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free
n m
Summer Rather Be Latch A sky full of stars … Turn Down For What
) ( m n O ×
Worst Case
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free Rather Be Latch A sky full of stars … Turn Down For What
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free Rather Be Latch A sky full of stars … Turn Down For What
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
Shake it off All about that bass Anaconda Bang Bang Stay with me Black Widow … Break Free Break Free Rather Be Bang Bang A sky full of stars … Turn Down For What All about that bass Anaconda Bang Bang Black Widow Break Free Shake it off … Stay with me A sky full of stars Bang Bang Break Free Rather Be … Turn Down For What
Merge Sort Merge Sort
) log ( n n O ) log ( m m O
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
n m
) log log ( ) ( ) log ( ) log ( m m n n O m n O m m O n n O + = + + + Worst Case
A sky full of stars Latch Rather Be Summer … Turn Down For What All about that bass Anaconda Bang Bang Black Widow Break Free Shake it off … Stay with me
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.11, page 118
n m
Best Case
All about that bass Anaconda Bang Bang Black Widow Break Free Shake it off … Stay with me
All about that bass Anaconda Bang Bang Black Widow Break Free Shake it off … Stay with me Turn Down For What …
) log log ( )) , (min( ) log ( ) log ( m m n n O m n O m m O n n O + = + +
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.15, page 118
1 2 3 4 5 6 5 3 4 2 8 6 n to 1 4 ? 3 + 4 + 2 = 9 to i j ? D[i] +D[i+1]+…+D[j-1] D: … to 1 n ? 3 + 4 + 2 + 8 + 6 + ...
Section 4, 15
[CS112] Recitation - Changkyu
Exercise E3.15, page 118
1 2 3 4 5 6 5 3 4 2 8 6 n 5 8 12 14 to 1 4 ? 14 - 5 = 9 to ? S[ j ] - S[ i ] D: S:
) 1 ( O
… to i j ? 1 n S[ n ] - S[ 1 ]
Section 4, 15