Data Structure Assignment - Answers-2013
Data Structure Assignment - Answers-2013
Data Structure Assignment - Answers-2013
Data Structure:
Data Structure is a way/method to store data so that various processes
(searching, filtering etc.) can be applied on the data and Information from
that stored data can be accessed quickly and efficiently.
OR
Linear Non-Linear
Data structure that stores the Data structure that stores the
elements in a linear fashion. elements in a non-linear fashion.
Row-major order:
Elements are stored row-by-row / row-wise.
First row, Second row and so on.
Column-major order:
Elements are stored column-by-column / column-wise.
First column, Second column and so on.
Example:
A11 A11
A11 A12
A12 A21
KEY = 45
Header ptr1 ptr ptr2
X 25 15 45 35 5 X
Algorithm:
DeleteAny_SL
Input:
Header: Pointer to the starting node of the linked list.
KEY: Data of the node to be deleted.
Output:
Node with data KEY deleted from the linked list or message on
failure.
Data Structure:
Single linked list whose address of starting node is known from
Header.
Steps:
ptr = Header
While(ptr->Link != NULL) AND (ptr->Data != KEY), do
ptr1 = ptr
ptr = ptr->Link
EndWhile
Sibling:
Nodes which have common or same parent are called Siblings.
In the above tree, nodes B, C and D are siblings as their parent is same, node
A.
Height of Tree:
Number of nodes in the longest path starting from root to leaf is called
Height of Tree.
Relationship between height and maximum level is: h = lmax + 1
Sparse Matrix:
A sparse matrix is a 2-dimensional array where majority of the elements are
NULL.
5 - -
- - 9
- - -
1 - -
Q. Convert the following expressions to prefix and postfix.
1) ( ( ( A + B ) * C ) – D ) / F
Postfix:
A B + C * D – F / [Postfix Expression]
Prefix:
/ - * + A B C D F [Prefix Expression]
Q. Convert the following expressions to prefix and postfix.
2) ( ( P + ( ( Q ^ R ) – S ) ) * ( U – ( P / R ) ) )
Postfix:
Step-1: Fully parenthesize the expression.
Prefix:
Step-1: Fully parenthesize the expression.