CSC 2720: Data Structures: Shiraj Pokharel
CSC 2720: Data Structures: Shiraj Pokharel
Shiraj Pokharel
Attendance (Please use GSU WiFi):
https://ousp.cs.gsu.edu/seat/
GSU :
" Every Instructor with in-person classes should
prepare a seating chart during the first class session.
This will enable contact tracers to identify who is in
“close contact” if a positive COVID-19 test is
reported. For this same reason, a daily attendance
sheet is recommended."
Classroom Values
●Respect
respect your professor, each other, and yourself
●Bravery
ask yourself “what is the worst that could happen?”
●Vulnerability
let me help you in whatever ways I can
●Grit
failure does not define you
The Medium
In a fine art context, “art medium” refers to the art
materials or art supplies used to create a work of
art. Basically, it is whatever you use to mark the
surface
The Medium: In Computer Science
Coding is actually just the medium in which we do
computer science.
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
Lecture 1 Agenda
• Guessing a number between 0 and 31
• Guessing a number between 0 and 2 -1
n
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
Guess My Number
I am thinking of a number between 0 and 31, inclusive.
Guess what it is! After each guess, I will tell you if your
number is correct, too low, or too high.
1) What are the lowest and highest number of guesses
possible?
2) What is the best strategy?
3) In the best strategy, what is the worst case?
Guess My Number
I am thinking of a number between 0 and 31, inclusive.
Guess what it is! After each guess, I will tell you if your
number is correct, too low, or too high.
1) What are the lowest and highest number of guesses
possible? Lowest: 1, Highest: 32
2) What is the best strategy?
3) In the best strategy, what is the worst case?
Guess My Number
I am thinking of a number between 0 and 31, inclusive.
Guess what it is! After each guess, I will tell you if your
number is correct, too low, or too high.
1) What are the lowest and highest number of guesses
possible? Lowest: 1, Highest: 32
2) What is the best strategy? Guess middle each time
3) In the best strategy, what is the worst case?
Guess My Number
I am thinking of a number between 0 and 31, inclusive.
Guess what it is! After each guess, I will tell you if your
number is correct, too low, or too high.
1) What are the lowest and highest number of guesses
possible? Lowest: 1, Highest: 32
2) What is the best strategy? Guess middle each time
3) In the best strategy, what is the worst case? 6
Guessing a number between 0 and
31
It turns out that the optimal strategy of guessing the
middle every time takes 6 guesses in the worst case.
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
Guessing a number between 0 and 2 k
-1
Fill in the below table of # of guesses G(n) as a
function of n (recall that we are guessing a number
between 0 and n-1)
n 1 2 4 8 16 32
G(n) 6
Guessing a number between 0 and
2 -1
k
n 1 2 4 8 16 32
G(n) 1 2 3 4 5 6
Lecture 1 Agenda
• Guessing a number between 0 and 31
• Guessing a number between 0 and 2 -1
n
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
Logarithms
What mathematical function fits the pattern below?
n 1 2 4 8 16 32
G(n) 1 2 3 4 5 6
Logarithms
What mathematical function fits the pattern below?
Recall that y = log2(n) is the solution to 2 = n.
y
n 1 2 4 8 16 32
G(n) 1 2 3 4 5 6
Logarithms
Here are some useful properties of logs:
• log(ab) = log(a) + log(b)
• log(a ) = b log(a)
b
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
Approximating a formula for G(n)
Recall that y = log2(x) is the solution to 2 = x.
y
n 1 2 4 8 16 32
log2(n)
G(n) 1 2 3 4 5 6
Approximating a formula for G(n)
Recall that y = log2(x) is the solution to 2 = x.
y
n 1 2 4 8 16 32
log2(n) 0 1 2 3 4 5
G(n) 1 2 3 4 5 6
Approximating a formula for G(n)
Recall that y = log2(x) is the solution to 2 = x.
y
log2(n) 0 1 2 3 4 5
G(n) 1 2 3 4 5 6
Lecture 1 Agenda
• Guessing a number between 0 and 31
• Guessing a number between 0 and 2 -1
n
• Logarithms
• Approximating a formula for number of guesses
G(n)
• An exact formula for number of guesses G(n)
An exact formula for number of
guesses G(n)
Fill in the below table of # of guesses G(n) as a function of n (recall
that we are guessing a number between 0 and n-1), and then fill in the
formula:
G(n) = ???
n 4 5 6 7 8
G(n) 3 4
An exact formula for number of
guesses G(n)
Fill in the below table of # of guesses G(n) as a function of n (recall
that we are guessing a number between 0 and n-1), and then fill in the
formula:
G(n) = Floor(log(n)) + 1
n 1 2 4 8 16 32
G(n) 6
An exact formula for number of
guesses G(n)
Fill in the below table of # of guesses G(n) as a function of n (recall
that we are guessing a number between 0 and n-1), and then fill in the
formula:
G(n) = Floor(log(n)) + 1
n 4 5 6 7 8
G(n) 3 3 3 3 4
Divide and Conquer