You are on page 1of 71

2.

Data Structures
Computer Science

12th Standard
Total 17 marks

1 MCQ X 1 Question = 1 Mark


3 Mark X 4 Question = 12 Marks
4 Marks X 1 Question = 4 Marks

Total
= 17 MArks
Questions :
▪ (c) What is Data structure ? Explain Linear Data Structure and Non-linear
Data Structure. (Ch. 2/Q. 2/Pg. 2-2)
▪ (b) What is Data Structure ? Define the following terms of data structure:
(i) Record (Ch. 2/Q. 1(vi)/Pg. No. 2-2)
(ii) File (Ch. 2/Q. 1(vii)/Pg. No. 2-2)
(iii) Field (Ch. 2/Q. 1(v)/Pg. No. 2-1)

3
Introduction to Data Structures
● Data
● Data Item
● Group Item
● Elementary Item
● Entity
● Attributes/Properties
● Entity Set
● Information
● Field
● Record
● File
● Primary Key
● Data structure
Data : Data are values or sets of values.
Eg. Student Name and id
Data Item : Data items refers to a single unit of values.
Eg. Student full name (First name,middle name , Last name)

Data Item

Group Item Elementary Item

Eg. Student full name Eg. Pincode,mobile no.


(First name,middle name , Last name)
5
Entity :
▪ Attributes/Properties = Values
▪ Values - > numeric/Non numeric
▪ Eg. Employee of an Organisation

▪ Employee ID = 123 Entity Set


▪ Name = Ramesh
▪ Age = 25
▪ Gender = Male
Entity 6
Information : Information means meaningful data.

Fields : Single elementary unit of information representing attributes of entity.


Eg. Name,Age

Record : Collection of Fields

File : Collection of record

Primary Key : Unique value

7
8
Data Structures:

“The logical or mathematical


model of particular organisation
is called a data structure ”.
Use OF DS : Operating System,
Compiler Design, Artificial intelligence,
Graphics and many more.

9
10
Questions :
(b) Explain any six data structure operations. (Ch. 2/Q.3/Pg. 2-2)
(b) Explain any three data structure operations.
(Ch. 2/Q. 3/Pg. No. 2-2)

11
Data StRUCTURE Operations
● Traversing
● Searching
● Inserting
● Deleting
● Sorting
● Merging 12
Algorithmic notation
Algorithm
An algorithm is a finite step-by-step list of well defined instructions
for solving a particular problem.

Algorithm 1 : Purpose of algorithm and input data and variable used

Step 1 : …………….
Step 2 : …………….

Step n : …………….

13
Algorithmic notation
Example : Q. Write an algorithm for sum of two numbers.

Algorithm 1: This algorithm take A and B as input


and print sum two numbers.

Step 1: Start

Step 2: Read A,B

Step 3: Sum=A+B

Step 4: Print Sum

Step 5 : stop 14
Questions :
Q. (a) Explain with flowchart the following control structure:
(i) Sequence logic (ii) Selection logic (iii) Iteration logic (Ch. 2/Q. 10/Pg. 2-7)
(b) Explain Conditional Flow and Repetitive Flow used in data structure with
diagram. (Ch. 2/Q. 7 and 8 OR Q. 10 /Pg. No. 2-5, 2-6 and 2-7)

15
Cntrol Structures
Sequential Flow Conditional Flow Repetitive Flow
(Sequential Logic) (Selection Logic) (Iteration Logic)

Single Alternative Double Alternative Multiple Alternative

16
Flowchart Symbols

17
Sequential Flow (Sequential Logic)
• Algorithms consists of modules.
• Each modules is a set of steps.
• In Sequential flow the modules are executed
one after the other.

Module A

Module B

Module C

18
Conditional Flow (Selection Logic)
• In conditional flow, one or other module is
selected depending on condition.

Conditional Flow
(Selection Logic)

Single Alternative Double Alternative Multiple Alternative

19
Single alternative
IF condition, then :
[Module A]
[End of IF structure]

No
Cinditition
?

Yes
Module A

20
double alternative
IF condition, then :
[Module A]
ELSE :
[MODULE B]
[End of IF structure]

No
Condition
?

Yes
Module A Module B

21
Multiple alternative
IF condition (1), then :
[Module A1]
ELSE IF condition (2), then :
[MODULE A2]
:
:
ELSE IF condition (N), then :
[MODULE AN]
ELSE :
[Module B]

[End of IF structure]

22
Repetitive Flow (ITERATION Logic)
Here certain module is executed repeatedly
until condition satisfies. K=R

For Loop :
Repeat for K=R to S by T No
[Module] Is K<=S
?
[End of loop]
Yes
Module A

K=K+T

23
While Loop :
Repeat While condition :
[Module]
[End of loop]

No
Condition
?

Yes

Module A

24
Questions :
▪ (a) What is an Algorithm ? Write an algorithm to find the roots of a
quadratic equation ax² + bx + c = 0, where a is not equals to 0.
(Ch. 2/Q. 4 & Q. 11/ Pg. 2-3 & 2-8)

25
Problem : Write an algorithm to find roots of quadratic equation ax2+bx+c=0

±
Where a≠0 and roots are given by, X=

Solutions:
Algorithm : This algorithm inputs coefficients a, b and c of quadratic equation and
finds real roots, if any.
Step 1: Start Else :
Step 2 : Read a,b,c Print “No real roots”
Step 3 : Calculate d=b2-4ac Step 5 : Stop
Step 4 : If d>0 then

1. X1= , X2=

2. Print X1 ,X2
Else if d=0 then
1. X1=X2= -b/2a
2 Print “Real and Same roots”
26
Problem : Write an algorithm to print numbers from 1 to 100
Solutions:
Algorithm : This algorithm will print numbers from 1 to 100

Using For Loop :


Step 1: Start
Step 2 : Repeat step 3 for K=1 to 100 by 1
Step 3 : Print k
Step 4: stop

Using While Loop :


Step 1: Start
Step 2 : Set K=1
Step 3 : Repeat step 4 and 5 while(K<=100)
Step 4 : Print k
Step 5 : Increment k=k+1
Step 4: stop
27
Questions :
▪ (c) What is Array ? Write an algorithm for Traversing linear Array.
(Ch. 2/Q. 15/Pg. 2-10)
▪ (a) What is a Linear Array? If lower bound is 26 and upper bound is
45, then compute length of Array. (Ch. 2/Q. 12/Pg. No. 2-9)

28
ARRAYs
• A linear array is a list of finite number n homogeneous data elements.
i.e. the data elements are of same type.
• The elements of the array are referenced respectively by an index set
consisting of n consecutive numbers.
• The elements of array are stored respectively in successive memory
locations.
• Length=UB-LB+1
• UB = Upper bound (largest index)
• LB = Lower bound (smallest index)
• The elements of array A may be denoted by subscript notation
A0, A1, A2, A3,……., An, or A[0],A[1],A[2],…….,A[n]

29
Marks ARRAYs
0 75

1 87 Marks[0]=75
Marks[1]=87
2 91 Marks[2]=91
Marks[3]=92
3 92 Marks[4]=95
Marks[5]=99
4 95

5 99

30
Representation of linear arrays in memory
• The elements of linear array are stored in successive memory cells.
• The number of memory cells required depends on type of data
elements.
• Computer keep track of address of the first elements of array.
• If LA is linear array then address of first elements is denoted by base
(LA) and called base address of LA.
• Using this address, computer calculates the address of any
elements of LA by using the formula-
LOC (LA[k]) = Base (LA) + W (K-LB)
K : Index of array element

Base (LA) : Address of first elements

W : Number of words per memory cell for LA

LB : Lowest index

31
Representation of linear arrays in memory
Memory Address

1000

1001
Array elements are
stored sequentially
1002

1003
.
.
.
.
.

32
Traversing linear arrays
• Traversing array means accessing each element of the array only once.
• We need to performs this operation several times in a program.
• The algorithm for this operation is described below.

Algorithm- Traversing a linear array.


Suppose LA is linear array with lower bound LB and upper bond UB. This algorithm
apply PROCESS to each element LA.

Step 1 : Start
Step 2 : Initialize counter
1. Set K=LB
2. Step 3 : Repeat steps 4 and 5 while K <= UB
Step 4 : Visit element
Apply PROCESS to LA [K]
Step 5 : Increase counter
Set K= K+1
[End of loop]
Step 6 : Stop 33
Inserting And deleting
• Inserting refers to the operation of adding another element to the existing elements.
• Deleting refers to the operation of removing one of the element from existing
elements.
• The element can be inserted at the end of array or in the middle of the array.
• insertion at end can be easily done provided memory space is available .
• But when we want to insert element in the middle of array, then we need to create
space for the element ,by moving down the other element.
• Similarly deleting an element at end of array is easy .
• But when element in the middle of array is deleted, then we have to move other
element upward to fill the gap.

34
Algorithm for inserting into linear array is given below:
Algorithm – Inserting element into liner array.
INSERT (LA, N, K, ITEM)
Here LA is linear array with N element and K is position integer such that K<= N. This
algorithm inserts an element ITEM into the Kth position in LA.
Step 1 : Start
Step 2 : Intialize counter.
Set J=N-1
Step 3 : Reapeat steps 4 and 5 while J>=K.
Step 4 : Move Jth element downward.
Set LA[J+1] = LA [J]
Step 5 : Decrease the counter.
Set J=J-1.
Step 6 : Insert the element
Set LA[K]=ITEM
Step 7 : Reset N.
N=N+1.
Step 8 : Stop 35
Questions :
▪ (b) Explain bubble sort algorithm with suitable example. (Ch. 2/Q. 19/Pg.
2-13)
▪ (b) Explain Bubble sort algorithm with suitable examples. (Ch. 2/ Q. 19/
Pg. No. 2-13)

36
The algorithm for deleting element from array is given below :

Algorithm – Deleting element from linear array.

DELETE (LA, N, K,ITEM)

Here LA is linear array with N element and K is a positive integer such that K<N . This algorithm
deletes the Kth element from LA.
Using while loop :
Step 1 : Start
Step 2 : Set ITEM =LA [K]
Step 3 :Initialize Counter
J=K
Step 4 : Repeat steps 5 and 6 while J<=N – 2
Step 5 : set LA [J] = LA [J+1]
Step 6 : Increase the counter.
Set J=J+1.
Step 7 : Reset N
N=N-1.
Step 8 : Stop 37
The algorithm for deleting element from array is given below :

Algorithm – Deleting element from linear array.

DELETE (LA, N, K,ITEM)

Here LA is linear array with N element and K is a positive integer such that K<N . This algorithm
deletes the Kth element from LA.

Using for loop :


Step 1 : Start
Step 2 : Set ITEM =LA [K]
Step 3 : Repeat for J=K to N – 2
Move J+1st element upward.
set LA [J] = LA [J+1]
[End of loop]
Step 4 : Reset N
N=N-1.
Step 5 : Stop
38
Sorting
Algorithm- Bubble sort.
Sort (DATA, N)
Here DATA is an array with N elements. This algorithm sorts the elements in DATA.
Step 1 : Start
Step 2 : Repeat steps 3 and 4 for K=1 to N-1
Step 3 : Set PTR = 0
Step 4 : Repeat step 5 and 6 while PTR <= (N-1 - K ):
Step 5 : If DATA [PTR] > DATA [PTR + 1] then:
Interchange DATA [ PTR ] and DATA [PTR +1]
[END of IF structure]
Step 6: Set PTR = PTR +1
[End of inner loop]

[End of outer loop]


Step 5 : Stop.
39
Questions :
▪ (b) Write any three distinguishing points between Linear Search and
Binary Search. (Ch. 2/Q. 24/ Pg. 2-18)
▪ (b )Explain Binary Search algorithm with a suitable example. (Ch. 2/Q.
23/Pg. No. 2-17)

40
Searching

• Searching refers to the operation of finding the location of given element in the list.
• The search is said to be successful if item is found.
• There are many searching algorithms.
• The most commonly used algorithms are linear search and binary search.

41
Algorithm - Linear search
linear search
LINEAR (DATA, N, ITEM, LOC)
Here DATA is a linear array with N elements, and ITEM is given elements. This algorithm finds the location LOC of
ITEM in DATA
Step 1: Start
Step 2 : Initialize counter.
Set LOC=0
Step 3 : Repeat step 4 and 5 while LOC<N
Step 4 : IF(ITEM==DATA[LOC])
Print : ITEM found at LOC
[break loop]
Step 5 : Set LOC = LOC + 1
[ End of loop]
Step 6 : IF LOC = N, then :
Print : ITEM not found
42
Step 5 : Stop
Algorithm – Binary search
Binary search
Binary (DATA, LB,UB,ITEM)
Here DATA is sorted array with lower bound LB and upper bound UB. ITEM is given element. BEG denote beginning,
MID demotes middle and END denotes end locations of segment of DATA. This algorithm finds the location of ITEM in
DATA
Step 1: Start ELSE :
Step 2 : Set BEG=LB, Set BEG=MID+1
END=UB [End of If structure]
[End of loop]
Step 3 : Repeat steps 4 and 5 while BEG<=END
Step 6 : IF Data[MID]!= ITEM then :
Step 4 : Set MID=INT((BEG+END)/2)
Print : Item not found
Step 5 :IF ITEM==DATA[MID] then :
Step 7: Stop
Print: Item found at MID
[Break Loop and go to step 7 ]
ELSE IF ITEM <DATA[MID] Then :
Set END=MID-1
43
Pointer arrays
• A variable is called pointer if it points to an element in list.
• The pointer variable contain the address of an element in the list.
• An array is called pointer array if each element of array is a pointer.
• The use of pointer array can be Discussed as below :
• Suppose we have four groups consist of list of members. The membership list is to be stored in
memory.
• The most efficient method is to form two arrays.
• One is member consisting of list of all members one after the other another pointer array group
containing the starting location of different groups.
• It is shown in figure

44
Pointer arrays

45
Pointer arrays

46
Questions :
▪ (a) What is Record ? Explain how records are represented in
memory using array ? (Ch. 2/Q. 26 & Q. 28/ Pg. 2-19 & 2-21)
▪ (a) Write four difference point between Record and Linear Array.
(Ch. 2/Q. 27/Pg. No. 2-20)

47
records
• Records is a collection of field.
• A record may contain non homogenous data. i.e. data items in a record may have different data
types.
• In records, the natural ordering of element is not possible.
• The elements in records can be described by level numbers.
• For example, a hospital keeps a record of new born baby.
• It contains following data items : Name, gender, birthday, father, mother.
• Birthday is a group item consisting of month, day and year.
• Father and mother are also group item with subitems name and age.
• The structure of this record is shown below :

48
records
1. New born
2. Name
2. Gender
2. Birthday
3. Month
3. Day
3. Year
2. Father
3. Name
3. Age
2. Mother
3. Name
3. Age
49
The number to left of each variable is called a level number.
Each group item is followed by its subitem. The level of subitem is 1 more than the level of group item.
To indicate number of records in a file we may write
1 Newborn ( 20 ).

It indicates a file of 20 records.


Any particular field in record can be accessed by using period.
For example in above record, if we want to refer to the age of the father then it can be done by writing
Newborn.father.Age

If there are 20 records and we want to refer to gender of sixth newborn then it can be done by writing
Newborn.gender[6].

50
Representation of records in memory
• Records contains non homogenous data.
• To store record in memory we may use linear arrays.
• For above example of new-born record, we requires nine linear arrays such as Name, gender,
month, day, year, father name, father age, mother name, mother age.
• One array for each element of data item.
• All the arrays should be parallel that is for subscript K the elements Name[K], gender[K], ……..,
mother age[K]
• Must belong to same record.

51
Questions :
▪ How linked list are represented in memory ? ( ch.2 / Q.32 / Pg.2-23)
▪ ( c ) Write two features of each of data structure:
(i) Record (Ch. 2/Q. 26/Pg. No. 2-19)
(ii) Array (Ch. 2/Q. 12/Pg. No. 2-9)
(iii) linked list
▪ (a) Define linked list. Draw and explain labelled diagram of linked
list with 5 nodes. (Ch. 2/Q. 30/Pg. No. 2-21)

52
Linked Lists
• A linked list is a linear collection of data elements, called nodes.
• Where linear order is given by means of pointers.
• Each node is divided into two parts.
• The first part contains the information of the element and second part is link field which
contains the address of the next node in the list.
• The left part represents the information part of the node.
• The right pointer is next pointer field of node.
• The arrow is drawn from this field to next node.
• The pointer field of last node contains null pointer.
• The list pointer variable is start or name.
• This contains address of first node in list.
• We need only this address to trace the list.

53
Linked Lists - Node

54
Linked Lists

55
Array Vs Linked List
Array Linked List

Array require consecutive memory Linked Lists doesn’t require consecutive


locations. memory locations.

Arrays can not be easily extended. Linked list can be easily extended.

Insertion and deletion of array element is One can easily insert and delete array
expensive. element.

56
Representation of linked list in memory
• Linked list can be represented by two linear arrays.
• One is INFO, containing information part and other is LINK, containing next pointer field.
• The name of linked list, start, contains beginning of the list.
• Start points to 5th element.
• INFO[5] = A and LINK[5] = 2.
• So the next node is 2.
• INFO[2] = B and LINK[2] = 9.
• The next node is 9.
• INFO[9] = C and LINK[9] = 10.
• Where INFO[10] = 0 i.e. null.
• The list is ended here.

57
Representaion of linked list in memory

58
Questions :
▪ (a) Define the following terms with reference to tree:
(i) Root (Ch. 2/Q. 38/Pg. 2-30)
(ii) Leaf (Ch. 2/Q. 38/Pg. 2-30)
(iii) Sibling (Ch. 2/Q. 38/Pg. 2-30)
(iv) Depth (Ch. 2/Q. 39(2)/Pg. 2-30)
▪ (a) Define the following terms with respect to data structures :
(i) Array (Ch * .2 / Q * .12 / P g * .2 - 9)
(ii) Stack (Ch * .2 / Q * .37 / P g * .2 - 29)
(iii) Queue (Ch * .2 / Q * .37 / P g * .2 - 29)
▪ (c) Draw a binary tree structure for the following expression : F = (a
- b) / ((P* m) + h) (Ch. 2/Q. 60/Pg. 2-40)
▪ ( c ) What is Binary Tree? With suitable example show the
relationship between Total Number Nodes and Depth of Binary
Tree. (Ch. 2/Q. 42/Pg. 2-32) 59
Questions :
▪ (b) Explain following terms used in Binary Tree:
(i) Sibling (Ch. 2/Q. 38/Pg. No. 2-29, 2-30)
(ii) Successor (Ch. 2/Q. 41/Pg. No. 2-31)
(iii) Leaf (Ch. 2/Q. 38/Pg. No. 2-29, 2-30)
▪ (b) What is Binary Tree? Draw the Tree diagram for the expression.
B = (3R/5T)²-(R+Q³)
(Ch. 2/Q. 40 and Q. 62/Pg. No. 2-31 and 2-41)
▪ (a) Explain the memory representation of Binary Tree with suitable example.
(Ch. 2/Q. 44/Pg. No. 2-32)
▪ (b) Explain linked representation of binary tree in memory with suitable
example. (Ch. 2/Q. 44/Pg. No. 2-32)

60
Questions :
▪ (b) Define Binary tree. Draw a Tree diagram for following expression.
Y= [(a-b-c) + (a+b-c)]³/2
(Ch. 2/Q. 40 and Q. 63/Pg. No. 2-31 and 2-41)

61
OPT
3. Exit

Stack and Queue


o.37
Explain Stack and Queue with
suitable examples. OR
Explain LIFO and FIFO (Mar.2013,July 2017)
Ans. LIFO System: Systems with suitable examples.
Oct. 2005, 2010)
(i) LIFO
system is
last-in-first-out system.
inserted at last, will In this type of
(ii) Stack is an
be deleted first. system, the elemernt which 1s

takes place example


of LIFO
svstem. It is a linear svstem in
(iii) The insertion
only at one end i.e.
top of the list.
which insertion and deletion
operation is referred to as push and
eg. consider a stack of
at the dishes. If we want to add a deletion operation as pop.
top stack also deletion
of new dish to this
stack thern it is added
FIFO System: takes place from the top.
(i) A FIFO
system is
inserted first in thefirst-in-first-out
list will
system. In this type of
system, the element which is
(ii) Queue is an example of also be deleted first.
FIFO
place only at one end of the listsystem. A queue is a linear list, in which insertion takes
other end, called as known as 'rear' of the list and
'front' of the list. deletion takes place at the
e.g. A queue for tickets in a cinema hall.

Tree
Q. 38 What is a tree ? What do
you mean by root, leaf, siblings and child
about tree.
Ans.: Tree: Oct. 2006, 2010
Tree is a non-linear
hierarchical data structure which consists of
nodes (i.e. collected data finite set of one
items) such that: or more
a) There is specially
designated node called the root. (A)
b) The remaining nodes are
partitioned into n2 0 finite disjoint sets B
T1, T2,..., Tn where each of these set is tree.
T1, T2, Tn are called 'subtrees' of the
..,

For e.g. figure shows tree which has 11


root.
D
(G)
nodes, each item of data
being a single letter. O K
Root
A node which has no parent.
Generally first node is called as 'root node'. In figure, a the
node A is the root of the tree.
Leaf July 2018
The node which has no child or children. Such nodes have degree zero. In figure a D, I
F,J, K are the leaf nodes. Also called as terminal node.
Child
The nodes which are reachable from a node, say u, through a single edge are called the
children of u. e.g In figure a, the children of node C are F, G, and H.

Sibling: July 2018)


Children of the same parent are said to be siblings. eg. The nodes D and E are both
children of node B. So D and E are siblings.
Q.39 Explain the
following terms:
Ans.: 1. Level of tree:
Each node in a tree is assigned a level number. Generally, the level number of root 'R' of
the tree is zero and every other node is assigned to level number which is one more than
the level number of its parent.
It is the distance from the root.
For e-g (A) Level 0
Level 1
(B)

D) F G) Level 2
2 Depth/Height: (March2017
Depth of a tree is defined as maximum level of any node in a tree. If root is level 0 then
depth or height of tree is equal to 1 + largest level number.
e.g. Depth of above tree is 3
3. Degree
The number of subtrees of a node is called degree of a node.
The degree of a tree is the maximum degree of the node in tree.
e.g. the degree of each node in figure is as

Node Degree
A 2
B C B 2
C
D, E, E G, H 0

The tree has degree 3.


Q. 41 What is a binary tree ? With a suitable example, explain the terminology
describing
family relationship between the elements of a binary tree. (March 2005,11; July 18)
Please refer Q. No. 40.
Ans.: Binary tree:
Basic terminology : Consider the example:
The binary tree contains 8 nodes (A to H). Root A is at the top of tree.
Left successor: B is left successor of node A. B
(1)
Right successor: C is right successor of node A.
(2)
(3) Left subtree: Left subtree consists of nodes B, D andE.
4) Right subtree: Right subtree consists of nodes C, F, G and H.
(5) Terminal node: The node with no successors are is called terminal node D. E, H and G
are terminal nodes.
(6) Binary tree Tl and T2 are similar if they have same structure.
Any node N in a binary tree T has either 0, 1 or 2 sucessors.
Q. 42 What is a binary tree ? With a suitable example show the relationship between total
numbers of nodes and depth of a tree. Oct. 2003,15, March 2006, March 2018)
Ans.
Binary tree: Please refer Q. No. 40.
Relationship between total number of nodes and depth of a tree:
Depth of a tree means maximum level of any node in a tree. Maximum number of nodes
ofbinary tree with depth n are 2-1
For example:
Consider the following tree with depth 3.
So with depth 3, the total number of nodes in a given tree is A)
2-1 23-1
(B)
= 8-1

= 7 depth
4 The tree with depth n having 2"-1 number of total nodes.
Q. 44 How binary trees are represented in memory ? OR
With suitable
(Mar.2015, 20, July 2016,19
example and labelled diagram, show the representation of binary tree
in memory.
Ans. (March2003, 2009
A binary tree T can be represented in memory by two types of
(i) Linked representation
representation:
(ii) Sequential representation.
(i) Linked representation:
Linked
(Oct. 2008,15)
representation three parallel arrays INFO and, LEFT and RIGHT and a
uses
pointer variable ROOT such that for an index K, INFO [K] contains actual
LEFT [K] contains address of left child and RIGHT element
[K] contains address of right child.
e.g. Consider a binary tree as below
The above tree can be represented in memory as,
INFO LEFT RIGHT
1 B 14
2 G 12 13
3 0
ROOT 4 E 11 0
5 A 9

6 3
AVAIL 7 D 0 0

10 8 6
9 C 14 2

10
11 H 0 0
12 0 0

13 0

14 F
The ROOT stores address of first node of tree T.
another node to tree T, it is inserted at
AVAIL stores address of first null node. To insert
memory location pointed by AVAIL
then it will be inserted at INFO [10]. After
Note In above example, to insert an element K,
will contain and AVAIL will
(null pointer)
insertion, LEFT [10] and RIGHT [10]
zero

inserted at 8.
contain 8 i.e. next element is to be
(ii) Sequential representation:
linear array is used. This array is generally
sequential representation, only
one
For
known as TREE such that:

(a) The root R of the tree is stored


in TREE [1]
TREE .K], then,
(b) If a node N of tree stored in
its left successor is stored in
TREE |2"K] and right successor is stored in TREE [(2*K) + 11
tree as follows:
e.g. Consider a binary
This tree can be represented in memory as,
TREE
1 A
2 B
3 C
D
5 E
6
7 F
8
9
10
In general, the sequential representation of a tree with depth d will require an array with
approximately 2d+l elements.
Q.60 Draw a binary tree structure for the following expression :
July 201
F (a b) / ((P * m) + h)

Ans.
0.62 What is Binary Tree ? Draw the Tree diagram for the
expression.
B (3R/5T)? - (R+ Q) (Ch. 2/Q. 40/Pg. No. 2-31)
Ans.
March 2019

3
Q.63 Define Binary tree. Draw a Tree diagram for following expression.
Y= [(a
March 2020
-b - c) + (a +b-c)]32 (Ch. 2/Q. 40 and Q. 63/Pg. No. 2-31 and 2-41)
Ans.
2. Data items that are divided into subitems are called as -

(March 2018
) Group items (ii)Elementary items
(ii) Nodes iv) Arrays
Ans.: (i) Group items
3. In LINKED LIST, Link field contains-
i) Value of next node (ii) Address of next node
(ii) Value of previous node (iv) None of these
Ans.: (i) Address of next node

4. A record is a collection of- (March 2017


(i) Files (ii) Arrays
(iii) Fields (iv) Maps
Ans.: (ii) Fields
in huhhle sort aleorithm having 'n' input items is directly

You might also like