किसी problem को solve करनेकेलिए data को computer memory मेंएकsystematic तरीकेसे store और
organize करनाताकिउसे efficiently use कियाजासके data structure कहलाताहै।
एक programmer केरूपमेंआपकोकई real world problems को solve करनाहोताहै।इन problems को solve करतेसमय data औरउसका organization बहुतImportant होताहै।
एक programmer केरूपमें problems को solve करनेकेलिएआपकोनिचेदिएजारहे tasks perform करनेपड़सकतेहै।
Data structures create करना।
Data structures केसाथ operations (searching, sorting, traversing आदि) perform करना।
Data structures की performances को analyze करना।
आगेआनेवाली tutorials
मेंआपअलगअलगतरहके data structures create करनाऔरउन data structures केसाथ operations perform करनासीखेंगे।इसकेअलावाआप data structures की performances को analyze करनाभीसीखेंगे।
एकबातआपकोहमेशाध्यानरखनीचाहिएकी data structures कोई language नहींहोतीहै। Data
structure सिर्फ data को store और organize करनेकातरीकाहोताहैजिसेकिसीभी programming language जैसेकी C, C++ और java आदिमें implement कियाजासकताहै।
क्योंकि C
एक
basic language हैजिसका syntax
ज्यादातर modern
programming languages द्वारा follow कियाजाताहै।इसलिए Data
structures कीइस
tutorial series में C language केद्वाराही
data structures को implement करनाबतायाजाएगा।
Characteristics of Data Structures
किसीभी
data structure मेंनिचेदीगयी characteristics होतीहै।
Correctness
किसी data structure कीसबसेमहत्वपूर्णविशेषतायहहोतीहैकीवह problem को correctly solve करताहै।यदिकोई data structure problem को partially (आधीअधूरी)
solve करताहैतोवहउस problem केलिए correct data
structure नहींमानाजासकताहै।
Time Complexity
कोई data structure operations
perform करनेमेंजितनासमयलेताहैवहउस data
structure की time
complexity कहलातीहै।अलगअलग
data structures की
time complexity check करनेकेलिए
performance analysis और
measurement tools प्रयोगकियेजातेहै।
एक data structure केद्वारा
perform होनेवाले
operations कमसेकमसमयलेतेहै।जिस data structure केद्वारा
perform होनेवाले
operations कमसेकमसमयलेतेहैवही
data structure problem को
solve करनेकेलिएसहीमानाजाताहै।
Space Complexity
कोई data structure data के storage और operations केलिएजितना
computer memory space use करताहैवहउस data structure की space complexity कहलातीहै।
Space complexity को
test करनेकेलिएभीकई performance और analysis tools प्रयोगकियेजातेहै।
एक data structure केद्वारा
store कियाजानेवाला data और perform कियेजानेवाले
operations कमसेकम memory space use करतेहै।जिस
data structure द्वाराकमसेकम space use कियाजाताहैवही
problem को solve करनेकेलिए best solution मानाजाताहै।
Advantages of Data Structures
Data
structures को implement और use करनेकीकुछ advantages निचेदीजारहीहै।
Gives Ability to Store and
Process Data in Desired Way
Data
structures कीसबसेबड़ी
advantages यहहोतीहैकीआपअपनेमनचाहेतरीकेसे
data को store करसकतेऔरऔरमनचाहेतरीकेसेहीउसपर
operations peform करसकतेहै।आपकिसीनिश्चित framework को follow करनेकेलिएबाध्यनहींहोतेहै।
इससेआपको
problems को solve करनेकेलिए creative solutions implement करनेकीआजादीमिलतीहै।
Uses Less
Processor Time
Data
structure द्वारा performकियेजानेवाले operations processor काकमसेकम
time utilize करतेहै।इससे
computer processor परकम load पड़ताहैऔरवहबड़ीमात्रामें available data कोभीकमसमयमें process करपाताहै।
Uses Less Memory Space
जबआपकिसीबड़े
project परकामकरतेहैतो computer की memory कोठीकसे utilize करनाएक
priority होतीहै। Data structures किसी problem के solution केरूपमेंकमसेकम memory space acquire करतेहै।इससेआपकेलिएदूसरे
tasks perform करनेकेलिएपर्याप्त memory होतीहैऔर memory loss या shortage जैसीसमस्याएँनहींआतीहै।
Easy to Perform Complex
Operations
Data
structures केद्वाराकिसी
problem केसन्दर्भमें complex operations आसानीसेप्रयोगकियेजासकतेहै।
Introduction to Stack Push Operation
जबएक
stack data structure मेंकोईनया
element insert कियाजाताहैतोवह
operation push operation कहलाताहै।
जबभीआप stack मेंकोई
element insert करतेहैतोसबसेपहलेयह check करतेहैकीकँही
stack full तोनहींहै।यदि stack full होताहैतोआपउसमेंकोई
element insert नहींकरसकतेहै।यह
condition stack overflow कहलातीहै।
Introduction to Stack Pop Operation
जब stack मेंसेकिसी item को remove कियाजाताहैतोवह
operation pop operation कहलाताहै। Stack items एकही side
(TOP) से remove कियेजासकतेहै।किसीभी
item कोआप
stack केबीचसेनहीं
remove करसकतेहै।
जबकिसी empty stack मेंसेकोई item remove करनेकाप्रयासकियाजाताहैतोवह situation stack underflow
कहलातीहै। Stack underflow की condition मेंआप user को message show करतेहैकी stack empty है।
Introduction to Queue Insertion
जब queue मेंकोई
element add कियाजाताहैतोवह
operation insertion कहलाताहै। Queue केअंदरकोईभी
element हमेशा rear side सेही insert कियाजाताहै।इसलिएजबभी
queue data structure मेंकोई element add कियाजाताहैतो
rear variable की value
increase होजातीहै।
जब queue मेंकोई
element add कियाजाताहैतोसबसेपहलेयह
check कियाजाताहैकीकँही queue empty तोनहींहै।ऐसाइसप्रकारकियाजाताहै।
Introduction to Queue Deletion
जब queue मेंसेकिसी element को remove कियाजाताहैतोवह
operation deletion कहलाताहै। Queue मेंकिसीभी element का deletion front सेहोताहै।
Queue मेंबीचमें deletion operation perform नहींकियाजाताहै।ऐसाइसलिएहोताहैक्योंकि queue data structure First in First Out
structure को follow करताहै।
Queue
को define करतेसमय
front और
rear variables भी
define कियेजातेहै।जबभी queue मेंसेकोई element remove कियाजाताहैतो
front variable की
value change होतीहै।
Queue मेंसे
element को REMOVE करतेसमयसबसेपहलेयह check कियाजाताहैकीकँही queue empty तोनहींहै।यदि deletion करतेसमय queue empty पायीजातीहैतोवह condition queue overflow कहलातीहै।ऐसी situation में user को appropriate message show कियाजानाचाहिए।
Introduction to Tree Data Structure
Tree
एक non-linear data structure है।अबतकआपनेजितनेभी
data structures केबारेमेंपढ़ाहैवेसब
data को sequence में organize करतेहै।लेकिन tree data को non-linear way में
store करताहै।
Tree
data structure काउपयोगप्राकतिकरूपसे
hierarchical data को
organize करनेकेलिएकियाजाताहै।यदिदूसरेशब्दोंमेंकहाजायेतोजब data elements केबीच
hierarchical relationship होतोउसे
tree data structure केद्वारा represent कियाजाताहै।
Hierarchical
relationship में data elements केबीच
parent/child relationship होतीहै।इसतरहकी
relationship मेंएक data element केकई
child elements होसकतेहैऔरउन
child elements केभीकई
child elements होसकतेहै।
एक linear data structure जैसेकी
linked-list, stack और
queue आदिमेंएक element next और previous elements को point करताहै।लेकिन tree एक non linear data structure है, tree मेंएक element बहुतसारेदूसरे elements को point करसकताहै।
आइयेअब
tree data structure का
example देखतेहै।मानलीजियेआपकिसी
organization में employees की position को tree केद्वारा represent करनाचाहतेहै।ऐसाआपइसप्रकारकरसकतेहै।
जैसाकीआपऊपरदिएगए diagram मेंदेखसकतेहै, एक
tree में data elements को node केद्वारा represent कियाजाताहै। Tree कीसबसे top node root कहलातीहै। Tree में
nodes को links या edges द्वारा connect कियाजाताहै।
ऊपरदिएगए
diagram में CEO (Chief Executive Officer) के under में CTO (Chief Technical Officer) और CFO (Chief Financial Officer) कोदर्शायागयाहै।इसकेबाद CTO और CFO के under मेंदोदो
software engineers और
charted accountants कोदर्शायागयाहै।
Tree Data Structure
Terminology
Tree data structure केउपयोगकेलिएकुछऐसी termsहैजिनकेबारेमेंआपकोपताहोनाचाहिए।इनकेबारेमेंनिचेबतायाजारहाहै।
Node – Node द्वारा information/data को represent कियाजाताहै। Tree में store कियेजानेवालाहर data item एक node होताहै।
Root – किसी tree की origin node root कहलातीहै।यहवह node होतीहैजँहासे tree start होताहै।
Degree of Node – किसी node केजितने child होतेहैयाफिरकिसी node सेजितने sub tree बनतेहैवेउस node की degree कहलातेहै।
Parent -किसी node की origin node उसकी parent node कहलातीहै।
Child – किसी node सेनिकलनेवाली sub
node उसकी child कहलातीहै।
Degree of Tree – Node केअधिकतम degree ही tree की degree कहलातीहै।यदि tree मेंकिसी node कीअधिकतम degree 3 हैतो tree की degree
भी 3 हीहोगी।
Terminal/Leaf Node – वह node जिसकीकोई child node नहींहोतीहै terminal या leaf
node कहलातीहै।
Non Terminal Node – जिस node की degree zero नहींहोतीहैवह non-terminal node कहलातीहै।
Siblings – Same parent की child nodes sibling कहलातीहै।
Edges/Links – किसी tree में nodes कोआपसमेंजिन lines द्वारा connect कियाजाताहैवे edges या links कहलातीहै।
Path – Source node सेकिसी node तकजिन nodes से travel कियाजाताहैउनका set उस node का path कहलाताहै।
Levels – Tree की root node का level हमेशा 0 होताहै। Root की child
nodes का level 1 होताहैऔरउनकी child nodes का level 2 होताहै।इसीप्रकारहर subtree केसाथएक level बढ़ताजाताहै।
Branch – Tree केअंदरएक path जो leaf node द्वारा terminate होताहै branch कहाजाताहै।
Depth – Tree कीजिस branch मेंसबसेअधिक nodes होतीहैवहउस tree की depth कहलातीहै।
Introduction to Binary Tree Traversal
Binary
tree कीसभी nodes कोकोई
operation perform करनेकेलिएएकसाथ
visit करना traversal कहलाताहै।एक binary tree को traverse करतेसमयउसकीहर node कोसिर्फएकबार
access कियाजाताहैऔरउसकेसाथकुछ operation perform कियाजाताहै।
उदाहरणकेलिएआप
binary tree को traverse करकेउसकीसभी nodes का data print करसकतेहै।इसकेअलावा
binary tree को traverse करके node में available data को increase या decrease कियाजासकताहै।
Introduction to Binary Tree Insertion
Binary
tree को programmatically struct केद्वारा
represent (या create) कियाजाताहै।इसे
linked list representation भीकहाजाताहै।इसकेबारेमेंपिछली tutorial (Binary Tree Introduction) मेंबतायाजाचूकाहै।
एकबारफिरसे
binary tree (node) create करनेकेलिएआपजिस
syntax काप्रयोगकरतेहैवहनिचेबतायाजारहाहै।
हालाँकि
binary tree को array केद्वाराभी
create कियाजासकताहैलेकिन
memory केबेहतर
utilization केलिएज्यादातर
struct द्वाराही
binary tree को create कियाजाताहै।
Binary
tree केअंदरकोईभीनयी
node create करनेकेलिएऊपरदिएगए struct का variable create कियाजाताहै।इस
struct केजितने
variables create कियेजातेहैउतनी nodes tree की create होतीहै।
Binary
tree कोउसकी
root node define करकेही
create कियाजाताहै।
Root node define करनेकेबादआपदूसरी
nodes को
binary tree में insert करसकतेहै।
इसलिए insertion function मेंआपसबसेपहलेयह check करतेहैकी root की value NULL हैयानहीं।यदि root की value NU LL होतीहै root को memory assign कीजातीहैऔरउसके
data, left और right
variables को initialize कियाजाताहै।