Topological Sorting algorithm

 

Questions:
1. (15 points) During lecture we discussed the Topological Sorting algorithm and situations
in which it might be used. Use the pseudocode below to write a script that performs a
topological sorting of a partially ordered set.
Algorithm 0.1 (Topological Sorting).
procedure topological sorting ((S, ≼): finite poset)
k := 1
while S ̸= ∅
ak := a minimal element of S { such that an element exists by the Lemma }
S := S − {ak}
k := k + 1
return a1, a2, . . . , an ({a1, a2, . . . , an} is a compatible total ordering of S.)
2. (15 points) Expanding on this idea, write a script that will take a partial ordering on a
finite set, constructs the covering relation, i.e. the Hasse Diagram, in adjacency matrix
form, and then applies your topological sorting script to find a compatible total ordering.
1
3. (20 points) In project management, there are two algorithms/tools often used in conjunction with one another to schedule tasks involved in completing a project. These
methods are known as Program Evaluation and Review Technique (PERT) and
Critical Path Method (CPM). From Wikipedia:
PERT and CPM are complementary tools, because ”CPM employs one time
estimation and one cost estimation for each activity; PERT may utilize three
time estimates (optimistic, expected, and pessimistic) and no costs for each
activity. Although these are distinct differences, the term PERT is applied
increasingly to all critical path scheduling.”
Below you will find some data describing a set of activities, their respective precedence,
and some time estimates for completion, where o is optimistic time, m is normal or most
likely time, and p is pessimistic time. Expected time is then calculated as a weighted
average of these by (o + 4m + p)/6.
Activity Predecessor Time estimates Expected time Opt. (o) Normal
(m)
Pess. (p)
A – 2 4 6 4.00
B – 3 5 9 5.33
C A 4 5 7 5.17
D A 4 6 10 6.33
E B,C 4 5 7 5.17
F D 3 4 8 4.50
G E 3 5 8 5.17
As we have not discussed weighted graphs or shortest-path problems yet, please complete
the following:
(a) Construct the precedence relation and represent it as a graph for the given set of
activities. Plot this graph.
(b) Construct the adjacency matrix for the precedence relation and display this matrix.
(c) Use your topological sorting script to find a compatible total ordering for the precedence relation.
(d) What other information should we consider if we wanted to optimize the schedule
for the tasks given? What would the “worst case scenario” be?

Sample Solution

Anne Frank needs a mother and a father to be born and that makes up a family. Anne’s mother was a tall broad woman that was married to Otto Frank. Otto and Edith had a daughter 3 years before Anne. Her name was Margot Frank. They lived together until the concentration camps. Otto was a wealthy businessman and ended up owning his own company. Mrs Frank was a stay home mom who would hold big parties there would be beef stew and bread and always pastries. Anne’s sister was everyone’s favorite. She never threw a fit or made a scene, yes she was the perfect child. In my opinion Anne had a loving family that always loved her.

Life before imprisonment was good. They didn’t have to worry about Germans or discrimination. Life was great for the Frank family and the other Jews.

Anne was born in Germany and had lots of memorable moments. She didn’t have to worry about Germans or discrimination. She could go to school with all the other kids and go see a movie with her family. With all the big cities like Hamburg, Bremen, Frankfurt, Munich, and East Prussia. Amsterdam had to be the most known with so many tourist attractions. I wish I could go and see Germany when I’m older so I can see the hiding place of Anne Frank.

Netherlands

Anne Frank moved to the Netherlands with her family for freedom from Germany. They moved hoping to get out of Hitler’s control but then Hitler took over almost all of Europe. But before that things were good. Anne was in school as well as Margot and Otto had a business to run. Anne also had many friends at school and never thought of Hitler being a threat. I wonder if Anne went to see the flowers a lot. She once said she used to take it all for granted and that she missed the flowers.

The Holocaust

Adolf Hitler comes to power. Hitler hated anyone who was not German and even then still didn’t trust everyone and even killed thousands of his own soldiers. He particularly discriminated against Jews. He would torture, beat, and killed millions of Jews so he could take over Germany.

Nazi parties were held in celebration of Adolf Hitler and his coming to power. People and children were taught to celebrate and appreciate the things that Hitler did and many didn’t question it. Children would give him flowers and teens would play in bands at the Nazi parties. It annoys and aggravates me to think about Hitler wanting fame for persecuting and killing Jews. Hitler was quoted saying in m

This question has been answered.

Get Answer
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, Welcome to Compliant Papers.