언젠가는 되어있겠지
데이터 공부 노트
언젠가는 되어있겠지
전체 방문자
오늘
어제
  • 분류 전체보기 (410)
    • Programming (14)
      • Python (6)
      • Algorithm (8)
    • OS (9)
      • Linux (9)
    • DBMS (2)
      • MySQL (2)
    • IoT Apps (6)
      • AppInventor (5)
      • Arduino (1)
    • LeetCode (151)
      • Easy (136)
      • Medium (13)
      • Hard (2)
    • Course (207)
      • [IBM] Data Science (9)
      • [IBM] Data Engineering (5)
      • [Inflearn] Pandas (12)
      • [Inflearn] Public Data Anal.. (8)
      • [Kaggle] Data Science (49)
      • [Youtube] Informations (2)
      • [Coursera] Machine Learning (40)
      • [Progrmiz] Data Structure A.. (15)
      • [DataQuest] Data Engineerin.. (67)
    • Data Engineering (20)
      • [Data Quest] Handling Datas.. (16)
      • [Data Quest] Data Pipeline (4)
    • Certificate (0)
      • 빅데이터 분석기사 (0)
    • SQLD (0)
    • 하고 싶은 이야기 (0)
    • 소설 (0)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • Kaggle Course
  • Data Science

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
언젠가는 되어있겠지

데이터 공부 노트

[DS1] Queue
Course/[Progrmiz] Data Structure Algorithm

[DS1] Queue

2022. 8. 10. 21:45

1. What is Queue

A queue is a useful data structure in programming. Queue follows the First in First Out(FIFO) rule - the item that goes in first is the item that comes out first.

In programming terms, putting items in the queue is called enqueue, and removing items from the queue is called dequeue.

 

2. Basic Operations of Queue

  • Enqueue : Add an element to the end of queue
  • Dequeue : Remove an element form the front of the queue.
  • IsEmpty : Check if the queue is empty
  • IsFull : Check if the queue is full
  • Peek : Get the value of the front of the queue without removing it

 

3. Working of Queue

3.1 Class Workflow

  • Two pointers FRONT and REAR
  • FRONT track the first element of the queue
  • REAR track the last element of the queue
  • initially, set value of FRONT and REAR to -1

3.2 Enqueue Operation

  • check if the queue is full
  • for the first element, set the value of FRONT to 0
  • increase the REAR index by 1
  • add the new element in the position pointed to by REAR

3.3 Dequeue Operation

  • check if the queue is empty
  • return the value pointed by FRONT
  • increase the FRONT index by 1
  • for the last element, reset the values of FRONT and REAR to -1

 

4. Queue Implementation

class Queue: 
    def __init__(self): 
        self.queue = []
        
    def enqueue(self, item): 
        self.queue.append(item) 
        
    def dequeue(self): 
        if len(self.queue) < 1 : 
            return None 
        return self.queue.pop(0) 
        
    def display(self):
        print(self.queue)
    
    def size(self):
        return len(self.queue)

 

5. Limitation of Queue

After a bit of enqueuing and dequeuing, the size of the queue has been reduced. And we can only add indexes 0 and 1 only when the queue is reset (when all the elements have been dequeued).

 

After REAR reaches the last index, if we can store extra elements in the empty spaces (0 and 1), we can make use of the empty spaces. This is implemented by a modified queue called the circular queue.

'Course > [Progrmiz] Data Structure Algorithm' 카테고리의 다른 글

[DS2] Linked List  (0) 2022.08.22
[DS1] Types of Queue  (0) 2022.08.16
[DS1] Stack  (0) 2022.08.10
[Introduction] Divide and Conquer Algorithm  (0) 2022.08.09
[Introduction] Asymptotic Notations  (0) 2022.08.08
    'Course/[Progrmiz] Data Structure Algorithm' 카테고리의 다른 글
    • [DS2] Linked List
    • [DS1] Types of Queue
    • [DS1] Stack
    • [Introduction] Divide and Conquer Algorithm
    언젠가는 되어있겠지
    언젠가는 되어있겠지

    티스토리툴바