Theory
वही slips, तीन drawers
Canteen दिन की हर order slip रखता है। उन्हें store करने के तीन तरीक़े:
- Drawer में ढीली फेंकी गई।
- एक nail पर spike की गई, नई सबसे ऊपर।
- एक tray में clip की गई, पुरानी सबसे आगे।
वही 500 slips। पर "अभी क्या आया?" या "अगला कौन है?" का जवाब देने की कोशिश कीजिए और हर drawer बिल्कुल अलग perform करता है।
आप data कैसे arrange करते हैं यह तय करता है आप इसे कितनी तेज़ी से इस्तेमाल कर सकते हैं। यह अकेला sentence इस subject का पूरा दूसरा आधा है।
Theory
Kitchen पहले से organized है
Canteen के आस-पास देखिए: stacked plates (top से लीजिए), एक line में customers (पहले वाले को serve कीजिए), menu board एक hierarchy के रूप में (sections, फिर dishes), delivery map roads का एक network।
कोई भी plates को queue में या customers को pile में store नहीं करता। हर arrangement इसलिए चुना गया क्योंकि यह एक काम आसान बनाता है। Data structures यही arrangements हैं, code में लिखे हुए।
Theory
Data structure, formally
एक data structure memory में data को organise और store करने का एक ख़ास तरीक़ा है ताकि इसे efficiently access और modify किया जा सके।
Exams जो classification खींचते हैं:
Data structures
├── Primitive: int, char, float, double
└── Non-primitive
├── Linear: array, stack, queue, linked list
└── Non-linear: tree, graph
Linear structures elements को एक sequence में रखते हैं, एक के बाद एक। Non-linear structures branch (trees) करते हैं या interconnect (graphs) करते हैं।
At a glance
कौन कहाँ इस्तेमाल होता है (application-areas table)
| Structure | Shape | असली applications |
|---|---|---|
| Array | Numbered row | Marksheets, lookup tables, matrices |
| Stack | Pile, सिर्फ़ top | Function calls, undo, infix to postfix |
| Queue | Line, दोनों ends | Token systems, printer jobs, CPU scheduling |
| Linked list | Nodes की chain | Playlists, dynamic memory allocation |
| Tree | Hierarchy | File systems, database indexes, HTML DOM |
| Graph | Network | Google Maps routes, social networks |
Quiz
Canteen tokens print करता है और customers को strictly arrival order में serve करता है। अंदर वाला printer भी jobs इसी तरह queue करता है। कौन सी structure दोनों को model करती है, और क्यों?
- Queue: first in, first out arrival-order service से match करता है
- Stack: सबसे आख़िरी print हुआ token पहले serve होता है
- Tree: customers veg और non-veg में branch करते हैं
- Array: tokens के numbers हैं, तो एक array चाहिए
Show the answer
Queue: first in, first out arrival-order service से match करता है
Arrival-order service FIFO है, queue की definition, और printer spooling textbook queue application है। एक stack सबसे नए customer को पहले serve करता (queue riot की कल्पना कीजिए)। Numbered tokens एक array force नहीं करते: numbering वह है जो queue देता है, memory कैसे arrange होनी चाहिए वह नहीं। Behaviour को structure से match करना, surface details से नहीं, exam skill है।
Think first
Drawer चुनिए
तीन needs: (1) browser का Back button, (2) college का folder-inside-folder file explorer, (3) दो campus gates के बीच shortest route ढूँढना। tap करने से पहले, table से हर एक को एक structure दीजिए।
Show the answer
(1) Stack: Back सबसे recent page पर लौटता है, LIFO।
(2) Tree: folders के अंदर folders एक root वाली एक hierarchy है।
(3) Graph: gates और paths एक network बनाते हैं, और shortest-route सवाल graph सवाल हैं।
अगर आपने तीनों सही कीं, आप पहले से data structures में सोचते हैं; आने वाले lessons बस mechanics जोड़ते हैं।
Watch out
Classification की चूक
Students "array, stack, queue, tree" को linear structures लिखते हैं: tree non-linear है, यह branch करता है। Reliable test: क्या आप पूरी structure को एक straight pass में बिना branch चुने walk कर सकते हैं? Arrays, stacks, queues, linked lists: हाँ, linear। Trees और graphs: नहीं, non-linear।
primitive बनाम non-primitive को linear बनाम non-linear से भी अलग रखिए: दूसरा split सिर्फ़ non-primitive के अंदर लागू होता है।
Theory
Companies interviews में यह क्यों test करती हैं
Wirth की मशहूर book का title सब कुछ कहता है: Algorithms + Data Structures = Programs। आपने जो भी धीमी app इस्तेमाल की है वह आमतौर पर ग़लत structure पर सही algorithm थी। आपके पास इस subject से पहले से दो structures हैं (plate-pile stack और token-line queue); बाक़ी lessons आपसे इन्हें implement और apply करवाते हैं।
Summary
Key takeaways
- एक data structure efficient access और change के लिए memory में data का एक चुना हुआ arrangement है।
- Primitive (int, char, float) बनाम non-primitive; non-primitive linear और non-linear में split होता है।
- Linear: array, stack, queue, linked list। Non-linear: tree, graph।
- Applications: calls/undo के लिए stack, scheduling के लिए queue, hierarchies के लिए tree, networks के लिए graph।
- One-straight-pass test linear को non-linear से अलग करता है।
- Memory hook: वही slips, तीन drawers।