CSE246-Report (1) (1)
CSE246-Report (1) (1)
Department of CSE
CSE246
Algorithms
Project Name
Amit Mandal
Md. Rayhan Ahamed Lecturer
2021-3-60-197 Department of Computer Science and
2. Objective
The objective of this project is to develop a Library Book Search System that:
3. Methodology
Algorithms
• Binary Search: Used to search for book titles efficiently. This algorithm
also supports the auto-complete feature by suggesting book titles based
on a given prefix.
• Breadth-First Search (BFS): Used to find the shortest path from the
user’s current location to the book’s location in the library.
Implementation
• Book Data Storage: Store book titles and their locations (row and
column) in a file.
• Binary Search for Title Lookup: Implement binary search to suggest
books based on user-entered prefixes.
• Shortest Path Calculation: Implement BFS to guide users from their
current location to the book’s location.
User Interaction
• The user is prompted to enter the title of the book and their current
location
• The user selects the exact book title from the book.txt file.
• The system then calculates and displays the shortest path to the book’s
location.
BFS Implementation
4. Limitations
• The system assumes a static library layout. Any changes in the layout
require updating the library map data.
• The efficiency of BFS may decrease if the library is very large or has
many obstacles.
• The binary search for auto-complete suggestions may not handle large
datasets optimally without additional data structures like a trie.
5. Time Complexity
Loading Books:
Binary Search:
BFS:
Flow Chart :
Start
|
Load Books from
File
|
Prompt User for
Exact Tilte Selection
|
Get User’s Current
Location
|
Find Shortest Path
Using BFS
|
Display Path to User
|
E
n
d
Source Code :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h> // For execution time measurement
#define MAX_ROWS 15
#define MAX_COLS 15
#define MAX_BOOKS 10 // Maximum number of books stored in the array
typedef struct {
QueueNode nodes[MAX_ROWS * MAX_COLS];
int front, rear;
} Queue;
// Function prototypes
int binarySearch(Book books[], int n, char *title);
void bfs(int startRow, int startCol, int destRow, int destCol, int rows, int cols, int
library[MAX_ROWS][MAX_COLS]);
void printPath(int parent[MAX_ROWS][MAX_COLS][2], int destRow, int destCol);
int main() {
int library[MAX_ROWS][MAX_COLS] = {{0}}; // Library grid (0 = free space, 1 = obstacle)
char title[50];
printf("Enter the Book Title to Search: ");
scanf("%[^\n]%*c", title);
if (index == -1) {
printf("Book not found.\n");
return 0;
}
return 0;
}
int directions[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // Up, Down, Left, Right
while (!isQueueEmpty(&queue)) {
QueueNode current = dequeue(&queue);
if (current.row == destRow && current.col == destCol) {
printf("Path found: ");
printPath(parent, destRow, destCol);
return;
}
if (newRow >= 0 && newRow < rows && newCol >= 0 && newCol < cols &&
!visited[newRow][newCol] && library[newRow][newCol] == 0) {
enqueue(&queue, newRow, newCol);
visited[newRow][newCol] = 1;
parent[newRow][newCol][0] = current.row;
parent[newRow][newCol][1] = current.col;
}
}
}
Simulation :
Function BFS
void bfs(int startRow, int startCol, int destRow, int destCol, int rows, int cols,
int library[MAX_ROWS][MAX_COLS]) { int visited[MAX_ROWS]
[MAX_COLS] = {0}; int parent[MAX_ROWS][MAX_COLS][2]; Queue
queue; initQueue(&queue);
Direction Array
int directions[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
• Purpose: Defines the possible moves (up, down, left, right) in the grid.
BFS Loop
assigns it to current.
Check Destination
Explore Neighbors
• Purpose: Check if the neighbor is within bounds, not visited, and not
an obstacle. If valid, enqueue it.
• Details:
• if (newRow >= 0 && newRow < rows && newCol >= 0
&& newCol < cols): Check if the
• This while loop continues as long as the left index is less than or equal to the
right index, meaning
• int cmp: strcmp is used to compare the book title at the mid index with
the target title.
6. Results
The program effectively finds and prints the shortest path from the user's
current location to the specified book's location, provided there is a path
available. If no path is found, it informs the user.This helps users quickly find
books and navigate the library efficiently, reducing the time spent searching for
books.
7. Conclusions