Posts

Showing posts from November, 2025

BT 4

  // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract StudentRegistry {     // Structure to store student data     struct Student {         string name;         uint256 age;     }     // Array to store multiple students     Student[] private students;       // Event to log Ether received     event ReceivedEther(address indexed sender, uint256 value);       // Receive function to accept Ether     receive() external payable {         emit ReceivedEther(msg.sender, msg.value);     }     // Fallback function     fallback() external payable {         emit ReceivedEther(msg.sender, msg.value);     }     // Function to add student data     function addStudent(string memory name, uint256 age) pub...

BT 3

  // SPDX-License-Identifier: MIT pragma solidity ^0.8.0;   contract Bank {     // Mapping of each user's address to their account balance     mapping(address => uint) public balances;       // Deposit Ether into your account     function deposit() public payable {         balances[msg.sender] += msg.value;     }       // Withdraw specified Ether amount from your account     function withdraw(uint _amount) public {         require(balances[msg.sender] >= _amount, "Insufficient balance");         balances[msg.sender] -= _amount;           // Transfer the Ether back to the sender         (bool sent, ) = msg.sender.call{value: _amount}("");         require(sent, "Transaction failed");     }       // Get t...

ML 4

  ipynb File Dataset

ML 3

  ipynb File

ML 2

  ipnyb File Dataset

ML 1

ipynb File   Datest

DAA 4

CODE # 8-Queens Problem using Backtracking  N = 8 def printBoard(board):     for row in board:         print(row) def isSafe(board, row, col):     for i in range(row):         if board[i][col] == 1 or \            (col - (row - i) >= 0 and board[i][col - (row - i)] == 1) or \            (col + (row - i) < N and board[i][col + (row - i)] == 1):             return False     return True def solve(board, row):     if row == N:         print("\nFinal 8-Queens Matrix:")         printBoard(board)         return True     for col in range(N):         if isSafe(board, row, col):             board[row][col] = 1             if solve(board, row + 1):       ...

DAA 3

CODE # 0/1 Knapsack using Dynamic Programming. n = int(input("Enter number of items: ")) v = [] w = [] for i in range(n):     v.append(int(input(f"Value {i+1}: ")))     w.append(int(input(f"Weight {i+1}: "))) cap = int(input("Enter capacity: ")) dp = [[0]*(cap+1) for _ in range(n+1)] for i in range(1, n+1):     for j in range(1, cap+1):         if w[i-1] <= j:             dp[i][j] = max(v[i-1] + dp[i-1][j-w[i-1]], dp[i-1][j])         else:             dp[i][j] = dp[i-1][j] print("Maximum value =", dp[n][cap]) 

DAA 2

CODE #Write a program to solve a fractional Knapsack problem using a greedy method. n = int(input("Enter number of items: ")) values = [] weights = [] for i in range(n):     v = float(input(f"Value {i+1}: "))     w = float(input(f"Weight {i+1}: "))     values.append(v)     weights.append(w) cap = float(input("Enter capacity: ")) items = [] for i in range(n):     items.append((values[i], weights[i], values[i]/weights[i])) items.sort(key=lambda x: x[2], reverse=True) val = 0 for v, w, r in items:     if cap >= w:         val += v         cap -= w     else:         val += v * (cap / w)         break print("Maximum value =", val)

DAA 1

CODE   # Iterative Fibonacci with step counter def fib_iterative(n):     steps = 0     if n == 0:         steps += 1         return 0, steps     elif n == 1:         steps += 1         return 1, steps          a, b = 0, 1     for i in range(2, n + 1):         steps += 1         a, b = b, a + b     return b, steps n = int(input("Enter n: ")) result, steps = fib_iterative(n) print(f"Fibonacci({n}) = {result}") print(f"Step count (iterative) = {steps}") # Recursive Fibonacci with step counter steps = 0  # global step counter def fib_recursive(n):     global steps     steps += 1  # count each call as a step     if n == 0:         return 0     elif n == 1:         return 1     else:     ...