Notes, summaries, assignments, exams, and exercises for Computer science for Other courses

Core Java Concepts: Inheritance, Polymorphism & OOP

Computer science10.07 KB

Q1. Inheritance in Java (10 Marks)

Inheritance is an important feature of object-oriented programming that allows one class to acquire the properties and methods of another class. The class that gives its features is called the parent class or superclass, and the class that receives them is called the child class or subclass. In Java, inheritance is implemented using the extends keyword.

There are three main types of inheritance in Java:
(1) Single-level inheritance – one parent and one child class.
(2) Multilevel inheritance – one class inherits another, and another class further inherits it.
(3) Hierarchical inheritance – one parent class is inherited by multiple child classes.

Java does not support multiple inheritance using classes to...

Continue reading "Core Java Concepts: Inheritance, Polymorphism & OOP" »

Universal Data Science Python Template for Machine Learning

Computer science2.89 KB

Universal Data Science Python Template

This template provides a streamlined workflow for common data science tasks, including data preprocessing, modeling, and visualization.

Step 1: Import Libraries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression, LinearRegression
from sklearn.cluster import KMeans, DBSCAN
from sklearn.metrics import accuracy_score, r2_score, silhouette_score

Step 2: Load Dataset

df = pd.read_csv('your_dataset.csv') # Replace with your dataset name
print(df.head())

Step 3: Data Cleaning

df = df.dropna()

Step 4: Feature Selection

X = df.drop(

...
Continue reading "Universal Data Science Python Template for Machine Learning" »

Database Fundamentals: SQL Queries and Relational Concepts

Computer science99.31 KB

Core Database Concepts and Relational Algebra

Question 1: Cartesian Product Size

Question 1: S is a relation instance. If S has 6 tuples, how many tuples are there in the result of the following SQL query?

SELECT * FROM S S1, S S2;

Answer: 36 (Calculated as 6 * 6, representing the Cartesian product of S with itself.)

Question 2: Maximum Tuples and Primary Keys

Question 2: Let R(A, B, C, D) be a relation, where (A, B, C) is the Primary Key (PK) of R, and attribute D cannot be NULL. Assume A's domain has 5 different values, B's domain has 2, C has 4, and D has 3. What is the maximum number of tuples that can be in an instance of R?

Answer: 40 (Calculated as 5 * 2 * 4. The maximum number of tuples is determined by the product of the domain sizes of the...

Continue reading "Database Fundamentals: SQL Queries and Relational Concepts" »

Understanding the Internet, Web Browsers, and HTML

Computer science1.29 MB

1. What is the Internet?

The Internet is a global communication system connecting millions of computers across the world. It uses the TCP/IP protocol to exchange data, allowing users to access information, communicate, and perform various online activities.

Definition: The Internet is a worldwide network of interconnected computer networks that enables the sharing of information and resources.
History: The Internet originated from ARPANET, developed in 1969 in the USA.

2. Internet Applications

Applications refer to the various ways we utilize the Internet in our daily lives. Key examples include:

  • Communication: Facilitates easy, affordable, and fast interaction.
    • Examples: Sending emails, instant messaging (e.g., WhatsApp), and video calls (e.g., Zoom,
...
Continue reading "Understanding the Internet, Web Browsers, and HTML" »

Relational Database Design and Normalization Essentials

Computer science4.82 KB

Database Management Systems and SDLC

Chapter 1: Introduction to Databases

  • Data: Raw facts like numbers, names, and pictures.
  • TFPS (Traditional File Processing System): The biggest problem was when data changes in one file, it could cause inconsistencies.
  • Cons of TFPS: Data redundancy, limited sharing, long development times, and high maintenance.
  • DBMS (Database Management System): Software used to manage databases.
  • SDLC (Systems Development Life Cycle): Plan, analysis, design, implementation, and maintenance.
  • Prototype: Build a prototype, implement, and improve it over time.

Entity-Relationship (ER) Modeling Concepts

Chapter 2: Database Design and ER Diagrams

  • Entity: A noun, such as a person, place, or thing.
  • Attributes: Descriptions or properties of
...
Continue reading "Relational Database Design and Normalization Essentials" »

Essential Network Packet Filtering Syntax Reference

Computer science12.41 KB

Basic Protocol Filters

Use these filters to quickly isolate traffic based on common protocols:

  • arp (Address Resolution Protocol)
  • dns (Domain Name System)
  • http (Hypertext Transfer Protocol)
  • https (HTTP Secure)
  • icmp (Internet Control Message Protocol)
  • ip (Internet Protocol)
  • ipv6 (Internet Protocol Version 6)
  • ntp (Network Time Protocol)
  • smtp (Simple Mail Transfer Protocol)
  • ftp (File Transfer Protocol)
  • ssh (Secure Shell)
  • tls (Transport Layer Security)
  • udp (User Datagram Protocol)
  • tcp (Transmission Control Protocol)
  • dhcp (Dynamic Host Configuration Protocol)
  • bootp (Bootstrap Protocol)
  • radius (Remote Authentication Dial-In User Service)
  • snmp (Simple Network Management Protocol)
  • kerberos
  • smb (Server Message Block)
  • nbns (NetBIOS Name Service)
  • nbss (NetBIOS Session Service)
...
Continue reading "Essential Network Packet Filtering Syntax Reference" »

Implementing REINFORCE Policy Gradient for CartPole-v1

Computer science3.14 KB

############################### lAB 9 ####################3
import gymnasium as gym
import numpy as np
import tensorflow as tf

# Create the environment
env = gym.Make("CartPole-v1")

# Define a simple neural network model for the policy
model = tf.Keras.Sequential([
    tf.Keras.Layers.Dense(16, activation='relu', input_shape=(env.Observation_space.Shape[0],)),
    tf.Keras.Layers.Dense(env.Action_space.N, activation='softmax')
])

# Define the optimizer
optimizer = tf.Keras.Optimizers.Adam(learning_rate=0.01)

# Function to choose an action based on the current policy
def choose_action(state):
    """
    Chooses an action based on the probabilities output by the policy model.
    Args:
        state (np.Array): The current observation/state from...

Continue reading "Implementing REINFORCE Policy Gradient for CartPole-v1" »

Practical Machine Learning Labs in TensorFlow and PyTorch

Computer science14.76 KB

Lab 1: Basic TensorFlow Computation Graph

This example demonstrates how to define and execute a simple computation graph in TensorFlow using the @tf.function decorator, which converts a Python function into a high-performance TensorFlow graph.

import tensorflow as tf

# Define a simple computation graph
@tf.function  # Converts Python function into a TensorFlow graph
def my_graph(x, y):
  return x * y + 5  # Simple equation: (x * y) + 5

# Create TensorFlow constants (nodes)
x = tf.constant(3.0)
y = tf.constant(4.0)

# Run the computation graph
result = my_graph(x, y)

# Print the result
# Convert tensor to a NumPy array to see the value
print(f"Result of (x * y) + 5: {result.numpy()}")

Lab 2: Simple Linear Regression with Keras

Here, we build,...

Continue reading "Practical Machine Learning Labs in TensorFlow and PyTorch" »

Software Engineering Fundamentals: Principles and Requirements Analysis

Computer science2.91 KB

Definition of Software Engineering

Software engineering is the establishment and use of sound engineering principles in order to obtain software economically that is reliable and works efficiently on real machines.

Need for Software Requirements Specification (SRS)

The Software Requirements Specification (SRS) is necessary because it provides:

  • A detailed overview of the software product, including its parameters and goals.
  • A description of the project's target audience, user interface, and hardware and software requirements.
  • A common understanding of how the client, development team, and audience perceive the product and its functionality.

Four Core Principles of Software Engineering

1. The Reason It All Exists (Value to Users)

  • A software system exists
...
Continue reading "Software Engineering Fundamentals: Principles and Requirements Analysis" »

Essential Definitions and Theorems in Graph Theory

Computer science103.48 KB

M1: Fundamental Graph Definitions

Walks, Paths, and Circuits

Walk

A Walk is a finite alternating sequence of vertices and edges, beginning and ending with vertices, such that each edge is incident with the vertices preceding and following it. No edge appears more than once in a walk, though a vertex may appear multiple times.

  • Closed Walk: A walk that begins and ends at the same vertex.
  • Open Walk: A walk that begins and ends at different vertices.

Path

A Path is an open walk in which no vertex appears more than once. The number of edges in a path is called the length of the path. A self-loop can be included in a walk but not in a path. The terminal vertices of a path are of degree 1, and the remaining intermediate vertices are of degree 2.

Circuit

A...

Continue reading "Essential Definitions and Theorems in Graph Theory" »