Data Structure Notes 1
Data Structure Notes 1
Row-major order
Let A be the array of order m x n. In row-major order, all the
first-row elements are stored in sequential memory locations
and then all the second-row elements are stored and so on.
Base(A) is the address of the first element.
The memory address of any element A[I][J] can be obtained
by the formula LOC(A[I][J]) = Base(A) + W[n(I-LB) + (J-LB)]
where W is the number of words per memory location.
Example: Consider the array of order 3 x 3.
Column-major order
Let A be the array of order m x n.
In column-major order, all the firstcolumn elements are
stored in sequential memory locations and then all the
second-column elements are stored and so on.
Base(A) is the address of the first element.
The memory address of any element A[I][J] can be obtained
by the formula LOC(A[I][J]) = Base(A) + W[(I-LB) + m(J-LB)]
where W is the number of words per memory location.
Example: Consider the array of order 3 x 3.
Example: Consider the array A of order 25 x 4 with base value 2000 and one
word per memory location. Find the address of A[12][3] in row-major order
and column-major order. Solution: Given Base(A) = 2000, m = 25, n = 4 LB = 0
W = 1, I = 12, J = 3
Row-major order:
LOC(A[I][J]) = Base(A) + W[n(I-LB) + (J-LB)]
LOC(A[12][3]) = 2000 + 1[4(12-0)+(3-0)]
= 2000 + 4(12) + 3
= 2000 + 48 + 3
= 2051
Column-major order:
LOC(A[I][J]) = Base(A) + W[ (I-LB) + m(J-LB)]
LOC(A[12][3]) = 2000 + 1[(12-0)+25(3-0)]
= 2000 + 1(12 + 75)
= 2000 + 87
= 2087
Q5)Define Queue?
A queue is an ordered collection of items where an item is inserted at one
end called the “rear,” and an existing item is removed at the other end,
called the “front.” Queues maintain a FIFO ordering property.
The above picture is linked list with 4 with nodes, each node is
containing two parts.
The left part of the node represents the information part of the
node and the right part represents the next pointer field that
contains the address of the next node.
A pointer START gives the location of the first node.
This pointer is also represented as HEAD.
The link field of the last node contains NULL
Q13) What are the different types of Linked List?Explain
There are three types of linked lists.
1.Singly linked list (SLL)
2. Doubly linked list (DLL)
3.Circular linked list (CLL)
The data field contains the data of that node while the link
field contains address of the next node.
Since there is only one link field in each node, the linked list
is called as singly linked list.
In the first node, if BACK contains NULL, it indicates that it is the first node
in the list.
The node in which FORW contains NULL indicates that the node is the last
node in the linked list.
Q19)Define a complete tree?
Tree in which each leaf is at the same distance from the
root. i.e. all the nodes have maximum two subtrees.
Q20)Define a graph ? and its type?
A graph is a collection of nodes called vertices, and the
connections between them, called edges