Background A partially ordered set ("poset") is a set S together with a partial order ≼ on the elements from S . A partial order graph for a finite poset (S,≼) is a directed graph ("digraph") with the...

1 answer below »

Background


A
partially ordered set
("poset") is a set S together with a partial order ≼ on the elements from
S.



A
partial order graph
for a finite poset (S,≼) is a directed graph ("digraph") with




  • the elements in S as vertices


  • a directional edge from s to t if, and only if, s ≼ t and s ≠ t


Example:
[Graph:Pic/order4.png]


where




  • S = {1, 11, 13, 143}


  • s ≼ t iff s is a divisor of t



A
monotonically increasing sequence
of length
k
over a poset (S,≼) is a sequence of elements from S,


s1
≺ s2
≺ … s
k-1

≺ s
k

such that si
≼ si+1
and si
≠ si+1, for all i=1…k-1. Examples:


  • 1 ≺ 11 ≺ 143 and 1 ≺ 13 ≺ 143 are monotonically increasing sequences of length 3 over the poset from above.


  • 1 ≺ 121 is a monotonically increasing sequence of length 2 over this poset.


Aim


Your task is to write a program poG.c for computing a partial order graph from a given specification and then find and output
all longest
monotonically increasing sequences that can be constructed over this poset.


Your program should:




  • accept a single positive number
    p
    on the command line;


  • compute the set S
    p

    of all (positive) divisors of
    p;


  • Task A:


    • build and output the partial order graph over S
      p

      corresponding to a specific partial order (see below);




  • Task B:


    • output all longest monotonically increasing sequences over this partial order.





Your program should include a time complexity analysis, in Big-Oh notation, for




  1. your implementation for Task A, depending on the number
    n
    of divisors of
    p
    and the length
    m
    of the decimal
    p;


  2. your implementation for Task B, depending on the number
    n
    of divisors of
    p.


Hints



You may assume that




  • the command line argument is correct (a number
    p
    ≥1);


  • p
    is at most 2,147,483,647 (the maximum 4-byte int);


  • p
    will have no more than 1000 divisors.


If you find any of the following ADTs from the lectures useful, then you can, and indeed are encouraged to, use them with your program:



You are free to modify any of the four ADTs for the purpose of the assignment (but without changing the file names). If your program is using one or more of these ADTs, you should submit both the header and implementation file, even if you have not changed them.



Your main program file should start with a comment: /* … */ that contains the time complexity of your solutions for Task A and Task B, together with an explanation.




Stage 1 (2 marks)


For stage 1, you should demonstrate that you can build the underlying graph correctly from all divisors of input
p
and the following partial order:


x ≼ y iff x is a divisor of y

All you need to do for Task B at this stage is to output all nodes of the graph in ascending order.


Here is an example to show the desired behaviour of your program for a stage 1 test:

./poG 121
Partial order: 1: 11 121 11: 121 121: Longest monotonically increasing sequences: 1

[Graph:Pic/order1.png]



Hint:
The only tests for this stage will be with numbers
p
for which the above order is identical to the stricter partial order for stages 2–4, and such that all of the divisors of
p
together form a monotonically increasing sequence.




Stage 2 (3 marks)


For stage 2, you should extend your program for stage 1 such that it puts an additional constraint on the partial order of the divisors of
p:



x ≼ y iff




  • x is a divisor of y,
    and


  • all digits in x also occur in y


For example, 11 ≺ 143 since 1 is also contained in 143, but 16 ⊀ 128 since 6 is not a digit in 128.

All you need to do for Task B at this stage is to find and oputput the path that starts in 1 and always selects the next neighbour in ascending order until you reach a node without outgoing edge.


Here is an example to show the desired behaviour of your program for a stage 2 test:

./poG 9481
Partial order: 1: 19 9481 19: 9481 499: 9481 9481: Longest monotonically increasing sequences: 1

[Graph:Pic/order2.png]




Hint:
All tests for this stage will be such that the only longest monotonically increasing sequence is the unique path from 1 to
p
obtained by always moving to the next neighbour in ascending order.




Stage 3 (3 marks)


For stage 3, you should demonstrate that you can find a
single
longest monotonically increasing sequence.


All tests for this stage will be such that there is a unique longest sequence.


Here is an example to show the desired behaviour of your program for a stage 3 test:

./poG 125
Partial order: 1: 125 5: 25 125 25: 125 125: Longest monotonically increasing sequences: 5

[Graph:Pic/order3.png]


Stage 4 (4 marks)


For stage 4, you should extend your program for stage 3 such that it outputs, in ascending order, all monotonically increasing sequences of maximal length.


Here is an example to show the desired behaviour of your program for a stage 4 test:

./poG 143
Partial order: 1: 11 13 143 11: 143 13: 143 143: Longest monotonically increasing sequences: 1

[Graph:Pic/order4.png]



Note:




  • It is required that the sequences be printed in ascending order.




Testing



We have created a script that can automatically test your program. To run this test you can execute the
dryrun
program for the corresponding assignment, i.e. assn2. It expects to find, in the current directory, the program
poG.c
and any of the admissible ADTs (Graph,WGraph,stack,queue) that your program is using, even if you use them unchanged. You can use dryrun as follows:



~cs9024/bin/dryrun assn2


Please note: Passing the dryrun tests does not guarantee that your program is correct. You should thoroughly test your program with your own test cases.


Submit


For this project you will need to submit a file named poG.c and, optionally, any of the ADTs named Graph,WGraph,stack,queue that your program is using, even if you have not changed them. You can either submit through WebCMS3 or use a command line. For example, if your program uses the Graph ADT and the queue ADT, then you should submit:

give cs9024 assn2 poG.c Graph.h Graph.c queue.h queue.c

Do not forget to add the time complexity to your main source code file poG.c.


You can submit as many times as you like — later submissions will overwrite earlier ones. You can check that your submission has been received on WebCMS3 or by using the following command:

9024 classrun -check assn2
Answered Same DaySep 16, 2020COMP9024

Answer To: Background A partially ordered set ("poset") is a set S together with a partial order ≼ on the...

Meenakshi answered on Sep 26 2020
136 Votes
#include
#include
typedef struct treeNode
{
int data;
struct treeNode *left;
struct treeNode *right;
}treeNode;
treeNode* Fin
dMin(treeNode *node)
{
if(node==NULL)
{
/* There is no element in the tree */
return NULL;
}
if(node->left) /* Go to the left sub tree to find the min element */
return FindMin(node->left);
else
return node;
}
treeNode* FindMax(treeNode *node)
{
if(node==NULL)
{
/* There is no element in the tree */
return NULL;
}
if(node->right) /* Go to the left sub tree to find the min element */
FindMax(node->right);
else
return node;
}
treeNode * Insert(treeNode *node,int data)
{
if(node==NULL)
{
treeNode *temp;
temp = (treeNode *)malloc(sizeof(treeNode));
temp -> data = data;
temp -> left = temp -> right = NULL;
return temp;
}
if(data >(node->data))
{
node->right = Insert(node->right,data);
}
else if(data < (node->data))
{
node->left = Insert(node->left,data);
}
/* Else there is nothing to do as the data is already in the tree. */
return node;
}
treeNode * Delete(treeNode *node, int data)
{
treeNode *temp;
if(node==NULL)
{
printf("Element Not Found");
}
else if(data < node->data)
{
node->left = Delete(node->left, data);
}
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here