Binary Search Tree
Binary Search Tree
Binary Search Tree
1
Search - BST
- Searching a key node(x) in a BST
- Compare each node starting from root node
- If key found - it returns the pointer of that node
- If BST is NULL, then it will return the NULL.
node *search(node *root, int key, node **parent) {
Node *T; T = root;
while(T!=NULL){
If(T -> data == key){
Parent = temp; ----->marking the parent node
If(temp -> data>key) ----->If current node is greater than key
temp = temp -> left; -----> Search for the left subtree
}else
temp = temp->right; -----> Search for the right subtree
} return NULL;
}
2
Insertion - BST
- used to add a new node with a given value at correct
position in BST.
- Adding new node at correct position - new node should
not violate the properties of BST. So we perform the
search function first.
- The insertion function changes the structure of BST, so
it is called recursively.
- Requires time proportional to the height of the tree in
the worst case. It takes O(log n) time to execute in the
average case & O(n) time in the worst case.
3
Insertion - BST
4
Deletion - BST
- Case 1: Deletion of a leaf node: delete immediately
5
Deletion Case 2 - BST
- Case 2: Deletion of a node having 1 children
- If the node has 1 child, then the node can be deleted
after its parents adjusts a pointed to bypass the node.
- Example – Delete node 54
6
Deletion Case 2 - BST
- Case 3: Deletion of a node having 2 children
- Find smaller value(in-order successor) in right subtree
or Find larger value(in-order predecessor) in left
subtree. Replace the node in place of deleted node.
- Example – Delete node 56
7
Find Min & Find Max
- This routine return the position of smallest element in
the BST.
- Start at root & go left subtree as long as there is a left
child, stopping point is smallest element.
- Start at root & go right subtree as long as there is a right
child, stopping point is largest element.
8
Expression Trees
Example 2. write down the expression that it represents.
9
Ex.1: A / B * C * D + E , Give the algorithm for inorder,
preorder, postorder traversals and show the result of these
traversals.
Ans:
Step 1: Step 2:
10
Ex.1: A/ B * C* D + E
Give the algorithm for inorder, preorder, postorder traversals and
show the result of these traversals.
Step 3: Step 4:
11
12
Trees
Basic terminologies:
- Level of the tree: Root node always at level 0
or L = 0. The adjacent nodes L + 1
- Height of the tree(Depth of the tree):
Maximum level = height of tree.
- Predecessor: Some particular node occurs
previous to some other node.
- Successor: is a node occurs next to some node
- Siblings: nodes with same parents
13
Trees
Types of Trees:
- General trees : store elements hierarchically
- Forests: Disjoint union of trees
- Binary trees
- Binary search trees
- Expression trees
- Tournament trees
14
Binary Tree ADT
- Defined as a collection of elements called
nodes, topmost element is called the root node,
each node has 0, 1, or at the most 2 children.
- Left pointer left child
- Right pointer right child
- Root element 'root' pointer
- Root = NULL, it means tree is empty
15
Binary Tree ADT
- R - root node and 2 trees(T1 & T2) are
16
Binary Tree ADT
- Levels in Binary node:
17
Binary Tree ADT
TERMINOLOGY:
Parent:
- If N is any node in T ( left successor S1 & right
successor S2), then N is the parent of S1 & S2.
- Every node other than the root node has a
parent
Level number:
- The root node -- at level 0 or L = 0. The left &
right child of the root node have a level number 1
or L + 1.
18
Binary Tree ADT
TERMINOLOGY:
Degree of a node: = No. of children that a node
has. The degree of a leaf node is 0.
- In-degree: No. of edges arriving at that node.
- Out-degree: No. of edges leaving that node.
Path: A sequence of consecutive edges.
Siblings: All nodes at same level & share same
parent.
Leaf node: no children is called a leaf node or a
terminal node.
19
Binary Tree ADT
TERMINOLOGY:
Edge: Line connecting a node N to any of its
successors, exactly n – 1 edges.
Depth: The depth of the root node is zero.
Height of a tree: total No. of nodes on the path
from the root node to the deepest node in the tree.
A tree with only a root node has a height of 1.
20
Binary Tree ADT
TERMINOLOGY:
- In-degree / out-degree of a node: No. of
edges arriving at that node / No. of edges
leaving that node.
21
Types of Binary Tree
Full binary tree: every node has zero or 2 children.
23
Types of Binary Tree
Left & Right Skewed trees: each node
attached as left child of a parent node –
left skewed tree. llly right skewed tree.
24
Types of Binary Tree
Extended Binary Trees: Every empty
sub-tree is replaced by a new node. The
original nodes - internal nodes, & the new
nodes added are - external nodes.
25
Representation of Binary Trees
in the Memory
In the computer’s memory, a binary tree can be
maintained either by using a linked or a
sequential representation.
1. Linked representation of binary trees:
Every node have 3 parts: the data element, a
pointer to left node, & a pointer to right node.
struct node {
struct node *left;
int data;
struct node *right; };
26
Representation of Binary Trees
in the Memory
In the computer’s memory, a binary tree can be
maintained either by using a linked or a
sequential representation.
1. Linked representation of binary trees:
Every node have 3 parts: the data element, a
pointer to left node, & a pointer to right node.
struct node {
struct node *left;
int data;
struct node *right; };
27
Linked representation of binary trees
28
Linked representation of binary trees
29
Representation of Binary Trees
in the Memory
2. Sequential or array representation of
binary trees: Each node is sequentially
arranged from top – bottom & from left – right.
- done using single or 1-dimensional arrays.
- Rules:
1. When n = 0, the root node placed at 0th
location.
2. parent(n) = floor(n-1)/2
3. Left(n) = (2n+1)
4. Right(n) = (2n+2)
30
Sequential representation of binary trees
31
Sequential representation of binary trees
32
Ex 1: Show the array and linked representation for the
following binary tree?
33
Ex 1: Show the array and linked representation for the
following binary tree?
34
Tree Traversal
- Visiting each node exactly once.
- 6 ways to traverse a tree:
L for moving to left child
R for moving to right child
D for parent node or Root node
- L, R, D : have 6 combinations : LDR, LRD, DLR, DRL, RLD,
RDL.
- From computation point of view, we consider only 3
combinations: LDR (inorder), DLR(preorder) &
LRD(postorder)
1. Inorder Traversal: Left node visited first, then parent node
and then right node is visited.
35
Inorder Traversal
Algorithm:
1. If tree is not empty then
a. traverse the left subtree in inorder
b. Visit the parent node or root node
c. traverse the right subtree in inorder
Recursive routine: void inorder(node *temp) { if (temp!=NULL)
}} 36
Preorder Traversal
- Parent node or root node visited first, then left node and finally
right node visited.
Algorithm:
1. If tree is not empty then
a. Visit the parent node or root node
b. traverse the left subtree in preorder
c. traverse the right subtree in preorder
Recursive routine: void preorder(node *temp) { if (temp!=NULL)
{
}} 37
Postorder Traversal
- Left node visited first, then right node & finally parent node
visited.
Algorithm:
1. If tree is not empty then
a. traverse the left subtree in postorder
b. traverse the right subtree in postorder
c. Visit the parent node or root node
Recursive routine: void postorder(node *temp){ if (temp!=NULL)
{
}} 38
Example Tree Traversal
}}
39
Expression Trees
Binary trees are widely used to store algebraic expressions.
For ex:, algebraic expression as:
Exp = (a – b) + (c * d)
Exp = A + (B*C)
Inorder traversal of expression tree gives Infix expression
Preorder traversal of expression tree - Prefix expression
Postorder traversal of expression tree - Postfix expression
40
Expression Trees
41
Expression Trees
Example 1. Given an expression,
Exp = ((a + b) – (c * d)) % ((e ^f) / (g – h)),
construct the corresponding binary tree
42
Application of Trees
- Binary Search tree
- Threaded binary tree
- Represent organization
- Represent computer filesystems
- Networks to find best path in the Internet
- Chemical formulas representation
- Gaming applications (one player has only 2 moves at a time)
43
44
DB Connect Code
try { Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundEx)
{ Logger.getLogger(DbCon.class.getName()).log(Level.SE
VERE, null, ex); } try {
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/myd
b","root","mypass");
} catch (SQLException ex)
{ Logger.getLogger(DbCon.class.getName()).log(Level.SE
VERE, null, ex); } return con; }
45
core modules in spring - 7
Object/Relational Mapping module
Core Container module
Appln Context module
Web module
Aspect-Oriented Programming
DAO module
Mobile View Controller (MVC) module
46
Hibernate
open source, A query service & an obj-
relational mapping which allows writing
Hibernate Query Language (HQL). It doesn’t
allow us to write SQL scripts. Hibernate is
faster than SQL, which has compelling
object-oriented contents like inheritance,
associations, and polymorphism. Hibernate
consists of substantial collections and
persuasive compositions. It allows query
makings by using the Java-based approach.
47
Java Server Faces (JSF)
• JSF acts as a UI for Java web applns in
designing a framework. based on Model
View Controller (MVC) pattern. It saves
form data on the server-side & populates
it on the client-side.
48
J2EE Container
• is the interface b/w a low-level platform & a
component. J2EE Container is termed as a
framework that provides relevant services to
the Appln server. Server platform to run J2EE
appln’s.
49
Limitations of Hibernate:
51
Advantages of ORM:
• Productivity: It reduces the data access coding
time with automatic code creation on the data
defined model.
• Maintainability: The codes generated from Object-
Relational Mapping are tested well. The developer
needs to correct only functionality.
• Performance: The Object-Relational Mapping code
manages the application data access. There is no
need for creating data access code and optimize
the speed up of the process.
• Vendor Independence: The code generated from
Object-Relational Mapping does not depend on the
vendor. It increases the application portability.
52
use - method save() & save
or update()
• save(): used to store the object in the DB.
Before inserting it, there is a check for
duplicate records in hibernate.
• Save or update(): used to update the object
by using an identifier. If the identifier value is
0, then this method directs to call save().
53
diff b/w load() & get() mtds
• Load(): never returns null & can’t find the
object from DB or cache.
Get(): If the object can’t found then get()
method returns null. Get() method never
returns a proxy, whereas load() returns proxy.
54
Connection Pooling:
• A mechanism which helps in re-using the
existing connectns.
• This pooling mechanism maintains obj-
oriented connectns which already created.
• Without creating a new connection, this
Pooling mechanism directly uses the existing
connectn.
55
core interfaces of Hibernate
• Session Factory Interface
• Transaction Interface
• Session Interface
• Config Interface
• Criteria & Query Interface
• Collection types in Hibernate:
• List - Set - Array - Bag - Map
56
diff being J2EE compatible & J2EE
license
• A J2EE license has signed as the J2EE
commercial distribution license. It means the
license commits compatibility & compatible
tests. It doesn’t convey the meaning that the
products are compatible. The J2EE brand
has significantly passed the Compatibility
Test Suite (CTS).
57
JSP
• The JSP tags 4 types:
• Declaratives - Directives
• Expressions - Scriptlets
JSP Directives:
• Include Directives (include= header.jsp)
• Page Directives (page language= java)
• Taglib Directives
• (prefix=html & taglib uri= tlds/taglib.tld)
58
Struts framework
• An MVC architecture used to design large-
scale applns.
• It is the combination of Java Server Pages,
Java Servlets, message, & Custom tags.
• Struts used to create a development
environment to the appln based on the
proven design patterns & published
standards.
59
ActionMapping
• the user specifies action class a particular URL like
target views & paths at which the request-response
starts forwarding.
• It represents the mapping of a request for a specific
class of action that an ActionServlet knows.
• The mapping can pass to the Action class execute()
mtd by enabling information access directly.
• ActionForm: A Java Bean that associates with
ActionMapping. A Java Bean becomes FormBean
when it extends .apache .org. Action. Structs.
ActionForm class.
• On the server-side, the object of ActionForm is
populated at which UI client enters the data.
ActionForm maintains web application session state. 60
funs RequestProcessor &
ActionServlet:
Handling Content type Issues
Populating Java Bean
Receiving request from HttpServlet
Providing extension points
Displaying web page issue response
61
EJB (Enterprise Java Beans):
62
EJB appln’s design principles?
loosely coupled.
The interfaces specify EJB appln behaviour.
In the client-side, the implementation can be
hidden.
The Appln API lies -session tier.
The data source API lies in entity tier.
63
JNDI, JTA, and JMS
64
adv of spring appln
- used to development testability of applications.
- The Plain Old Java Obj (POJO) is based on the
facility development in re-using the existing
components.
- Improves maintainability by reducing code
coupling.
- To reduce cost by improving appln productivity.
- It doesn’t need an appln server.
65
Hash table
HashTable is just like Hash Map,
Collection having a key(Unique), value
pairs. Hashtable is a collection
Synchronized object. It does not allow
duplicate values or null values.
66
EVALUATION METHODS
• Disease Predictor is the ability to predict the disease that has been
provided to the system. For disease prediction, need to implement
classification algorithms, which analysed by assessing the
affectability, specificity, & accuracy of the classification.
• The sensitivity & specificity are the proportion of positive &
negative instances respectively.
67
Comparisons of accuracy, precision, recall and F1-Measure under S-data for NB,
KNN and DT
Comparison of the running time in the data center,
68
MEASURE ACCURACY
69
SYSTEM TESTING
• Unit Testing:
- Verified all field entries & entry screen work properly.
- Pages must be activated from the identified link.
- Verified that all entries are of the correct format.
- No duplicate entries should be allowed.
• Integration Testing:
- All the test cases mentioned are passed successfully without
any defects encountered.
- e.g. components in a s/w applns are interacted without
errors.
70
CONCLUSION
71
FUTURE ENHANCEMENT
• The main challenge with this project is the very small number of
datasets are not sufficient , as well as a limited number of features
and some are correlated.
Integrate this model in hospital & clinic system to predict TORCH
Infection.
• In the future, need to try 4 TORCH infections by using CNN –
Effective MDRP to make accurate predictions.
72
SCREEN SHOTS
User can login into the system
73
SCREEN SHOTS
User can view or upload the patient details into the system,
SCREEN SHOTS
User can load the patient record for classification and prediction
74
SCREEN SHOTS
User input requests are collected & processed on server to estimate the
diagnosis result.
75
SCREEN SHOTS
The dataset is loaded to preprocess the data, replace missing
values, feature selection and apply classification algorithms.
SCREEN SHOTS
On this system, the algms are executed on train dataset & classifies
the test dataset.
76
SCREEN SHOTS
Separating data into test & training datasets to evaluating the prediction models.
CNN algms (uni)& multimodel) run in a parallel to predict the infection.
SCREEN SHOTS
comparing the outputs of the CNN algms (uni & multimodel) results, measure the
accuracy of the TORCH Infection.
77
REFERENCES
[1] Min Chen, Yixue Hao, Kai Hwang,” Disease Prediction by Machine
Learning over Big Data from Healthcare Communities,” , Lu Wang, and Lin
Wang, vol-3, ISSN: 2169-3536, 2017.
[2] Patrice Monkam, Shouliang Q, Weiming Gao, Yudong Yao,” Detection and
classification of pulmonary nodules using convolutional neural networks,” IEEE
Access., vol.29, no.4, pp.2405-2409, 2019.
[3] Seung Seog Han, Myoung Shin Kim, Woohyung Lim, Gyeong Hun Park,”
for Benign and Malignant Cutaneous Tumors Using a Deep Learning
Algorithm,’ IEEE, vol.69, no.16, pp.4284-4297, 2009.
[4] Ramona Gabriela Ursu, Diana Costin, LuminiĠa Smaranda Iancu,” The
Clinical Utility of TORCH Testing of Pregnant Women - Application of
electrochemiluminiscence assay,” IEEE., vol.61,no.23, pp.5947-5959, 2008.
[7] Jagdeep Singh, Amit Kamra, Harbhag Singh,” Prediction of Heart Diseases
Using Associative Classification,” IEEE Trans.Inf. Theory, vol.61, no.3,
pp.1389-1409, 2017.
[9] Huy Phan, Fernando Andreotti, Navin Cooray, Oliver Y. Chen and Maarten
De Vos,” Joint Classification and Prediction CNN Framework for Automatic
Sleep Stage Classification,” IEEE Trans., Vol.66, No.5, May 2019.
80