[CS112] Data Structure Recitation (Section 02, 05) 1 st week - - PowerPoint PPT Presentation

cs112 data structure recitation
SMART_READER_LITE
LIVE PREVIEW

[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


slide-1
SLIDE 1

[CS112] Data Structure Recitation

(Section 02, 05) 1st week

Changkyu Song cs1080@cs.rutgers.edu Office Hours: Tue 12:00a.m. ~ 2:00 p.m. @ Hill 206

slide-2
SLIDE 2

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

slide-3
SLIDE 3

Section 4, 15

[CS112] Recitation - Changkyu

Intro.

  • Programming
slide-4
SLIDE 4

Section 4, 15

[CS112] Recitation - Changkyu

Intro.

  • Programming
slide-5
SLIDE 5

Section 4, 15

[CS112] Recitation - Changkyu

Intro.

  • Programming
slide-6
SLIDE 6

Section 4, 15

[CS112] Recitation - Changkyu

Intro.

  • Programming
slide-7
SLIDE 7

Section 4, 15

[CS112] Recitation - Changkyu

Intro.

  • Programming Language
slide-8
SLIDE 8

Section 4, 15

[CS112] Recitation - Changkyu

Problem Set 1 – Big O

  • Good Programming
  • Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
slide-9
SLIDE 9

Section 4, 15

[CS112] Recitation - Changkyu

Problem Set 1 – Big O

  • Good Programming
  • Ref. “Quality Control” http://agilesoftwaresolutions.com/qa-services.asp.htm
slide-10
SLIDE 10

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

slide-11
SLIDE 11

Section 4, 15

[CS112] Recitation - Changkyu

Problem Set 1 – Big O

  • The speed of algorithm is related with complexity of algorithm.
slide-12
SLIDE 12

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

slide-13
SLIDE 13

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 , ⋅ ≤ ⇔ =

slide-14
SLIDE 14

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

slide-15
SLIDE 15

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

slide-16
SLIDE 16

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

slide-17
SLIDE 17

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

slide-18
SLIDE 18

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 /

slide-19
SLIDE 19

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)

slide-20
SLIDE 20

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

slide-21
SLIDE 21

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

slide-22
SLIDE 22

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

slide-23
SLIDE 23

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

slide-24
SLIDE 24

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

slide-25
SLIDE 25

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

slide-26
SLIDE 26

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

slide-27
SLIDE 27

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

slide-28
SLIDE 28

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

slide-29
SLIDE 29

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 + = + +

slide-30
SLIDE 30

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

slide-31
SLIDE 31

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 ]

slide-32
SLIDE 32

Section 4, 15

[CS112] Recitation - Changkyu

Q & A