Intro to Asymptotics and Bits (Discussion 6) (Ký hiệu tiệm cận và các phép toán bit) - Christine Zhou

UN
Uni24h
0 downloads
12
0

Document content

Page 2

Agenda - Announcements - And time to fill out surveys - Asymptotics Review - Problem 1,2 - Bits and Bitwise Operators - Problem 3

Page 3

Announcements - Midterm grades have been released! - Place to Vent (ANONYMOUS): tinyurl.com/placetovent - HW3 due yesterday - TLDR: Make sure everything works on the instructional account - Start Project 1 if you haven’t already! - (PLEASE FILL OUT TODAY) Discussion survey: tinyurl.com/disc6cz

Page 4

Asymptotics: Big Ө(...) - Called “big theta notation” - R(N) = runtime, f(N) = function, k’s = constants - The runtime can be both upper and lower bounded by the function - Let’s say R(N) = 3n3 + 2n2 + 1 - What is a good f(N), k , k ? 1 2 - f(N) = n3, k = 2, k = 4 1 2

Page 5

Asymptotics: Big O(...) - Called “big oh notation” - R(N) = runtime, f(N) = function, k = constant - The function is an upper bound on the runtime - DOES NOT MEAN WORST CASE - True or false? - N2 ∈ O(N2) - N2 ∈ O(N500) - N log N ∈ O(N) - log N ∈ O(N2)

Page 6

Asymptotics: Big Ω(...) - Called “big omega notation” - R(N) = runtime, f(N) = function, k = constant - The function is a lower bound on the runtime - DOES NOT MEAN BEST CASE - True or false? - N2 ∈ Ω(N2) - N ∈ Ω(1) - N2 ∈ Ω(N3)

Page 7

1 Basic Algorithmic Analysis Solutions: 1. f ∈ 𝛳(g) 2. f ∈ O(g) 3. f ∈ O(g) 4. f ∈ Ω(g) 5. f ∈ 𝛳(g)

Page 11

Bitwise Operators AND (&) OR (|) 0 __ 0 0 0 0 __ 1 0 1 1 __ 1 1 1 - x << y: shift the bit representation of x by y to the left (rest are filled with 0’s) - If x is 10011 and y is 2 - x << y is 01100 - x >> y: shift the bit representation of x by y to the right (rest are filled with 0’s) - If x is 10011 and y is 2

Page 12

3 A Bit with some Bits Let’s figure out what this question is asking first... Complete the following method such that it does what it is intended to do: given a list of integers, it returns an integer such that the i-th bit of the return value is 1 if and only if more than half of the integers in the list have 1 in the ith bit. Keep in mind that Java ints are 32 bits long!

Showing the first 12 pages. Download the document to see it all.

Comments (0)

Sign in to join the discussion

No comments yet. Be the first!