Exercise 4: Conjunctive Queries, CSP, and Hypergraphs Database - - PowerPoint PPT Presentation

exercise 4 conjunctive queries csp and hypergraphs
SMART_READER_LITE
LIVE PREVIEW

Exercise 4: Conjunctive Queries, CSP, and Hypergraphs Database - - PowerPoint PPT Presentation

Exercise 4: Conjunctive Queries, CSP, and Hypergraphs Database Theory 2020-05-04 Maximilian Marx, David Carral 1 / 55 Exercise 1 Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO


slide-1
SLIDE 1

Exercise 4: Conjunctive Queries, CSP, and Hypergraphs

Database Theory 2020-05-04 Maximilian Marx, David Carral

1 / 55

slide-2
SLIDE 2

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

2 / 55

slide-3
SLIDE 3

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph.

3 / 55

slide-4
SLIDE 4

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution.

4 / 55

slide-5
SLIDE 5

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y z v

5 / 55

slide-6
SLIDE 6

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y z v (1) delete x, y

6 / 55

slide-7
SLIDE 7

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y z v (1) delete x, y (1) delete y, z

7 / 55

slide-8
SLIDE 8

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y z v (1) delete x, y (1) delete y, z (1) delete z, v

8 / 55

slide-9
SLIDE 9

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y z v (1) delete x, y (1) delete y, z (1) delete z, v (2) delete x

9 / 55

slide-10
SLIDE 10

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. y z v (1) delete x, y (1) delete y, z (1) delete z, v (2) delete x (2) delete y, z, v

10 / 55

slide-11
SLIDE 11

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. (1) delete x, y (1) delete y, z (1) delete z, v (2) delete x (2) delete y, z, v query is acyclic.

11 / 55

slide-12
SLIDE 12

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. (1) delete x, y (1) delete y, z (1) delete z, v (2) delete x (2) delete y, z, v

12 / 55

slide-13
SLIDE 13

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y v z u w

13 / 55

slide-14
SLIDE 14

Exercise 1

  • Exercise. Decide if the following conjunctive queries are tree queries by applying (one version of) the GYO algorithm.
  • 1. ∃x, y, z, v. r(x, y) ∧ r(y, z) ∧ r(z, v) ∧ s(x, y, z) ∧ s(y, z, v)
  • 2. ∃x, y, z, u, v, w. r(x, y) ∧ s(x, z, v) ∧ r(u, z) ∧ t(x, v, u, w)

Definition (Lecture 6, Slides 24)

A GYO-reduction is a procedure to check acyclicity: ◮ Input: hypergraph H = V, E (we do not need relation labels here) ◮ Output: GYO-reduct of H Apply the following simplification rules as long as possible: (1) Delete all hyperedges that are empty or that are contained in other hyperedges. (2) Delete all vertices that occur in at most one hyperedge. The input query is a tree query if the GYO-reduct of its hypergraph is the empty hypergraph. Solution. x y v z u w query is not acyclic.

14 / 55

slide-15
SLIDE 15

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly?

15 / 55

slide-16
SLIDE 16

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution.

16 / 55

slide-17
SLIDE 17

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution. ◮ ∃x, y, z . mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden")

17 / 55

slide-18
SLIDE 18

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution. ◮ ∃x, y, z, v . mother(x, y) ∧ father(x, z) ∧ bornIn(y, v) ∧ R"Dresden"(v) ∧ bornIn(z, "Dresden")

18 / 55

slide-19
SLIDE 19

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution. ◮ ∃x, y, z, v, w. mother(x, y) ∧ father(x, z) ∧ bornIn(y, v) ∧ R"Dresden"(v) ∧ bornIn(z, w) ∧ R"Dresden"(w)

19 / 55

slide-20
SLIDE 20

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution. ◮ ∃x, y, z, v, w. mother(x, y) ∧ father(x, z) ∧ bornIn(y, v) ∧ R"Dresden"(v) ∧ bornIn(z, w) ∧ R"Dresden"(w) ◮ The query is acyclic.

20 / 55

slide-21
SLIDE 21

Exercise 2

Exercise. It was outlined in the lecture how to eliminate constants from CQs to transform them to graphs. Apply this transformation to the following query: ∃x, y, z. mother(x, y) ∧ father(x, z) ∧ bornIn(y, "Dresden") ∧ bornIn(z, "Dresden"). Is the transformed query a tree query? Imagine we would keep constants in the hypergraph, so that each hypergraph would contain two kinds of vertices (variables and constants). How could we modify the GYO algorithm to handle such hypergraphs directly? Solution. ◮ ∃x, y, z, v, w. mother(x, y) ∧ father(x, z) ∧ bornIn(y, v) ∧ R"Dresden"(v) ∧ bornIn(z, w) ∧ R"Dresden"(w) ◮ The query is acyclic. ◮ Add rule: “Delete all vertices labelled with constants.”

21 / 55

slide-22
SLIDE 22

Exercise 3

  • Exercise. Solve the following combinatorial crossword puzzle using Yannakakis’ algorithm (in spirit). Specify the join

tree that you are using.

22 / 55

slide-23
SLIDE 23

Exercise 3

  • Exercise. Solve the following combinatorial crossword puzzle using Yannakakis’ algorithm (in spirit). Specify the join

tree that you are using. Solution.

23 / 55

slide-24
SLIDE 24

Exercise 3

  • Exercise. Solve the following combinatorial crossword puzzle using Yannakakis’ algorithm (in spirit). Specify the join

tree that you are using. Solution. Join tree: 1 hor. 1 vert. 3 vert. 7 vert. 13 hor. 21 hor.

24 / 55

slide-25
SLIDE 25

Exercise 3

  • Exercise. Solve the following combinatorial crossword puzzle using Yannakakis’ algorithm (in spirit). Specify the join

tree that you are using. Solution. Join tree: 1 hor. 1 vert. 3 vert. 7 vert. 13 hor. 21 hor. S P I N A C H H N O A F W I N R E E K R W A Y

25 / 55

slide-26
SLIDE 26

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

26 / 55

slide-27
SLIDE 27

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain. Solution.

27 / 55

slide-28
SLIDE 28

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

28 / 55

slide-29
SLIDE 29

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w)

29 / 55

slide-30
SLIDE 30

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z)

30 / 55

slide-31
SLIDE 31

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}.

31 / 55

slide-32
SLIDE 32

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}. ◮ Then I |= q iff I′ |= q′.

32 / 55

slide-33
SLIDE 33

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}. ◮ Then I |= q iff I′ |= q′. ◮ Query q′ is acyclic and can thus be answered in polynomial time with respect to the size of the database I′.

33 / 55

slide-34
SLIDE 34

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}. ◮ Then I |= q iff I′ |= q′. ◮ Query q′ is acyclic and can thus be answered in polynomial time with respect to the size of the database I′. ◮ But computing I′ from I requires adding | adom(I)|5 new facts.

34 / 55

slide-35
SLIDE 35

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}. ◮ Then I |= q iff I′ |= q′. ◮ Query q′ is acyclic and can thus be answered in polynomial time with respect to the size of the database I′. ◮ But computing I′ from I requires adding | adom(I)|5 new facts. ◮ Thus answering q′ still takes exponential time with respect to the size of I.

35 / 55

slide-36
SLIDE 36

Exercise 4

  • Exercise. It is easy to see that the following is true: For a hypergraph H = V, E, the hypergraph H′ = V, E ∪ {eV }

is acyclic with eV a hyperedge that contains every vertex of V. Therefore, every BCQ can be transformed into a tree query by adding suitable atoms. Does this imply that every BCQ can be answered in polynomial time? Explain.

  • Solution. Let us consider a naive strategy:

◮ Let q = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ◮ Let q′ = ∃v, w, x, y, z. P(x, y, z) ∧ Q(z, w) ∧ R(w, v, x) ∧ S(y, w) ∧ X(v, w, x, y, z) ◮ For a database instance I, let I′ = I ∪ {X(c1, . . . , c5) | c1, . . . , c5 ∈ adom(I)}. ◮ Then I |= q iff I′ |= q′. ◮ Query q′ is acyclic and can thus be answered in polynomial time with respect to the size of the database I′. ◮ But computing I′ from I requires adding | adom(I)|5 new facts. ◮ Thus answering q′ still takes exponential time with respect to the size of I. ◮ In general, | adom(I)||V| new facts are necessary.

36 / 55

slide-37
SLIDE 37

Exercise 5.

Exercise. Sudoku is a one-player puzzle game where one has to fill a grid with numbers. An example 4 × 4-Sudoku is as follows: The grid has to be filled with numbers {1, 2, 3, 4} such that every number occurs exactly once in each row, each column, and each 2 × 2-subgrid bordered in bold. For an arbitrary 4 × 4-Sudoku, specify a BCQ q and a database instance J such that J |= q if and only if the given Sudoku has a solution.

37 / 55

slide-38
SLIDE 38

Exercise 5.

Exercise. Sudoku is a one-player puzzle game where one has to fill a grid with numbers. An example 4 × 4-Sudoku is as follows: The grid has to be filled with numbers {1, 2, 3, 4} such that every number occurs exactly once in each row, each column, and each 2 × 2-subgrid bordered in bold. For an arbitrary 4 × 4-Sudoku, specify a BCQ q and a database instance J such that J |= q if and only if the given Sudoku has a solution. Solution.

38 / 55

slide-39
SLIDE 39

Exercise 5.

Exercise. Sudoku is a one-player puzzle game where one has to fill a grid with numbers. An example 4 × 4-Sudoku is as follows: The grid has to be filled with numbers {1, 2, 3, 4} such that every number occurs exactly once in each row, each column, and each 2 × 2-subgrid bordered in bold. For an arbitrary 4 × 4-Sudoku, specify a BCQ q and a database instance J such that J |= q if and only if the given Sudoku has a solution. Solution. ◮ We define J =        S(c1

1, . . . , c4 1, . . . , c1 4, . . . , c4 4)

  • cj

i ∈

       { k } if position i, j contains the number k, and { 1, 2, 3, 4 } otherwise       .

39 / 55

slide-40
SLIDE 40

Exercise 5.

Exercise. Sudoku is a one-player puzzle game where one has to fill a grid with numbers. An example 4 × 4-Sudoku is as follows: The grid has to be filled with numbers {1, 2, 3, 4} such that every number occurs exactly once in each row, each column, and each 2 × 2-subgrid bordered in bold. For an arbitrary 4 × 4-Sudoku, specify a BCQ q and a database instance J such that J |= q if and only if the given Sudoku has a solution. Solution. ◮ We define J =        S(c1

1, . . . , c4 1, . . . , c1 4, . . . , c4 4)

  • cj

i ∈

       { k } if position i, j contains the number k, and { 1, 2, 3, 4 } otherwise       . ◮ We set y = y1

1 , . . . , y4 1 , . . . , y1 4 , . . . , y4 4 , and let q be the query

∃y.

  • S(y) ∧

4

  • k=1

4

  • i=1

4

  • j=i+1
  • yi

k yj k) ∧ 4

  • k=1

4

  • i=1

4

  • j=i+1
  • yk

i yk j ) ∧

  • i∈{ 1,3 }
  • j∈{ 1,3 }

(yj

i yj+1 i+1 ) ∧ (yj i+1 yj+1 i

)

  • .

40 / 55

slide-41
SLIDE 41

Exercise 5.

Exercise. Sudoku is a one-player puzzle game where one has to fill a grid with numbers. An example 4 × 4-Sudoku is as follows: The grid has to be filled with numbers {1, 2, 3, 4} such that every number occurs exactly once in each row, each column, and each 2 × 2-subgrid bordered in bold. For an arbitrary 4 × 4-Sudoku, specify a BCQ q and a database instance J such that J |= q if and only if the given Sudoku has a solution. Solution. ◮ We define J =        S(c1

1, . . . , c4 1, . . . , c1 4, . . . , c4 4)

  • cj

i ∈

       { k } if position i, j contains the number k, and { 1, 2, 3, 4 } otherwise       . ◮ We set y = y1

1 , . . . , y4 1 , . . . , y1 4 , . . . , y4 4 , and let q be the query

∃y.

  • S(y) ∧

4

  • k=1

4

  • i=1

4

  • j=i+1
  • yi

k yj k) ∧ 4

  • k=1

4

  • i=1

4

  • j=i+1
  • yk

i yk j ) ∧

  • i∈{ 1,3 }
  • j∈{ 1,3 }

(yj

i yj+1 i+1 ) ∧ (yj i+1 yj+1 i

)

  • .

◮ Then J |= q iff the Sudoku has a solution.

41 / 55

slide-42
SLIDE 42

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?

42 / 55

slide-43
SLIDE 43

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?

Reduction.

43 / 55

slide-44
SLIDE 44

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q }

44 / 55

slide-45
SLIDE 45

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q } ◮ Given a graph G = V, E, let I = {E(r, b), E(b, g), E(g, r)} and let q be the BCQ ∃

v∈V xv.

  • v,u∈E

E(xv, xu) containing the atom E(xv, xu) if and only if there is an edge between v and u in G.

45 / 55

slide-46
SLIDE 46

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q } ◮ Given a graph G = V, E, let I = {E(r, b), E(b, g), E(g, r)} and let q be the BCQ ∃

v∈V xv.

  • v,u∈E

E(xv, xu) containing the atom E(xv, xu) if and only if there is an edge between v and u in G. ◮ Then G ∈ 3C iff I, q ∈ QE.

46 / 55

slide-47
SLIDE 47

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q } ◮ Given a graph G = V, E, let I = {E(r, b), E(b, g), E(g, r)} and let q be the BCQ ∃

v∈V xv.

  • v,u∈E

E(xv, xu) containing the atom E(xv, xu) if and only if there is an edge between v and u in G. ◮ Then G ∈ 3C iff I, q ∈ QE. Solution.

47 / 55

slide-48
SLIDE 48

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q } ◮ Given a graph G = V, E, let I = {E(r, b), E(b, g), E(g, r)} and let q be the BCQ ∃

v∈V xv.

  • v,u∈E

E(xv, xu) containing the atom E(xv, xu) if and only if there is an edge between v and u in G. ◮ Then G ∈ 3C iff I, q ∈ QE. Solution.

  • 1. q is a tree query when G is acyclic.

48 / 55

slide-49
SLIDE 49

Exercise 6.

  • Exercise. It was shown in the lecture that the 3-colourability problem for graphs can be reduced to the homomorphism
  • problem. Therefore, it can also be expressed as a BCQ answering problem.
  • 1. In which cases is the resulting BCQ a tree query?
  • 2. What is the complexity of solving the 3-colourability problem for these cases?
  • Reduction. Recall the definition of the two decision problems:

3C = { G | G is three-colourable } QE = { I, q | I |= q } ◮ Given a graph G = V, E, let I = {E(r, b), E(b, g), E(g, r)} and let q be the BCQ ∃

v∈V xv.

  • v,u∈E

E(xv, xu) containing the atom E(xv, xu) if and only if there is an edge between v and u in G. ◮ Then G ∈ 3C iff I, q ∈ QE. Solution.

  • 1. q is a tree query when G is acyclic.
  • 2. If G is acyclic, then q can be answered in constant time.

49 / 55

slide-50
SLIDE 50

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

50 / 55

slide-51
SLIDE 51

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

  • Remark. This yields an alternative proof of the NP-hardness of the homomorphism problem.

51 / 55

slide-52
SLIDE 52

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

  • Remark. This yields an alternative proof of the NP-hardness of the homomorphism problem.

Solution.

52 / 55

slide-53
SLIDE 53

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

  • Remark. This yields an alternative proof of the NP-hardness of the homomorphism problem.

Solution. ◮ Iϕ is the hypergraph consisting of all edges C(Li

1, Li 2, Li 3) with 1 ≤ i ≤ n and all edges V(L, ¬L) for every positive

literal L syntactically occurring in ϕ.

53 / 55

slide-54
SLIDE 54

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

  • Remark. This yields an alternative proof of the NP-hardness of the homomorphism problem.

Solution. ◮ Iϕ is the hypergraph consisting of all edges C(Li

1, Li 2, Li 3) with 1 ≤ i ≤ n and all edges V(L, ¬L) for every positive

literal L syntactically occurring in ϕ. ◮ J =

  • C(x, y, z)
  • x, y, z ∈ { 0, 1 } with x + y + z > 0
  • V(0, 1), V(1, 0)
  • 54 / 55
slide-55
SLIDE 55

Exercise 7.

  • Exercise. A propositional formula is in 3CNF if it has the following form:

(L1

1 ∨ L1 2 ∨ L1 3) ∧ (L2 1 ∨ L2 2 ∨ L2 3) ∧ · · · ∧ (Ln 1 ∨ Ln 2 ∨ Ln 3),

where each L is a literal, that is, a propositional variable or the negation of a propositional variable. The 3SAT problem is the problem of deciding if a given 3CNF formula is satisfiable. It is known to be NP-complete. Reduce 3SAT to the homomorphism problem: define a suitable hypergraph Iϕ for every 3CNF ϕ and give a template J, such that there is a homomorphism from Iϕ to J iff ϕ is satisfiable (the template J can be the same for all inputs.)

  • Remark. This yields an alternative proof of the NP-hardness of the homomorphism problem.

Solution. ◮ Iϕ is the hypergraph consisting of all edges C(Li

1, Li 2, Li 3) with 1 ≤ i ≤ n and all edges V(L, ¬L) for every positive

literal L syntactically occurring in ϕ. ◮ J =

  • C(x, y, z)
  • x, y, z ∈ { 0, 1 } with x + y + z > 0
  • V(0, 1), V(1, 0)
  • ◮ Then ϕ is satisfiable iff there is a homomorphsim from IϕtoJ.

55 / 55