GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
469 views
Which of the following statement is/are correct?

1. If we use only Front pointer in queue, then insertion takes O(n) time while deletion in O(1) time.

2. If we use only Rear pointer in queue, then insertion is O(1) and deletion is not possible.
asked in DS by Loyal (2.8k points) 4 63 108 | 469 views
Tushar.... What type of Data structure you are assuming in thus scenario?
it should be linked list

2 Answers

0 votes

What u are talking about is not implemented in simple queue.

so both are false.

1..If we use only Front pointer in queue, then insertion takes O(n) time while deletion in O(1) time.  flase.

Deletion in O(1) time thats ok but if 1st element insert then u can delete second in O(1) time.

2..If we use only Rear pointer in queue, then insertion is O(1) and deletion is not possible.

insertion not possible b/c u can go in left direction in simple queue.

 

answered by Veteran (52.8k points) 21 71 325
0 votes

Both 1st and 2nd statements are Correct only if we are using Simple List for queue implementation.

But only 1st statement is Correct if we are using Circular List for queue implementation.

In Simple list, if only FRONT is available we can perform delete operation in O(1) time and insert operation (using an extra pointer temp) in O(n) time.

In Simple list, if only REAR is available we can only perform insertion operation in O(1) time but no delete operation.

Its because, in simple list, Front/Rear pointer only moves in forward direction. Never backward. 

BUT In Circular list, If only FRONT is available again we can perform delete operation in O(1) time and insert operation (using an extra pointer temp) in O(n) time.

While If only REAR is available then both Insertion and deletion can be performed in O(1) time in Circular list.

Example : While using REAR in Circular list.

Insertion : 

newNode --> next = rear --> next;

rear --> next = newNode;

rear = newNode;

Deletion :

temp = rear --> next;

rear --> next = temp --> next;

free(temp);

 

 

 

answered by Junior (725 points) 3 9
edited by

Related questions

+4 votes
2 answers
1
asked in DS by SSrawat (81 points) 3 | 31 views
0 votes
1 answer
3
asked in Programming by Xylene Loyal (4.3k points) 3 19 72 | 69 views


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
Top Users Oct 2017
  1. Arjun

    23338 Points

  2. Bikram

    17048 Points

  3. Habibkhan

    7912 Points

  4. srestha

    6228 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4968 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4286 Points

  9. sushmita

    3964 Points

  10. Rishi yadav

    3794 Points


Recent Badges

Popular Question makhdoom ghaya
Popular Question junaid ahmad
Notable Question learner_geek
Notable Question jothee
Popular Question jothee
Notable Question Jeffrey Jose
Notable Question air1ankit
Nice Question jothee
Verified Human shaleen25
Popular Question jothee
27,290 questions
35,142 answers
83,920 comments
33,231 users