• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Data Structures

Python Queue

  • Categories Data Structures, Python

In this post we will cover Queue in Python. You can watch our videos on Queue in Python – Click Here

Q.1 What are queues? What all operations can be performed on queues?
Ans.

  • Queues are the data structures where data is entered into the queue at one end — the rear end and deleted from the other end – the front end, i.e., these follow First In-First Out (FIFO) principle.
  • Following basic operations can be performed on queues :
    • Enqueue i.e., Insertion of an element in the queue
    • Dequeue i.e., Deletion of an element from the queue
    • Peek i.e., viewing frontmost element without removing it
    • Display or view all the elements in the queue.

Q. 2 Define Queue
Ans. Queue is a first-in, first-out(FIFO) data structure. i.e the element added first to the queue will  be the one to be removed first. Elements are always added to the rear of the queue and removed from the front of the queue

 Q. 3 What are the two major queue operations?
Ans. Addition of element is known as Insert operation, also known as enqueuing, It is done using  rear terminal position i.e. tail end. Removal of element is known as Delete operation, also known as dequeuing

Q. 4 What are the different type of queue?
Ans. Queue can be of four types:

  • Simple Queue
  • Circular Queue
  • Priority Queue
  • De-queue ( Double Ended Queue)

Q. 5 Enlist some applications of queues.
Ans. Applications of queues include the situations where FIFO property is exploited. Some  common applications of queues include :

  • Sharing of one resource among multiple users or seekers such as shared printer among multiple computers; Call center  executive’s response among  waiting callers etc.
  • Airport authorities make use of queues in situation of sharing a single runway of airport for both landing and take-off of flights
  • CPU uses queues to implement round-robin scheduling among waiting processes
  • Queues are used in many computer algorithms also

Q. 6 What is deque?
Ans.  Deques or double ended queues are refined queues in which elements can be removed or added at either end but not in the middle.

Q.7 What are Circular Queues?
Ans.

  • Circular Queues are the queues implemented in circular form rather than a straight line.
  • These are used in programming languages that allow the use of fixed-size linear structure(such as arrays of c/c++ etc )as
  • Unutilized spaces problem is overcome by circular Queues

Q. 8 Difference between Input and Output restricted Deque
Ans.

Input restricted dequeOutput restricted deque
Input restricted deque is one which allows insertions at only one end but deletions are allowed at both endsOutput restricted deque is one which allows deletions at only one end of the list but insertions are allows at both ends

Q. 9 Difference between Dequeue and Enqueue
Ans.

DequeueEnqueue
Removes the item from the front of the queue(at front-end) and returns itAdds item at the back of the queue(at rear end)

Q.10 What is the single queue, deque and circular queues?
Ans.

  • Queues can be used in several forms and ways, depending upon the requirements of the program. Two popular variations of queues are circular queues and dequeues (double-ended queues).
  • Circular Queues are the queues implemented in circle form rather than a straight line. Circular queues overcome the problem of unutilised space in linear queues implemented as arrays (if shifting is not done to avoid the problem of unutilised space, but shifting as such makes it complex to implement).
  • Deque (double-ended queues) are the refined queues in which elements can be added or removed at either end but not in the middle.
  • There are two variations of a deque – an input restricted deque and an output restricted deque. An input restricted deque is a deque which allows insertions at only one end but allows deletions at both ends of the list. An output restricted deque is a deque which allows deletions at only one end of the list but allows insertions at both ends of the list.

 Q.11 Write a program to perform insert and delete on a Queue containing Members details as given in the following definition of itemnode:

     MemberNo                 integer
     MemberName            String
     Age                                integer

queue: implemented as a list
front: integer having position of first (frontmost) element in queue
rear: integer having position of last element in queue

Ans. 

def isEmpty(Qu):
  if Qu==[]:
    return True
  else:
    return False
def Enqueue(Qu, item) : Qu.append(item) if len(Qu)==1 : front=rear=0 else: rear=len(Qu)-1 print (Qu) def Dequeue(Qu): if isEmpty(Qu): return "Underflow" else: item =Qu.pop(0) if len(Qu)==0: front=rear=None return item print (Qu) def Display(Qu): if isEmpty(Qu): print("Queue Empty!") elif len(Qu)==1: print(Qu[0],"<==front,rear") else: front= 0 print(len(Qu)) rear=len(Qu)-1 print(Qu[front],"<-front") for a in range(1,rear): print (Qu[a]) print(Qu[rear],"<-rear") queue=[] front =None while True: print("Queue Operations") print("1.Enqueue") print("2.Dequeue") print("3.Display queue") print("4.Exit") ch=int(input("Enter your choice(1-4)")) if ch==1: print("for the new member,enter details below:") memberNo=int(input("Enter member no:")) memberName= input("Enter member name:") age=int(input("Enter member's age")) item =[memberNo,memberName,age] Enqueue(queue,item) elif ch==2: item=Dequeue(queue) if item=="underflow": print("Queue is empty!") else:
print("Dequeue-ed item is",item) elif ch==3: Display(queue) elif ch ==4: break else:
print("Invaild choice!")

Ans.

Output
Queue Operations
1.Enqueue
2.Dequeue
3.Display queue
4.Exit

Enter your choice(1-4)1

for the new member,enter details below:
Enter member no:3
Enter member name:Rita
Enter member’s age10
[[3, ‘Rita’, 10]]

Queue Operations

1.Enqueue
2.Dequeue
3.Display queue
4.Exit

Enter your choice(1-4)1

for the new member,enter details below:

Enter member no:6
Enter member name:sita
Enter member’s age12
[[3, ‘Rita’, 10], [6, ‘sita’, 12]]

Queue Operations

1.Enqueue
2.Dequeue
3.Display queue
4.Exit

Enter your choice(1-4)3

2
[3, ‘Rita’, 10] <-front
[6, ‘sita’, 12] <-rear

Queue Operations

1.Enqueue
2.Dequeue
3.Display queue
4.Exit

Enter your choice(1-4)2

Dequeue-ed item is [3, ‘Rita’, 10]

Queue Operations

1.Enqueue
2.Dequeue
3.Display queue
4.Exit

Enter your choice(1-4)4

  • Share:
author avatar
Simply Coding

Previous post

Constructors
June 17, 2021

Next post

Python Data Structures - Stack
June 19, 2021

You may also like

Python function
Python function
3 July, 2021
for & while
Learn Python for & while
19 June, 2021
Dictionary
Python Dictionary
15 June, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now