Академический Документы
Профессиональный Документы
Культура Документы
organizing data in a computer so that it can be used efficiently. Data Structure is a group of memory locations used to represent the information used by the algorithm. It is a way to store and organize data in the structured manner. Computer's memory is divided into small parts, we use different data structures to store data in those small blocks. Example: Arrays, Linked list, Trees ,etc. Why Do we need them Computers take on more and more complex tasks. Software implementation and maintenance is difficult.
element is adjacent to each other. It has exactly two neighbors elements to which it is connected as its previous and next member. Eg: Array, Linked list, Stack, Queue. Non Linear Data Structures: Non-Linear data structure is that if one element can be connected to more than two adjacent element then it is known as non-linear data structure. Eg: Tree, Graph.
Arrays
Array is basic data structure in which we store data in continues
memory locations. Array is variable which holds multiple elements of same type.
Generic form of arrays: data type array_name[size]; Data type: what type of data(int, float, char...)
element.
Stack
Stack New nodes can be added and removed only at the top Similar to a pile of dishes Last-in, first-out (LIFO) Eg: A stack of books When a person wear bangles the last bangle worn is the first one to be removed and the first bangle would be the last to be removed.
Queue
Queue Similar to a supermarket checkout line First-in, first-out (FIFO). Nodes are removed only from the head. Nodes are inserted only at the tail. The bullet in a machine gun..(you cannot fire 2 bullets at the same time).
Linked Lists
It is a list or chain of items where each item points to
the next one in the list. Each item in a linked list is called a node. Each node contains the data and also the location to the next item. START
bat
cat
sat
vat
NULL
Trees
The data structure which reflects a hierarchical relationship between various elements is called rooted tree/tree.
Graph
A graph G = (V,E) is composed of: V: set of vertices E: set of edges connecting the vertices in V An edge e = (u,v) is a pair of vertices Example: V= {a,b,c,d,e}
a b
c d e
which is not supposed to change within the scope of the problem. When a single element is to be added or deleted, the update of a static data structure incurs significant costs, often comparable with the construction of the data structure from scratch. In real applications, dynamic data structures are used, which allow for efficient updates when data elements are inserted or deleted. Have fixed maximum size. Memory is reserved at the time of compilation. Eg: Array
Dynamic: Have flexible size Memory allocation for the data structure takes place at the run time, only required amount of memory is allocated. Eg: Linked List
homogeneous data elements. (a) The elements of the array are referenced respectively by an index set consisting of n consecutive numbers. (b) The elements of the array are referenced respectively by an index set consisting of n consecutive numbers. n- length/ size if index set consists of 1,2,3n
Length= UB-LB+1
UB= largest index LB=lowest index Let LA be liner array K- index LOC(LA[k])- Address of the element LA[k] of the array
Eg
Consider the array AUTO which records the number of
automobiles sold each year from 1932 through 1984. given Base(AUTO)=200, w=4. Find the address of the array element for the year 1965. LOC(AUTO[1965]=Base(AUTO)+w(1965-LB) =200+4(1965-1932)=332
column Row major order-(1,1)(1,2)(1,3)- 1 row m*n array LOC(A[j,k]=Base(A)+w[M(k-1)+(j-1)]- column major LOC(A[j,k]=Base(A)+w[N(j-1)+(k-1)]- row major
Eg
Suppose a 3d array MAZE is declared using MAZE(2:8,
-4:1, 6: 10), base(MAZE)=200, w=4. find loc of MAZE[5,-1,8] L1=8-2+1=7, L2=1-(-4)+1=6, L3=10-6+1=5 Total elements in maze= li.l2.l3=7.6.5=210 E1=5-2=3, E2=-1-(-4)=3, E3=8-6=2 Row major E1L2=3.6=18 E1L2+E2=18+3=21 (E1L2+E2)L3=21.5=105
(E1L2+E2)L3+E3=105+2=107
LOC(MAZE[5,-1,8])=200+4(107)=200+428=628
Sparse Matrices
Matrices with a relatively high portion of zero entries
are called sparse matrices. If all entries above the main diagonal are zero is known as lower triangular matrices. If non zero entries can only occur on the diagonal or on elements immediately above or below the diagonal, is called a tridiagonal matrix. B[1]=a11, B[2]=a21, B[3]=a22 4 5 6 3 -5 2 4 8 1 9 6 9 3 6
[Visit Element] Apply Process to LA[K] 4. [Increase Counter] Set K:=K+1 [end of step 2 loop] 5. Exit
[Move Jth element downward] Set LA[J+1]:=LA[J] 4. [Decrease Counter] Set J=J-1 [End of step 2 loop] 5. [Insert element] Set LA[K]:= ITEM 6. [Reset N] Set N=N+1 7. Exit
[Move J+Ist element upward] Set LA[J]=LA[J+1] [End of Loop] 3. [Reset the number N of elements in LA] Set N=N-1 exit