Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*please calculate the complexity of the program below : #include #include #include #include struct Queue // circular queue struct { int size; int front; int

image text in transcribed

*please calculate the complexity of the program below :

#include #include #include #include

struct Queue // circular queue struct { int size; int front; int rear; int *time_arr; };

int isEmpty(struct Queue *q) // function to check is queue is empty { if (q->rear == q->front) { return 1; } return 0; }

void enqueue(struct Queue *q, int time) // funntion to enqueue elements into the queue {

q->rear = (q->rear + 1) % q->size; q->time_arr[q->rear] = time; }

int dequeue(struct Queue *q) // funciton to dequeue elements from queue { int a = -1;

q->front = (q->front + 1) % q->size; a = q->time_arr[q->front]; }

int main() { // creating queue instances for gold and platinum customers struct Queue gold; struct Queue platinum;

// fixing size of queue as 10 , although user can change as per requirement gold.size = 10; platinum.size = 10;

// setting front and rear position of queue gold.front = gold.rear = 0; platinum.rear = 0; platinum.front = 0;

// dynamically allocating the queue array space gold.time_arr = (int *)malloc(gold.size * sizeof(int)); platinum.time_arr = (int *)malloc(platinum.size * sizeof(int));

printf("Enter total number of customers : "); int n; scanf("%d", &n); for (int i = 0; i

int random;

if (x == 1)

{

random = rand() % 30; enqueue(&gold, random); printf("your expected waiting time is %d ", random); }

if (x == 2)

{ random = rand() % 30; enqueue(&platinum, random); printf("your expected waiting time is %d ", random); } } printf(" "); while (isEmpty(&platinum) == 0)

{

printf("platinum customer with time %d served!!!! ", dequeue(&platinum)); }

while (isEmpty(&gold) == 0)

{ printf("gold customer with time %d served!!! ", dequeue(&gold)); }

return 0; }

Task 2: Complexity Analysis - 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. Include the following statement at the first page of your report

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

=+ 2. What is the opportunity cost of seeing a movie?

Answered: 1 week ago

Question

=+ what roles should government play in them ?

Answered: 1 week ago

Question

=+ Why do we have markets and, according to economists,

Answered: 1 week ago