Data Structure introduction

Data Structure ဆိုတာ data တွေကို memory ထဲမှာ ပုံစံတစ်ခုခု ဒါမှမဟုတ် structure တစ်ခုအဖြစ်သိမ်းဆည်းထားတဲ့အရာဖြစ်ပြီး data structure တစ်ခုစီတိုင်းမှာ advantage တစ်ခုစီရှိပါတယ်။


အပေါ်ကပုံထဲကအတိုင်း data structure ကိုအမျိုးအစားခွဲထားပါတယ်။

Linear data structure ဆိုတာကတော့ data တွေက sequential ဖြစ်နေပြီး data တစ်ခုက သူ့ရဲ့ ရှေ့က data နဲ့ နောက်က data နဲ့ တစ်နည်းနည်းနဲ့ချိတ်ဆက်နေပါတယ်။ ဉပမာ array, stack, queue, linked list လိုမျိုပေါ့။

. Static data structure မှာတော့ data တွေက fixed memory size ရှိပါတယ်။ အဲ့တာကဘာလဲဆိုတော့ static data structure တစ်ခုကို ဖန်တီးပြီးရင် hard code လုပ်ရုံကလွဲပြီး ကျန်တဲ့နည်းနဲ့ ပြောင်းလို့မရပါဘူး။ python က tuple နဲ့ concept တူပါတယ်။ ဉပမာ array လိုမျိုးပေါ့။ array ကိုပြောင်းလဲလို့ရတာသိပါတယ်။ တစ်ချို့ Programming Laguage တွေဖြစ်တဲ့ java, c++ တွေမှာ array ကို create ပြီးပြန်ပြင်လို့မရတာကို static array ဖြစ်ပြီး၊ java.util package ထဲက ArrayList ကိုတော့ create ပြီးလည်းပြင်လို့ရတဲ့အတွက် dynamic array ပဲ ဖြစ်ပါတယ်။

. Dynamic data structure ကတော့ fixed memory size မရှိပါဘူး။ program runtime မှာ ​အပြောင်းအလဲလေးတွေ ဖြစ်ပါတယ်။ size က အများကြီးလည်းဖြစ်သွားနိုင်သလို နည်းနည်းလေးလည်းဖြစ်သွားနိုင်ပါတယ်။ ဉပမာ python ထဲက list ဆို dymamic data structure ဖြစ်ပါတယ်။ queue, stack တို့လည်း dynamic data structure ဖြစ်ပါတယ်။

Non-linear data structure ဆိုတာကတော့ linear data structure မဟုတ်တဲ့ data structre ပါ။ data တွေက တစ်ခုနဲ့တစ်ခု sequentical မဖြစ်ပါဘူး။ ပြီးတော့ data တွေအကုန်လုံးကို single run တစ်ခုတည်းနဲ့ data အကုန်လုံးစီမရောက်ပါဘူး။ ဉပမာ array ဆို for loop သုံးပြီး array ထဲက data တွေအကုန်လုံးကို access လုပ်နိုင်ပေမယ့် Non-linear data structure ဖြစ်တဲ့ trees, graphs စတာတွေကတော့ မရပါဘူး။

Linked List ဆိုတာကတော့ data တွေက တစ်ခုနဲ့တစ်ခု ချိတ်ထားတဲ့ data structure ဖြစ်ပါတယ်။ data တစ်ခုစီကို node လို့ခေါ်ပြီး၊ data နဲ့ next ဆိုပြီး ပါပါတယ်။ data ကတော့ တကယ့် data value ဖြစ်ပြီး next ကတော့ နောက် data ရဲ့ memory location ကိုအဲ့ထဲမှာသိမ်းဆည်းပေးပါတယ်။

Stack ကတော့ Last in First Out ပုံစံဖြစ်ပါတယ်။ ဉပမာ ပန်းကန်တွေကို တစ်ခုခုနဲ့ တစ်ခုခု ထပ်ထားပြီး၊ ပန်းကန်တစ်ခုစီက data တစ်ခုကို ကိုယ်စားပြုပါတယ်။ ပန်းကန်တစ်ခုကိုယူချင်တယ်ဆို အပေါ်ဆုံးကဟာကို အရင်ယူရသလိုမျိုးပါ။ Last in First out ဆိုတာ နောက်ဆုံးမှဝင်တဲ့အရာ အရင်ထွက်ပုံစံမျိုးပါ။

Queue ကတော့ First in First out ဖြစ်ပြီး၊ atm မှာငွေထုတ်ဖို့တန်းစီနေကြတဲ့ လူတွေက queue ဖြစ်ပြီး၊ အရင်ရောက်တဲ့လူ အရင်ထုတ်ရတဲ့ data structure ပါ။

Binary Tree ဆိုတာကတော့ data တစ်ခုမှာ left and right ဆိုတဲ့ data တွေရှိတဲ့ structure ပါ။ အပေါ်ဆုံးက data ကို root node လို့ခေါ်ပြီး အောက်ဆုံးက data တွေကိုတော့ leaf nodes လို့ခေါ်ပါတယ်။

Binary Heap မှာ min heap နဲ့ max heap ရှိပြီး။ max heap မှာ root node က data တွေအကုန်လုံးထဲမှာ အကြီးဆုံးဖြစ်ပြီး၊ min heap ကတော့ root node က data တွေအကုန်လုံးထဲမှာ အငယ်ဆုံးဖြစ်ပါတယ်။ parent node တိုင်းက children node တိုင်းထက် ကြီးတယ် ဒါမှမဟုတ် ငယ်ပါတယ်။

Graph မှာ edges တွေက vertex တွေကို ချိတ်ဆက်ပေးထားပါတယ်။ google map မှာ vertex ကတော့ နေရာတွေဖြစ်ပြီး edge ကတော့ လမ်းပဲ ဖြစ်ပါတယ်။ graph က advanced ဖြစ်တဲ့ data structure ပဲ ဖြစ်ပါတယ်။

နောက် blog မှာတော့ အဲ့တာတွေကို ဘယ်လို implement လုပ်ရမလဲဆိုတာ ဖော်ပြသွားပါမယ်။

ဒီ blog ကိုတော့ geeksforgeeks website ရဲ့ data structures blog တစ်ခုကနေ idea တွေယူထားပါတယ်။

Popular posts from this blog

Algorithm basic examples

Dom introduction