The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
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 (461 points)
retagged by | 266 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 (889 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
49,984 questions
55,135 answers
85,105 users