Monday, 7 July 2025

Implement student database using dynamically allocated memory and perform various operations.


 NEP 2020 Compliant Curriculum Structure

Second Year Engineering (2024 Pattern) – Information Technology


1. Title:
Implement student database using dynamically allocated memory.

2. Objective:
Study various data structures and do the implementation of specific applications.


3. Problem Statement:

Design a program to maintain a student database that performs the following tasks: 

1. Add and store student details (ID, Name, CGPA) using dynamically allocated memory.

2. Expand the student list using realloc () as new entries are added.

3. Implement Linear Search and Binary Search to find student records by ID.

4. Implement at least two Sorting Algorithms (Bubble Sort, Selection Sort, or Insertion Sort) to sort student records by: 1. Name (Alphabetically) 2. CGPA (Ascending/Descending)

5. Analyze and compare the performance of search operations before and after sorting.


4. Outcomes:

After implementing the above problem statement, the expected outcome are as follows:

1. We learn how to allocate memory dynamically and then we store student details in it like id, name, CGPA.

2. We learn how to reallocate memory that is expansion of student list using realloc() function. for e.g. first, we allocate only 10bytes of memory but right now we want to store one more record but there is no sufficient memory so once again we do the reallocation of memory means expansion of memory and store the record.

3. We learn how to search particular student from the list of students by using two searching technique Linear Search and Binary Search.

4. We learn how to sort (Ascending /Descending) the student record using three sorting techniques 1. Bubble Sort 2. Selection Sort and 3. Insertion Sort.

5. We analyze and able to do the comparisons of performance of search operations before and after sorting.


5. Algorithms:



data structures and algorithms Web Developer

Tuesday, 24 June 2025

Implement a robust Java calculator program that computes user input dynamically. ( OOPCGL 2024 Course)



PCC-205-COM: Object Oriented programming and Computer Graphics Lab (2024 Course)



Group A

1. Title: Implement a robust Java calculator program 


2. Objective: To explore & understand the principles of Object-Oriented Programming (OOP).


3. Problem Statement: Implement a robust Java calculator program that captures user input dynamically, processes mathematical operations using conditional logic and looping constructs, and ensures efficient error handling.


4. Outcomes:

After implementing the above problem statement, the expected output is as follows:

1. Dynamically user can accept any input.

2. User can perform following mathematical operations using conditional logic (operational rules R) and looping constructs.

    2.1 Addition of input a, b (a + b)

    2.2 Subtraction of input a, b (a - b)

   2.3 Multiplication of input a, b (a * b)

    2.4 Division of input a, b (a / b)

    2.5 Reminder of input a, b (a % b)

3. Error like divide by zero error gets handle by using try and catch block.


5. Software and Hardware Requirements:

5.1 Software Requirements: 

1. Operating System: 64-bit Open-source Linux or its derivative

2. Programming tools: - Open-Source Java Open JDK,

3. Programming IDE: BlueJ, Eclipse, NetBeans, JDeveloper.

5.2 Hardware Requirements:

13th Gen Intel(R) Core (TM) i5-13400   2.50 GHz, 8 GB RAM


6. Mathematical Model:

The model can be expressed as:

Given a, b ∈ R and O ∈ {+×÷%} 

Compute R using the operation rules given in Output Section above, Subject to b 0 if O∈ {÷, %}.

Where,

Input: a, b, : operator chosen by user

Operations: The calculator performs operations O on inputs a and b

Error: if b = 0 and O∈ {÷, %}.

Constraints: b! = for division (/) and modulus (%)


7. Algorithm:

Step 1: Start

Step 2: Accept input a, b and operator O belongs to +, -, x, / and mod from user dynamically.

Step 3: Now as per the operator following operations are going to be performed.

Step 3.1: if operator is + then show result = a + b

Step 3.2: if operator is - then show result = a - b

Step 3.3: if operator is * then show result = a * b

Step 3.4: if operator is / then check the constraint b (b! =0) is not equal to zero if this constraint is true then you have to throw the exception and handle it by using catch block. else if this constraint is false you have to do normal operation & show result = a / b.

Step 3.5: if operator is % (mod) then check the constraint b (b! =0) is not equal to zero if this constraint is true then you have to throw the exception and handle it by using catch block. else if this constraint is false you have to do normal operation & show result = a % b.

Step 4: Stop


8. Flowchart:


9. Program Code:



10. Sample Output:

Test Case: 01 Inputs to test all basic operation of calculator using valid inputs.


Test Case: 02 Inputs to test Exception Handling



11. Conclusion:

Hence, we learn how to apply fundamental programming constructs in Java for implementing an application.


Note: 

Dear Readers,
    if you have any suggestions or find any misconception in above implemented code, please guide me for the same. so that i can improve myself for the same. Thanking you in advance. Please reply to your valuable feedback here in comments or DM me on +91 9096454130

data structures and algorithms Web Developer

Saturday, 21 June 2025

Group A: Library Management System using Python (SPPU SE Computer New Syllabus 2024 PAT)


National Education Policy (NEP)-2020 Compliant Curriculum
SE - Second Year Engineering (2024 Pattern) 
in
Computer Engineering
&
Computer Science and Engineering


Problem Statement:

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

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

 • Find the book with the highest and lowest number of borrowings 

    in the library. 

 • Count the number of members who have not borrowed any books 

    (denoted by a borrow count of 0). 

 • Display the most frequently borrowed book (i.e. the mode of 

    borrow counts).

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


Dear Reader,

By reading the above problem statement, we come to know that we want to implement Library Management System using Python Programming language with some specific functionalities.


Algorithm:

First thing we need to implement Class with some basic functionalities.
1. Types of Data Structures we are using such as Dictionary, Nested Dictionary, List of      Tuples.
2. Basic Functionalities are as follows:
    2.1 Register Users or Enroll users inside the library.
    2.2 Display all the enrolled or registered users from the library.
    2.3 Add book information inside the library.
    2.4 Display all books information added inside the library.
    2.5 Borrow book functionality through which user can borrow books available                      inside library.
    2.6 Display the borrow log of books.
3. Finding the book with the highest and lowest number of borrowings in the library.
4. Display the most frequently borrowed book.
5. Count the number of members who have not borrowed any books.
6. Compute the average number of books borrowed by all library members.


Let's start the implementation of above problem statement.

1. Types of Data Structures we are using such as Dictionary, Nested Dictionary, List of      Tuples.




2. Basic Functionalities are as follows:
    2.1 Register Users or Enroll users inside the library.
    2.2 Display all the enrolled or registered users from the library.
    2.3 Add book information inside the library.
    2.4 Display all books information added inside the library.
    2.5 Borrow book functionality through which user can borrow books available                      inside library.
    2.6 Display the borrow log of books.




3. Finding the book with the highest and lowest number of borrowings in the library.



From line number 96 we have created the object (nmshivalelibrary) of MyLibrary Class and through that object we are calling all member function of that respective MyLibrary class.



After calling all the member functions let's check how our code is going to execute. let's understand it through below output:




4. Display the most frequently borrowed book.

Algorithm:
1. Start

2. First check is their book in books dictionary, if not say No books else go to next step.

3. As we know in book dictionary, we store every book information along with book id - book name and it borrow count. for e.g. 101, {'book_name':'TOC', 'borrow_count': 2} 
we also know dictionary stores data in key value pair so here book id is key and remaining like book_name and borrow_count acts as a value. now from this value we want to find out the max borrow_count for that purpose we write lambda function inside max function so that we will get max value of borrow count.

4. once we get the max value i:e max_borrow from borrow_count of books dictionary then we will search for book name of that particular max_borrow from book_name and stored it inside most_borrowed variable.

5. finally we display the most borrowed book or frequently borrowed book.


By referring the code of above function, we can find out the most frequently borrowed book.

5. Count the number of members who have not borrowed any books.

Algorithm:

1. Start

2. First of all, from the borrower_log you have to find out the user id of users who borrow the book into the set of borrowed_user_ids. To do this we iterate inside the borrower_log list where we store user_id and book_id in tuple format like (user_id, book_id).

3. Now from that tuple we just want to deal with 0th index record of each tuple so to do this we have written a code like user_id = record [0] by doing this we are just collecting the user id from borrower_log and store it inside the borrower_user_ids set using add ( ) method

4. Once we get all user ids from borrower_log next, we have to search user_id from user's dictionary who is not in  borrower_user_ids set. Those who are not in borrower_user_ids set we put or store them inside users_without_books list.

5. finally we display them as users who have not issued or borrowed any book with its user id and username.

6. Stop




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

Algorithm:

1. Start

2. Find out the total number of books borrowed in sum_of_book_borrow

3. Find the length of number of users registered inside library system in 
    no_of_lib_members

4. Find out the average = (sum_of_book_borrow / no_of_lib_members)

5. Show the computed average number of books borrowed by 
    all library members.

6. Stop




Note: Dear readers if you have any suggestion, please guide me for the same write your comment in comment box so that I can correct myself. Thanking you in advance.


data structures and algorithms Web Developer

Monday, 7 April 2025

Write a code in JAVA for a simple WordCount application that counts the number of occurrences of each word in a given input set using the Hadoop MapReduce Framework on local standalone set up.



 

To perform the wordcount program in Hadoop framework we need following software.
First you have to download the setup:
1. cloudera-quickstart-vm-5.13.0-0-vmware (mandatory)
2. putty-64bit-0.83-installer (optional) putty: to make connection with Hadoop cluster

3. Filezilla_3.6.0.6_win32-setup (optional)

   FileZilla: Data transfer from local to Hadoop machine and Hadoop to local all over world. For that it uses a network

Once you have setup of cloudera-quickstart-vm-5.13.0-0-vmware 

1. Goto the folder of cloudera-quickstart-vm-5.13.0-0-vmware and then search file.

2. cloudera-quickstart-vm-5.13.0-0-vmware (3kb size) of type VMware virtual machine configuration just double click on it.

3. Your Cloudera virtual machine gets start with Centos 6.7 operating system.



4. Now open Terminal and just do some basic commands in terminal as follows.
5. type command: [cloudera@quickstart ~]$ jps 
//this command shows us java processes for that perticular user.

6. Now here will see only one or two processes with process id and process name. because it's not a super user.

7. Now just check with super user to do this type command: 
[cloudera@quickstart ~] $ sudo su

8. You will get the prompt as follows with processes.


9. Now you can observe here user gets change now it's a root user and root are having all privileges.

10. Here you will get all the services with process id and process name.

Hadoop Architecture Overview

Hadoop is composed of two main components:

  1. HDFS (Hadoop Distributed File System) – Storage layer

  2. MapReduce – Processing layer

HDFS Architecture (Storage Layer)

Master Node:

  • NameNode: Manages metadata (file names, block locations, permissions)

  • Secondary NameNode: Not a backup but a helper that periodically pulls metadata from the NameNode and compacts it

Slave Nodes:

  • DataNodes: Store actual data blocks

MapReduce Architecture (Processing Layer)

Master Node:

  • JobTracker: Manages job scheduling and resource management. Assigns tasks to TaskTrackers.

Slave Nodes:

  • TaskTracker: Executes individual map and reduce tasks as instructed by the JobTracker.

Note: In newer versions of Hadoop (Hadoop 2.x+), YARN replaces JobTracker and TaskTracker with ResourceManager and NodeManager, respectively. But Hadoop 1.x  JobTracker/TaskTracker, I’m sticking to here.

Reducer in MapReduce

  • A Reducer takes the output from the Mapper, aggregates/interprets the results, and writes the final output to HDFS.



Figure: Hadoop Internal Working


11. Resourse Manager + NodeManager(MapReduce responsible /Master)

NameNode + DataNode + SecondaryNameNode (HDFS responsible / Slave)

NodeManager reports to the ResourseManager. one RM manages 4 NodeManager(every machine is having its own nodemanger)

ResourseManager(ip address of that machine put as a RM in NM machine for reporting is a Master and NodeManager is slave.

NameNode Page
Hadoop works in cluster if there are many clusters then all above components works in cluster, so they required their own id to identify. so, every cluster is having its own cluster id (1-2-3-4) clusterid:11 (5-6-7-8) clusterid:12. NameNode gives the cluster id

12. Now let's do some basic commands in Centos 6.7 using terminal

13. How to create, remove, view, list file and folder using command.


14. By using vi command we can open already existing file or if file does not exist it will create it and open it in vi editor

15. To write something in it first of all we have to go in insert mode so press i

16. then you have to write some text in it like hello jspms bsiotr

17. Now to save this file and exit press Esc button first and the type :wq




18. using touch command also you can create file and using rm command you can remove it.

19. how do i move one folder into another folder using command in terminal



20. Now moving towards the wordcount assignment: 

We need three (3) java programs files inside wordcount folder in hdfs,
So first create a folder
$ mkdir wordcount & then store this file code in this folder.
1.WordCount.java
2.WordMapper.java
  3.SumReducer.java




21. Let's explain each file logic in detail along with code. First Let's discuss with WordCount.java file logic.




Explanation:

a. When we run the code at that time we are passing two argumnets on command line, if args.length is not equal to two then it will return -1. means no code execution we have to provide appropriate command.

b. Create new Job and setJarbyClass, setJobName

c. Set input and output path

d. Set Mapper and Reducer Class

e. Sets map output key class and output value class.

f. Final Output as key, value pairs.

From the above steps we come to know that WordCount. java acts as a driver class or configuration class.

22. WordMapper.java code as follows.


Explanation:

From the above codes we come to know that in line number 12 we are taking String s, after that we are separating word from that whole string by using split (" \\W+") function iteratively. while doing this simultaneously we are checking length of each word if it is greater than 0 then we are emitting the output of mapper like (word, 1).

23. SumReducer.java code as follows.



Explanation:

From the above codes we come to know that in line number 12 we are initializing the wordCount = 0. Then iteratively performing the summation of all the value. Finally output the key and its exact count as an output to the client.

How to execute the above code?

Step 1: Compile all the java classes present inside the folder. while doing this we included all Hadoop classes at the time of compilation. *.java means all java files.

and the compilation command is:
[root@quickstart WordCount]#
 javac -cp /usr/lib/hadoop/*:/usr/lib/hadoop-mapreduce/*:/usr/lib/hadoop-0.20-mapreduce/* *.java


If we carefully, observe the above compilation command you come to know 3 .class files gets created.

Step 2: Now we want to wrap all the .class files into one package that is called as jar file.

and the jar formation command is:
[root@quickstart WordCount]# jar -cvf filename.jar *.class




Step 3: Now we want to provide input file to the measure the wordcount. for this we have created one folder wordcount on hdfs. now the input file UN.txt we want to put inside hdfs so to do this we are using a command. hdfs dfs -put UN.txt /wordcount 

means you're uploading a local file named UN.txt into HDFS (Hadoop Distributed File System).

Explanation of commands:

hdfs dfs: This is the command-line interface to interact with HDFS.

-put: This tells Hadoop to copy a file from the local filesystem to HDFS.

UN.txt: This is the local file you want to upload.

/wordcount: This is the destination directory in HDFS where you're placing the file.



Step 4: To run a MapReduce job in Hadoop. to run this, we have to use following command: 

hadoop jar wc.jar WordCount /wordcount/ /wc_opMarch 

“Run the WordCount class from wc.jar, process the files in /wordcount/, and save the output in /wc_opMarch.”

Explanation:

hadoop jar: This tells Hadoop to run a JAR file that contains a MapReduce program.

wc.jar:
This is the name of the JAR file containing your MapReduce code (most likely a WordCount program).

WordCount:
This is the main class inside the JAR file which contains the main() method to be executed.

/wordcount/:
This is the input path in HDFS. It should contain the file(s) to be processed — in this case, likely the UN.txt you uploaded earlier.

/wc_opMarch:
This is the output directory in HDFS where the results of the MapReduce job (word counts) will be stored.




Step 5: Now we want to check output that is wordcount.





Note: You reach up to bottom means you are succeeded. if you really think the provided material is worth and you gain little bit knowledge from this blog. Please do write your feedback for the same in comment.
data structures and algorithms Web Developer