0% found this document useful (0 votes)
102 views19 pages

Chp 2 Data Structure TPS

Chapter 2 covers data structures, including definitions of data, group items, elementary items, entities, fields, records, and files. It explains the organization of data through data structures, their types, and operations like traversing and inserting. The chapter also discusses linear arrays, their representation in memory, sorting algorithms like bubble sort, and searching algorithms including linear and binary search techniques.

Uploaded by

sarahman1357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views19 pages

Chp 2 Data Structure TPS

Chapter 2 covers data structures, including definitions of data, group items, elementary items, entities, fields, records, and files. It explains the organization of data through data structures, their types, and operations like traversing and inserting. The chapter also discusses linear arrays, their representation in memory, sorting algorithms like bubble sort, and searching algorithms including linear and binary search techniques.

Uploaded by

sarahman1357
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Chapter(2 DATASTRUCTURES

Scope of the Syllabus Probable marks: 17


Introduction to data structures.
Data structure operations.
Algorithmic notations.
Control structures.
Arrays-Representation in memory, Traversing, Deleting, Sorting, Binary search in
an array, Pointer arrays, Records in memory using array.
Linked list - Representation in memory
Trees, Binary trees - Representing binary tree in memory.

INTRODUCTION TO DATASTRUCTURES
Q.1 Define the following terms:
(i) Data:
Ans. Data are simply values or set of values.
(i) Group items: m23 (March 2018)
Ans. Data items which are divided into subitems are called as group items. e.g. Date may be
divided into three subitemns - day, month and year. So Date becomes group item.
(iii) Elementary items: M23 (March 2018
Ans. Data items which are not divided into subitems are called as elementary items. e.g.
pincode number cannot be divided into subitems. So it is elementary item.
(iv) Entity: M23(March 2018
Ans. An entity is something that has certain attributes or properties which may be assigned
values.
The values themselves mnay be numeric or nonnumeric.
e.g. A Bio-data sheet mainly contains :
Attributes Name Age Sex Education

Values Atul 22 M B.E. (Computer)


(v) Field: (March 2005, 2009,2016: Oct. 2007.2014 July 2013
Field is a single elementary unit of information representing an attribute of an entity.
TPS Computer Science -1 2-2 Data Structures

(vi) Record:
(Mareh 2005, 2009,2016, Oct. 2007,2014; July 2019
Bocord is a colletion of field values of a
given entity.
(vii) File:
ile is the collection of recOrds of the
(March 2005,2009,2016, Oct. 2007 2014 July 2019
entities in a givenentity set.
R# Serial Number Name Address Telephone
001 ABC Pune 5671922
002
XYZ Mumbai 2259649

Record
Field

Q.2 What is a data structure ?


(Mar. 2006,2015; Oct.2002, 2004, March 2018, Dec. 2020
Ans. :
Data may be organized in many different ways. Data structure is the way in which
different data elements are logically related.
ii Collection of data elements forming an organisation characterized by the accessing
functions is called data structure.
iüi) The data structure should be simple and it should show the relationship between data
elements.
ir) Types :
(i) Linear data structure (ü) Non-linear data structure.
In linear data structure, data elemnents are stored in consecutive memory locations or by
using linked representation. e.g. arrays, linked list.
In non-linear data structures the linear order cannot be maintained between data
elements. Generally data elements have hierarchical relationship between them.
e.g. trees
V) Computer language provides different data structures like arrays, stack,queue, tree etc.
Data Structure Operations
Q.3 Explain in brief any six data structure operations. H24
(Oct, 2002,04,06,12,15; Mar. 2002,06,12, July 2017, 19, March 2020, Dec. 202
Ans. :The data appearing in data structures are processed by means of certain operations like :
(i) Traversing :
Accessing each record or element exactly once, so that it can be processed is called as
traversing
For e.g. multiplying each element of an array by 6.
(i) Inserting:
Adding a new record to the existing structure is called as inserting.
Q.0. 10 Explain with flowcharts the following control structures: Flowchart equivalent
(i) Sequence logic, (ii) Selection logic, (ii)Iteration logic
(Mar. 09,12,17;Oct. 03, 04, 05,11,14,21; July 18, 19 Module A
OR Explain 3types of control structures used for flow of controll
Ans. :
Module B
(i) Sequence logic :
In the sequence logic modules are executed sequentially,
one after the another. The sequence may be present Module C

explicitly by means of numbered step or by the order in


which modules are written.
(ii) Selection logic:
Selection logic uses number of conditions, which cause
No
condition
selection of one out of several alternative modules.
(a) Single alternative: Yes
If condition is satisfied then module A, which consists of Module A

number of statements, is executed. Otherwise module A is


skipped and next module is executed.
TPS Computer Science - I 2-8 Data Structures

No
condition
(b) Double alternative:
Yes

Module A Module B

If the condition is satisfied, then module A will be


executed otherwise module B will be executed.
(c) Iteration logic :
Here certain module is executed repeatedly until condition satisfies. At first, the
body of loop i.e. module will be executed withK=Rand then with K= R+T, then with
K=R+2T and so on until K=S. The loop ends when K>S.
K R

Yes
K>S No
Condition

No The repeat-while structure has


Module
the form: Yes

Module

K+ K+T

Here module is executed until the condition is satisfied.


A RyC-0AZhere
TPS Computer Science -I 2-9
Data Structures
Else
Write:NO REAL SOLUTION'
|Endof lfstructurel
4 Exit
ARRAY

Q. 12 What are linear arrays ? (Oct. 2006,i3,14; Mar.2015, July 2016, 17, 19, March 18,
Ans. : Adata structure is said to be linear if its elements forma sequence. J22
A linear array is the data structure which consists of finite, ordered set of homogeneous
data elements such that:
1
The elements of the array are referenced respectively by an index set (subscript
Consisting of 'n' consecutive numbers.
2
The elements of the array are stored respectively in successive memory locations.
The number 'n' of the elements is called length or size of array.
In general, the size or length of the array can be obtained from the index set by the
formula:
Length =UB-LB + 1
where UB- the largest index called Upper Bound.
LB - the smallest index called Lower Bound.
e.g. Let DATA be 5 element linear array as follows :
DATA
1 247
2 500
3 600
4 399
499
The element of an array may bedenoted by the subscript notation such that:
DATA (3] = 600
In C++, array is declared as -
int data [100]; which specify an array data of 100 integers.
Q. 13 How arrays are represented in memory ? (Oct. 2014
Ans. :
i) The elements of linear array are stored in consecutive memory locations.
i) Computer does not need to keep track of the address of every element of array. It jus
requires the address of first element of array, LA, denoted by Base (LA) and called te
base address of linear array LA.
iii) Using this base address, the computer calculates address of any element of array y
using the formula.
LOC (LA[K]) = Base (LA) + W (K-LB)
Q. 19 Explain Bubble sort algorithm with suitable example.
(Match. 2002, 05, 08,.12; 17,; 20; Oct.-2005, 20n
Ans. : Algorithm: M 23
Bubble Sort (DATA, N)
Here DATA is a linear array with N elements. This algorithm sorts elements of DATA ;
ascending order.
Step 1: Repeat steps 2 and 3for K:=1 To N-1:
Step 2: Set Ptr:=1
Step 3: Repeat While Ptr <N-K:
(a) IfDATA [Ptr]> DATA (Ptr + 1], then interchange
DATA [Ptr] and DATA (Ptr +1]
[End of If structure]
(b) [increment pointer]
Set ptr := ptr +1
[End of inner loopl
[End of outer loop]
Step 4: Exit
Explanation :
Suppose DATA is an array of N elements. Sorting these elenents in ascending orde
means arranging the elements such that:
DATA [1<= DATA (2] <=...<= DATA .N]
In Bubble sort, compare DATA(1] with DATA[2] and exchange them
DATA[1] > DATA2J.
Next DATA[2] is compare with DATA(3|. They are exchanged if necessary. This proc
is repeated till DATAJN - 1] is compared with DATAN..
One makes N - 1comparisons, this is called a pass.
After the first pass the largest element is sink to the last position. and second large
During the next pass, compare elements upto the last but one
element moves to the (N-1)" position.
After N-1 passes, all elements are sorted.
TPS Computer Science - 1 2-14 Data Structures

Consider a linear arrayconsisting of 5 elements, given below :


Datal1] 55
Data|2] 43
Data<3] 05
Data<4] 06
Data<5] 09
Pass 1:
(a) Compare DATA[1] with DATA[2] since 55 > 43 .. exchanged
55 43 5 6 9

.:. New list is 43 55 5 6 9


(b) Next compare DATA[2] with DATA[3] since 55 >5.. exchanged
43 55) 5) 6 9
.:. New list is 43 5 55 6
(c) Now, compare DATA[3] with DATAJ4Jsince 55>6 :. exchanged
43 5 (55) 9

.:. New list is 43 6 55 9

(d) Compare DATA|4]with DATA[5] since 55>9.. exchanged


43 5 6 55) (9)
.:. New list is 43 5 6 9 55

At the end of first pass, the largest element 55, has moved to the last position.
Pass 2: In this pass,only three comparisons since K= 2.
(a) (43) (5) 6 55 Since 43 >5.. exchanged
.:. New list is 5 43 6 55

(b) 5 (43 6 55 Since 43 >6.. exchanged


.:. New list is 5 6 43 55

(c) 5 6 (43) (9 55 Since 43>9.. exchanged


.:. New list is 5 6 9 43 55

At the end of second pass, the second largest element 43 has maked to its proper
position.
Pass 3:
9 43 55 Since 5<6.. No exchange
5 6 9 43 55 Since 6 <9.:. No exchange
:. New list is 5 6 9 43 55
TPS Conmputer Science -1 2-15
Data Structure
Pass 4:
array gets sorted in
In this way after complete execution of this algorithm, the
order as followS ascending
DATA||] 05
DATA|2] 06
DATA|3] 09
DATA[4] 43
DATA[5] 55
Q. 20 What do you understand by the term searching ? Which are the different types
searching algorithms ? Explain the linear searching algorithm.
HO3 (March 2004, Oct. 2004, 2010, 202
Ans. : Searching :Searching means to find out particular element from a given list of elenent
or check whether required element is present or not in an array. There are two types o
searching algorithmsas follows:
(1) Linear search (2) Binary search
Linear searching algorithm :
In linear search the given element is compared with each element of list one by on
For algorithm, refer to Q. No. 21.
Q. 21 Write an algorithm for linear search technique with suitable example.
(March 2003, 07, 09;Oct. 2007, 10, 21, July 2016, Dec. 201
Ans. :
Algorithm :Linear Search
LINEAR(DATA, N, ITEM, LOC)
Here DATA is a linear array with N elements and ITEM is given element. This algorithm finc
the location LOCof ITEM in DATA or sets LOC = 0, if search is unsuccessful.
Step 1: [Insert ITEM at the end of DATA]
Set DATAN +1] :=ITEM
Step 2: [Initialize counter]
Set LOC:=1
Step 3: [Search for item]
Repeat While DATA (LOC]= ITEM :
Set LOC:=LOC +1
(End of loop]
Step 4: If LOC =N+1, then:
Set LOC:=0
Step 5: Exit
For example: Given DATA array with following 5 elements
11 22 33 44 55
Suppose ITEM =33
TPS Computer Science - I 2-16 Data Structures

Step 1: Set DATA[6]=33, List becomes


11 22 33 44 55 33
Step 2: LOC= 1
Step 3: Since DATA |1|= 1133. LOC=2
Since DATA (2]= 22 +33 :.LOC=3
Here DATA (3] = 33 = 33 = ITEM
Step 4: Hence ITEM = 33 found at position, LOC = 3.
0. 22 Write an algorithm for binary search technique with example(Oct.
2002,06,11,12,13)
Ans. : Binary search is used to search an element from sorted array. (Mar.2013, 14, 15,19, 22
Algorithm :Binary search W23
Binary (DATA, LB,UB, ITEM, LOC)
Here DATA is a sorted array with lower bound LB and upper bound UB. ITEM is given
element. BEG denotes beginning, MID denoted middle and END denotes end location
of DATA. This algorithm finds the location LOC of ITEM in DATA or sets LOC =
NULL, if search is unsuccessful.
Step 1: [Initialize Variables]
Set BEG:=LB, END :=UB and MID:= INT (BEG + END)/2)
Step 2: Repeat steps 3 and 4
while BEG = END AND DATAMID] ITEM
Step 3: If ITEM < DATAJMID], then:
set END := MID -1
Else :
Set BEG:= MID + 1
[End of If structure]
Step 4: Set MID ;= INT(BEG + END)/2)
[End of step 2loop]
Step 5: If DATA[MID]= ITEM, then:
set LOC:=MID
Else:
LOC:= NULL
[End of If structure]
Step 6: Exit
e.g. Given DATA be the following sorted 13 element array:
11 22 30 33 40 44 55
60 66 77 80 88 99
Suppose ITEM = 40
Step 1 : Initially BEG =1 and END =13
Hence MID = INT(1 + 13)/2]= 7
and so DATA[MID] =DATA [7] =55
IPS Computer Science - 1 2-18 Data Structures

4 Write difference between Linear search and Binary


search.
(Mar.2014, 2017, July 2017
Ans. :
Linear Search Binary Search Binary Search
1 Linear search performs on unsorted 1 For binary search, the elernents in
list of elements as well as sorted list. array are stored in alphabetically Or
numerically in sorted manner.
Comparethe desired element with all 2. Compare the value of midpoint with
elements in an array until the match is desired value. If the value is greater
found
than midpoint value, the first half is
checked, otherwise second half is
checked until search is successful or
interval is empty.
3 Insertion of an element in an array can 3. An insertion of a new element
be performed very efficiently when requires that many elements be
array is not ordered.
physically moved to preserved order.
4 For large size of array, time required 4. For large size of array,comparatively
for this search is very large. time required is less.
5 Time complexity is as follows: 5.
Time complexity as follows:
worst case : N comparison WOrst case log, N comparison
Best case:1comparison Best case:1comparison
Q. 25 What are pointer arrays ? (Oct. 2003,06; Mar. 2012,I5,19, July 2016
Ans. : J22
i) An array is called pointer array, if each element of that array is a pointer.
ii) The variable is called as pointer variable, if it points to another variable i.e. it contains
the memory address of other variable.
iü) Consider an organization, which divides its employee list into four groups, depending
on certain conditions. Following figure shows the list of 4 groups. There are 15
employes and groupscontain 2, 5, 4and 4 employes respectively as
Group 1 Group 2 Group 3 Group 4
Deepak Swapnil Rajdeep Yashwant
Nitin Amit Amol Chintamani
Vivek Yogesh Kishore
Ravi Shekhar Rohit

Omprakash
iv) II these groups are to be represented in memory, the most efficient way is to use
2arrays. The first is Employee array, which contains list of enmployees in ll four groups
sequentialy, while the second array is Group array, which is a pointer array, which
contains the starting address of each group inthe Employee array, respectively.
TPS Computer Science - I
2-19
Data Structure
It is shown in figure: TI
v)
Employee
Preyas
Group 1
Nitin
3 Swapnil
Group Pointer array
4 Amit
5 Vivek 1 1
Group 2
6 Ravi 3 2
7 Omprakash 8 3
8 Rajdeep 12 4
Amol
Group 3 10 Yogesh
11 Shekhar
p12 Yeshwant
13 Chintamani
Group 4 Kishore
14
15 Rohit

vi) Each element of Group array is apointer, which holds the starting addresses of differe
groups. Hence, it is called as pointer array.
considering suitable
Q. 29 Show representation of records in memory Mar. 2003,11,13; Ot. 2011
records and three fields.
Ans. :
array.
1) Records contain non-homogeneous data, so it cannot be stored in
But in entire file of records, all data elements belonging
to the same identifier will be o
2) collection of arrays.
same type. So a file may be stored in memory as
should be parallel.
3) One array for each of data item. Allthe arrays
4) For e.g records and three fields.
A student file consisting three
Address Phone
Name
11,J.M. Road 5662000
Lokesh
24,M.G. Road 4240020
Jayesh 4261900
Anushka 10, Sahkarnagar
figure shows representation of above file in three parallel arrays Name
Following
Address and Phone -
Address Phone
Name
11, J.M. Road 5662000
Lokesh
24, M.G. Road 4240020
Jayesh
Anushka 10, Sahkarnagar 4261900

Allarrays should be parallel that is for subscript Kthe elements


Name [K], Address (K], Phone [K]must belong to same record.
Linked List

Q. 30 What are linked lists ? Show a liked list with suitable example having six nod
with a properly labelled diagram.
(Mar. 2002,04,05,06,07,08,13,14,15; Oct. 2003,07,14, Dec. 2
OR
J22
nodes havi
With suitable example, show labelled diagram for link between two
the information part and next pointer field.
five
What are linked lists ? Show aliked list with suitable example having
with a properly labelled diagram. (Mar. 2013,March20
TPS Conmputer Science - I 2-22 DataStructures
Áns. :
i) A linked list is a linear collection of data elements, called nodes, where the linear order
is maintained with the help of pointers,
ii) Linked list is also called as one-way list.
ii) Each node in the linked list is divided into two parts. First part is called as INFOpart,
which contains the information about the element or actual element and second part is
called as LINK part, which isnext pointers field i.e. it contains the address of next node
in the list.

Start
i)
10
Info Link (Pointer to next node)

10
13B9
13
c14D12
19 14
E
12
18

FX
18

Fig. 1:Linked list with 6nodes


START

10 Info link (pointer to nest node)

+A|13
10
B 19 C4 D|12 EX
13 19 14 12

Fig. 2:Linked list with 5nodes


(a) The left part of the node is the Info part, which contains information of the element,
while the right part is Link part, which is next pointers field i.e. it points to next node.
(b) An arrow is drawn from Link part of one node to the next node to indicate link.
(c) The address of the list is stored in Start or Name of the list.
(d) The Link part of last node is NULL pointer i.e. it contains nothing.
(e) To trace the linked list, we just require the address of Start or Name.
TPS Computer Science - 1 2-23
Data Structur
OR
Q. 32 How linked lists are represented in memory ?
(March 2003,12;14,17,19,22; Oct. 2006, 07,13,21,
With suitable example show the representation of linked list in memory
july 16,1
Ans. :
Linked lists can be represented in memory by using two arrays respectively known.
INFO and LINK, such that INFO[K] and LINK[K] contains information of element
next node address respectively.
ii) The list also requires a variable 'Name' or 'Start, which contains address of first nod.
Pointer field of last node denoted by NULL whichindicates the end of list. e.g. Consid.
a linked list given below :
Start

5
9
- 9

D X

ii) The linked list can be represented in memory as -


INFO LINK
D 0
START
5 2

5 A

8
9 B 4

Above figure shows linked list. It indicates that the node of alist need not occup!
adjacent elements in the array INFO and LINK.
Q. 33 Explain insertion and deletion from linked list with example.
Ans. :
It iseasier to insert an element into or delete an element from a linked list than arrays.
5. Set Ptr:= LINK [Ptr)
End of step 3 loop]
6. Write:N
7. Exit
1. Set Ptr:=START
(iii)
2. Repeat While Pr NULIL:
INFO[Pr]:=1NFO|Pr] +K
Set
Set Ptr :=LINK |Pr]
[End of loopl
3. Exit Stack and Queue
OR J22 (Mar.2013, July2015
with suitable examples.
Queue
Q.37 Explain Stack and Systems with suitable examples.
(Oct2005,201
Explain LIFOand FIFO
Ans.: LIFOSystem :
In this type of system, the element which
system.
(i) LIFO Svstem is last-in-first-outdeleted first.
inserted at last, will be system in which insertion and deleti
LIFO system. It isa linear
(ii) Stack is an example of endiie. top of thelist.
takes place only at one as push and deletion operationstack as pop.
operation is referred to then it is add.
(ii) The insertion we want to add a new dish to this
stack of dishes. If
e.g. consider a takes place from thetop.
at the top of stack also deletion
FIFOSys tem : In this type of system, the element which
first-in-first-out system.
(i) A FIFO system is list will also be deleted first.
inserted first in the in which insertion tak
FiFO systenm. A queue is a linear list,
(ü) Queue is an example of list known as 'rear' of the list and deletion takes place at
place only at one end of the
other end, called as 'front of the list.
cinema hall.
e.g. A queue for tickets ina
Tree
siblings and child about tree.
Q. 38 What isa tree ? What do you mean by root, leaf, (Oct. 2006, 10,2
J22
Ans. : Tree:
set of one or mo
Tree is a non-linear hierarchical data structure which consists of finite
nodes (i.e. collected data items) such that: A

a) There is specially designated node called the root.


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 root.
For e.g. figure shows tree which has 11 nodes, each item of data
being a single letter.
TPS Computer Science - I 2-30 Data Structures

Root :
Anode 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,
E.J, Kare the leaf nodes. Alsocalled 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 Care F, G, and H.
Sibling : (July 2018)
Children of the same parent are said to be siblings. e.g, The nodes D and E are both
children of node B. SoD and E are siblings.
Q. 39 Explain the following terms : (Marçh 2022)
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
Level 0
B Level 1

Level 2
2. Depth/Height : (March 2017
Depth ofatree is defined as maximum level of any node in atree. If root is level 0then
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.
Thedegree of a tree is the maximum degree of the node in tree.
e.g. the degree of each node in figure is as
A
Node Degree
A 2
2
3
H
D, E, E, G, H 0

The tree has degree 3.


2-31
Data Structura.
Science - I
TPS Conputer
binary tree ? (March2002,04,05,,14,15,19, 20; Oct. 2004,06,11,12,13;| Dec. 202
Q. 40 What is a
such that is: J22 M23
finite set ofelements called nodes H24
a
Ans.:Binarv tree is
empty or
1. It may be three disjoint subsets :
partitioned into tree.
It is distinguished elementcalled the rootof A

(a) there is a
single left
subsets are themselves binary tree called
(b) other two original tree.
subtree and right subtree of the
be empty.
A left and right subtree can D
binary tree, there isno node with degree greater than two.
In
e.g

suitable example, explain the terminology describ


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

4. The tree with depth n having 2"-1number of total nodes.


Science -1
TrS Computer 2-32 Data Structures

Q43 Define the following:


Ans. : Left subtree Right subtree
1. Complete Binary Tree :lfall leaf nodes of a binarytree
bave same level number and every non-leaf node has
D
non-emptr lett and right subtreesthen the tree iscalled
as complete binarytree. Al nodes at the last level appears
as far left as possible.
Extended binary tree or 2-tree (Mar,2015)
Abinary tree T is said to be a 2-tree or an extended binarv tree if each node N has either
Oor 2children. The nodes with 2 children are called internalnodes and the nodes with 0
children are called external nodes.

internal node

external node

3 Binary Search Tree:


It is a binary tree in which each node N of tree has the
property that the value at N is greater than every node (18
value in the left subtree of N and is less than or equal to 14

every node value in the right subtree of N.

Q.44 How binary trees are represented in memory ? OR (Mar.2015, 20, July 2016, 19
With suitable example and labelled diagram, show the representation of binary tree
in memory. (March 2003, 2009)
Ans. :

Abinary tree Tcan be represented in memory by two types of representation :


i) Linked representation
(1) Sequential representation.
i Linked representation: (Oct: 2008,15)
Linked representation uses three parallel arrays INFO and, LEFT and RIGHT and a
Pointer variable ROOT such that for an index K, INFO (K] contains actual element.
LEFT (K] contains address of left child and RIGHT |K]contains address of right child.
e-g. Consider a binarytree as below:
Data Structur.
2-41
TPS Computer Science - I
Ans. :

diagram for the expression.


Q. 62 What is Binary Tree? Draw the Tree (March 201
2-31)
B= (3R/5T} - (R + Q)(Ch. 2/Q. 40/Pg. No.
Ans. :

R 5

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

Q. 64 If symmetric binary tree contains 31 nodes then calculate in level of tree 202
(March
depth.
Ans. :

2-1 31

You might also like