Double-Ended Queue (Deque): Input-Restricted and Output-Restricted Notes in Hindi & English : डीकतार (Deque): इनपुट-प्रतिबंधित और आउटपुट-प्रतिबंधित डीकतार और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Double-Ended Queue (Deque): Input-Restricted and Output-Restricted (डीकतार (Deque): इनपुट-प्रतिबंधित और आउटपुट-प्रतिबंधित डीकतार) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: A Double-Ended Queue (Deque, pronounced 'deck') is a generalized linear ADT permitting O(1) insertion and deletion at both front and rear ends, unifying Stack and Queue behaviors. Restricting operations yields two specialized variants: Input-Restricted Deque (insert at 1 end, delete at 2 ends) and Output-Restricted Deque (insert at 2 ends, delete at 1 end).

अध्याय सार: डबल-एंडेड कतार (Deque, उच्चारण 'डेक') एक बहुउद्देशीय रैखिक संरचना है जो front और rear दोनों सिरों से O(1) समय में प्रविष्टि तथा विलोपन की अनुमति देती है। इसके दो प्रतिबंधित रूप हैं: इनपुट-प्रतिबंधित डीकतार (1 सिरे से प्रविष्टि, 2 से निकासी) और आउटपुट-प्रतिबंधित डीकतार (2 सिरों से प्रविष्टि, 1 से निकासी)।

Double-Ended Queue (Deque): Input-Restricted and Output-Restricted: Detailed Notes & Architecture (डीकतार (Deque): इनपुट-प्रतिबंधित और आउटपुट-प्रतिबंधित डीकतार)

1. Deque ADT and the Four O(1) End Primitives (डीकतार ADT और चार O(1) एंड ऑपरेशन्स)

[EN] A full unrestricted Deque exposes four primary mutators: insertFront(), insertRear(), deleteFront(), and deleteRear(), plus getFront() and getRear() inspection helpers. Because access occurs symmetrically at both extremities, a single Deque trivially emulates a Stack (using insertRear + deleteRear, or insertFront + deleteFront) as well as a FIFO Queue (using insertRear + deleteFront). Unlike Dequeue (the verb meaning deleting from a queue), Deque is the noun denoting the data structure.

[HI] एक पूर्ण डीकतार चार मुख्य परिवर्तन ऑपरेशन्स प्रदान करती है: insertFront(), insertRear(), deleteFront(), और deleteRear(), साथ ही getFront() व getRear()। दोनों सिरों पर पहुंच होने से एक ही डीकतार को आसानी से स्टैक (एक ही सिरे पर जोड़ना-हटाना) और सामान्य कतार (एक सिरे से जोड़ना, दूसरे से हटाना) दोनों के रूप में चलाया जा सकता है।

2. Input-Restricted vs Output-Restricted Deque Variants (इनपुट-प्रतिबंधित बनाम आउटपुट-प्रतिबंधित डीकतार)

[EN] An Input-Restricted Deque allows insertions strictly at ONE end (conventionally rear), while deletions remain permitted at BOTH front and rear ends. Conversely, an Output-Restricted Deque permits insertions at BOTH front and rear ends, while restricting deletions strictly to ONE end (conventionally front). Both restricted variants still retain sufficient flexibility to simulate either a Queue or a Stack depending on which delete/insert pair is chosen.

[HI] इनपुट-प्रतिबंधित डीकतार (Input-Restricted Deque) में नया डेटा केवल एक ही सिरे (प्रायः rear) से जोड़ा जा सकता है, जबकि हटाया दोनों सिरों (front व rear) से जा सकता है। इसके विपरीत, आउटपुट-प्रतिबंधित डीकतार (Output-Restricted Deque) में डेटा दोनों सिरों से जुड़ सकता है, परंतु निकल केवल एक ही सिरे (प्रायः front) से सकता है। ये दोनों रूप भी स्टैक व कतार दोनों की तरह काम कर सकते हैं।

3. Circular Array Wrap-Around vs Doubly Linked List Implementation (सर्कुलर एरे रैप-अराउंड बनाम डबली लिंक्ड लिस्ट कार्यान्वयन)

[EN] When implementing a bounded Deque in an array of capacity MAX, advancing rightward uses `(idx + 1) % MAX`, whereas decrementing leftward from index 0 must avoid C/C++ negative modulo bugs by computing `(front - 1 + MAX) % MAX`. Dynamically, a Deque requires a Doubly Linked List (with prev and next links plus head/tail pointers) so deleteRear() updates `tail = tail->prev` in O(1); a Singly Linked List fails to delete at tail in O(1) without scanning from head.

[HI] MAX आकार के सर्कुलर एरे में डीकतार बनाते समय दाईं ओर बढ़ने के लिए `(idx + 1) % MAX` तथा इंडेक्स 0 से बाईं ओर घटने हेतु ऋणात्मक मान से बचने के लिए `(front - 1 + MAX) % MAX` सूत्र लगता है। लिंक्ड लिस्ट कार्यान्वयन में O(1) deleteRear() के लिए डबली लिंक्ड लिस्ट (prev व next पॉइंटर्स) अनिवार्य होती है, क्योंकि सिंगली लिस्ट में पिछले नोड तक जाने में O(n) समय लग जाता है।

4. Algorithmic and Real-World Deque Applications (एल्गोरिदमिक और वास्तविक प्रणाली अनुप्रयोग)

[EN] Monotonic Deques solve the Sliding Window Maximum/Minimum problem across an array of n elements in optimal O(n) time instead of O(nk). Multi-threaded runtime schedulers (such as Java ForkJoinPool and Cilk) use work-stealing deques where owner threads push/pop locally at one end while idle threads steal tasks from the opposite end. Deques also drive palindrome verification, bounded browser Undo/Redo histories, and A-Steal job scheduling.

[HI] मोनोटोनिक डीकतार की सहायता से Sliding Window Maximum जैसी समस्या O(nk) के बजाय इष्टतम O(n) समय में हल हो जाती है। मल्टी-थ्रेडेड वर्क-स्टीलिंग शेड्यूलर्स में मालिक थ्रेड एक सिरे से कार्य जोड़ता-निकालता है और खाली थ्रेड दूसरे सिरे से कार्य चुराते हैं। पैलिंड्रोम जांच, ब्राउज़र इतिहास और Undo/Redo बफर में भी डीकतार उपयोगी है।

Syntax, Formula & Technical Example (Double-Ended Queue (Deque): Input-Restricted and Output-Restricted)

// Circular Array Deque: insertFront & deleteRear (safe wrap-around)
void insertFront(int dq[], int *front, int *rear, int x) {
    if ((*front == 0 && *rear == MAX - 1) || (*front == *rear + 1)) return;
    if (*front == -1) *front = *rear = 0;
    else *front = (*front - 1 + MAX) % MAX;
    dq[*front] = x;
}
void deleteRear(int *front, int *rear) {
    if (*front == -1) return; // Empty
    if (*front == *rear) *front = *rear = -1;
    else *rear = (*rear - 1 + MAX) % MAX;
}

Double-Ended Queue (Deque): Input-Restricted and Output-Restricted Quick Reference & Comparison Table

Deque ConfigurationAllowed End OperationsKey Exam Fact
Unrestricted DequeInsert & Delete allowed at BOTH front and rearGeneralizes both Stack and FIFO Queue
Input-Restricted DequeInsert at ONE end only; Delete at BOTH endsSupports Queue (rear+front) or Stack (rear+rear)
Output-Restricted DequeInsert at BOTH ends; Delete at ONE end onlySupports Queue (rear+front) or Stack (front+front)
Doubly Linked DequeMaintains head/tail with next & prev linksRequired for O(1) deleteRear() in linked memory

Double-Ended Queue (Deque): Input-Restricted and Output-Restricted Top 20 Bilingual MCQs with Answers

Q1. How many insertion ends and deletion ends are permitted in an Input-Restricted Deque?

(इनपुट-प्रतिबंधित डीकतार (Input-Restricted Deque) में प्रविष्टि और निकासी के लिए क्रमशः कितने सिरे उपलब्ध होते हैं?)

(A) Insertion at 2 ends; Deletion at 2 ends

(B) Insertion at 1 end; Deletion at 1 end

(C) Insertion at 2 ends; Deletion at 1 end

(D) Insertion at 1 end only; Deletion at both 2 ends

Correct Answer: (D)

[EN] Input-Restricted limits input (insert) to a single end while keeping output (delete) open at both front and rear.

[HI] Input-Restricted में इनपुट (प्रविष्टि) केवल एक सिरे तक सीमित रहता है, जबकि दोनों सिरों से डेटा हटाया जा सकता है।

Q2. Which operations characterize an Output-Restricted Deque?

(आउटपुट-प्रतिबंधित डीकतार (Output-Restricted Deque) की सही परिभाषा क्या है?)

(A) Deletion allowed at both ends; Insertion at one end

(B) Deletion allowed only from the middle

(C) Both insertion and deletion forbidden at front

(D) Insertion allowed at both ends; Deletion restricted to one end only

Correct Answer: (D)

[EN] Output-Restricted permits inserting at either front or rear, while restricting removals strictly to one designated end.

[HI] Output-Restricted में दोनों सिरों से तत्व जोड़े जा सकते हैं, लेकिन विलोपन (आउटपुट) केवल एक ही सिरे से होता है।

Q3. In a circular array Deque of size MAX, which formula safely decrements `front` backward from index 0 without producing a negative array index in C?

(MAX आकार की सर्कुलर एरे डीकतार में इंडेक्स 0 से `front` को पीछे ले जाने के लिए कौन सा सूत्र ऋणात्मक त्रुटि से बचाता है?)

(A) front = front / MAX

(B) front = (front - 1 + MAX) % MAX

(C) front = (front - 1) % MAX

(D) front = (front + 1) % MAX

Correct Answer: (B)

[EN] In C/C++, (-1) % MAX evaluates to -1 (invalid array index); adding MAX first guarantees (0 - 1 + MAX) % MAX == MAX - 1.

[HI] C भाषा में (-1) % MAX का मान -1 आता है जो अमान्य इंडेक्स है; इसलिए पहले MAX जोड़कर `(front - 1 + MAX) % MAX` लिखा जाता है।

Q4. Why is a Singly Linked List insufficient to implement ALL four Deque operations in O(1) time?

(सिंगली लिंक्ड लिस्ट सभी चार डीकतार ऑपरेशन्स को O(1) समय में पूरा करने में असमर्थ क्यों होती है?)

(A) Singly linked lists cannot store head pointers

(B) deleteRear() cannot jump to the second-last node in O(1) without a `prev` pointer

(C) insertFront() takes O(n) time in singly linked lists

(D) deleteFront() requires scanning to tail

Correct Answer: (B)

[EN] Removing the tail node requires updating the penultimate node's `next` to NULL, requiring O(n) traversal unless nodes have `prev` pointers (Doubly Linked List).

[HI] अंतिम (rear) नोड हटाने पर उससे ठीक पहले वाले नोड का `next` NULL करना होता है, जिसके लिए `prev` पॉइंटर (डबली लिंक्ड लिस्ट) के बिना O(n) समय लग जाता है।

Q5. Can an Input-Restricted Deque (insertion at rear only) behave like BOTH a Queue and a Stack?

(क्या केवल rear पर प्रविष्टि वाला एक इनपुट-प्रतिबंधित डीकतार Queue और Stack दोनों की तरह कार्य कर सकता है?)

(A) Yes, but only with O(n) shifting

(B) No — it can only act as a Queue

(C) Yes — Queue via insertRear+deleteFront; Stack via insertRear+deleteRear

(D) No — it can only act as a Stack

Correct Answer: (C)

[EN] Using insertRear with deleteFront gives FIFO Queue; pairing insertRear with deleteRear gives LIFO Stack.

[HI] हाँ: insertRear + deleteFront से FIFO Queue बनती है, और insertRear + deleteRear से LIFO Stack बनता है।

Q6. Which sliding-window array algorithm uses a monotonic Deque to achieve O(n) total time?

(कौन सा एरे एल्गोरिदम मोनोटोनिक डीकतार की मदद से O(n) कुल समय में हल होता है?)

(A) Binary Search on unsorted arrays

(B) Sliding Window Maximum / Minimum over subarray of size k

(C) Floyd-Warshall All-Pairs Shortest Path

(D) Counting Sort on unbounded floats

Correct Answer: (B)

[EN] Each index enters and exits the monotonic deque at most once, solving all k-sized window extrema in O(n) rather than O(nk).

[HI] मोनोटोनिक डीकतार में हर तत्व अधिकतम एक बार जुड़ता व हटता है, जिससे k-आकार की स्लाइडिंग विंडो का अधिकतम मान O(n) में निकलता है।

Q7. Suppose a Deque starts empty and executes: insertRear(10), insertFront(20), insertRear(30), deleteFront(), insertFront(40), deleteRear(). What remains from front to rear?

(खाली डीकतार पर क्रमशः insertRear(10), insertFront(20), insertRear(30), deleteFront(), insertFront(40), deleteRear() चलाने पर front से rear तक क्या बचेगा?)

(A) [40, 10]

(B) [40, 30]

(C) [20, 30]

(D) [10, 40]

Correct Answer: (A)

[EN] Trace: [10] -> [20,10] -> [20,10,30] -> [10,30] -> [40,10,30] -> [40,10].

[HI] क्रम: [10] -> [20,10] -> [20,10,30] -> deleteFront से [10,30] -> insertFront से [40,10,30] -> deleteRear से [40,10]।

Q8. How do you check whether a word of length n is a Palindrome using a Deque?

(डीकतार (Deque) के प्रयोग से n अक्षरों का शब्द पैलिंड्रोम (Palindrome) है या नहीं, यह कैसे जांचा जाता है?)

(A) Sort characters inside the deque alphabetically

(B) Insert all characters, then repeatedly match deleteFront() == deleteRear() until size <= 1

(C) Insert all characters and pop twice from front only

(D) Compare getFront() with middle pointer

Correct Answer: (B)

[EN] Simultaneously removing and comparing characters from both ends mirrors comparing first with last inward.

[HI] सभी अक्षर डालकर जब तक आकार 1 या 0 न रह जाए, तब तक बार-बार deleteFront() और deleteRear() की तुलना की जाती है।

Q9. How is the word 'Deque' correctly pronounced and what does it stand for?

('Deque' शब्द का सही उच्चारण और पूरा नाम क्या है?)

(A) Pronounced 'de-queue'; stands for Deleted Queue

(B) Pronounced 'd-queue'; stands for Dynamic Queue

(C) Pronounced 'de-key'; stands for Decoded Queue

(D) Pronounced 'deck'; stands for Double-Ended Queue

Correct Answer: (D)

[EN] Deque stands for Double-Ended Queue and is pronounced 'deck' to distinguish it from the verb dequeue.

[HI] Deque का पूर्ण रूप Double-Ended Queue है और इसे डिलीट ऑपरेशन (dequeue) से अलग रखने हेतु 'डेक' बोला जाता है।

Q10. In a circular array Deque of size 6 with front = 0 and rear = 2, after executing `insertFront(99)`, what becomes the new value of `front`?

(साइज 6 की सर्कुलर एरे डीकतार में front = 0 और rear = 2 होने पर `insertFront(99)` चलाने से `front` का नया मान क्या होगा?)

(A) -1

(B) 1

(C) 5

(D) 3

Correct Answer: (C)

[EN] Using (front - 1 + 6) % 6 = (0 - 1 + 6) % 6 = 5, placing 99 at index 5.

[HI] सूत्र (0 - 1 + 6) % 6 = 5 से नया front इंडेक्स 5 पर सेट हो जाएगा।

Q11. Which parallel scheduling pattern specifically relies on Deques so idle CPU cores steal tasks without blocking owner cores?

(कौन सा पैरेलल प्रोसेसिंग शेड्यूलिंग पैटर्न डीकतार का उपयोग करता है ताकि खाली कोर दूसरे सिरे से काम चुरा सकें?)

(A) Banker's Deadlock Matrix

(B) Batch Spooling Queue

(C) Work-Stealing Scheduler (e.g., Cilk, Java ForkJoinPool)

(D) Strict FCFS Single Lock

Correct Answer: (C)

[EN] Owner threads operate LIFO at their own end (maximizing cache warmth), while thieves steal older tasks FIFO from the opposite end.

[HI] Work-Stealing में मालिक थ्रेड एक सिरे पर कार्य करता है और खाली कोर विपरीत सिरे से पुराने कार्य चुरा लेते हैं।

Q12. In an Output-Restricted Deque where deletion is allowed ONLY at front, which operation pair simulates a LIFO Stack?

(जिस आउटपुट-प्रतिबंधित डीकतार में हटाने की अनुमति केवल front पर हो, उसमें किन दो ऑपरेशन्स से LIFO Stack बनाया जा सकता है?)

(A) insertFront() and deleteRear()

(B) insertFront() and deleteFront()

(C) insertRear() and deleteRear()

(D) insertRear() and deleteFront()

Correct Answer: (B)

[EN] Inserting and deleting at the exact same front end produces LIFO stack semantics.

[HI] जब एक ही सिरे (front) पर insertFront() और deleteFront() चलाया जाए, तो वह ठीक LIFO स्टैक जैसा व्यवहार करता है।

Q13. What condition detects a Full Deque in a circular array (without separate count variable) when front and rear track active ends?

(सर्कुलर एरे डीकतार (बिना count वेरिएबल) में कतार पूरी भर जाने (Full) की सही जांच कौन सी है?)

(A) front == rear

(B) rear == MAX - 1 always

(C) (front == 0 && rear == MAX - 1) || (front == rear + 1)

(D) front == -1

Correct Answer: (C)

[EN] Equivalently written as `(rear + 1) % MAX == front`, covering both straight end-to-end span and wrapped adjacency.

[HI] `(rear + 1) % MAX == front` या `(front == 0 && rear == MAX - 1) || (front == rear + 1)` दोनों पूर्ण अवस्था जांचते हैं।

Q14. In Python's standard library `collections.deque`, what are the time complexities of `append()`, `appendleft()`, `pop()`, and `popleft()`?

(Python की `collections.deque` लाइब्रेरी में `append()`, `appendleft()`, `pop()` और `popleft()` की समय जटिलता कितनी होती है?)

(A) O(1) amortized/worst-case for all four end operations

(B) O(log n) for all four

(C) O(n) for appendleft() and popleft()

(D) O(1) at right, O(n) at left

Correct Answer: (A)

[EN] Python implements collections.deque as a doubly linked list of fixed-size memory blocks, giving O(1) at both ends (unlike Python list.pop(0) which is O(n)).

[HI] Python की deque मेमोरी ब्लॉक्स की डबली लिंक्ड लिस्ट है, इसलिए इसके चारों सिरे वाले ऑपरेशन्स O(1) समय लेते हैं।

Q15. If a Deque contains 1 element (front == rear != -1) and `deleteRear()` is executed, what must both pointers reset to?

(जब डीकतार में केवल 1 तत्व हो (front == rear != -1) और `deleteRear()` चले, तो दोनों पॉइंटर्स को किस मान पर सेट करना चाहिए?)

(A) rear = rear - 1 leaving front unchanged

(B) front = -1 and rear = -1

(C) front = 0 and rear = -1

(D) front = MAX - 1 and rear = 0

Correct Answer: (B)

[EN] Whenever the final remaining item leaves from either front or rear, resetting both to -1 ensures clean Empty state detection.

[HI] अंतिम तत्व चाहे front से हटे या rear से, दोनों पॉइंटर्स को -1 पर रीसेट करना जरूरी होता है।

Q16. Which statement is NOT true about Double-Ended Queues (Deque)?

(डबल-एंडेड कतार (Deque) के बारे में इनमें से कौन सा कथन असत्य (NOT true) है?)

(A) An Output-Restricted Deque allows deletion at both front and rear ends

(B) Input-Restricted Deque restricts insertion to a single end

(C) A Deque supports O(1) operations at both ends using circular arrays or doubly linked lists

(D) A single Deque can simulate both a Stack and a Queue

Correct Answer: (A)

[EN] An Output-Restricted Deque allows insertion at both ends and restricts deletion (output) strictly to one end.

[HI] आउटपुट-प्रतिबंधित डीकतार में आउटपुट (विलोपन) केवल एक सिरे तक सीमित होता है, दोनों सिरों पर नहीं।

Q17. Within Double-Ended Queue (Deque): Input-Restricted and Output-Restricted, which deque configuration directly maps to: "Insert & Delete allowed at BOTH front and rear"?

(Double-Ended Queue (Deque): Input-Restricted and Output-Restricted में कौन सा Deque Configuration सीधे "Insert & Delete allowed at BOTH front and rear" से संबंधित है?)

(A) Input-Restricted Deque

(B) Unrestricted Deque

(C) Output-Restricted Deque

(D) Doubly Linked Deque

Correct Answer: (B)

[EN] In Double-Ended Queue (Deque): Input-Restricted and Output-Restricted, 'Unrestricted Deque' handles 'Insert & Delete allowed at BOTH front and rear' (Generalizes both Stack and FIFO Queue).

[HI] Double-Ended Queue (Deque): Input-Restricted and Output-Restricted में 'Unrestricted Deque' का कार्य/विवरण 'Insert & Delete allowed at BOTH front and rear' (Generalizes both Stack and FIFO Queue) है।

Q18. Which option accurately describes 'Input-Restricted Deque' in Double-Ended Queue (Deque): Input-Restricted and Output-Restricted?

(Double-Ended Queue (Deque): Input-Restricted and Output-Restricted के संदर्भ में 'Input-Restricted Deque' की सही विशेषता कौन सी है?)

(A) Insert at BOTH ends; Delete at ONE end only

(B) Maintains head/tail with next & prev links

(C) Insert at ONE end only; Delete at BOTH ends

(D) Insert & Delete allowed at BOTH front and rear

Correct Answer: (C)

[EN] 'Input-Restricted Deque' provides 'Insert at ONE end only; Delete at BOTH ends' — key point: Supports Queue (rear+front) or Stack (rear+rear).

[HI] 'Input-Restricted Deque' का मुख्य विवरण 'Insert at ONE end only; Delete at BOTH ends' है (Supports Queue (rear+front) or Stack (rear+rear))।

Q19. In Double-Ended Queue (Deque): Input-Restricted and Output-Restricted, identify the correct parameter for the specification: "Insert at BOTH ends; Delete at ONE end only".

(Double-Ended Queue (Deque): Input-Restricted and Output-Restricted में "Insert at BOTH ends; Delete at ONE end only" विवरण किस विकल्प के लिए सही है?)

(A) Doubly Linked Deque

(B) Input-Restricted Deque

(C) Unrestricted Deque

(D) Output-Restricted Deque

Correct Answer: (D)

[EN] 'Output-Restricted Deque' corresponds to 'Insert at BOTH ends; Delete at ONE end only' (Supports Queue (rear+front) or Stack (front+front)).

[HI] 'Output-Restricted Deque' का संबंध 'Insert at BOTH ends; Delete at ONE end only' (Supports Queue (rear+front) or Stack (front+front)) से है।

Q20. Considering Double-Ended Queue (Deque): Input-Restricted and Output-Restricted, what key behavior defines 'Doubly Linked Deque'?

(Double-Ended Queue (Deque): Input-Restricted and Output-Restricted में 'Doubly Linked Deque' की मुख्य भूमिका या मान क्या है?)

(A) Maintains head/tail with next & prev links

(B) Insert & Delete allowed at BOTH front and rear

(C) Insert at ONE end only; Delete at BOTH ends

(D) Insert at BOTH ends; Delete at ONE end only

Correct Answer: (A)

[EN] 'Doubly Linked Deque' represents 'Maintains head/tail with next & prev links' (Required for O(1) deleteRear() in linked memory).

[HI] 'Doubly Linked Deque' का अर्थ/मान 'Maintains head/tail with next & prev links' है (Required for O(1) deleteRear() in linked memory)।

Double-Ended Queue (Deque): Input-Restricted and Output-Restricted — Exam FAQs

Q1: What is the exact difference between 'Dequeue' and 'Deque'?

'Dequeue' और 'Deque' के बीच सटीक अंतर क्या है?

[EN] 'Dequeue' (verb/operation) means removing an element from the front of any Queue, whereas 'Deque' (noun, pronounced 'deck') stands for Double-Ended Queue—a data structure supporting insertions and deletions at both ends.

[HI] 'Dequeue' एक ऑपरेशन (क्रिया) है जिसका अर्थ कतार के आगे से तत्व हटाना है, जबकि 'Deque' (उच्चारण 'डेक') स्वयं Double-Ended Queue डेटा संरचना का नाम है।

Q2: Why is Python `collections.deque` much faster than `list.pop(0)` for queues?

कतार के लिए Python में `list.pop(0)` की तुलना में `collections.deque` इतना तेज क्यों है?

[EN] Removing index 0 from a contiguous Python `list` shifts all remaining n - 1 elements left in O(n) time, whereas `deque.popleft()` simply advances the head pointer in O(1) time.

[HI] Python `list` में इंडेक्स 0 हटाने पर बाकी सभी तत्व खिसकाने में O(n) समय लगता है, जबकि `deque.popleft()` केवल पॉइंटर बदलकर O(1) में हो जाता है।

Q3: Can an Input-Restricted Deque accept insertions at front instead of rear?

क्या इनपुट-प्रतिबंधित डीकतार में प्रविष्टि को rear के बजाय केवल front पर सीमित किया जा सकता है?

[EN] Yes! 'Input-Restricted' simply means insertion is restricted to ONE chosen end (either front-only or rear-only) while deletion remains open at both ends.

[HI] हाँ! इनपुट-प्रतिबंधित का अर्थ केवल यह है कि प्रविष्टि किसी भी एक निश्चित सिरे तक सीमित हो और निकासी दोनों सिरों से संभव हो।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)