Notes, summaries, assignments, exams, and exercises for Computer science for Primary education

Structural and Behavioral Design Patterns in Software Development

Computer science2.12 KB

Structural Design Patterns

Decorator - Adds additional functionality to a class

Adapter - 'adapts' one interface for a class into one that the client expects

Façade - creates a simplified interface from an existing one

Flyweight - A high quantity of objects share common properties to save space.

Bridge - decouples an abstraction from its implementation so that the two can vary independently.

Behavioral Design Patterns

Chain of Responsibility - Linked list of handlers

Command - Enables all the info for a request to be contained within a single object.

Interpreter - Developing domain specific languages

Iterator - Sequentially access elements of an aggregate object.

Mediator - Removes the need for classes to communicate with each other directly.

Observer...

Continue reading "Structural and Behavioral Design Patterns in Software Development" »

Java Programs: Character Frequency, Inheritance, Palindrome, Matrix Multiplication & Polymorphism

Computer science5.03 KB

Character Frequency

FREQUENCY

import java.util.Scanner;
class Test2 {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
System.out.print("ENTER THE STRING:");
String abc = s.nextLine();
System.out.println("Enter The Character for checking:");
char ch = s.nextLine().charAt(0);
int count = 0;
for(int i = 0; i < abc.length(); i++) {
if(ch == abc.charAt(i)) {
count++;
}
}
System.out.println("The given character repeats " + count + " times");
} }

OUTPUT

ENTER THE STRING: MALAYALAM
Enter The Character for checking:
M
The given character repeats 2 times

Inheritance Example

import java.util.Scanner;
class Employee {
String name = "Name";
String address = "Address";
int age = 23, phn_no = 123456789, salary = 500000;
void printsalary() {
System.out.println(

...
Continue reading "Java Programs: Character Frequency, Inheritance, Palindrome, Matrix Multiplication & Polymorphism" »

Network Types, MAC Addresses, and OSI Model Explained

Computer science2.86 KB

Network Classification by Device Roles

Networks can be classified based on the roles of the devices within them:

  • Client-Server: This is the most common type. A powerful server provides services to multiple clients and is always available. Example: A web server.
  • Peer-to-Peer: In this model, all computers have equal roles and share resources directly. Example: BitTorrent.

Router Functions in Home Networks

Routers provided by Internet Service Providers (ISPs) often integrate the functions of multiple devices, including:

  • Hub
  • Modem
  • Access Point

MAC Address Translation

The MAC address 08-2E-5F-14-93-A0 in decimal is 8-46-95-20-147-160.

Switches and the OSI Model

Switches operate at Level 2 (Data Link Layer) of the OSI model. Other devices that work at this level...

Continue reading "Network Types, MAC Addresses, and OSI Model Explained" »

Mastering C Pointers, Structures, and Unions

Computer science8.51 KB

Pointers in C

A pointer is a variable that stores the memory address of another variable. They are essential in C for dynamic memory allocation, array manipulation, and implementing complex data structures.

1. Declaring and Initializing Pointers

A pointer variable must be declared to hold the address of a specific data type.

A. Declaration

The asterisk (*) is the dereference operator or value-at-address operator. When declaring a pointer, it signifies that the variable is a pointer to a specific type.

data_type *pointer_name;
  • Example: int *ip; // Declares ip as a pointer that can hold the address of an integer variable.

B. Initialization

A pointer is initialized by assigning it the address of a variable using the address-of operator (&).

int num
...
Continue reading "Mastering C Pointers, Structures, and Unions" »

FCFS and SJF CPU Scheduling C Program Example

Computer science3.03 KB

FCFS and SJF CPU Scheduling C Program Example

Corrected and formatted C source code for FCFS and SJF scheduling.

FCFS Scheduling C Implementation

#include <stdio.h>

int FCFS() {
    int bt[15], n, i, wt[15];
    float twt = 0, tat = 0, att, awt;
    printf("\nTHE FCFS SCHEDULING\n");
    printf("Enter the number of processes: ");
    scanf("%d", &n);
    printf("Enter burst time of all the processes:\n");
    for (i = 0; i < n; i++) {
        printf("P%d: ", i + 1);
        scanf("%d", &bt[i]);
    }

    wt[0] = 0;
    // for calculating waiting time of each process
    for (i = 1; i < n; i++)
        wt[i] = bt[i - 1] + wt[i - 1];

    printf("ProcessID\tBurstTime\tWaitingTime\tTurn Around Time\n");
    for (i = 0; i <
...
Continue reading "FCFS and SJF CPU Scheduling C Program Example" »

Java AWT GUI Development and OOP Inheritance

Computer science7.41 KB

Building Java GUI Applications with AWT

Creating GUI applications using Abstract Window Toolkit (AWT) involves setting up a top-level container, adding components, arranging them with a Layout Manager, and making the container visible.

Steps to Create an AWT Application

1. Choose a Top-Level Container

The application needs a primary window to hold all components. The most common choice is the Frame class, which provides a title bar, borders, and window controls.

import java.awt.*;

// Class extends Frame to be the application window itself
public class AWTExample extends Frame {
    // Constructor and other methods
}

2. Initialize the Container (The Frame)

Inside the constructor, you set up the basic properties of the window:

  • Title: Set the window
...
Continue reading "Java AWT GUI Development and OOP Inheritance" »

Vector Databases & RAG for Semantic Search and Retrieval

Computer science206.28 KB

1. Vector Databases — High-Dimensional Embeddings

Store and search high-dimensional vector embeddings. Used in semantic search, similarity search, and RAG pipelines.

Indexing Techniques

  • Flat Index (Brute Force) → accurate but slow.
  • Approximate Nearest Neighbor (ANN) → fast and scalable.
    • Algorithms: HNSW, FAISS, Annoy.
    • f3Q1622KC84AAAAASUVORK5CYII= 8pk5+AsHqPHAAAAAElFTkSuQmCC

3. Retrieval-Augmented Generation (RAG)

Overview

Enhances LLM output by integrating retrieved external knowledge.

  • Reduces hallucination and outdated responses.
  • Improves factual grounding.

RAG Workflow

  1. Indexing: Convert raw data (PDF, HTML, Word) → embeddings.
  2. Retrieval: Retrieve relevant document chunks using similarity search.
  3. Generation: LLM synthesizes results with the query to produce the final answer.

Retrieval Types

TypeDescriptionExample
Sparse
...
Continue reading "Vector Databases & RAG for Semantic Search and Retrieval" »

Hehhrhrhr

Computer science9.2 KB

Sequential circuits are fundamental components of digital systems, defined by the fact that their output depends not only on the current inputs but also on the past history of inputs (i.E., their current state).
The most basic element of a sequential circuit is the Flip-Flop, which is a 1-bit memory cell.
Here is a detailed explanation of the basic Flip-Flops and their operation:
1. Latches vs. Flip-Flops
Both latches and flip-flops are 1-bit storage elements, but they differ in how they are controlled:
| Feature | Latch | Flip-Flop |
|---|---|---|
| Triggering | Level-triggered (Transparent) | Edge-triggered (Synchronous) |
| Control | Changes state as long as the Enable or Clock is HIGH (or LOW). | Changes state only at the rising edge or falling...

Continue reading "Hehhrhrhr" »

Protecting Against Phishing, Trojan Horses, Worms, and Viruses

Computer science2.75 KB

Phishing:

Hackers attempt to impersonate genuine organisations to fool the user into providing sensitive personal data. Emails are very official-looking, and they usually contain a link to a website which is an exact copy of the organisation's actual site, but it is operated by the criminals. When the user logs in with their details, the data is sent to the criminal. 

Guarding against phishing:

No reputable organisation would request personal details in an email or unsolicited phone call, because it does not need your sensitive data to access your account information. Never follow links to a bank/organisation- manually type it.

Trojan Horses:

Malware program that comes in disguise. Rely on tricking the user into downloading and running them. Involves...

Continue reading "Protecting Against Phishing, Trojan Horses, Worms, and Viruses" »

Enterprise IT Optimization: Virtualization, Big Data, and Information Management

Computer science7.37 KB

Enterprise Virtualization: Optimizing IT Infrastructure

Virtualization in enterprise solutions allows organizations to consolidate workloads, reduce hardware costs, and improve resource utilization by creating multiple virtual machines on a single physical server. This technology enables efficient management, enhanced flexibility, and better scalability, making it a cornerstone of modern IT infrastructure.

Key Benefits of Enterprise Virtualization

  • Reduced Costs

    Virtualization minimizes the number of physical servers required, leading to lower hardware, energy, and maintenance costs.

  • Improved Resource Utilization

    By consolidating workloads onto fewer servers, virtualization maximizes hardware capacity and optimizes resource allocation.

  • Enhanced Flexibility

...
Continue reading "Enterprise IT Optimization: Virtualization, Big Data, and Information Management" »