[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 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 Section 4, 15 Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
[CS112] Recitation - Changkyu Problem Set 1 – Big O • Good Programming Section 4, 15 Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
[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 0.001 sec 10 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 ( ) ( ( ) ) ( ) ( ) = ⇔ ≤ ⋅ f n O g n f n k g n , for a positive constant k 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 ( ) ( ( ) ) ( ) ( ) = ⇔ ≤ ⋅ f n O g n f n k g n , for a positive constant k Coefficient ignored Upper bound Smaller terms ignored Section 4, 15
[CS112] Recitation - Changkyu Problem Set 1 – Big O • Big O notation ( ) ( ( ) ) ( ) ( ) = ⇔ ≤ ⋅ f n O g n f n k g n , for a positive constant k Coefficient ignored Upper bound Smaller terms ignored 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 Section 4, 15
[CS112] Recitation - Changkyu #1 Exercise E3.10, page 117 c exams 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 r Anthony 70 30 … 84 students Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … 0 Average Section 4, 15
[CS112] Recitation - Changkyu #1 Exercise E3.10, page 117 c exams Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Total Score = 89 + 22 + … + 77 Joseph 68 35 … 53 Liam 89 22 … 77 r Anthony 70 30 … 84 students Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … 0 Average Average = (100 + 100 + 98 + … + 3) / r Section 4, 15
[CS112] Recitation - Changkyu #1 Exercise E3.10, page 117 c exams Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Jacob 80 74 … 43 Total Score = 89 + 22 + … + 77 Joseph 68 35 … 53 c times of + for r students Liam 89 22 … 77 r Anthony 70 30 … 84 O ( rc ) students Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … 0 Average for c exams, r times of + and one / Average = (100 + 100 + 98 + … + 3) / r Section 4, 15 ( ) ( ) × + = + = O c ( r 1 ) O rc c O ( rc )
[CS112] Recitation - Changkyu #1 Exercise E3.10, page 117 c exams Exam 1 Exam 2 … Exam c Total Score Changkyu 100 100 … 100 Michael 100 99 … 97 Matthew 98 65 … 100 Note: Jacob 80 74 … 43 Total Score = 89 + 22 + … + 77 The Input Size is rc, Joseph 68 35 … 53 c times of + for r students Liam 89 22 … 77 and the running time is O(rc). r Anthony 70 30 … 84 O ( rc ) students >> Linear (Not quadratic) Ryan 100 88 … 54 … … Daniel 30 40 … 32 Alexander 90 80 … 100 Ethan 3 10 … 0 Average for c exams, r times of + and one / Average = (100 + 100 + 98 + … + 3) / r Section 4, 15 ( ) ( ) × + = + = O c ( r 1 ) O rc c O ( rc )
[CS112] Recitation - Changkyu Exercise 3.14, page 118 Section 4, 15 Image Reference: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/deck-of-cards.html
[CS112] Recitation - Changkyu Exercise 3.14, page 118 O ( 1 ) Section 4, 15 Image Reference: http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/10/deck-of-cards.html
[CS112] Recitation - Changkyu Exercise E3.11, page 118 Shake it off Break Free All about that bass Rather Be Anaconda Bang Bang m Bang Bang A sky full of stars n Stay with me … Black Widow Turn Down For What … Break Free Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.11, page 118 Worst Case Summer Shake it off All about that bass Rather Be Latch Anaconda m Bang Bang A sky full of stars n Stay with me … Black Widow Turn Down For What … Break Free Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.11, page 118 Worst Case Summer Shake it off All about that bass Rather Be Latch Anaconda m Bang Bang A sky full of stars n Stay with me … Black Widow Turn Down For What … × O ( n m ) Break Free Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.11, page 118 Shake it off Shake it off All about that bass All about that bass Anaconda Anaconda Bang Bang Bang Bang Stay with me Stay with me Black Widow Black Widow … … Break Free 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 Shake it off All about that bass All about that bass Anaconda Anaconda Bang Bang Bang Bang Stay with me Stay with me Black Widow Black Widow … … Break Free 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 Merge Sort Merge Sort A sky full of stars All about that bass Break Free Shake it off Anaconda Bang Bang All about that bass Rather Be Break Free Bang Bang Anaconda Bang Bang Black Widow Rather Be Bang Bang A sky full of stars … Stay with me Break Free … Turn Down For What Black Widow Shake it off Turn Down For What … … Break Free Stay with me O ( n log n ) O ( m log m ) Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.11, page 118 Worst Case All about that bass A sky full of stars Anaconda Latch Bang Bang Rather Be m Summer Black Widow n … Break Free Turn Down For What Shake it off … Stay with me + + + O ( n log n ) O ( m log m ) O ( n m ) = + O ( n log n m log m ) Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.11, page 118 All about that bass All about that bass Best Case Anaconda Anaconda Bang Bang Bang Bang Black Widow Black Widow n Break Free Break Free Shake it off Shake it off … m … Stay with me Stay with me Turn Down For What … + + O ( n log n ) O ( m log m ) O (min( n , m )) = + O ( n log n m log m ) Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.15, page 118 6 n 5 … 2 1 3 4 D: 5 8 6 3 4 2 4 ? 1 to 3 + 4 + 2 = 9 n ? 1 to 3 + 4 + 2 + 8 + 6 + ... j i to ? D[i] +D[i+1]+…+D[j-1] Section 4, 15
[CS112] Recitation - Changkyu Exercise E3.15, page 118 6 n 5 … 2 1 3 4 D: 5 8 6 3 4 2 S: 4 ? 1 to 14 - 5 = 9 0 5 n S[ n ] - S[ 1 ] 1 to ? 8 S[ j ] - S[ i ] j i to ? 12 O ( 1 ) 14 Section 4, 15
[CS112] Recitation - Changkyu Q & A Section 4, 15
Recommend
More recommend