0% found this document useful (0 votes)
37 views13 pages

DSA Project

The document describes a library management system project that uses various data structures like binary search trees, hashmaps, and 2D arrays. It allows admins to add, delete, and update book information, which is stored in a binary search tree sorted by book name. Students can search for books, issue books which records the issue date, and return books noting the return date. The document outlines the key data structures used, operations performed on each, flowcharts of the user and admin processes, source code examples, sample inputs and outputs, and references consulted.

Uploaded by

Abdullah Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views13 pages

DSA Project

The document describes a library management system project that uses various data structures like binary search trees, hashmaps, and 2D arrays. It allows admins to add, delete, and update book information, which is stored in a binary search tree sorted by book name. Students can search for books, issue books which records the issue date, and return books noting the return date. The document outlines the key data structures used, operations performed on each, flowcharts of the user and admin processes, source code examples, sample inputs and outputs, and references consulted.

Uploaded by

Abdullah Habib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Searching catalogues in library using binary search tree

➢ Team members:
Rajvi Patel-1741078
Krushna Shah-1741086
Kalagee Anjaria-1741052

● Brief Description:
Our main objective in this project is to create a library management
system wherein students can issue books and the admin or librarian
can update/delete the record of books kept in the library.
So we have the system into two parts : from user’s perspective and
from admin’s perspective.

First of all, the admin must login to handle the accounts where the
username and password are already set. After he has logged in
successfully, he can add, delete and update the books. He can add
any new book in the already existing list of books. Similarly he can
also delete any existing book. In the update option, the admin can
update the quantity of books as well as the name of the book. As
and when the admin adds the books, a binary search tree will be
created where the nodes contain the name of books and are put in
sorted order.

Now if a student wants to issue/return any book, then he/she must


login into the system, by enetering their valid university ID. The
student will be allowed to issue/return only if their ID matches the
list of university ID’s of students. When the student enters the name
of book to be issued, that particular book will be searched by it’s
name, in the already created binary search tree. If the book is not
found in the tree, then a message will be printed “Book is not
available in the library”. And if the book is out of stock, then this
message will be printed, “This book is currently unavailable. Please
try after some days.” Moreover, the student cannot issue more than
2 books simultaneously. When the student issues a book, the issuing
date and time is recorded by the librarian. And if the student misses
the due date of returning the book, then he has to pay that particular
fine.
● List of Data Structures used with logic design

1) Binary Search Tree:


Binary search is used to search for a particular subject where
the searching operation performs an in-order traversal on the
created binary search tree to get the elements in sorted order,
where the binary search tree is created using Linked List.
➢ Doubly linked list

2) Hash-map:
Generally Hash-map, maps keys to values such that no
duplicate keys are generated. So, in our project, unique
keys are generated using hash map and it is assigned to
every book such that using this keys we can store and
fetch records of books in 2-D array.

3) 2-D array
Here, we have used 2-D array to store the record of each book
where rows indicate unique value for particular book which
hash-map returns and columns indicate total quantity of books
and availbale quantity of books.

 Operations to be perform on each data structure:

 Insertion:
We are using insertion operation to add books in the binary
search tree. And the tree will contain the name of the added
books.

 Deletion:
We use deletion operation to delete the node of that particular
book from the binary search tree. After the node is deleted, the
remaining elements are again rearranged in the tree.

 Updation:
The librarian can upate the quantity of already existing set of
books which is stored in the 2D array.
 List or print all the values:
There is also an option where all the details of the books are
printed. Name of the book, available quantity of the books that
can be issued and total number of books that library has.

 Print book in-order:


Prints the contents of the binary search tree i.e. the names of the
books in ascending order as the tree is balanced.

 Requirements of processing on data structures


 Keeping elements in a specific order (ascending order) in
 Binary Search tree is balanced.
● Flowcharts
1) User :
2) Librarian/ admin :
 List of programs

 Filename: finaldsa.java

 Source codes:

Insertion:

void insert(String key)


{
root = insertRec(root, key);
}

Node insertRec(Node root, String key)


{
if(root == null)
{
root = new Node(key);
return root;
}

//If book name < root then place it as left child


if (key.compareTo(root.key)<0)
root.left = insertRec(root.left, key);

//If book name > root then place it as Right child


else if (key.compareTo(root.key)>0)
root.right = insertRec(root.right, key);

return root;
}

Deletion:

void deleteKey(String key)


{
root = deleteRec(root, key);
}

Node deleteRec(Node root, String key)


{
if (root == null) return root;

//If book name < root then search it at left side and delete
if (key.compareTo(root.key)<0)
root.left = deleteRec(root.left, key);

//If book name > root then search it at right side and delete
else if (key.compareTo(root.key)<0)
root.right = deleteRec(root.right, key);

else
{
if (root.left == null)
return root.right;
else if (root.right == null)
return root.left;

root.key = minValue(root.right);

root.right = deleteRec(root.right, root.key);


}

return root;
}
String minValue(Node root)
{
String minv = root.key;
while (root.left != null)
{
minv = root.left.key;
root = root.left;
}
return minv;
}

Updation:

void update(String key,String key1)


{
deleteKey(key);
insert(key1);
}

Print tree in 2D:

void printTree()
{
root = printTreeRec(root, 0);
}

Node printTreeRec(Node t , int space)


{
if(t == null)
return root;

space += 5;

printTreeRec(t.right ,space);
System.out.println();

for(int i = 5 ; i < space ; i++)


System.out.print( " ");

System.out.print("[" +t.key+ "]");

return printTreeRec(t.left ,space);


}

Print in-order:

void printInorder(Node node)


{
if (node == null)
return;

printInorder(node.left);

System.out.print(node.key + " ");

printInorder(node.right);
}

void printInorder()
{
printInorder(root);
}

void inorder()
{
inorderRec(root);
}
void inorderRec(Node root)
{
if (root != null)
{
inorderRec(root.left);
System.out.println(root.key);
inorderRec(root.right);
}
}

Searching the book:

public boolean containsNode(String value)


{
return containsNodeRecursive(root, value);
}

private boolean containsNodeRecursive(Node current,


String key)
{
if (current == null)
{
return false;
}

//If book name < root then place it as left child


if (key.equalsIgnoreCase(current.key))
{
return true;
}
//If book name < root then search at left side of
root else right side
return key.compareTo(current.key)<0
? containsNodeRecursive(current.left, key)
: containsNodeRecursive(current.right, key);
}

● Input data and output generated

1) Add book

 Input data
Enter name of the book:
Enter quantity of book:

 Output generated
Book added successfully...

2) Delete book

 Input data
Enter name of the book:
Enter quantity of book:

 Output generated
Book deleted successfully...

2) Update book

 Input data
Enter name of book:
Enter quantity of book to add more:

 Output generated
Successfully updated...
4) Print book details

 Output generated
All the details of book will be printed

5) Print books in-order

 Output generated
The list of all books will be printed in ascending order of their
names as it is balanced binary search tree (Balanced BST).

6) Print tree

 Output generated
Balanced binary search tree is printed

7) Isuue book by user

 Input data
Enter your university ID:
Enter name of book:

 Output generated
Book issued successfully!!
Current date time:
Due date and time:

8) Return book:

 Input data
Enter your university ID:
Enter name of book:

 Output generated
Book returned successfully!!
Current date time:
Return date and time:
References:

1. How to get Key From Value in Hashtable, HashMap or Map in


Javahttps://javarevisited.blogspot.com/2013/02/how-to-get-key-from-value-in-
hashtable.html#axzz5VJAsUOtP

2. Number of days between dates (Beginning Java forum at Coderanch)


https://coderanch.com/t/543495/java/Number-days-dates

3. Masking password input from the console : Java - Stack Overflow


https://stackoverflow.com/questions/8138411/masking-password-input-from-
the-console-java

4. Binary Search Tree | Set 1 (Search and Insertion) – GeeksforGeeks


https://www.geeksforgeeks.org/binary-search-tree-set-1-search-and-insertion/

5. How to Get Current Date and Time in Java – Javatpoint


https://www.javatpoint.com/java-get-current-date

6. How to compare dates in Java? - Stack Overflow


https://stackoverflow.com/questions/2592501/how-to-compare-dates-in-java

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy