Upload
kishore-dm
View
217
Download
1
Embed Size (px)
DESCRIPTION
intro ds
Citation preview
IntroductiontoBasicDataStructuresandAlgorithmsIntroductiontoBasicDataStructuresandAlgorithmsClassificationofDataStructures
ArraysLinkedListStackQueueTreeHeapDictionaryHashTableGraph
ReferencesIntroductiontoBasicDataStructuresandAlgorithmsBeforeintroducingdatastructuresweshouldunderstandthatcomputersdostore,retrieve,andprocessalargeamountofdata.Ifthedataisstoredinwellorganizedwayonstoragemediaandincomputer'smemorythenitcanbeaccessedquicklyforprocessingthatfurtherreducesthelatencyandtheuserisprovidedfastresponse.
Datastructureintroductionreferstoaschemefororganizingdata,orinotherwordsadatastructureisanarrangementofdataincomputer'smemoryinsuchawaythatitcouldmakethedataquicklyavailabletotheprocessorforrequiredcalculations.Adatastructureshouldbeseenasalogicalconceptthatmustaddresstwofundamentalconcerns.First,howthedatawillbestored,andsecond,whatoperationswillbeperformedonit?Asdatastructureisaschemefordataorganizationsothefunctionaldefinitionofadatastructureshouldbeindependentofitsimplementation.ThefunctionaldefinitionofadatastructureisknownasADT(AbstractDataType)whichisindependentofimplementation.Theimplementationpartisleftondeveloperswhodecidewhichtechnologybettersuitstotheirprojectneeds.
Forexample,astackADTisastructurewhichsupportsoperationssuchaspushandpop.Astackcanbeimplementedinanumberofways,forexampleusinganarrayorusingalinkedlist.
Alongwithdatastructuresintroduction,inreallife,problemsolvingisdonewithhelpofdatastructuresandalgorithms.Analgorithmisastepbystepprocesstosolveaproblem.Inprogramming,algorithmsareimplementedinformofmethodsorfunctionsorroutines.Togetaproblemsolvedwenotonlywantalgorithmbutalsoanefficientalgorithm.Onecriteriaofefficiencyistimetakenbythealgorithm,anothercouldbethememoryittakesatruntime.
Sometimes,wecanhavemorethanonealgorithmforthesameproblemtoprocessadatastructure,andwehavetochoosethebestoneamongavailablealgorithms.Thisisdonebyalgorithmanalysis.Thebestalgorithmistheonewhichhasafinebalancebetweentimetakenandmemoryconsumption.But,asweknowthebestexistsrarely,andwegenerallygivemoreprioritytothetimetakenbythealgorithmratherthanthememoryitconsumes.Also,asmemoryisgettingcheaperandcomputershavemorememorytodaythanprevioustime,therefore,runtimeanalysisbecomesmoresignificantthanmemory.Theanalysisofalgorithmsisanentirelyseparatetopicandwewilldiscussthatseparately.
ClassificationDataStructuresDatastructurescanbebroadlyclassifiedintwocategorieslinearstructuresandhierarchicalstructures.Arrays,linkedlists,stacks,andqueuesarelinearstructures,whiletrees,graphs,heapsetc.arehierarchicalstructures.
Everydatastructurehasitsownstrengths,andweaknesses.Also,everydatastructurespeciallysuitstospecificproblemtypesdependingupontheoperationsperformedandthedataorganization.Forexample,anarrayissuitableforreadoperations.Followingisaquickintroductiontoimportantdatastructures.
ArraysArraysarestaticallyimplementeddatastructuresbysomeprogramminglanguageslikeCandC++hencethesizeofthisdatastructuremustbeknownatcompiletimeandcannotbealteredatruntime.Butmodernprogramminglanguages,forexample,Javaimplementsarraysasobjectsandgivetheprogrammerawaytoalterthesizeofthematruntime.Arraysarethemostcommondatastructureusedtostoredata.
Arraysareunarguablyeasierdatastructurestouseandaccess.Butinsertinganitemtoanarrayanddeletingitfromthearrayaresituationdependent.Ifyouwanttoinsertanitemataparticularpositionwhichisalreadyoccupiedbysomeelementthenyouhavetoshiftallitemsonepositionrightfromthepositionnewelementhastobeinsertedtheninsertthenewitem.Thetimetakenbyinsertoperationisdependonhowbigthearrayis,andatwhichpositiontheitemisbeinginserted.Thesameistrueaboutdeletionofanitem.
IfthearrayisunsortedthensearchoperationisalsoprovedcostlyandtakesO(N)timeinworstcase,whereNissizeofthearray.ButifthearrayissortedthensearchperformanceisimprovedmagicallyandtakesO(logN)timeinworstcase.
LinkedListLinkedlistdatastructureprovidesbettermemorymanagementthanarrays.Becauselinkedlistisallocatedmemoryatruntime,so,thereisnowasteofmemory.Performancewiselinkedlistisslowerthanarraybecausethereisnodirectaccesstolinkedlistelements.
Linkedlistisprovedtobeausefuldatastructurewhenthenumberofelementstobestored
KishoreHighlightand linear
isnotknownaheadoftime.
Therearemanyflavorsoflinkedlistyouwillsee:linear,circular,doubly,anddoublycircular.
StackStackisalastinfirstoutstrategydatastructurethismeansthattheelementstoredinlastwillberemovedfirst.Stackhasspecificbutveryusefulapplicationssomeofthemareasfollows:
SolvingRecursionrecursivecallsareplacedontoastack,andremovedfromthereoncetheyareprocessed.EvaluatingpostfixexpressionsSolvingTowersofHanoiBacktrackingDepthfirstsearchConvertingadecimalnumberintoabinarynumber
QueueQueueisafirstinfirstoutdatastructure.Theelementthatisaddedtothequeuedatastructurefirst,willberemovedfromthequeuefirst.Dequeue,priorityqueue,andcircularqueuearethevariantsofqueuedatastructure.Queuehasthefollowingapplicationuses:
Accesstosharedresources(e.g.,printer)MultiprogrammingMessagequeue
TreesTreeisahierarchicaldatastructure.Theverytopelementofatreeiscalledtherootofthetree.Excepttherootelementeveryelementinatreehasaparentelement,andzeroormorechildrenelements.Allelementsintheleftsubtreecomebeforetherootinsortingorder,andallthoseintherightsubtreecomeaftertheroot.
Treeisthemostusefuldatastructurewhenyouhavehierarchicalinformationtostore.Forexample,directorystructureofafilesystemtherearemanyvariantsoftreeyouwillcomeacross.SomeofthemareRedblacktree,threadedbinarytree,AVLtree,etc.
HeapHeapisabinarytreethatstoresacollectionofkeysbysatisfyingheapproperty.Maxheapandminheaparetwoflavorsofheapdatastructure.Theheappropertyformaxheapis:eachnodeshouldbegreaterthanorequaltoeachofitschildren.While,forminheapitis:eachnodeshouldbesmallerthanorequaltoeachofitschildren.Heapdatastructureisusuallyusedtoimplementpriorityqueues.
DictionaryDictionaryisadatastructurethatmaintainsasetofitemsindexedonbasisofkeys.
Social
Like Us on Facebook
Follow Us on Twitter
Connect Us on Google+
Digg
Delicious
RSS Feed
Stumble Upon
Tumblr
SiteLinks
Home
C Programming
Java Programming
Data Structures
Web Development
Tech Interview
About Us
Contact Us
Sitemap
Dictionarystoresdatainformofkeyelementpairs.
HashTableHashTableisagainadatastructurethatstoresdatainformofkeyelementpairs.Akeyisanonnullvaluewhichismappedtoanelement.And,theelementisaccessedonthebasisofthekeyassociatedwithit.Hashtableisausefuldatastructureforimplementingdictionary.
GraphGraphisanetworkeddatastructurethatconnectsacollectionofnodescalledvertices,byconnections,callededges.Anedgecanbeseenasapathorcommunicationlinkbetweentwonodes.Theseedgescanbeeitherdirectedorundirected.Ifapathisdirectedthenyoucanmoveinonedirectiononly,whileinanundirectedpaththemovementispossibleinbothdirections.
LastWordInthistutorialwesawabriefintroductionofvariousimportantdatastructures.Wealsotalkedofwhatdatastructuresare,andwhydatastructuressomuchimportantforinformationsystems.Datastructuresalongwithalgorithmsisacoresubjectofcomputerscience.Hopeyouhaveenjoyedreadingthistutorial.Pleasedowriteusifyouhaveanysuggestion/commentorcomeacrossanyerroronthispage.Thanksforreading!
References1. AlgorithmDesign[Foundations,Analysis,andInternetExamples]2. Algorithms,4thEdition3. HandbookofDataStructuresandApplications
copyright 2015 cs-Fundamentals.com [By Krishan Kumar]