HW 5
HW 5
CENG 223
Discrete Computational Structures
Fall 2018-2019
Homework 5
S = {w : w is a binary string, |w| ≤ 3 , |n0 (w) − n1 (w)| ≤ 1 , and w does not begin and does not end with 00}
R = {(w1 , w2 ) : w1 ∈ S , w2 ∈ S and w1 is a substring of w2 }
where |w| denotes the length of the string w, n0 (w) and n1 (w) are functions that map input strings w to the number
of 0's and 1's in w, respectively. Also, use the convention that w1 is a substring of w2 if and only if w1 is contained
entirely within w2 for any given strings w1 and w2 .
a. Draw R as a directed graph. (2 pts)
b. Prove that (S, R) is a poset. (4 pts)
c. Is (S, R) a total order? Prove your answer. (3 pts)
d. Draw a Hasse diagram for (S, R). State the maximal and minimal elements. (4 pts)
e. Identify whether (S, R) constitutes a lattice or not. (2 pts)
a e
d c f g
1
a. Provide an adjacency list representation of G. (3 pts)
b. Provide an adjaceny matrix representation of G. (3 pts)
c. Compute indegrees and outdegrees of every vertex in V . (3 pts)
d. List 6 different simple paths of length 4 in G. (3 pts)
e. List all simple circuits of length 3 in G. (3 pts)
f. Prove that G is weakly-connected. (3 pts)
g. Identify strongly-connected components of G. (3 pts)
h. How many different paths of length 3 exist between every distinct pairs of vertices in the subgraph H of G
induced by the vertices {a, b, c, d} ⊂ V ? (3 pts)
a b c d
e f g
h i j k
2
Question 5 (20 pts)
Given the undirected graph G in Figure 3, answer the questions.
11 y
u
6
4 8 1 9
5 2
1 s v x 4 t
3 3 6 3
8
w z
12
a. Find the shortest path from s to t using Dijkstra's algorithm. Clearly show each step. (7 pts)
b. Find a minimum spanning tree with root as vertex x using Prim's algorithm in Section 11.5 of the textbook.
Explicitly show every step of computation. (5 pts)
c. Following edges are added to G one-by-one in order:
• (s, x, 1)
• (t, u, 6)
• (s, z, −3)
• (u, y, 3)
• (w, z, −1).
Without ever calling Prim's algorithm (or any other algorithm computing minimum spanning trees for graphs
from scratch), modify the minimum spanning tree you generated in b so that it maintains to be a minimum
spanning tree after the first weighted edge is added to G. Repeat this for the remaining edges, each time
modifying the previously constructed minimum spanning tree. Separately draw minimum spanning trees of
G for each new edge in given order. (5 pts)
d. Do you think you can iteratively update the shortest path from s to t without calling Dijkstra's algorithm
upon the arrival of listed edges in c? Justify your answer. (3 pts)
3
p:42
q:34 r:75
n:61
a. What are the number of vertices, the number of edges and the height of T ? (1 pt)
b. Carry out a postorder traversal of T and write down the order in which vertices are visited. (1 pt)
c. Carry out an inorder traversal of T and write down the order in which vertices are visited. (1 pt)
d. Carry out a preorder traversal of T and write down the order in which vertices are visited. (1 pt)
e. Is T a full binary tree? Justify your answer. (1 pt)
f. Is T a binary search tree using provided keys under comparison with respect to the ≤ relation defined on
Z × Z? Justify your answer. (1 pt)
g. What is the minimum number of vertices in a full ternary (m = 3) tree of height h such that h ∈ N+ ? (1 pt)
h. Construct a binary search tree of minimum height for the following set of integer keys {9, 3, 11, 15, 1, 7, 22, 21, 4}
employing the ≤ relation defined on Z × Z. (2 pts)
i. Using the binary search tree in h, give sequences of vertices that are probed in order to find vertices with
key values 2 and 22, repsectively. (1 pt)
j. Construct a binary search tree of maximum height for the following set of binary string keys {001, 1, 10, 010, 0000}
using lexicographic ordering (how strings would be listed in a dictionary assuming that 0 comes before 1 in
the alphabet) for comparison. (2 pts)
k. Using the binary search tree in j, give sequences of vertices that are probed so as to find vertices with key
values 001 and 011, respectively. (1 pt)
l. Construct a spanning forest for the directed graph G in Figure 1 via breadth-first search under the assumption
that unvisited vertices are selected for expansion in reverse alphabetic order of vertex identifiers. (2 pts)
4
1 Regulations
1. You have to write your answers to the provided sections of the template answer file given. Other than that,
you cannot change the provided template answer file. If a latex structure you want to use cannot be compiled
with the included packages in the template file, that means you should not use it.
2. Do not write any other stuff, e.g. question definitions, to answers’ sections. Only write your answers.
Otherwise, you will get 0 from that question.
3. Late Submission: Not allowed
4. Cheating: We have zero tolerance policy for cheating. People involved in cheating will be punished
according to the university regulations.
5. Newsgroup: You must follow the newsgroup (news.ceng.metu.edu.tr) for discussions and possible updates
on a daily basis.
6. Evaluation: Your latex file will be converted to pdf and evaluated by course assistants. The .tex file will be
checked for plagiarism automatically using ”black-box” technique and manually by assistants, so make sure
to obey the specifications.
2 Submission
Submission will be done via COW. Download the given template file, “hw5.tex”, when you finish your exam upload
the .tex file with the same name to COW.
Note: You cannot submit any other files. Don’t forget to make sure your .tex file is successfully compiled in
Inek machines using the command below.
$ pdflatex hw5.tex