0% found this document useful (1 vote)
4K views6 pages

Assignment NO 1

The document outlines an assignment to create a Python program for managing library book borrowing records, including functionalities like calculating average borrowings, identifying the most and least borrowed books, and counting members who haven't borrowed books. It also discusses the time and space complexity of various operations involved in the program. The assignment aims to provide practical experience with data structures and algorithms in the context of a library management system.

Uploaded by

omchakre07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
4K views6 pages

Assignment NO 1

The document outlines an assignment to create a Python program for managing library book borrowing records, including functionalities like calculating average borrowings, identifying the most and least borrowed books, and counting members who haven't borrowed books. It also discusses the time and space complexity of various operations involved in the program. The assignment aims to provide practical experience with data structures and algorithms in the context of a library management system.

Uploaded by

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

Assignment NO 1

TITLE: Write a Python program to manage the borrowing records of books in a library. Implement
the following functionalities:

1) Compute the average number of books borrowed by all library members.

2)Find the book with the highest and lowest number of borrowings in the library.

3)Count the number of members who have not borrowed any books (denoted by a borrow count of 0).

4)Display the most frequently borrowed book (i.e., the mode of borrow counts).

After performing, determine the time and Space complexity of each operation

Objectives:
1. To provide hands-on experience with basic and advanced data structures.
2. To apply Data Structures for real-world problem solving.

Learning Objectives:
To understand importance of data structures in context of writing efficient programs.

Learning Outcome:
1. Analyze basic searching and sorting algorithms to solve problems and evaluate their efficiency
in different scenarios.
2. Understand and analyze various types of data structures and algorithms.

Theory:
A Library Management System using Python GUI typically involves creating an application that
manages book records, member information, and borrowing processes. Can build an interactive system
that allows users to add, update, and search for books efficiently.
The architecture of a Library Management System (LMS) using Python typically follows a layered
structure that enhances modularity and maintainability.
process model for borrowing books that commonly operate in libraries:
The components and functionalities

1. Book Management:

 Adding Books: Allows librarians to add new books to the system, including details like title,
author, ISBN, and quantity.
 Viewing Books: Displays a list of all books in the library, including their details.
 Updating Books: Enables modification of book information (e.g., quantity, location).
 Removing Books: Allows for deleting books from the system.
2. Member Management:

 Adding Members: Allows registration of new library members with their details.
 Viewing Members: Displays a list of all registered members.
 Updating Members: Allows modification of member information.
 Deleting Members: Removes members from the system.
3. Borrowing/Returning:

 Borrowing Books: Links a book to a member's ID and records the borrowing date and due
date.
 Returning Books: Updates the book's availability and removes the borrowing record.
 Overdue Books: Tracks books with a past due date and may include a mechanism for fines.

Space complexity
 Definition: Space complexity measures the amount of memory or storage space an algorithm
needs to complete its execution, relative to the input size (n).
 Components: It considers both the fixed part (space for code, constants, simple variables) and
the variable part (space for dynamic data structures, recursion stack, etc.).

 Notation: Like time complexity, space complexity is also commonly expressed using Big O
notation.

 Examples:

o O(1) (Constant Space): Algorithms using a fixed amount of memory regardless of input
size, like swapping two numbers or an in-place sort like Bubble Sort.

o O(n) (Linear Space): Algorithms where memory usage grows linearly with input size,
such as creating an array of 'n' elements or using data structures like linked lists or
stacks.

o O(n²) (Quadratic Space): Algorithms requiring memory proportional to the square of


input size, often seen in algorithms that create two-dimensional arrays based on the
input size.

Time complexity
 Definition: Time complexity measures the amount of time an algorithm takes to run to
completion as a function of the input size (n).

 Focus: It focuses on the number of operations or computational steps the algorithm performs,
rather than the actual time taken, which can be influenced by factors like the programming
language, hardware, and operating system.

 Notation: Time complexity is typically expressed using asymptotic notations like Big O, Big
Theta (Θ), and Big Omega (Ω), with Big O (worst-case scenario) being the most commonly
used.

 Examples:

o O(1) (Constant Time): Operations that take the same amount of time regardless of input
size, like accessing an element in an array by its index.

o O(log n) (Logarithmic Time): Operations where the time taken increases


logarithmically with input size, like binary search on a sorted array.

o O(n) (Linear Time): Operations where the time taken increases linearly with input size,
like iterating through an array or linked list to find an element.
o O(n log n) (Log-linear/Linearithmic Time): Common in efficient sorting algorithms
like Merge Sort, where the time grows proportionally to the input size multiplied by the
logarithm of the input size.

o O(n²) (Quadratic Time): Operations involving nested loops, where the time taken grows
proportionally to the square of the input size, like simple sorting algorithms such as
Bubble Sort, Selection Sort, and Insertion Sort.

Conclusion
By leveraging Python's capabilities and object-oriented programming principles, libraries can create a
system that is efficient, user-friendly, and adaptable to their specific needs. The potential for growth
and integration of new technologies ensures that the system can evolve alongside the changing
landscape of libraries and information management.

*************Library management system complexity*************

Time and Space Complexity Analysis

Let:

 n = number of members
 m = total number of borrowed books
 u = number of unique books

1) Average books borrowed per member

 Time Complexity: O(n)


 Space Complexity: O(1) (ignores input storage)

2) Highest and lowest borrowed books

 Time Complexity: O(u)


 Space Complexity: O(1) (additional, beyond the Counter object)

3) Members with 0 borrowings

 Time Complexity: O(n)


 Space Complexity: O(1)

4) Most frequently borrowed book

 Time Complexity: O(u)


 Space Complexity: O(k) where k is the number of books with max frequency (≤ u)

***************************************END***************************************
*********************Assignment 1 Code****************************************

from collections import defaultdict, Counter

# Sample data
# Dictionary where keys are member names and values are lists of borrowed book titles
borrow_records = {
'Alice': ['Book1', 'Book2'],
'Bob': [],
'Charlie': ['Book2', 'Book3', 'Book3'],
'David': ['Book1'],
'Eve': [],
}

# Flatten all borrowed books to count each book's borrowing frequency


all_borrowed_books = [book for books in borrow_records.values() for book in books]
book_borrow_count = Counter(all_borrowed_books)

# 1) Average number of books borrowed by all members


def average_books_borrowed(records):
total_borrowed = sum(len(books) for books in records.values())
num_members = len(records)
return total_borrowed / num_members if num_members else 0

# 2) Book with highest and lowest number of borrowings


def highest_and_lowest_borrowed_books(book_counts):
if not book_counts:
return None, None
most_borrowed = max(book_counts.items(), key=lambda x: x[1])
least_borrowed = min(book_counts.items(), key=lambda x: x[1])
return most_borrowed, least_borrowed
# 3) Number of members with 0 borrowings
def count_zero_borrowers(records):
return sum(1 for books in records.values() if len(books) == 0)

# 4) Most frequently borrowed book (mode)


def most_frequent_borrowed_books(book_counts):
if not book_counts:
return []
max_count = max(book_counts.values())
return [book for book, count in book_counts.items() if count == max_count]

# --- Run operations ---


print("1. Average books borrowed per member:", average_books_borrowed(borrow_records))
most, least = highest_and_lowest_borrowed_books(book_borrow_count)
print("2. Most borrowed book:", most)
print(" Least borrowed book:", least)
print("3. Members with 0 borrowings:", count_zero_borrowers(borrow_records))
print("4. Most frequently borrowed book(s):", most_frequent_borrowed_books(book_borrow_count))

****************Output:**************************************************************
1. Average books borrowed per member: 1.2
2. Most borrowed book: ('Book1', 2)
Least borrowed book: ('Book1', 2)
3. Members with 0 borrowings: 2
4. Most frequently borrowed book(s): ['Book1', 'Book2', 'Book3']

You might also like