Data Structure
Data Structure
3) Elementary items : Items which are not divided into subitems are called a
elementary items.
e.g. Pincode number cannot be divided into subitems.
4) Entity : An entity is something that has certain attributes or
properties which may be assingned values.
Bio -Data
Name Age Address Education
Amar 25 Delhi B.A.
Nisha 30 Nagpur [Link].
1..
Q. 3 : What are the different data structure operations :
Ans : 1) Traversing : Accessing each record or element exactly once, so that it can be
processed is called traversing.
2) Inserting : Adding new record to the existing data structure is called inserting.
3) Deleting : Removing a record from the existing data structure is called deleting.
4) Searching : Finding the location of record with given values is called searching.
5) Sorting : Arranging records in some logical order is called sorting.
i.e Ascending or descending
6) Merging : Merging means combining the records in two different files to form
a single file.
>
i) In theis logic modules can be executed one after another.
Module A
ii)The sequence may be present by means of numberd step.
>
Module A
>
Module A
>
2) Conditional Flow or Selection logic :
i) This logic depends on condition.
ii) Select one out of several alternative module.
>
>
module A Module A
End of if structure
If a condition is satisfied then module A will
>
>
execute, otherwise module A will skipped.
>
2..
ii) Double alternative :
If (condition)
>
module A if
else condition >
?
module B
>
( End of If statement) Yes
>
If a condition is satisfied then module A
Module A Module A
will execute, otherwise module B will
execute.
>
>
>
>
iii) Multiple alternatives :
If(condition 1) , then :
module A
else if (condition 2) , then :
module 2
.
.
.
elseif (contition n), then :
module An
else
module B
( End of if statement)
The logic of this structure allows only one module to be executed. The module following
the condition which is satisfied the condition will be executed. If no conditionis satisfied then
the module which follows last else statetment will execute.
>
>
>
>
module
> >
>
>
3..
Q. 5 : What is linear array ?
Ans : 1) A linear array is group or set of finite elements having same type of data i.e homogeneous.
2) All the elements in a array are stored on consecutive memory location.
3) The number of elements in a array is called length of the array.
4) The first element of array is called lower bound and last element of array is called
upper bound.
Q. 7 : What is inserting ? Write algorithm for inserting element into linear array.
Ans : Algorithm
INSERT(A , N , K , Item)
Here A- is Linear array
N - Number of elements of array
K- is positive integer such that K<N
Item - is to be inserted at K position
Step 1 : Initialize counter Set J=N
Step 2 : Repeat step 3 and 4 while J>=K
Step 3 : Move element forward Set A [ J + 1 ] = A[ J ]
Step 4 : Decrement counter Set J=J-1
Step 5 : Insert the element Set A [ K ] = Item
Step 6 : Reset N Set N=N+1
Step 7 : Exit
4..
Q. 8 : What is deleting ? Write algorithm for deleting elemet into linear array.
Ans : Algorithm
DELETE(A , N , K , Item)
Here A- is Linear array
N - Number of elements of array
K- is positive integer such that K = N
Item - is to be deleted from A at K position
Step 1 : item = a [ K ]
Step 2 : Repeat for J = K to N - 1
Move [ J + 1 ] element backward
set A [J ] = A[ J + 1 ]
Step 3 : Reset N Set N=N-1
Step 7 : Exit
Q. 9 : Write algorithm for linear search.
Ans : Linear ( A , N , Ietm , LOC)
Here A- is Linear aray
N- is number of elements in array
Item : the elemenet is to be find out.
LOC - means the location of search item
Step 1 : Insert item at the end of the A. Set A [ N + 1 ] = Item
Step 2 : Initialize Counter Set LOC = 1
Step 3 : Search for item
Repeat while A [ LOC ] item Set LOC = LOC + 1
End of Loop
Step 4 : If LOC = N + 1
then Set LOC = 0
Sep 5 : Exit
5..
Ex. Given A array with five elements.
11 22 33 44 55
Step 2 : LOC = 1
6..
Q. 11 : Write algorithm for bubble sort.
Ans : Algorithm
Bubble Sort ( A , N )
Here A- is Linear array
N- Number of elements in array.
The algorithm sort the given element in ascending order.
Step 1 : Repeat step 3 and 4 K = 1 to N - 1
Step 2 : Set P =1
Step 3 : Repeat while P <= N - K
if A[ P ] > A [ P + 1 ] then Interchange
Increment pointer
Set P=P+ 1
Step 4 : Exit
7..
Q. 13 : What is pointer array ?
Ans : 1) An array is called pointer array , if each element of that array is a pointer.
2) The variable is called as pointer variable , i.e it contains the address of the another variable.
Mahesh Deepak
Ram
1 Rani <
2 Ashish
Group 1
3 Megha
4 Ramesh <
Group - Pointer array
5 Priya
Group 2
6 Devaand 1 1
7 Mahesh 4 2
8 Sagar < 8 3
9 Rupali 13 4
Group 3 10 Yogesh
11 Deepak
12 Ram
13 Dilip <
Group 4
14 Rita
3) Each element of group array is pointer, which holds the starting address of different groups.
Hence it is called as pointer array.
8..
Q.14 : What is record ?
Ans. : i) A record is collection of relative data items, each of which is called as field or attribute.
ii) Collection of records is known as files. Collection of data is frequently organized into a
hierarchy of fields, records and files.
iii) A records may contain non-homogneous data i.e. data iteams of record need not to be of
same data type. In a record, natural ordering of elements is not possible. The elements record
can be described by level number.
iv) e.g. An organization keeps records of its [Link] contains following data items.
Nams, Sex, Salary, Birthday, Address.
Name is group item consisting of First name, Middle name and Last name. Also, Birthdate and
address are group items.
The structure of this record is shown in figure below:
1. Employee
2. Name
3. First name
3. Middle name
3. Last name
2. Sex
2. Salary
2. Birth date
3. Date
3. Month
3. Year
2. Address
3. City
3. Pincode
v) The number to the left of each variable indicates level number.
vi) Employee (30)
This indicates a file of 30 records.
Q. 15 : What is a record ? How it differs from a linear array ?
Ans.: A record is collection of fields or attributes i.e. relative data items. Collection of data is
frequency orgnized into hierarchy of fields i.e. records.A file is nothing but Collection of records.
9..
Difference between records and linear arrays :
i) A records is a collection of fields, while an array is list of homogeneous data elements.
ii) A record may contain non-homogeneous data.
iii) In a record, nature ordering of elements is not possible. Array elements can be naturally
ordered.
iv) Elements of record are referenced by level number, while those of array can be referenced
by an index set consisting of n consecutive numbers.
Following figure show of above file in three parallel array Name, Address and Phone :
Q. 17 : What are linked lists ? Show a liked list with suitable example having six nodes with a
properly labelled diagram.
OR
With suitable example, show labelled diagram for link between two nodes having the
information part and next pointer field.
Ans. : i) A Linked list is a linkear collection of data elements, called nodes, where the linear order is
maintained with the help of pointers.
10..
ii) Linked list is also called as one-way list.
iii) Each node in the linked list is divided into two parts. First part is called as INFO part,
which contain the information about the elements or actual elements and second part is
called as LINK part, which is next pointers fields i.e. it contains the address of next node in the
list.
START
10
INFO LINK NULL POINTER
>
>
>
> A 13 > B 19 > C 14 > D 12 > E 18 > F X
10 13 19 14 12 18
11..
Q. 18 : How linked lists are represent in memory ? OR
With suitable diagram show the representation of linked in memory.
Ans : 1) Linked list can be represented in memory by using two arrays respectively known as INFO
and LINK.
2) The list also requires a varible Name or Start wnich contain address of first node.
A 9 B 4 C 1 D 6 E
INFO LINK
5 D 6
1
2
3
4 C 1
> 5 A 9
6 E
7
8
9 B 4
2) In this system the element which is inserted last will be deleted first.
3) It is a linear system in which insertion and deletion taking place from one end only i.e.
top of the list.
12..
FIFO system OR Queue
2) In this system the element which is inserted first will be deleted first.
3) It is a linear system in which insertion taking place from one end called rare end and
deletion taking place from another end called front end.
Q. 20 : What is tree ?
Ans : 1) Tree is hierarchical or Non linear data structure which consists of finite set of one or
more nodes.
A
Define the following terms.
1) Root : B C
2) Leaf :
The node having no child or children. Such node have degree zero. This node is also
called as terminal node.
3) Child :
4) Sibling :
In the given fig. the nodes D and E are the child of B so D and E are sibling.
5) Level of tree :
13..
6) Depth or Height of tree:
7) Degree of Node :
NODE DEGREE
A 3 A
B 2 B C
C 3 D F G G
E
D,E,F,G 0
7) Degree of a tree :
Node Degree
A 2 A
B 2 B C
C 3 F G
D E G
D, E, F, G, H 0
If all leaf nodes of a binary tree have same level number and every non leaf node
has non empty left and right subtree then the tree is called complete binary tree.
1) A binary tree T is said to be a 2 tree or an extended binary tree if each node N has
either 0 or 2 children.
2) A node with 2 children are called internal nodes and the node with 0 children are
called external node.
14..
MCQ’s
1) An array is a collection of ________data element.
a) Homogeneous b) Non-homogeneous c) Linear d) Non - linear
Ans : a) Homogeneous
2) A record is collection of ______ data elemets.
a) Homogeneous b) Non-homogeneous c) Linear d) Non - linear
Ans : b) Non-homogeneous
3) Tree is ______ data structure.
a) a) Homogeneous b) Non-homogeneous c) Linear d) Non - linear
Ans : d) Non - linear
4) Linked list is ______ data structure.
a) Homogeneous b) Non-homogeneous c) Linear d) Non - linear
Ans : c) Linear
5) The principle of stack is ______.
a) FIFO b) LIFO c) FILO d) LOFI
Ans : b) LIFO
6) The principle of queue is ______.
a) FIFO b) LIFO c) FILO d) LOFI
Ans : a) FIFO
7) A record is a collection of ______.
a) Fields b) Files c) Arrays d) Maps
Ans : a) Fields
8) Maximum number of nodes in a binary tree with depth ‘n’ are
a) 2n b) n c) Log2n d) 2n-1
Ans : d) 2n-1
9) Accessing the elements of records in an array only once is called _____.
a) Searching b) Sorting c) Traversing d) Deleting
Ans : c) Traversing
10) Finding the location of given elemnts is called as _____.
a) Searching b) Sorting c) Traversing d) Deleting
Ans : a) Searching
11) Data items that are divided into subitems is called as ____
a) Group Items b) Elementary Items c) Nodes d) None
Ans : a) Group Items
12) 11) Data items that are not divided into subitems is called as ____
a) Group Items b) Elementary Items c) Nodes d) None
Ans : b) Elementary Items
13) The time required to execute bubble sort algorithm having ‘n’ inputs items is directly proportional to
______
a) n2 b) n c) Log2n d) Logen2
Ans : a) n2
14) Maximum number of nodes in a binary tree with depth 5 are
a) 5 b) 31 c) 32 d) 25
Ans : b) 31
15) Maximum number of nodes in a binary tree with depth 6 are
a) 64 b) 63 c) 65 d) 36
Ans : b) 63
15..
16) Maximum number of nodes in a binary tree with depth 4 are
a) 4 b) 15 c) 16 d) 5
Ans : b) 15
17) In _____ data strcture an elemets may be inserted or deleted only at one end called top.
a) Queue b) Array c) Tree d) Stack
Ans : d) Stack
18) To arrange the given elemnts in some logical order is called as____
a) Searching b) Sorting d) Combining d) Deleting
Ans : b) Sorting
19) The most efficient search algotithm is _____
a) Binary search b) REverse search
c) Linear search d) Pointer search
Ans : a) Binary search
20) ______ data structure does not require contiguous memory location.
a) Array b) String c) Pointer array d) Linked List
Ans : d) Linked List
21) Tree is a ___________collection of nodes.
a) Hierarchical b) Linear c) Relational d) Graphical
Ans : a) Hierarchical
22) ______ is very useful in situation when data is to be stored and retrived in reverse order.
a) Stack b) Queue c) Linked List d) Tree
Ans : a) Stack
23) _____is the operation of rearranging the elements of an array either in increasing or decreasing
order.
a) Sorting b) Searching c) DMS d) DBMS
Ans : a) Sorting
24) Sorted list is essential requirement for _______ process of an array.
a) Linear search b) Binary search c) Traversing d) Insertion
Ans : b) Binary search
25) Maximum number of nodes of symmetric binary tree with depth 7 are
a) 125 b) 127 c) 128 d) 124
Ans : b) 127
26) _____is the only non linear data structure from the following.
a) Array b) Stack c) Tree d) Linked List
Ans : c) Tree
27) The number of comparisons required for bubble sortingof an array of n elements is _____
a) n(n-1)/2 b) n/2 c) Log2n d) Log10n
Ans : a) n(n-1)/2
16..