data structure book

download data structure book

of 16

description

data structure

Transcript of data structure book

Data Structures Lecture-1: Introduction

Data Structures

IntroductionLecture 4,Jan 21, 20131Data StructureA data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Formal definitionThe logical and mathematical model of a particular organization of data is called a data structure.Data structure operations

TraversingAccessing each record exactly once. SearchingFinding the location of the record with a given key value.

InsertingAdding new records to the structure.

DeletingRemoving a record from the structure.

Sorting:Arranging the records in some logical orderMerging:Combining the records in two different sorted files into a single sorted files

Data structure operations (Continued)Types of Data StructureLinear Data Structure A data structure is said to be linear if its data element form a sequence or a linear list. Array, Linked list, Queue , StackNon Linear Data structure A non linear data structure is mainly used to represent data containing a hierarchical relationship between elements.Tree GraphArrayLinear array (One dimensional array) : A list of finite number n of similar data elements referenced respectively by a set of n consecutive numbers, usually 1, 2, 3,..n.

ExampleA linear array STUDENT consisting of the name of six students123456Dalia RahamanSumonaMubtasim FuadAnamul HaqueIbtisam RahamanJarinSTUDENTHere, STUDENT[4] denote Anamul HaqueLinked listsA linked list, or one way list, is a linear collection of data elements, called nodes, where the linear order is given by means of pointers.

Each node is divided into two parts: data and link.

First part data contain information of element.

Second part link contain the address of the next node.

NextDataNodeLinked listsStartDataNextnodenodeDataLinked list with two nodesStacksStacks is linear list which follow LIFO (Last in first out) operation.Deletion and insertion take place from the one end.Two methods - add item to the top of the stack - remove an item from the top of the stack

QueuesQueue is also a list follow FIFO operation (First in First Out). Insertion is done at one end, while deletion is performed at the other endThe insertion end is called rearThe deletion end is called frontInsertRemove

rearfront GraphA graph G = (V,E) is composed of:V: set of verticesE: set of edges connecting the vertices in VAn edge e = (u,v) is a pair of verticesExample:abcdeV= {a,b,c,d,e}

E= {(a,b),(a,c),(a,d),(b,e),(c,d),(c,e),(d,e)}

14AlgorithmAn algorithm is a definite procedure for solving a problem in finite number of stepsAlgorithm is a well defined computational procedure that takes some value (s) as input, and produces some value (s) as output.

15ComplexityComplexity is the consumptions of resources.

Time complexity is a function f(n) describing the amount of time an algorithm takes in terms of the amount of input to the algorithm.

Space complexity is a function f(n) describing the amount of memory (space) an algorithm takes in terms of the amount of input to the algorithm. 16Complexity of AlgorithmBest Case Average Caseworst Case