c241 pltl session – 2/22/2015 graph theory & binary search trees

6
C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Upload: annis-ryan

Post on 19-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

C241 PLTL SESSION – 2/22/2015Graph Theory & Binary Search Trees

Page 2: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Warm-Up Exercise• Grab a worksheet• Begin completing the worksheet in pairs or small groups

Page 3: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Problem 1Put the following sequence of numbers into a binary search tree data structure:8, 7, 9, 5, 20, 12, 1, 4

What is the root of your tree?

What is the depth of the resulting tree?

Page 4: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Problem 2Consider the binary search tree data structure. What other sorts of data could it be useful for storing? Come up with three different situations in which you would use a binary search tree (BST) to represent your data.

Page 5: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Problem 3Draw the following situation as a graph, (like the one from class today): In the domain of all people, everyone is mortal. Alex is nice and he trusts everyone, but no one trusts Alex. Ben and Chris trust each other, but only Ben is nice. Also, assume that everyone trusts themselves. (Note: In this context, “everyone” means Alex, Ben, and Chris. Also, think of the truth relation as a two-way street).

T(x, y) = x trusts yM(x) = x is mortalN(x) = x is nice

Page 6: C241 PLTL SESSION – 2/22/2015 Graph Theory & Binary Search Trees

Problem 4Given the situation drawn above, translate the following into statements of predicate logic, and then assess the truth of each statement:• A. Everyone is mortal.• B. Everyone is mortal or nice.• C. Everyone trusts someone.• D. Everyone who is trustworthy is also nice.• E. Someone trusts everyone.• F. Everyone trusts someone nice, excluding themselves.