Queue data structure: please answer these two question properly
Q(1) What are their respective logical and physical / storage structures .Q(2) At least one application example combining data structure and algorithm should be given.
Answer:
1.)
logical and physical structure for Queue are mentioned below:
2.)
An example where queue is used is First Come First Serve OS
scheduling algorithm.
The sample code using Queue as data structure and output is given
below:
// Java program for array
// implementation of queue
// A class to represent a queue
class Queue {
int front, rear, size;
int capacity;
int array[];
public Queue(int cap)
{
this.capacity = cap;
front = this.size = 0;
rear = cap - 1;
array = new
int[this.capacity];
}
// Queue can be full when size becomes
// equal to the capacity
boolean isFull(Queue q)
{
return (q.size ==
q.capacity);
}
// Queue is empty when size is 0
boolean isEmpty(Queue q)
{
return (q.size == 0);
}
// Method to add an item to the queue.
// It changes rear and size
void enqueue(int item)
{
if (isFull(this))
return;
this.rear = (this.rear + 1)
% this.capacity;
this.array[this.rear] = item;
this.size = this.size + 1;
System.out.println(item
+ "
enqueued to process queue");
}
// Method to remove an item from queue.
// It changes front and size
int dequeue()
{
if (isEmpty(this))
return
Integer.MIN_VALUE;
int item =
this.array[this.front];
this.front = (this.front + 1)
% this.capacity;
this.size = this.size - 1;
return item;
}
// Method to get front of queue
int front()
{
if (isEmpty(this))
return
Integer.MIN_VALUE;
return
this.array[this.front];
}
// Method to get rear of queue
int rear()
{
if (isEmpty(this))
return
Integer.MIN_VALUE;
return
this.array[this.rear];
}
}
/**
* Driver class to execute FCFS in cpu scheduling of process
* */
public class Main {
public static void main(String[] args)
{
Queue processQueue = new
Queue(1000);
processQueue.enqueue(10);
processQueue.enqueue(20);
processQueue.enqueue(30);
processQueue.enqueue(40);
System.out.println(processQueue.dequeue() + " is first process to be executed from queue\n");
System.out.println("Front process is " + processQueue.front());
System.out.println("Rear process
is " + processQueue.rear());
}
}
OUTPUT=>
(plz give me a thums up...if my answer helped you and if any suggestion plz comment, Yr thums up boost me)
Queue data structure: please answer these two question properly Q(1) What are their respective logical and...
please answer these two questions properly about Stack data structure Q(1) What are their respective logical and physical / storage structures .Q(2) At least one application example combining data structure and algorithm should be given.
Binary tree please answer these two question properly about binary tree Q(1) What are their respective logical and physical / storage structures .Q(2) At least one application example combining data structure and algorithm should be given.
Linked list: 1) What are their respective logical and physical / storage structures .2) At least one application example combining data structure and algorithm should be given. please answer these two questions properly
i am writing thesis paper for these question (why do we need data structures? What is the relationship between data structure and algorithm? What data structures have we learned? What are their respective logical and physical / storage structures? What are their advantages and disadvantages? In which cases do they apply to (combined with time complexity analysis)? Please analyze the learned data structure one by one. At least one application example combining data structure and algorithm should be given) i...
i need an conclusion for my research thesis paper and my research paper covered these areas(why do we need data structures? What is the relationship between data structure and algorithm? What data structures have we learned? What are their respective logical and physical / storage structures? What are their advantages and disadvantages? In which cases do they apply to (combined with time complexity analysis)? Please analyze the learned data structure one by one. At least one application example combining data...
Array list, Linkedlist, Stack, Queue, binary tree, hash table What are their respective logical and physical / storage structures? i am asking this question note what are their respective logical and physical / storage structures?
Array list, linked list, Stack, Queue, Binary tree, Hash table At least one application example combining data structure and algorithm should be given.
please justify. A Fibonacci heap is a fancy priority queue data structure. For a heap of size n, it takes O(log n) time to do an extractMin() operation but only O(1) time to do an insert or decrease operation. Suppose we replace the binary heap used in Dijkstra's algorithm by a Fibonacci heap. 6. If the graph is dense, what is the asymptotic complexity of Dijkstra's algorithm using a Fibonacci heap, in terms of V|? 7. If the graph is...
please use java Question 1- Without using extra data structures, write a recursive method recursiveProdcutQueue ( Queue <Integer> q) in Test class (in stacks_queues package) that receives a queue of integers and return the product of the integers inside the queue. Then don't forget to test the method in the main. Note: Make sure not to change values in queue after calling the method. Example: If we have a Queue q of integer values as follows: 1 2 9 4...
CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...