DSA TillL21 Merged
DSA TillL21 Merged
Source: https://www.geeksforgeeks.org/
POLYMORPHISM: FUNCTION OVERLOADING
OPERATOR OVERLOADING
#include <iostream> #include <iostream>
using namespace std;
using namespace std;
class employee {
int main() { public:
int a = 45; int empno;
float salary;
int b;
};
b = a; //a variable to another int main() {
cout << “value of b: “ <<b; employee e1= {123, 60000.50}, e2;
e2 = e1; // assign an object to another
return 0;
cout << e1.empno << ‘\t’ << e2.salary;
} return 0;
}
FUNCTION OVERRIDING
It is the redefinition of base class function in its derived class with same signature.
A C++ virtual function is a member function in the base class that you redefine in a derived
class.
FRIEND CLASS
A friend class is a class whose members have
access to the private members of another
class.
https://www.geeksforgeeks.org/
STANDARD TEMPLATE LIBRARY (STL) IN C++
•A set of powerful template classes that implement many
popular and commonly used data structures and
algorithms like vector, list, queue, deque, priority_queue,
stacks, substr, replace, sorting, searching etc.
•Alternatively, it is a library of container classes,
algorithms, and iterators.
STL on strings:
insert, append, swap, size,
resize, reverse etc.
Output
deleteItemFromIndex(Index)
shrink()
IMPLEMENTATION: STORING GAME ENTRIES
class GameEntry { class Scores {
public: public:
GameEntry ( const string &n = " ", int s = 0); Scores(int maxEnt = 10);
string getName() const; ~Scores();
int getScore() const; void add(const GameEntry &e);
private: GameEntry remove(int i) ;
string name; void printAllScores();
int score; private:
}; int maxEntries; //maximum number of entries
int numEntries; //actual number of entries
( A Class representing a Game entry)
GameEntry *entries;
}; ( A Class for storing Game scores)
GameEntry::GameEntry(const string &n, int s) : name(n),
score(s) { } Scores::Scores(int maxEnt) {
string GameEntry::getName() const { return name; } maxEntries = maxEnt; // save the max size
int GameEntry::getScore() const { return score; } entries = new GameEntry[maxEntries];
numEntries = 0;
( Constructor and member functions) } Scores::~Scores() { delete[] entries; }
INSERTING INTO AND DELETING FROM ARRAY
void Scores::add(const GameEntry &e) { GameEntry Scores::remove(int i)
int newScore = e.getScore(); // score to add {
if (numEntries == maxEntries) { // the array is full if ((i < 0) || (i >= numEntries)) //
if (newScore <= entries[maxEntries - 1].getScore()) invalid index
return; // not high enough - ignore throw("IndexOutOfBounds -
} Invalid index");
else numEntries++; // if not full, one more entry GameEntry e = entries[i]; // save
the removed object
int i = numEntries - 2; // start with the next to last
for (int j = i + 1; j < numEntries; j++)
while (i >= 0 && newScore > entries[i].getScore() ) {
entries[j - 1] = entries[j]; // shift
entries[i + 1] = entries[i]; // shift right if smaller
entries left
i--;
} numEntries--; // one fewer
entries[i + 1] = e; // put e in the empty spot entry
} return e; // return the
removed object
}
(Inserting a Game entry object) (Removing a Game entry object)
More sorting & searching algos later…
3-dimensional
Head Tail
Applications: Implementation of Stacks, queues, Graphs (Adj list), Keep track OS process states, Free memory blocks
IMPLEMENTING A SINGLY LINKED LIST
Step 1: Define a class for the Node Step 3: Define a set of member functions for the
class StringNode { Linked list class defined in Step 2
//let us write it up…
StringLinkedList::StringLinkedList() : head(NULL){ }
StringLinkedList::~StringLinkedList() {
};
Step 2: Define a class for the Linked list while(!empty())
class StringLinkedList { // let us write it up...
public: StringLinkedList(); }
~StringLinkedList(); bool StringLinkedList::empty() const {
bool empty() const; return ???;
const string& front() const; }
void addFront(const string& e);
void removeFront(); const string& StringLinkedList::front() const {
private: StringNode* head; return ???;
}; }
INSERTING & REMOVING AT THE HEAD OF LINKED
LIST
1. Create a new node
2. Store data into this node
3. Have new node point to old head X Goa
Dubai
4. Update head to point to new node
void StringLinkedList::addFront(const string& e)
{ Pilani
StringNode* v = ??? StringNode; Inserting at the head
v->elem = e;
v->??? = head; void StringLinkedList::removeFront()
head = ???; {
} StringNode* old = head;
head = old->next;
1. Save old head
delete old; 2. Advance head to the next
} node
Deleting at the head
3. Delete the old head node
INSERTING AT THE TAIL & INSIDE A LINKED LIST
1. Allocate a new node
2. Insert new element (Hyd)
Pilani Dubai Goa
3. Have new node point to null (v->next
= NULL)
4. Have old last node point to new node
Head Hyd
Pilani Dubai Goa
Stack: How can you implement a stack Queue: How can you implement a queue as a
as a linked list? linked list?
Lab 4 Next
Week
CIRCULAR LINKED LISTS
•A circular linked list is a singly-linked list except for the last element
of the list pointing to the first. Without starting over we can go
back to the first.
•What is the need of cursor node?
int i, counter = 0;
Amit
for (i=0; i<6; i++) {
if (person.manager == employeeName) {
counter ++;
counter=counter+countEmployeeUnder(person.name) Raj Deb
}
}
return counter;
} Ragini Rohit Sachin
(Recursion to find out how many people work under, say Amit) (Business Organization Chart)
RECURSION: ENGLISH RULER EXAMPLE
drawTicks (length-1)
drawTicks (length-1)
• An interval with a central tick length L >1 consists of:
• An interval with a central tick length L-1
• An single tick of length L
• An interval with a central tick length L-1
BITS F232: FOUNDATIONS OF DATA STRUCTURES
& ALGORITHMS Chittaranjan Hota, PhD
tail recursion
• What are those two calls? Let us see the recursion trace…
COMPUTING FIBONACCI NUMBERS
nk denote the number of calls
performed in the execution of fib(k)
Is binary recursion better here? Let us draw the tree too… What is the type of this rec.?
WHAT IS COMPLEXITY & HOW IMPORTANT IS IT?
• To find out square of a number (n), will you prefer multiplication or repeated addition?
• You want to look for a word in a dictionary that has every word sorted alphabetically. How
many algorithms are there and which one will you prefer?
for ( i=1; i < c; i++) {
FUNCTIONS FOR ALGORITHM ANALYSIS }
a = a + 1;
complexity?
•The Constant function: Output is same i.e. independent of input. It characterizes the number of
steps needed to do a basic operation on a computer like, what types of operations? Constant
algorithm does not depend on the input size.
What about f(w) = w2 ? Is it a constant function? Which ones are not constant
functions?
Rules:
3. Log (nr) = r log n (Img. source: wiki)
x = logbn if and only if ? 4. Loga n = logb n/logb a
•The reason why it is used with base 2 most, a common operation in many while (low <= high) {
algorithms is to repeatedly divide the input into half, integers are also
stored in binary etc. mid = (low + high)/ 2;
Many programs require an encoding for a collection of objects. What is if (target < list [mid])
high = mid - 1;
the minimum number of bits needed to represent ‘n’ distinct code values?
else if (target > list [mid])
for (i = n; i > 0; i = i/2 { low = mid + 1;
a = a +1; else break;
1000 codes to store ?
} complexity? } complexity?
LINEAR AND N-LOG-N FUNCTIONS void quicksort(list[], left, right) {
int pivot = partition(list, left, right);
quicksort(list, left, pivot-1);
quicksort(list, pivot+1, right);
Linear Function: Given an input value ‘n’, the linear function g (n) } complexity? ?
assigns the value ‘n’ itself. g(n) = ?
Used in Algorithm analysis when we have to do a single basic
operation for each of ‘n’ elements. g(n) = n
Ex: Let us see some examples…
N-log-N Function: A function that assigns to an input ‘n’ the value of
‘n’ times logarithm base 2 of ‘n’. g(n) = nlog2n.
This function grows a little ??? than the linear function and a ???
than the quadratic function.
g(n) = n log n
How is it used in Algorithms?
for ( i = 0; i < n; i++) {
a = a+1;
} complexity?
QUADRATIC FUNCTIONS
Quadratic: Given an input value ‘n’,
the function ‘g’ assigns the product V
of ‘n’ with itself. Also, called ‘n I
squared’. S
U
Used in analysing algorithms where A
nested loops are used. L
I
Z
g(n) = n2 A
T
I
O
N
CUBIC AND POLYNOMIAL FUNCTIONS g(n) = n3
T(n)
1E+17
1E+15
No of 1E+13
1E+11
multiplications? 1E+9
1E+7
1E+5
1E+3
1E+1
1E-1
1E-1 1E+2 1E+5 1E+8
Interestingly, all the functions that we have listed are part of (In this log-log graph, the slope of the line
large class of functions called, polynomials: corresponds to the growth rate)
EXPONENTIAL FUNCTIONS AND OTHERS
Exponential function: The function g(n) assigns to the input argument ‘n’ the value obtained by
multiplying the base ‘b’ by itself n times. It is: g(n) = bn.
For instance, if we have a loop that starts by performing one operation
and then doubles the number of operations performed with each
iteration, then the number of operations performed in the nth iteration is
?. Ex? g(n) = 2n
The Floor and Ceiling Functions: The value of logarithm is not an integer,
typically. Hence, Floor and Ceiling functions are used to round them.
• ⌊x⌋ = the largest integer less than or equal to x and ⌈x⌉ = the
smallest integer greater than or equal to x.
GROWTH RATES OF SEVEN FUNCTIONS
Idle for what
types of
Infeasible?
operations? Practical?
Running time
measure of the actual running time. Or use a profiler to count
number of instructions executed at run time.
•Plot the results (running time vs. different test inputs of
varying sizes)
Input size
Limitations:
• It is necessary to implement the complete algorithm, which may be difficult.
• Results may not be indicative of the running time on other inputs not included in the experiment.
• In order to compare two algorithms, the same hardware and software environments must be used
NEXT LAB
recursive
EXAMPLE RUN TIME…
Inside main()
CONTINUED…
NEXT LAB
THEORETICAL ANALYSIS
•Uses a high-level description of the algorithm instead of an Primitive
implementation. operations:
CPU Add, sub,
•Characterizes running time as a function of the input size, n. 1
2 cmp,
0 indexing,
•Takes into account all possible inputs RAM branching
•Allows us to evaluate the speed of an algorithm etc.
independent of the hardware/software environment (The RAM Model)
u for i 1 to n 1 do
d The algorithm arrayMax executes
if A[i] max then
o about 8n - 3 primitive operations
max A[i]
in the worst case.
return max
BITS F232: FOUNDATIONS OF DATA STRUCTURES
& ALGORITHMS Chittaranjan Hota, PhD
Definition of Big-O:
Consider a function f(n) that is non-negative n 0.
We say that “f(n) is Big-O of g(n)” i.e., f(n) O(g(n)),
if n0 0 and a constant c > 0 such that:
?
n n0
Dominant Total Lesser Contribution of lesser
term terms terms
ASYMPTOTIC COMPLEXITY n
10
100
n2
100
10,000
n2 + 4n + 4
144
10,404
4n + 4
44
404
Lesser/total * 100
30.55 %
3.88 %
There are many pairs of (n0, c) that satisfy above
2n+10 10,000 n
1,000
n
1,000
100
100
10
10
1 1
1 10 100 1,000 1 10 100 1,000
n n
f(n) = 3 log n + 5
3 log n + 5 is O(log n)
need c > 0 and n0 1 such that 3 log n + 5 c.log n for n n0
this is true for c = 8 and n0 = 2
BIG-O: IMPLICATION OF THE DEFINITION
For all sufficiently large n, c *g(n) is an upper bound of f(n).
Let us see an example:
f(n) = 3n + 4 is O(n)
i.e., 3n + 4 cn
3n + 4 cn2 f(n) is also O(n2),
3n + 4 cn3 f(n) is also O(n3),
...
3n + 4 cnn f(n) is also O(nn)
There are many g’s now. Which one should be chosen? As small as possible.
Hence, 3n + 4 is O(n), and not O(n2), or O(n3), etc.
TRY YOURSELF…
Assume that you lost your wedding ring on the beach,
and have no memory of when it came off. Thus, you
decide to do a brute force grid search with your
metal detector, where you divide the beach into strips,
and walk down every strip, scanning the whole beach,
until you find it. For simplicity, assume the beach is a
square of side length ’l’ meters, each of your strips
has a constant width of 1 meter, and it takes 10
seconds to walk 1 meter (it's hard to walk while
searching). Find the big-oh performance of your ring
finding algorithm.
Source: https://brilliant.org/
BIG-O AND GROWTH RATE
Increasing complexity
10 2 sec ~ 1 hr
Ex: Searching in a sorted array using Linear 100 20 sec ~ 1.8 hrs
search (on fast computer A) and Binary search (on
slow computer B). 106 ~ 55.5 hrs ~ 5.5 hrs
Source: https://www.geeksforgeeks.org/
109 ~ 6.3 yrs ~ 8.3 hrs
O(n2) O(n)
STACKS
•A stack S is a linear sequence of elements to which elements x can only be inserted and deleted
from the head of the list in the order they appear.
•A stack implements the Last-In-First-Out (LIFO) policy.
top F
top E
E
D
D
C
C
B Usages:
B
String reversal, undo/redo, recursion, dfs,
bottom A backtracking, expression conversion etc.
bottom A
STACK USAGES CONTINUED…
main ()
{
int i = 5;
foo(i);
}
foo (int j)
{
int k; (Runtime Stack)
k = j+1;
bar(k);
}
bar (int m) {
…
}
(Stock span)
EXAMPLE USAGE2: RAT IN A MAZE
CONTINUED…
Move down
CONTINUED…
Move left
CONTINUED…
Move down
CONTINUED…
Move downward
CONTINUED…
Move right
Backtrack
CONTINUED…
Move downward
CONTINUED…
Move right
CONTINUED…
Algorithm size()
…
S return t + 1
0 1 2 t
CONTINUED…
C
O
M
P
L
E
X
I
T
Y
?
STACK USAGE: PARENTHESIS MATCHING EXAMPLE
Let S be an empty stack
for i=0 to n-1 do
if X[i] is an opening grouping symbol then (Output)
S.push(X[i])
else
if X[i] is a closing grouping symbol then
if S.empty() then
return false {nothing to match with}
if S.pop() does not match the type of X[i] then
return false {wrong type}
if S.empty() then
Task 1 and Task 2 of Lab6
return true {every symbol matched}
What are the demerits of Array implementation?
else
return false {some symbols were never matched}
STACK USAGE: REVERSING A VECTOR EXAMPLE
Non-recursive algo…
BITS F232: FOUNDATIONS OF DATA STRUCTURES Chittaranjan Hota, PhD
& ALGORITHMS (1 ST SEMESTER 2022-23) Professor of Computer Sc.
// opening tag?
Lab6
1. Get a vector of HTML tags from the input, and store them in a vector of strings. 2. Check whether HTML tags stored in the vector tags are matched
COMPUTING STOCK SPAN: STACK USAGE
• Stock span can be defined as the number of consecutive days before the current day where the price
of the stock was equal to or less than the current price.
Approach 2: Using an Array with three variables to avoid moving objects once
they are placed in the queue.
Use three variables: f, r, and n (front, rear, and number of elements). Let us see
the dequeue and enqueue operations… (What is the complexity?)
If we repeatedly enqueue and dequeue a single element, what problem it might
cause? Out-of-bounds
CONTINUED…
Approach 3: Use a circular array with ‘f’ and ‘r’ indices wrapping around the end of the
queue.
Lab7: Task2
size(), empty(), push(e),
pop(), front(), back()
5
Which operation is costly here?
2 5
3 2
3 Pop Out
3 5
2 2
5 3
Stack 1 Stack 2
DOUBLE-ENDED QUEUE ADT: DEQUE
•A queue-like data structure that supports insertion and
deletion at both the front and the rear of the queue.
•Applications: Ticketing line, Steal-scheduling algorithm in
Intel’s parallel programming, etc.
•insertFront(), front(), eraseFront(), insertBack(), back(),
eraseBack()
size(), empty(),
push_front(e),
push_back(e), pop_front(),
pop_back(), front(), back()
What are some of the scenarios where
Deque operations might be applicable?
(The STL deque)
DEQUE IMPLEMENTATION
Complexity of Operations?
BITS F232: FOUNDATIONS OF DATA STRUCTURES Chittaranjan Hota, PhD
& ALGORITHMS (1 ST SEMESTER 2022-23) Professor of Computer Sc.
Main methods:
at(i), set(i, o), insert(i, o), erase(i), size(), empty()
0 ≤ i ≤ size()−1
Algorithm remove(p):
u = pprev
w = pnext
unext = w {linking out p}
elements wprev = u
CONTAINERS AND ITERATORS
•What is a Container?
Let C be a container and p be an iterator for
• Can you give some examples? C:
•Various notions of iterator:
How will you iterate through the container?
• (standard) iterator: allows read-write access to
elements Example: (with an STL vector)
typedef vector<int>::iterator Iterator;
• const iterator: provides read-only access to elements int sum = 0;
• bidirectional iterator: supports both ++p and --p for (Iterator p = V.begin(); p != V.end(); ++p)
sum += *p;
• random-access iterator: supports both p+i and p-i return sum;
STL LISTS & ITERATORS
o/p
Source: https://www.geeksforgeeks.org/
Using Indexing Operator
Using Iterators
INDEX VS POSITION: MORE EXAMPLES
SEQUENCE ADT
•The Sequence ADT generalizes the Vector and List
ADTs
•Elements are accessed by:
Index, or
Position
•Generic methods:
size(), empty()
begin, end 1 1
A position object stores: set(p,e) 1 1
Element set(i,e) 1 n
positions
insert(p,e), n 1
erase(p)
Array based: atIndex takes O(1) O(n2) for Bubble sort. Iterator increment takes O(1) in either array or node-based
Node based: atIndex takes O(n) O(n3) for Bubble sort. sequence implementations O(n2) worst case for Bubble sort.
TREES: NON-LINEAR DATA STRUCTURES
•In computer science, what is a tree?
•A tree consists of nodes with a parent-child relation.
•Applications???
Worker1
ORDERED TREES
What are Ordered Trees?
TYPES OF TRESS IN DATA STRUCTURES
NULL
(The node structure) (The portion of the data structure associated (Running times of the functions of
with root node and its children) an n-node linked tree structure)
BITS F232: FOUNDATIONS OF DATA STRUCTURES Chittaranjan Hota, PhD
& ALGORITHMS (1 ST SEMESTER 2022-23) Professor of Computer Sc.
i
Algorithm preOrder(v) { t
e
Let us write it out in a r
recursive way… a
} t
i
v
Lab 8 next week e
Can you draw the binary tree for the preorder traversal output: 1 2 4 5 3?
POSTORDER TRAVERSAL
•In a postorder traversal, a node is visited after its
descendants.
•Application: compute space used by files in a directory Lab 8 next week
and its subdirectories, delete the tree, compute postfix
expression…
csf211/
Algorithm postOrder(v){
for each child w of v notices.txt
homeworks/ programs/
postOrder (w); 1K
visit(v);
}
h1.doc h2.doc p1.cpp p2.cpp p3.cpp
2K 5K 7K 22K 18K
BITS F232: FOUNDATIONS OF DATA STRUCTURES Chittaranjan Hota, PhD
& ALGORITHMS (1 ST SEMESTER 2022-23) Professor of Computer Sc.
Source: https://www.enjoyalgorithms.com/
FULL VS COMPLETE: TRY YOURSELF…
Full (X), or complete (X) Full (X), or complete (Y) Full (Y), or complete (N) Full (Y), or complete (Y)
EXAMPLE USAGES
Binary tree associated with an
arithmetic expression
internal nodes: ???
external nodes: ??? Want a quick breakfast?
Example: arithmetic expression tree for Yes No
the expression (4 (a - 4) + (5 - b)) Coffee & burger? Pizza and Pasta
Let us draw it…
Yes No Yes No
Binary tree associated with a decision process:
@CafeCoffeeDay Inst Cafe Bits&bytes Alankrita
- internal nodes: questions with yes/no
answer
- external nodes: ???
• Properties:
• e=i+1
• n = 2e - 1
• hi
• h (n - 1)/2
• e 2h
• h log2 e
• h log2 (n + 1) - 1
BINARY TREE ADT
INORDER TRAVERSAL
•In an inorder traversal a node is visited after its left subtree and before its right subtree
Application: draw a binary tree
Algorithm inOrder(v)
if v.isExternal()
inOrder(v.left())
visit(v)
if v.isExternal()
inOrder(v.right())
complete it…
PRINT ARITHMETIC EXPRESSION
Specialization of an inorder traversal
print operand or operator when visiting node +
print “(“ before traversing left subtree
print “)“ after traversing right subtree
Algorithm printExpression(v)
if v.isExternal()
print(“(’’) 2 - 5 b
inOrder(v.left())
print(v.element())
if v.isExternal() a 4
inOrder(v.right())
print (“)’’) Let us write it out…
EVALUATE ARITHMETIC EXPRESSION
Specialization of a postorder traversal
recursive method returning the value of a subtree
when visiting an internal node, combine the values of the subtrees
+ Algorithm evalExpr(v)
if v.isExternal()
return v.element()
else
x evalExpr(v.left())
2 - 3 2
y evalExpr(v.right())
operator stored at v
5 1 return x y
EULER TOUR TRAVERSAL
• Generic traversal of a binary tree
• We can unify the tree-traversal algorithms (in-order,
pre-order, and post-order) into a single framework by
relaxing the requirement that each node be visited
exactly once.
• Walk around the tree and visit each node three times:
on the left (preorder)
from below (inorder)
on the right (postorder)
+: It allows for more general kinds of algorithms to be
expressed easily.
(Source: Wiki)
Applications: finding no. of descendants, classifying advance and retreat edges, level of each node,
lowest common ancestor, etc.
BITS F232: FOUNDATIONS OF DATA STRUCTURES Chittaranjan Hota, PhD
& ALGORITHMS (1 ST SEMESTER 2022-23) Professor of Computer Sc.
preOrder(t->rightChild);
/ * +a b - c d +e f
}
} Gives prefix form of expression!
BINARY TREE TRAVERSAL: INORDER
template <class T> / Squishing
void inOrder(binaryTreeNode<T> *t)
{ * +
if (t != NULL)
e f
{ + -
inOrder(t->leftChild);
a b c d
visit(t);
inOrder(t->rightChild);
a + b * c - d / e + f
}
} Gives infix form of expression!
BINARY TREE TRAVERSAL: POSTORDER (RECAP)
template <class T>
/
void postOrder(binaryTreeNode<T> *t)
{
if (t != NULL) * +
{ e f
+
postOrder(t->leftChild); -
postOrder(t->rightChild); a b c d
visit(t);
} a b +c d - * e f + /
} Gives postfix form of expression!
EULER TOUR TRAVERSAL (RECAP)
•Generic traversal of a binary tree
•We can unify the tree-traversal
algorithms (in-order, pre-order, and
post-order) into a single framework by
relaxing the requirement that each
node be visited exactly once.
•We visit each node three times
•Euler tour: walk around a binary tree
where each edge is treated as a wall,
which you cannot cross. Each node will Img. Source: https://www.andrew.cmu.edu/
be visited either on the left, or under Applications: printing fully parenthesized expression
the below, or on right. etc.
BINARY TREE CONSTRUCTION FROM TRAVERSAL ORDER
Can you construct the binary tree, given two traversal sequences?
preorder = ab Try: a
Postorder: DEBFCA
postorder = ba Inorder: DBEAFC
gdhbei fjc
do they uniquely define a binary tree?
a
inorder = g d h b e i a f j c
preorder = a b d g h e i c f j
b fjc
preorder = a b d g h e i c f j
Similarly, Scan postorder from right to left using inorder. gdh ei …
IMPLEMENTATION OF TREES: LINKED STRUCT.
B
A node is represented by an object storing
Element
Parent node
Sequence of children nodes A D F
Node objects implement the Position ADT
C E
A VECTOR-BASED IMPLEMENTATION OF BINARY
TREE
• A simple structure for representing a binary tree T is based on a way of numbering the nodes
of T.
• If v is the root of T, then f(v) = 1; If v is the left child of node u, then f(v) = 2f(u); If v is the right
child of node u, then f(v) = 2f(u) +1 function f is called level numbering function.
tree[ ] a b c d e f g h i j a - b - - - c - - - - - - - d
0 5 10 0 5 10 15
tree[ ]
BINARY TREE IMPLEMENTATION USING LINKED
STRUCT
7 8
(Lab 8)
3 4
BINARY TREE UPDATE FUNCTIONS
expandExternal(const Position& p)
removeAboveExternal (const Position& p)
CONTINUED…
More later
…
(Searching successfully 36 through blue solid path, and unsuccessfully 71 through dashed path)
THE TEMPLATE FUNCTION PATTERN
•The template function pattern describes a generic computation method that can be
tuned for a particular application by redefining certain steps.