Binary Search Tree

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 80

Binary Search Tree

- BST is a binary tree - the nodes are arranged in specific


order.
- The values at left subtree are less & right subtree are
greater than the root node value.
- Operation: Insertion, Deletion and searching.

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.

Ans: Exp = ((a / b) + (c * d)) ^ ((f % g) / (h – i))

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

left and right subtrees of R. T1 - left


successor of R. T2 - right successor of R

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.

Binary trees are commonly used to implement


binary search trees, expression trees, tournament
trees and binary heaps.

21
Types of Binary Tree
Full binary tree: every node has zero or 2 children.

COMPLETE BINARY TREES: is a full binary tree which


All leaves at the same depth, it satisfies 2 properties.
i.) Every level, except the last, is completely filled.
ii.) All nodes appear as far left as possible.
22
Types of Binary Tree
Total No. of nodes in a complete binary tree are
where h is height of tree. h = 3. tree has
exactly 15 nodes.

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

The tree has 11 nodes:

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

Inorder traversal (L – D - R): A + B * C


Preorder traversal (D – L - R) : + A * BC
Postorder traversal(L – R - D) : A B C *+

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:

• In HQL query execution, it takes more time


than the usual period.
• no shared reference values.
• It prevents the options of advanced query &
supports only composite keys.
advantages of Hibernate:
- Hib map the Domain obj’s to relational DB.
- independent of vendor & DB; that’s why it is
called a portable framework.
When compared to JDNS, Hibernate has
better connectivity of DB.
50
Object-Relational Mapping ORM
• the Java class mapped obj’s to the relational
DB metadata tables which describe obj
mapping & DB. The working method of ORM
is to transform the data from 1 representation
into another form.

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

is a component in the server-side that encapsulates


the business logic & executes in an EJB container
for the enterprise appln.

System services provided by EJB container:


Security - Connection pooling
Component lifecycle management
Persistence -Transaction - Threading

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

JNDI: Java Naming Directory Interface


(JNDI) is used to access DIR service data.
JTA: Java Transaction API (JTA)is used to
manage & coordinate the transactions of the
information enterprise system.
JMS: Java Messaging Service (JMS) is
used to send & receive messages by using
messaging systems.

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.

Work Flow of Classification

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

• use of the independent feature extraction by CNN algms


(uni)& multimodel) run in a parallel by the use of data center
to predict the infection.
• The accuracy of disease prediction is more and fast as compared
to the CNN-UDRP.

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

To improve the accuracy and efficiency of the


system the process proposes CNN-MDRP algm & by analyzing the
experimental results, it’s concluded that CNN-MDRP algm turned out
to be best classifier for TORCH infection prediction.

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.

[5] Jahanzaib Latif, Chuangbai Xiao, Shanshan TU and Anas Bilal,


”Implementation and use of Disease Diagnosis Systems for Electronic Medical
78
Records Based on Machine Learning,” IEEE, vol.18, no.9, pp. 4108-4120, 2009.
REFERENCES
[6] C. Romero, S. Ventura, “Classification and Prediction based Data Mining
Algorithms to Predict the Chronic Diseases,” IEEE Transactions on Systems,
Vol. 40, Issue 6, pp 601- 618, 2018.

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

[8] Thirunavukkarasu K, Ajay S. Singh, Md Irfan and Abhishek Chowdhury,”


Prediction of Liver Disease using Classification Algorithms,” IEEE., Vol. 6,
Issue-6, pp.4809-4813.

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

[10] P. Groves, B. Kayyali, D. Knott, and S. van Kuiken, The‘Big


Data’Revolution in Healthcare: Accelerating Value and Innovation. USA: Center
for US Health System Reform Business Technology Office, 2016.
79
THANK YOU

80

You might also like