The Gateway to Computer Science Excellence
0 votes
On other sources, it is given that we need to assign high priorities to newly inserted element in case of stack otherwise low priority to newly inserted element in case of queue. My doubt here is that shouldn't  stack be implemented with max-heap priority queue and queue with min-heap priority queue keeping above assumption of assigning priorities to newly inserted element?
in Algorithms by (477 points)
retagged by | 320 views

1 Answer

0 votes

If priority of an element is directly proportional to the arrival time of an element then yes you can implement stack with max-heap priority queue and queue with min-heap priority queue.

Since Stack follows LIFO(Last In First Out) order, the greater the arrival time, the greater will be the priority and hence you can emulate LIFO, just by using priorities. Similar logic applies for FIFO data structure queue.

by Junior (941 points)
arrival time doesnot depending on priority of a process
in case of priority queue elements can be ordered by time insertion
No the arrival time does not depend on priority but its the other way round as clearly mentioned.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,833 questions
57,733 answers
107,886 users