Question
Theoretically discuss and compute the complexity of all algorithms that you implemented. The discussion will describe your understanding of the algorithm. Define the complexity of
Theoretically discuss and compute the complexity of all algorithms that you implemented. The discussion will describe your understanding of the algorithm. Define the complexity of the algorithm by using Big O notation.
Please calculate time complexity of the coding below :
#include
void insert_by_priority(float); void delete_by_priority(float); void average_waiting_time(float,float,int); void create(); void check(float); void display_queue(float, char);
float priority_queue[max]; int front, rear;
char call;
void main() { int choice, n; float time; float total_time=0;
printf("1 - Insert waiting time for call into queue"); printf(" 2 - Delete waiting time for call into queue"); printf(" 3 - Display arrangement queue waiting time for call"); printf(" 4 - Average of time waiting for call"); printf(" 5 - Exit ");
create();
while (1) { printf(" Enter your choice : "); scanf("%d", &choice);
switch (choice) { case 1: printf(" What is types of customer? : P(platinum) or G(gold) : "); scanf(" %c", &call);
if(call== 'G' || call== 'g'){ printf(" Enter time waiting for this call : "); scanf("%f",&time); total_time=total_time+time; n=n+1; insert_by_priority(time); }
else if(call=='P' || call=='p'){ printf(" Enter time waiting for this call : "); scanf("%f",&time); total_time=total_time+time; n=n+1; insert_by_priority(time); }
else{ printf(" Wrong section, please try again "); }
break;
case 2: printf(" Enter value to delete : "); scanf("%f",&time); delete_by_priority(time); total_time=total_time-time; n=n+1; break;
case 3: display_queue(time, call); break;
case 4: average_waiting_time(time,total_time,n); break;
case 5: exit(0); break;
default: printf(" Choice is incorrect, Enter a correct choice");
return 0; } } }
/* Function to create an empty priority queue */ void create() { front = rear = -1; }
/* Function to insert time into priority queue based on arrangement */ void insert_by_priority(float data) { if (rear >= max - 1) { printf(" Queue is full"); return; }
if ((front == -1) && (rear == -1)) { front++; rear++; priority_queue[rear] = data; return; } else check(data); rear++; }
/* Function to check priority and place time waiting for job */ void check(float data) { int i,j;
for (i = 0; i <= rear; i++) { if (data <= priority_queue[i]) { for (j = rear + 1; j > i; j--) { priority_queue[j] = priority_queue[j - 1]; } priority_queue[i] = data; return; } } priority_queue[i] = data; }
/* Function to delete an data from buffer */ void delete_by_priority(float data) { int i;
if ((front==-1) && (rear==-1)) { printf(" Queue is empty, so no customer to delete"); return; }
for (i = 0; i <= rear; i++) { if (data == priority_queue[i]) { for (; i < rear; i++) { priority_queue[i] = priority_queue[i + 1]; }
priority_queue[i] = -99; rear--;
if (rear == -1) front = -1; return; } } printf(" %.2fs not found in queue to delete", data); }
/* Function to display queue waiting time */
void display_queue(float data, char typecall) { int i, j;
if ((front == -1) && (rear == -1)) { printf(" Queue is empty"); return; }
for (; front <= rear; front++) { printf(" %.2fs ", priority_queue[front]); }
printf(" Call had been arranged in queue according to time. "); printf("If type P and type G had the same time waiting. "); printf("Type P caller need to be answered first than type G caller. ");
return;
front = 0; }
/* Function to display average time for all jobs */ void average_waiting_time(float data, float total, int num) { float average=0;
printf(" Listed for waiting call : ");
for (; front <= rear; front++) { printf(" %.2fs ", priority_queue[front]); }
printf(" Total waiting time for all call is: %.2f seconds", total);
printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); printf(" Total call that have been requested is: %d", num); printf(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
average=total/num;
printf(" #########################################################"); printf(" Average time waiting for the call is: %.2f seconds", average); printf(" #########################################################"); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started