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

Inhalt des Dokuments

Seite 2

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

Seite 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

Seite 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

Seite 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)

Seite 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)

Seite 7

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

Seite 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

Seite 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!

Die ersten 12 Seiten werden angezeigt. Laden Sie das Dokument herunter, um alles zu sehen.

Kommentare (0)

Anmelden um an der Diskussion teilzunehmen

Noch keine Kommentare. Seien Sie der Erste!