Chap2 - Data Structure
Chap2 - Data Structure
Record
Field
Data Structure 4
Traversing
Inserting
Deleting
Searching
Sorting
Merging
Algorithm Notation 8
Sequence Logic
- modules are executed sequentially, one after another.
Module 1
Module 2
Module 3
Flow Control 11
Selection Logic
- uses number of conditions to execute the modules.
1. Single alternative
2. Double alternative
If no
no condi
If
tion
condition
yes
yes
Module 1 Module 2
Module 1
Flow Control 12
Iteration Logic
- certain module is executed repeatedly until
condition is satisfied.
If no
condition
yes
Module
Linear Array 13
2 20
Array index 3 30
Elements
4 40
5 50
6 60
UB
6
While 7<=6
60
false
UB
Inserting 17
3 30 30 LA[3] =45
45
6+1 =7
4 40 40 30
N=7
5 50 40
6 50 50
7 60 60 60
Deleting 20
06 02 09 07 12 First Pass
Now we will consider First Pass array for further comparison
06 02 09 07 12 27
02 06 07 09 12 Second Pass
Linear Search 28
DATA 30
11 22 33 44 55
11 22 33 44 55 33
= 33
11 22 33 44 55 33
= 33
11 22 33 44 55 33
= 33
BEG=MID+1
END=MID -1 5 4+1
5 6-1
The following is our sorted array and let us assume that we need to search
the location of value 31 using binary search. 35
36
37
Difference between Linear and
38
Binary Search
Linked list can be visualized as a chain of nodes, where every node points
to the next node.
As per the above illustration, following are the important points to be
considered.
1. Linked List contains a link element called first.
2. Each link carries a data field(s) and a link field called next.
3. Each link is linked with its next link using its next link.
4. Last link carries a link as null to mark the end of the list.
10 20 30 40
51
head
05 04 08 07
10 04 20 08 30 07 40 null
Link List Representation 52
IN Memory
Linked lists can be represented in memory by
using two arrays respectively known as INFO and
LINK, such that INFO[K] and LINK[K] contains
information of element and net node address
respectively.
The list also requires a variable ‘Name’ or ‘Start’,
which contains address of first node.
Pointer field of last node denoted by NULL which
indicates the end of list.
Start
53
5
A 9 B 4 C 1 D 8
5 9 4 1
Info Link
Start
1 D 8
5 E X
2
3 8
4 C 1
5 A 9
6
7
8 E 0
9 B 4
54
26 1 94 4 89 3 65 X
2 1 4 3
Info Link
Start
1 94 4
2
2 26 1
3 65 0
4 89 3
5 0
Avail 6 0
5 Insert element on second position of the list (39)
Start
56
2
26 5 94 4 89 3 65 X
2 1 4 3
39 1 Info Link
Start
1 94 4
5 2
2 26 5
3 65 0
4 89 3
5 39 1
Avail 6 0
6
Start
57
2
26 1 94 4 89 3 65 X
2 1 4 3
Info Link
Start
1 94 4
2
2 26 1 Delete second node from the list
3 65 0
4 89 3
5 0
Avail 6 0
5
Start
58
2
26 4 94 4 89 3 65 X
2 4 3
Info Link
Start
1 94 0
2
2 26 4
3 65 0
4 89 3
Avail 5 0
5 6 0
Tree 59
1. E = (A + B) / [ (C * D) –E]
2. E = (A - B) / (C * D) + E
3. [(A + B) * C] / [ A * ((B – C) +
A)]
4. (2X + Y) (A – 7B)3
5. X = (P + Q) / ((R + S) + T)
6. E = (2X – Y) / (5A – B)3
7. Z = (A + B / C) * (C + D / F)
E=(a+b)/[(c*d)-e]
68
=
E /
+ -
a b * e
c d
= =
69
E / E /
+ - - +
A B * E A B * E
C D C D
/
70
* *
+ C A +
A B - A *
B C + ↑
* Y - 3
2 X A *
7 B