0% found this document useful (0 votes)
12 views73 pages

Data Structures

The document outlines the fundamentals of data structures, including definitions of data items, entities, and various operations such as traversing, inserting, deleting, searching, sorting, and merging. It also explains control structures like sequential, conditional, and iterative flows with corresponding algorithms and flowcharts. Additionally, it provides algorithms for inserting and deleting elements in linear arrays and discusses sorting techniques.
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)
12 views73 pages

Data Structures

The document outlines the fundamentals of data structures, including definitions of data items, entities, and various operations such as traversing, inserting, deleting, searching, sorting, and merging. It also explains control structures like sequential, conditional, and iterative flows with corresponding algorithms and flowcharts. Additionally, it provides algorithms for inserting and deleting elements in linear arrays and discusses sorting techniques.
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/ 73

2.

Data Structures
Computer Science

12th Standard
Marks Distribution
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
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)
4
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 5
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

6
7
Data Structures:
“A data structure is a way of
organizing, storing, and managing
data so it can be accessed and
modified efficiently.”.
Use OF DS : Operating System, Compiler
Design, Artificial intelligence, Graphics and
many more.
8
9
Explain in brief any six data structure operations.
1.Traversing: Accessing each element of a data structure exactly once to process it. Example:
Multiplying each element of an array by 6.

2.Inserting: Adding a new element or record to a data structure. Example: Adding a new value
to a linked list or appending an item to an array.

3.Deleting: Removing an element or record from a data structure. Example: Removing a specific
value from a stack or array.

4.Searching: Finding the location of an element in a data structure that matches a given key or
satisfies specific conditions. Example: Searching for a name in a phone directory.

5.Sorting: Arranging elements in a particular order, such as ascending or descending. Example:


Sorting an array of numbers in increasing order using Bubble Sort or Quick Sort.

6.Merging: Combining two or more sorted data structures into one sorted data structure.
Example: Merging two sorted arrays into a single sorted array.
10
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 : …………….

11
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 12
Questions
Q. (a) Explain with flowchart the following control structure:
(i) Sequence logic (ii) Selection logic (iii) Iteration logic

Q. (b) Explain Conditional Flow and Repetitive Flow used in data structure with
diagram.
Cntrol Structures
Sequential Flow Conditional Flow Repetitive Flow
(Sequential Logic) (Selection Logic) (Iteration Logic)

Single Alternative Double Alternative Multiple Alternative

14
Flowchart Symbols

15
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

16
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

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

No
Cinditition
?

Yes
Module A

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

No
Condition
?

Yes
Module A Module B

19
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]

20
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

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

No
Condition
?

Yes
Module A

22
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
23
Questions for you :
Q1. When will be loop stop in repetitive flow ?
Q2. Type of Control structures ?
Q3. Which condition flow has only one IF condition ?
(Only IF no else)

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

−𝑏± 𝑏2 −4𝑎𝑐
Where a≠0 and roots are given by, X= 2𝑎

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= 2𝑎
, X2= 2𝑎

2. Print X1 ,X2
Else if d=0 then
1. X1=X2= -b/2a
2 Print “Real and Same roots”
25
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]

26
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

27
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

28
Representation of linear arrays in memory
Memory Address

1000

1001
Array elements are
stored sequentially
1002

1003
.
.
.
.
.

29
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 30
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.

31
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 32
Algorithm for inserting into linear array is given below:
Algorithm – Inserting element into liner array.
LA : {10, 20, 30, 40, 50} N=5, K = 2 , ITEM : 25, J=N-1=4, While J>=K
0 1 2 3 4
Iteration (Loop Expression Operation Updated Array State
Index) (LA)
LA[4+1] = LA[4] → LA[5] = 50 {10, 20, 30, 40, 50, 50}
j= 4 LA[J+1] = LA[J]
0 1 2 3 4 5
{10, 20, 30, 40, 40, 50}
J-- => J = 3 LA[J+1] = LA[J] LA[3+1] = LA[3] → LA[4] = 40
0 1 2 3 4 5
{10, 20, 30, 30, 40, 50}
J-- => J = 2 LA[J+1] = LA[J] LA[2+1] = LA[2] → LA[3] = 30
0 1 2 3 4 5
{10, 20, 25, 30, 40, 50}
Insert Step LA[K] = ITEM LA[2] = 25 → LA[1] = 25
0 1 2 3 4 5
{10, 20, 25, 30, 40, 50}
Final Step N++ Increment N to 6
0 1 2 3 4 5

33
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 34
The algorithm for deleting element from array is given below :

LA : {10, 20, 25, 30, 40, 50}, N=6, K = 2 , ITEM : 25,J=K=2 , J<=N – 2
0 1 2 3 4 5

Iteration (Loop Expression Operation Updated Array State


Index) (LA)
ITEM = LA[2] → ITEM = 25 {10, 20, 25, 30, 40, 50}
Initial State ITEM = LA[K]
0 1 2 3 4 5
{10, 20, 30, 30, 40, 50}
J=J+1 → J = 2 LA[J] = LA[J+1] LA[2] = LA[3] → LA[2] = 30
0 1 2 3 4 5
{10, 20, 30, 40, 40, 50}
J=J+1 → J = 3 LA[J] = LA[J+1] LA[3] = LA[4] → LA[3] = 40
0 1 2 3 4 5
{10, 20, 30, 40, 50, 50}
J=J+1 → J = 4 LA[J] = LA[J+1] LA[4] = LA[5] → LA[4] = 50
0 1 2 3 4 5
Final Step {10, 20, 30, 40, 50}
Reset N N=N-1→N=5
0 1 2 3 4

35
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.
36
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.

37
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
38
Step 5 : Stop
Algorithm - Linear search

LA : {10, 25, 20, 30, 40}, N=5, ITEM : 55, while LOC<N
0 1 2 3 4
Iteration Expression Operation
Result
(LOC)
{10, 25, 20, 30, 40, 50}
Initial State LOC = 0
0 1 2. 3. 4. 5

LOC = 0 ITEM == DATA [0] → 55 == 10 No match: ITEM != DATA [0] LOC = LOC + 1 → LOC = 1

LOC = 1 ITEM == DATA [1] → 55 == 25 No match: ITEM != DATA [1] LOC = LOC + 1 → LOC = 2

LOC = 2 ITEM == DATA [2] → 55 == 20 No match: ITEM != DATA [2] LOC = LOC + 1 → LOC = 3

LOC = 3 ITEM == DATA [3] → 55 == 30 Match found: ITEM != DATA [3] LOC = LOC + 1 → LOC = 4

LOC = 4 ITEM == DATA [4] → 55 == 40 Match found: ITEM != DATA [4] LOC = LOC + 1 → LOC = 5

Break Loop Stop further iterations

Final Check LOC == N Print: ITEM not found

39
Binary search

40
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= (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
41
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

42
Pointer arrays

43
Pointer arrays

44
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 :

45
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
46
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].

47
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.

48
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.

49
Linked Lists - Node

50
Linked Lists

51
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.

52
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 beginningof 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.

53
Representaion of linked list in memory

54
Questions :
• Define the following terms with reference to tree:
(i) Root
(ii) Leaf
(iii) Sibling
(iv) Depth

• Define the following terms with respect to data structures :


(i) Array
(ii) Stack
(iii) Queue
(iv) Depth

• Draw a binary tree structure for the following expression : F = (a-b)/((P* m) + h)


• What is Binary Tree? With suitable example show the relationship between Total
Number Nodes and Depth of a Binary Tree.

55
Questions :
• Explain following terms used in Binary Tree:
(i) Sibling
(ii) Successor
(iii) Leaf

• Define the following terms with respect to data structures :


(i) Array
(ii) Stack
(iii) Queue
(iv) Depth

• Explain the memory representation of Binary Tree with suitable example.


• What is Binary Tree? Draw the Tree diagram for the expression. B = (3R/5T)²-(R+Q³)
• Explain linked representation of binary tree in memory with suitable example.
• Define Binary tree. Draw a Tree diagram for following expression.Y= [(a-b-c) + (a+b-c)]³/2

56
Stack and Queue
Q. Explain Stack and Queue with suitable examples. OR. Explain LIFO and FIFO
Systems with suitable examples.

LIFO System (Stack):


• LIFO system is last-in-first-out system. In this type of system, the elements which 1st
inserted at last, will be deleted first.
• Stack is an example of LIFO system. It is a linear system in which insertion and
deletion takes place only at one end i.e. top of the list.
• The insertion operation is referred to as push and deletion operation as pop.
• eg. consider a stack of dishes. If we want to add a new dish to this stack then it is
added at the top of the stack also deletion takes place from the top.

57
Stack and Queue
FIFO System (Queue) :

• A FIFO (First-In-First-Out) system operates on the principle that the first element
added to the list is the first one to be removed.
• This system ensures that the order of processing remains the same as the order of
arrival, making it suitable for scenarios where fairness and sequence are crucial.
• A queue is a classic example of a FIFO system.
• It is a linear data structure where:
Insertion occurs only at one end, referred to as the "rear."
Deletion takes place from the other end, known as the "front.”

Example:
A real-world example of a queue is the line for tickets in a cinema hall. The person who
arrives first at the counter is served first, and the person at the end of the line is served
last, following the FIFO principle.
58
Stack and Queue

59
Tree
A tree is a hierarchical data structure consisting of nodes connected by edges.
It is widely used in computer science for organizing and representing data in a structured way.

A tree has the following characteristics:


1.It starts with a single node called the root.
2.Each node can have zero or more child nodes.
3.There are no cycles in a tree, making it a non-linear and acyclic structure.

Root :
• A node which has no parent.
• Generally first node is called as 'root node’.
• In figure, the node A is the root of the tree.

Leaf (Terminal Node)


• 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.
60
Tree
Child
• A node that is directly connected to another node in the direction away from the root.
• A child node is a descendant of its parent.
• e.g In figure a, the children of node C are F, G, and H.

Sibling:
• 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.

61
Tree
Ancestor
• The node is an ancestor of another node, if it is a parent of that node.
• Here, C is ancestor of F,G,H,J,K
• ROOT is always an ancestors of every node

Descendent :
• The nodes is a descendant of another node, if it’s a child of that node.
• Eg. C is descendent of A and G is descendent of C and A
• All nodes in the tree are descendants of the ROOT.

62
Tree
Left Subtree:

• The descendants of root’s left child which acts a root of subtree.


• The left subtree of A is the tree with root B

Right Subtree:

• The descendants of root’s right child which acts a root of subtree.


• The right subtree of A is the tree with root C

63
Tree
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.

64
Tree
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.
• The tree has degree 3.

65
Tree
Left Successor:

• The left successor of a node in a binary tree is its immediate left child.
• The left successor of A is B, and the left successor of B is D.

Right Successor

• The right successor of a node in a binary tree is its immediate right child.
• The right successor of A is C, and the right successor of C is H.

66
With a suitable example show the relationship between total numbers of nodes and
depth of a tree.
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 of binary tree with depth n are 2n-1
• For example:
• Consider the following tree with depth 3.
• So with depth 3, the total number of nodes in a given tree is the tree with depth n
having 2n-1 number of total nodes.

2n-1 =23-1

2n-1 = 8-1

2n-1 = 7

67
How binary trees are represented in memory ? OR With suitable example and
labelled diagram, show the representation of binary tree in memory.

A binary tree T can be represented in memory by two types of representation:


1. Linked representation
2. Sequential representation.

1. Linked representation:

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. The ROOT stores address of first node of tree T.

68
How binary trees are represented in memory ? OR With suitable example and
labelled diagram, show the representation of binary tree in memory.

69
2. Sequential representation:
• In the array representation, the binary tree is stored in a linear array.
• The position of each node in the array is determined by its relationship in the tree:
• The root is stored at index 1 (or 0 in 0-based indexing).
• For any node at index i:
• The left child is stored at index 2 * i.
• The right child is stored at index 2 * i + 1.
• In general, the sequential representation of a tree with depth d will require an array with
approximately 2d+1 elements.

70
Draw a binary tree structure for the following expression :
F =(a-b) / ((P * m) + h)

71
What is Binary Tree ? Draw the Tree diagram for the expression.
B=(3R/5T)2 -(R+ Q3)

72
What is Binary Tree ? Draw the Tree diagram for the expression.
Y= [(a -b -c) + (a +b-c)]3/2

73

You might also like