Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an algorithm that, given two nodes of a graph, uses the ideas of partition

ID: 3576614 • Letter: W

Question

Write an algorithm that, given two nodes of a graph, uses the ideas of partitioning sets as given below to determine if the two nodes are connected InitializePartition (N) {for i = 1 to N do Parent[1] = -1 end do} FindRoot (s) {result = s while Parent[result] > 0 do result = Parent[result] end while return result} Union (i, j) {//i, j - the partitions to join together totalElements = Parent[i] + Parent [j] if Parent[i] greaterthanorequalto Parent[j] then Parent [i] = j Parent[1] = totalElements else Parent[j] = i Parent[i] = totaElements end if}

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

struct node
;
typedef struct node n;

n* create_node(int);
void add_node();
void insert_at_first();
void insert_at_end();
void insert_at_position();
void delete_node_position();
void sort_list();
void update();
void search();
void display_from_beg();
void display_in_rev();

n *new, *ptr, *prev;
n *first = NULL, *last = NULL;
int variety = 0;

void main()
come new;
}
/*
*ADDS NEW NODE
*/
void add_node()
next = new;
new->prev = last;
last = new;
last->next = first;
first->prev = last;
" id="tip_19">
}
/*
*INSERTS part initially
*/
void insert_at_first()
currently new node is inserted however at first");
initial = last = new;
first->next = last->next = NULL;
first->prev = last->prev = NULL;
}
else
  
}
/*
*INSERTS THE part AT GIVEN POSITION
*/
void insert_at_position()
{
int info, pos, len = 0, i;
n *prevnode;

printf(" enter the worth that you simply would love to insert:");
scanf("%d", &info);
printf(" enter the position wherever you have got to enter:");
scanf("%d", &pos);
new = create_node(info);

if (first == last && initial == NULL)
{
if (pos == 1)
{
initial = last = new;
first->next = last->next = NULL;
first->prev = last->prev = NULL;
}
else
printf(" empty coupled list you cant insert at that specific position");
}
else
  
}
}
for (ptr = initial, i = 0;i < number;ptr = ptr->next,i++)
printf(" %d", ptr->val);
}
}
/*
*DELETION is completed
*/
void delete_node_position()
zero, key, i, f = 0;

printf(" enter the worth to be searched:");
scanf("%d", &key);

if (first == last && initial == NULL)
printf(" list is empty no elemnets in list to search");
else
{
for (ptr = initial,i = 0;i < number;i++,ptr = ptr->next)
{
count++;
if (ptr->val == key)
{
printf(" the worth is found at position at %d", count);
f = 1;
}
}
if (f == 0)
printf(" the worth isn't found in linkedlist");
}
}
/*
*DISPLAYING IN starting
*/
void display_from_beg()
{
int i;
if (first == last && initial == NULL)
printf(" list is empty no elemnts to print");
else
{
printf(" %d variety of nodes square measure there", number);
for (ptr = initial, i = 0;i < number;i++,ptr = ptr->next)
printf(" %d", ptr->val);
}
}
/*
* DISPLAYING IN REVERSE
*/
void display_in_rev()
{
int i;
if (first == last && initial == NULL)
printf(" list is empty there aren't any elments");
else
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote