Python एल्गोरिदम

Python में Queue Data Structure

Queue items को उसी क्रम में process करती है जिसमें वे जोड़े गए थे।

में Queue Data Structure क्या है?

Queue items को उसी क्रम में process करती है जिसमें वे जोड़े गए थे।

deque से प्रभावी FIFO queue बनाएँ।

इसका उपयोग कब करें?

  • Algorithms और data structures की कार्यप्रणाली समझें।
  • हर चरण देखें और edge cases जाँचें।
  • समय और memory की जटिलता की तुलना करें।

उदाहरण कोड

कोड चलाएँ →
main.py
from collections import deque

queue = deque(["first", "second"])
queue.append("third")

print("served:", queue.popleft())
print("waiting:", list(queue))

अपेक्षित आउटपुट

served: first
waiting: ['second', 'third']

यह कैसे काम करता है

deque दाईं ओर append और बाईं ओर popleft दोनों O(1) में करता है।

मान बदलें और Python इंस्टॉल किए बिना CodeUtility ऑनलाइन Python कंपाइलर में प्रोग्राम चलाएँ।

अभ्यास के कार्य

बड़े dataset पर जाने से पहले input बदलें और edge cases की जाँच करें।

  1. खाली input, एक element और duplicate values जाँचें।
  2. हर चरण के बाद state दिखाएँ।
  3. Performance को दूसरे solution से तुलना करें।
Python IDE में चलाएँ →