Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

Essential Data Structure Operations and Java Implementations

Classified in Computers

Written on in English with a size of 3.95 KB

Inserting the First Element into a Tree Structure

Method to add the first element (root) to a Tree Structure:

public void insertFirstNode(Object item)
{
    // If the tree is empty, the new node becomes the root of the tree
    if (theRoot == null)
    {
        Node theNewNode = new Node(item);
        theRoot = theNewNode;
    }
}

Deleting an Element from a Linked List

Method to remove an element at a specific index in a Linked List:

public void remove(int index) {
    // Special case: removing at the head of the list
    if (index == 1) {
        head = head.getNext();
    } else {
        // Find the previous and current node
        setCurrent(index);
        prev.setNext(curr.getNext());
    }
    size = size - 1;
}

Steps for Inserting an Element

... Continue reading "Essential Data Structure Operations and Java Implementations" »

Java Backtracking Algorithms: Sudoku, Knapsack, and Tasks

Classified in Computers

Written on in English with a size of 2.25 KB

Sudoku Solver Implementation

private boolean isValid(int r, int c, int n) {
  boolean valid = true;
  int sr, sc, fr, fc;
  for (int i = 0; i < 9 && valid; i++) {
    if (i != r) if (grid[i][c] == n) valid = false;
    if (i != c) if (grid[r][i] == n) valid = false;
  }
  if (valid) {
    sr = (r / 3) * 3; fr = sr + 3; sc = (c / 3) * 3; fc = sc + 3;
    for (int i = sr; i < fr && valid; i++) {
      for (int j = sc; j < fc && valid; j++) {
        if (grid[i][j] == n) valid = false;
      }
    }
  }
  return valid;
}

private boolean solveRec(int row, int col) {
  boolean solved = false;
  if (row == 9) solved = true;
  else {
    if (grid[row][col] == 0) {
      for (int i = 1; i < 10; i++) {
        if
... Continue reading "Java Backtracking Algorithms: Sudoku, Knapsack, and Tasks" »

Essential CSS and HTML Techniques for Web Development

Posted by Anonymous and classified in Computers

Written on in English with a size of 2.77 KB

Understanding CSS text-overflow

The text-overflow property in CSS specifies how overflowed content that is not displayed should be signaled to the user. It works only when text exceeds the container size.

Required Conditions

To use text-overflow, the following properties must be applied:

  • overflow: hidden;
  • white-space: nowrap;
  • Fixed width

Values of text-overflow

  • clip: Default behavior; cuts off text without showing any symbol.
  • ellipsis: Shows “...” at the end of truncated text.
<style>
.clipText { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: clip; border: 1px solid #000; }
.ellipsisText { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid red; }
</style>
<div class=
... Continue reading "Essential CSS and HTML Techniques for Web Development" »

Cybersecurity Threat Landscape: Actors, Vectors, and Defenses

Posted by Anonymous and classified in Computers

Written on in English with a size of 9.76 KB

🔎 Threat Actors & Their Attack Paths

Who is attacking?

Threat Actors are the people or groups launching attacks. Mnemonic: “NO HIS” (Nation-State, Organized Crime, Hacktivists, Insiders, Script Kiddies).

Actor TypeMotivationTactics
Nation-State (APT Groups)Espionage, warfareAdvanced, persistent attacks
Organized CrimeFinancial gainRansomware, phishing
HacktivistsSocial justice, ideologyWebsite defacement, data leaks
InsidersRevenge, profitData theft, sabotage
Script KiddiesFun, fameLow-skill attacks using existing tools

How do threats reach systems?

Threat Vectors are the attack paths used by threat actors. Mnemonic: “MFWDVN” (Messages, Files, Websites, Devices, Vendors, Networks).

Attack PathExampleHow It Works
Message-BasedPhishing, smishingTrick
... Continue reading "Cybersecurity Threat Landscape: Actors, Vectors, and Defenses" »

Essential C Programming Examples and Algorithms

Posted by Anonymous and classified in Computers

Written on in English with a size of 72.94 KB

wfSCE5je3rPDgAAAABJRU5ErkJggg==

Leap Year

#include <stdio.h>
int main() {
    int y;
    scanf("%d", &y);
    if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
        printf("Leap Year");
    else
        printf("Not Leap Year");
    return 0;
}

Simple Calculator Using Switch

#include <stdio.h>
int main() {
    char op;
    float a, b;
    scanf(" %c %f %f", &op, &a, &b);
    switch (op) {
        case '+': printf("%.2f", a + b); break;
        case '-': printf("%.2f", a - b); break;
        case '*': printf("%.2f", a * b); break;
        case '/':
            if (b != 0)
                printf("%.2f", a / b);
            else
                printf("Error");
            break;
        default: printf("Invalid Operator");
    }
    return
... Continue reading "Essential C Programming Examples and Algorithms" »

Ec lab

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.19 KB

Postfix evaluation 

#include<stdio.H>
int stack[20];
int top = -1;

void push(int x)
{
    stack[++top] = x;
}

int pop()
{
    return stack[top--];
}

int main()
{
    char exp[20];
    char *e;
    int n1,n2,n3,num;
    printf("Enter the expression :: ");
    scanf("%s",exp);
    e = exp;
    while(*e != '\0')
    {
        if(isdigit(*e))
        {
            num = *e - 48;
            push(num);
        }
        else
        {
            n1 = pop();
            n2 = pop();
            switch(*e)
            {
            case '+':
            {
                n3 = n1 + n2;
                break;
            }
            case '-':
            {
 ... Continue reading "Ec lab" »

C++ Concepts: Exception Handling to Friend Functions

Classified in Computers

Written on in English with a size of 3.16 KB

Exception Handling

#include <iostream>
#include <stdexcept>
using namespace std;
int main() {
    try {
        int numerator = 10;
        int denominator = 0;
        int res;
        if (denominator == 0) {
            throw runtime_error("Division by zero not allowed!");
        }
        res = numerator / denominator;
        cout << "Result after division: " << res << endl;
    }
    catch (const exception& e) {
        cout << "Exception " << e.what() << endl;
    }
    return 0;
}

Operator Overloading

#include <iostream>
using namespace std;
class Test {
private:
    int num;
public:
    Test(): num(8){}
    void operator ++() {
        num = num + 2;
    }
    void Print() {
... Continue reading "C++ Concepts: Exception Handling to Friend Functions" »

FCFS and SJF CPU Scheduling C Program Example

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.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" »

CUDA Matrix Multiplication: Shared Memory

Classified in Computers

Written on in English with a size of 3.23 KB

CUDA Matrix Multiplication Using Shared Memory

This code demonstrates matrix multiplication in CUDA, leveraging shared memory for optimization. It includes two examples: a kernel using shared memory and a host-side implementation using the Thrust library.

CUDA Kernel with Shared Memory

The following CUDA kernel performs matrix multiplication using shared memory to optimize data access:


__global__ void matMulShared(int *A, int *B, int *C, int rowsA, int colsA, int colsB) {
    __shared__ int tile_A[TILE_SIZE][TILE_SIZE], tile_B[TILE_SIZE][TILE_SIZE];
    int row = blockIdx.y * TILE_SIZE + threadIdx.y, col = blockIdx.x * TILE_SIZE + threadIdx.x, temp = 0;
    for (int i = 0; i < (colsA + TILE_SIZE - 1) / TILE_SIZE; ++i) {
        if (row <
... Continue reading "CUDA Matrix Multiplication: Shared Memory" »

Essential PHP Programming Examples for Beginners

Posted by Anonymous and classified in Computers

Written on in English with a size of 1.26 KB

Addition of Two Numbers

<?php
if(isset($_POST['n1']) && isset($_POST['n2'])){
    $n1 = $_POST['n1'];
    $n2 = $_POST['n2'];
    $res = $n1 + $n2;
    echo "<h3>User Input Numbers:</h3>";
    echo "First Number = $n1 <br>";
    echo "Second Number = $n2 <br>";
    echo "Sum = $res";
}
?>

Enter Two Numbers:





PHP Conditional, Loops and Arrays Example

<?php
echo "<h3>Loop Example (1 to 5):</h3>";
for($i=1;$i<=5;$i++){
    echo "Number: $i <br>";
}
echo "<h3>Array Example:</h3>";
$fruits = array("Apple","Banana","Mango","Orange");
foreach($fruits as $f){
    echo "$f<br>";
}
?>

Student Registration Form

Name:

Email:

Gender:
Male
Female

Subjects:
Math
Science
English

Course:

... Continue reading "Essential PHP Programming Examples for Beginners" »