slides

advertisement
CSE 20
DISCRETE MATH
Prof. Shachar Lovett
http://cseweb.ucsd.edu/classes/wi15/cse20-a/
Clicker
frequency:
CA
Todays topics
• Order relations
• Section 6.3 in Jenkyns, Stephenson
Order relations
• Natural order relations that we know on integer numbers:
• 𝑥≤𝑦
• What is an abstract definition of an order?
• What are other examples?
• What is it good for?
Partial order
• A relation R is a partial order if it satisfies three properties:
(think ≤)
• Reflexive: ∀𝑥, 𝑥𝑅𝑥
• Transitive: ∀𝑥, 𝑦, 𝑧, (𝑥𝑅𝑦 ∧ 𝑦𝑅𝑧) → 𝑥𝑅𝑧
• Anti-symmetric: ∀𝑥, 𝑦,
𝑥𝑅𝑦 ∧ 𝑦𝑅𝑥 → 𝑥 = 𝑦
Equivalently:
if 𝑥 ≠ 𝑦 then we cannot have both 𝑥𝑅𝑦 and 𝑦𝑅𝑥
Partial order
• Definition: reflexive, transitive, anti-symmetric
• Equality relation: xRy if 𝑥 ≤ 𝑦
• Is it a partial order?
A. Yes
B. No
Partial order
• Definition: reflexive, transitive, anti-symmetric
• Equality relation: xRy if x=y
• Is it a partial order?
A. Yes
B. No
Partial order
• U={1,2,3,4}
• Relation: 1 ≤ 2, 1 ≤ 4, 3 ≤ 4
• Is it a partial order?
A. Yes
B. No
Partial order
• U={1,2,3,4}
• Relation: 1 ≤ 2, 1 ≤ 4, 3 ≤ 4, 4 ≤ 2
• Is it a partial order?
A. Yes
B. No
Total order
• A partial order is a total order if any pair can be compared
• That is, ∀𝑥, 𝑦, 𝑥𝑅𝑦 ∨ 𝑦𝑅𝑥
• Is the usual ≤ order on rational numbers a total order?
A. Yes
B. No
Total order
• A partial order is a total order if any pair can be compared
• That is, ∀𝑥, 𝑦, 𝑥𝑅𝑦 ∨ 𝑦𝑅𝑥
• 𝑈 =𝑁×𝑁
• 𝑥1 , 𝑥2 ≤ (𝑦1 , 𝑦2 ) if 𝑥1 ≤ 𝑥2 and 𝑦1 ≤ 𝑦2
• Is it a total order?
A. Yes
B. No
Total order
• A partial order is a total order if any pair can be compared
• That is, ∀𝑥, 𝑦, 𝑥𝑅𝑦 ∨ 𝑦𝑅𝑥
• Lexicographic order (on pairs):
• 𝑈 =𝑁×𝑁
• 𝑥1 , 𝑥2 ≤ (𝑦1 , 𝑦2 ) if 𝑥1 < 𝑥2 ; or 𝑥1 = 𝑥2 and 𝑦1 ≤ 𝑦2
• Is it a total order?
A. Yes
B. No
Lexicographic order
• It is often useful to define orders on sequences
• Example: universe = sequences of integers of length n
𝑈 = { 𝑥1 , … , 𝑥𝑛 : 𝑥1 , … , 𝑥𝑛 ∈ 𝑍}
• Lexicographic order:
𝑥1 , … , 𝑥𝑛 ≤ (𝑦1 , … , 𝑦𝑛 )
If for some 1 ≤ 𝑖 ≤ 𝑛,
𝑥1 = 𝑦1 , … , 𝑥𝑖−1 = 𝑦𝑖−1 , 𝑥𝑖 ≤ 𝑦𝑖
That is, we compare the first element that is different
Orders on sequences
• Which one of the following is the largest one?
A. (1,2,5,10)
B. (10,5,2,1)
C. (5,100,3,3)
D. (10,7,100,1000)
Maximal / maximum elements
• We don’t always have the “largest element”
• There are two important definitions
• Maximum element: an element greater than all other
elements. x is the maximum of a set A if
∀𝑦 ∈ 𝐴, 𝑥 ≥ 𝑦
• Maximal element: an element which no other element is
greater from. x is a maximal element in a set A if
∀𝑦 ∈ 𝐴 ∖ {𝑥}, ~(𝑦 ≥ 𝑥)
Maximal / maximum elements
• U={1,2,3,4}
• Relation: 1 ≤ 2, 1 ≤ 4, 3 ≤ 4
• Is there a maximal element?
A. Yes
B. No
Maximal / maximum elements
• U={1,2,3,4}
• Relation: 1 ≤ 2, 1 ≤ 4, 3 ≤ 4
• Is there a maximum element?
A. Yes
B. No
Maximal / maximum elements
• There could be multiple maximal elements in a set, but
the maximal element (if it exists) must be unique
• Lets prove it
Maximal / maximum elements
• There could be multiple maximal elements in a set, but
the maximal element (if it exists) must be unique
• Lets prove it
• Theorem: a maximum element (if it exists) must be unique
Proof: assume towards contradiction there are two
maximum elements, x and y.
x is maximum → 𝑥 ≥ 𝑦
y is maximum → 𝑦 ≥ 𝑥
Relation is anti-symmetric: 𝑥 ≥ 𝑦 ∧ 𝑦 ≥ 𝑥 → 𝑥 = 𝑦
Minimal / minimum elements
• Very similar to maximal/maximum
• Minimum element: an element smaller than all other
elements. x is the minimum of a set A if
∀𝑦 ∈ 𝐴, 𝑥 ≤ 𝑦
• Minimal element: an element which no other element is
smaller from. x is a minimal element in a set A if
∀𝑦 ∈ 𝐴 ∖ {𝑥}, ~(𝑦 ≤ 𝑥)
Maximum/maximal/minimum/minimal
• 𝑈 =𝑁×𝑁
• 𝑥1 , 𝑥2 ≤ (𝑦1 , 𝑦2 ) if 𝑥1 ≤ 𝑥2 and 𝑦1 ≤ 𝑦2
• This is NOT lexicographical order
• Which one is larger?
A. (10,20)
B. (20,10)
C. None
Maximum/maximal/minimum/minimal
• 𝑈 =𝑁×𝑁
• 𝑥1 , 𝑥2 ≤ (𝑦1 , 𝑦2 ) if 𝑥1 ≤ 𝑥2 and 𝑦1 ≤ 𝑦2
• Does it have
A. Maximum element
B. Maximal elements, but no maximum element
C. Neither
Maximum/maximal/minimum/minimal
• 𝑈 =𝑁×𝑁
• 𝑥1 , 𝑥2 ≤ (𝑦1 , 𝑦2 ) if 𝑥1 ≤ 𝑥2 and 𝑦1 ≤ 𝑦2
• Does it have
A. Minimum element
B. Minimal elements, but no minimum element
C. Neither
Back to total orders
• Total order means that we can compare any two elements
• Theorem: in a total order, a maximal element must be the
(unique) maximum
Proof: let x be a maximal element. For any 𝑦 ≠ 𝑥, this
means that ~(𝑥 ≤ 𝑦). But since this is a total order, this
implies that 𝑦 ≤ 𝑥.
Sorting
• Sorting is a basic primitive used by many algorithms
• Most sorting algorithms are “abstract”, in the sense that
they can apply to any partial order
• Naïve sorting on n elements requires comparing all pairs
of elements, which takes ~n2 comparisons
• Fast sorting algorithms (for example, quicksort) can do it
using only n log n comparisons
• This can be proven to be tight!
Next class
• Knights and knaves
Download