mid-term answers & tree traversal
DESCRIPTION
Mid-term Answers & Tree traversal. 10/15/2014. How to Measure Efficiency?. Critical resources: Time, memory, programmer effort, user effort Factors affecting running time: For most algorithms, running time depends on “ size ” of the input . - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/1.jpg)
Mid-term Answers & Tree traversal
10/15/2014
![Page 2: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/2.jpg)
MIDTERM STATISTICSCount 30
Minimum Value 60Maximum Value 100
Average 89.52Standard Deviation 10.82
GRADE DISTRIBUTION90 - 100 1980 - 89 670 - 79 460 - 69 1
90 - 100 80 - 89 70 - 79 60 - 6902468
101214161820
100 8
90 - 99 1110090 - 99
![Page 3: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/3.jpg)
![Page 4: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/4.jpg)
How to Measure Efficiency?
• Critical resources:• Time, memory, programmer effort, user effort
• Factors affecting running time:• For most algorithms, running time depends on “size” of the input.• Running time is expressed as T(n) for some function T on input
size n.
4
![Page 5: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/5.jpg)
How do we analyze an algorithm?
• Need to define objective measures.
(1) Compare execution times? Not good:
times are specific to a particular machine.
(2) Count the number of statements? Not good:
number of statements varies with programming language and style.
5
![Page 6: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/6.jpg)
How do we analyze an algorithm? (cont.)
(3) Express running time T as a function of problem size n
(i.e., T=f(n) )
Asymptotic Algorithm Analysis
- Given two algorithms having running times f(n) and g(n), find which functions grows faster?
- Compare “rates of growth” of f(n) and g(n).
- Such an analysis is independent of machine time, programming style, etc.
6
![Page 7: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/7.jpg)
![Page 8: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/8.jpg)
Understanding Rate of Growth (cont’d)
• The low order terms of a function are relatively insignificant for large n
n4 + 100n2 + 10n + 50
Approximation:n4
• Highest order term determines rate of growth!
8
![Page 9: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/9.jpg)
Names of Orders of Magnitude
O(1) bounded (by a constant) time
O(log2N) logarithmic time
O(N) linear time
O(N*log2N) N*log2N time
O(N2) quadratic time
O(N3) cubic time
O(2N ) exponential time
9
![Page 10: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/10.jpg)
Visualizing Orders of Growth
• On a graph, as you go to the right, a faster growing function eventually becomes larger...
10
![Page 11: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/11.jpg)
Complexity
• Let us assume two algorithms A and B that solve the same class of problems.
• The time complexity of A is 5,000n, T = f(n) = 5000*n • the one for B is 2n for an input with n elements, T= g(n) = 2n
• For n = 10, • A requires 5*104 steps, • but B only 1024, • so B seems to be superior to A.
• For n = 1000, • A requires 5*106 steps, • while B requires 1.07*10301 steps.
11
![Page 12: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/12.jpg)
![Page 13: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/13.jpg)
if (i<j)
for ( i=0; i<N; i++ )
X = X+i;
else
X=0;
O(N)
O(1)
Running Time Examples (cont.’d)
13
Max (O(N), O(1)) = O(N)
Running time of the entire if-else statement?
![Page 14: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/14.jpg)
Some of the wrong solutions:
,
![Page 15: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/15.jpg)
i = 0;
while (i<N)
{
X=X+Y; // O(1)
result = mystery(X); // O(N)
i++; // O(1)
}
Running Time Examples15
• The body of the while loop: O(N)• Loop is executed: N times
Running time of the entire iteration? N x O(N) = O(N2)
![Page 16: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/16.jpg)
![Page 17: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/17.jpg)
Main IndexMain Index ContentsContents1717 Main IndexMain Index ContentsContents
C++ Arrays
An array is a fixed-size collection of values of the same data type.An array is a container that stores the n (size) elements in a contiguous block of memory.
arr[0 ] arr[1 ] arr[2 ]
0 1 2 n -1
. . . arr[n -1 ]
int arr[] = {1,2,3,4,5};cout << arr[4];
![Page 18: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/18.jpg)
Main IndexMain Index ContentsContents18
1. Allow for dynamic resizing2. Have a way to store the size internally3. Allow for assignment of one object to another
18 Main IndexMain Index ContentsContents
Vectors
v [ 0 ] v [ 1 ] v [ 2 ] . . . v [ n-1 ] ro o m to gro w
0 1 2 n-1
• A container is a class that stores a collection of data• It has operations that allow a programmer to insert, erase, and update elements in the collection
![Page 19: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/19.jpg)
Main IndexMain Index ContentsContents
C++ interview questions on “Vector”
19
What do vectors represent?a) Static arraysb) Dynamic arraysc) Stackd) Queue
Answer: bExplanation: Vectors are sequence containers representing arrays that can change in size.
More questions here
![Page 20: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/20.jpg)
![Page 21: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/21.jpg)
![Page 22: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/22.jpg)
2222 Main IndexMain Index ContentsContents
The List Container
15f ro nt
46123
B e fo re
f ro nt
46123
Af te r
Inserting into a List Container
fro nt b ac k
![Page 23: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/23.jpg)
Main IndexMain Index ContentsContents23
Vector List
Access an element at position/index i
Direct access, V[i]Has to iterate from a known position, may use distance function
Insert or remove an element at positions
other than end
Cause to relocate elements
No relocation, just rebuild the link
Sequential search an element with specific
value, return the position/index
Sequentially search Sequentially search
![Page 24: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/24.jpg)
![Page 25: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/25.jpg)
Main IndexMain Index ContentsContents2525 Main IndexMain Index ContentsContents
Map Containers
A map is a storage structure that implements a key-value relationship.
![Page 26: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/26.jpg)
1 2 3 4 5
1 2 3 4 5
![Page 27: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/27.jpg)
![Page 28: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/28.jpg)
Main IndexMain Index ContentsContents28
Stacks A stack is a sequence of items that are
accessible at only one end of the sequence.
Last in, first out, (LIFO)
![Page 29: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/29.jpg)
Main IndexMain Index ContentsContents29
Pushing/Popping a Stack Because a pop removes the item that last
added to the stack, we say that a stack has LIFO (last-in/first-out) ordering.
![Page 30: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/30.jpg)
What would be the output on screen?
![Page 31: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/31.jpg)
![Page 32: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/32.jpg)
Queues
A queue inserts new elements at the back and removes elements from the front of the sequence.
Queue: First in, first out, (FIFO)
PushPop
![Page 33: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/33.jpg)
Main IndexMain Index ContentsContents3333 Main IndexMain Index ContentsContents
The Queue
A Queue is a FIFO (First in First Out) Data Structure. Elements are inserted in the Rear of the queue and are removed at the Front.
C
B C
A B C
A
bac kf ro nt
p u s h A
A Bf ro nt bac k
p u s h B
f ro nt bac kp u s h C
f ro nt bac kp o p A
f ro ntbac k
p o p B
![Page 34: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/34.jpg)
![Page 35: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/35.jpg)
![Page 36: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/36.jpg)
![Page 37: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/37.jpg)
Example QuestionF
B
C E
I
H
DA
G
Pre-order? In-order? Post-order? Level-order ?
![Page 39: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/39.jpg)
Computing the Leaf Count
Pre-order scan
![Page 40: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/40.jpg)
Computing the Depth of a Tree
Post-order scan
![Page 41: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/41.jpg)
Deleting Tree Nodes
Post-order scan
![Page 42: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/42.jpg)
Outline of In-Order Traversal
• Three principle steps:– Traverse Left– Do work (Current)– Traverse Right
• Work can be anything• Separate work from traversal
![Page 43: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/43.jpg)
•Traverse the tree “In order”:–Visit the tree’s left sub-tree–Visit the current and do work–Visit right sub-tree
![Page 44: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/44.jpg)
In-Order Traversal Procedure
procedure In_Order(cur iot in Ptr toa Tree_Node)// Purpose: perform in-order traversal, call // Do_Something for each node// Preconditions: cur points to a binary tree// Postcondition: Do_Something on each tree// node in “in-order” order if( cur <> NIL ) then In_Order( cur^.left_child ) Do_Something( cur^.data ) In_Order( cur^.right_child ) endifendprocedure // In_Order
![Page 45: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/45.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
![Page 46: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/46.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
![Page 47: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/47.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
![Page 48: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/48.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
![Page 49: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/49.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
![Page 50: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/50.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
![Page 51: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/51.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
![Page 52: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/52.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
L
![Page 53: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/53.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
L
![Page 54: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/54.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
L
L
![Page 55: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/55.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9
LPR
L
L
L
L
![Page 56: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/56.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1
LPR
L
L
L
LP
![Page 57: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/57.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1
LPR
L
L
L
LP
![Page 58: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/58.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1
LPR
L
L
L
LPR
![Page 59: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/59.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1
LPR
L
L
L
LPR
![Page 60: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/60.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1
LPR
L
L
L
LPR
![Page 61: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/61.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
L
LPR
P
![Page 62: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/62.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
L
LPR
P
![Page 63: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/63.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
LPR
LPR
![Page 64: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/64.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
LPR
LPR
![Page 65: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/65.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
LPR
LPR
L
![Page 66: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/66.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3
LPR
L
L
LPR
L
LPR
![Page 67: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/67.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
L
LPR
P
![Page 68: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/68.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
L
LPR
P
![Page 69: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/69.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
LPR
LPR
![Page 70: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/70.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
LPR
LPR
![Page 71: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/71.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
LPR
LPR
![Page 72: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/72.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7
LPR
L
L
LPR
LPR
LPR
![Page 73: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/73.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LP
LPR
LPR
LPR
![Page 74: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/74.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LP
LPR
LPR
LPR
![Page 75: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/75.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LPR
LPR
LPR
LPR
![Page 76: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/76.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LPR
LPR
LPR
LPR
![Page 77: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/77.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LPR
LPR
LPR
LPR
L
![Page 78: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/78.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9
LPR
L
LPR
LPR
LPR
LPR
L
![Page 79: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/79.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LP
![Page 80: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/80.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LP
![Page 81: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/81.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LPR
![Page 82: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/82.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LPR
![Page 83: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/83.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LPR
![Page 84: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/84.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14
LPR
L
LPR
LPR
LPR
LPR
LPR
![Page 85: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/85.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LP
LPR
LPR
LPR
LPR
LPR
![Page 86: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/86.jpg)
Continue?
Yes!EnoughAlready!
![Page 87: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/87.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LP
LPR
LPR
LPR
LPR
LPR
![Page 88: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/88.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 89: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/89.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 90: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/90.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 91: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/91.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 92: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/92.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
L
![Page 93: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/93.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
L
![Page 94: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/94.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LP
![Page 95: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/95.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LP
![Page 96: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/96.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
![Page 97: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/97.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
![Page 98: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/98.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
L
![Page 99: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/99.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
L
![Page 100: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/100.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LP
![Page 101: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/101.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LP
![Page 102: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/102.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
![Page 103: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/103.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
![Page 104: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/104.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
![Page 105: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/105.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
![Page 106: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/106.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
P
![Page 107: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/107.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
LPR
LPR
P
![Page 108: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/108.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 109: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/109.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 110: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/110.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 111: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/111.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 112: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/112.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LP
![Page 113: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/113.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LP
![Page 114: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/114.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 115: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/115.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 116: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/116.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 117: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/117.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
L
![Page 118: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/118.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LP
![Page 119: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/119.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LP
![Page 120: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/120.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 121: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/121.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 122: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/122.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 123: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/123.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 124: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/124.jpg)
Proc InOrderPrint(pointer) pointer NOT NIL? InOrderPrint(left child) print(data) InOrderPrint(right child)
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 125: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/125.jpg)
Algorithm Example. . . InOrderPrint(root). . .
22
root
67
363 14
447
94
971
9Output: 1 3 7 9 14 22 36 44 67 94 97
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
LPR
![Page 126: Mid-term Answers & Tree traversal](https://reader035.vdocuments.mx/reader035/viewer/2022062304/568131d3550346895d983db0/html5/thumbnails/126.jpg)
Summary
• An In-Order traversal visits every node– Recurse left first– Do something with current– Recurse right last
• The “left, current, right” logic is repeated recursively at every node.
• For a BST, an in-order traversal accesses the elements in ascending order.