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

Sort by
Subject
Level

Python Fundamentals: Code Examples and Exercises

Posted by Anonymous and classified in Computers

Written on in English with a size of 10.65 KB

Python Operations and Operators

This section covers fundamental operations and operators in Python, which are symbols used to perform operations on values and variables.

# Examples of different operators
a = 10 // 3  # Floor Division
a = 10 % 3   # Modulo Operator
a = 3        # Assignment
b = 1        # Declaring variables
a == b       # Comparison

Types of Operators

Operators are used for operations between values and variables. The main types are:

  • Assignment Operators: Used to assign values to variables.
  • Logical Operators: Used to combine conditional statements.
  • Comparison Operators: Used to compare two values.
  • Arithmetic Operators: Used with numeric values to perform common mathematical operations.
  • Bitwise Operators: Used to compare binary numbers.
... Continue reading "Python Fundamentals: Code Examples and Exercises" »

Core Graph Algorithms Pseudocode Reference

Classified in Computers

Written on in English with a size of 3.58 KB

Core Graph Algorithms Pseudocode

Kruskal's Algorithm for MST

def Kruskal(V, E):

  1. Sort E by increasing weight.
  2. For each vertex v in V: create a tree for each v.

MST = {}

For i from 1 to |E|:

  1. (u, v) ← lightest edge in E.
  2. If u and v are not in the same tree:
  • MST.add((u,v))
  • Merge u and v trees.

Return MST.

Huffman Tree Construction

BuildHuffman(characters[1..n], frequencies[1..n]):

  • Create nodes for each character.
  • For i ← 1 to n: create a min-heap Q with each node frequency as a key.

While(length(Q) > 1):

  1. x = pop minimum value from Q.
  2. y = pop minimum value from Q.
  3. Create new node z.
  4. z.key = x.key + y.key
  5. z.leftChild = x
  6. z.rightChild = y
  7. Insert z into Q.

Return the root value from Q.

Topological Sort

topological_sort(G):

Stack = []

While (unvisited Nodes):

helper_toposort(

... Continue reading "Core Graph Algorithms Pseudocode Reference" »

Sistema de Gestión de Usuarios con Java Web

Classified in Computers

Written on in English with a size of 21.85 KB

Archivos HTML del Frontend

INDEX.HTML: Menú Principal del Sistema

<!DOCTYPE html>
<html>
<head>
    <title>Menú Principal del Sistema</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        h2 { color: #789; font-size: 45px; }
        select { color: brown; font-size: 30px; }
        h3 { color: #8b4513; font-size: 30px; }
    </style>
</head>
<body>
    <h2>Menú de Opciones del Sistema</h2>
    <h3>Seleccione una opción:</h3>
    <ol>
        <li><a href="Registro.html">Registrar Usuario</a></li>
        <li><a href="Acceso.html">Acceso
... Continue reading "Sistema de Gestión de Usuarios con Java Web" »

PHP Programming Essentials and Core Features

Classified in Computers

Written on in English with a size of 2.95 KB

What is PHP?

PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for web development. It runs on the server-side, meaning the code is executed on the web server before the output is sent to the user's browser. PHP is embedded within HTML and supports various databases, making it a powerful tool for creating dynamic and interactive web applications.

Key Features of PHP

PHP has several features that make it a popular choice for web development:

  • Open-Source – PHP is free to use, with a large community of developers providing support and updates.
  • Cross-Platform Compatibility – PHP works on multiple operating systems like Windows, Linux, and macOS.
  • Easy to Learn and Use – Its syntax is simple and similar
... Continue reading "PHP Programming Essentials and Core Features" »

C++ Code Examples: Arithmetic Mean, Sum, Product, Square

Classified in Computers

Written on in English with a size of 1.55 KB

Arithmetic Mean

The following C++ code calculates the arithmetic mean of numbers from 1 to n:

int main() {
    int n;
    double suma = 0;
    cout << "Vnesi broj: ";
    cin >> n;
    if (n <= 0) {
        cout << "Brojot na elementi mora da bide pogolem od 0!" << endl;
        return 1;  
    }
    for (int i = 1; i <= n; i++) {
        suma += i;  
    }
    double sredina = suma / n;
    cout << "Aritmetichkata sredina na broevite od 1 do " << n << " e: " << sredina << endl;
    return 0;
}

Sum

The following C++ code calculates the sum of numbers from 1 to n:

int main() {
    int n, sum = 0;
    cout << "Vnesi broj n: ";
    cin >> n;
    for (int i = 1; i <= n; i++)
... Continue reading "C++ Code Examples: Arithmetic Mean, Sum, Product, Square" »

Network Security & Configuration: Routing, VLANs, DHCP, and Attack Mitigation

Classified in Computers

Written on in English with a size of 2.38 KB

Router-on-a-Stick Inter-VLAN Routing

The router's port connecting to the LAN has multiple sub-interfaces, each the default gateway for a specific VLAN. For example, VLAN 10 traffic destined for VLAN 20 is first forwarded to VLAN 10's default gateway (the router sub-interface). The router then routes this traffic to VLAN 20's gateway (its corresponding sub-interface) and finally to the user in VLAN 20.

Why STP Is Needed for Redundant Ethernet LANs

  • Preventing Broadcast Storms: In redundant networks, frames can loop endlessly, exponentially increasing traffic. STP prevents this by disabling redundant paths, ensuring one active path between devices.
  • Ensuring MAC Address Table Consistency: Loops cause switches to receive the same frame on different
... Continue reading "Network Security & Configuration: Routing, VLANs, DHCP, and Attack Mitigation" »

Python Programming Essentials: Core Concepts & Techniques

Classified in Computers

Written on in English with a size of 1.35 MB

Understanding Variables & Data Types

Variables: Storing Data

Variables are containers used to store data. They are assigned values using the = operator (e.g., x = 5).

Essential Data Types

Python supports several fundamental data types:

  • int: Represents integer numbers (e.g., 10, -5).
  • float: Represents floating-point numbers (e.g., 3.14, -0.01).
  • str: Represents strings of characters (e.g., "hello", "123").
  • bool: Represents Boolean values, either True or False.

GOQmZWnx2PAAAAABJRU5ErkJggg==

Type Casting: Converting Data Types

Type casting allows you to convert data from one type to another using functions like int(), float(), and str().

Example: x = int("5") converts the string "5" to an integer. y = float("3.14") converts the string "3.14" to a float.

Input and Output Operations

Getting

... Continue reading "Python Programming Essentials: Core Concepts & Techniques" »

Banker's Algorithm Implementation in C

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.52 KB

This program demonstrates the Banker's Algorithm, a classic deadlock avoidance strategy used in operating systems to manage resource allocation safely.

C Source Code

#include <stdio.h>

int n, m;
int alloc[10][10], max[10][10], need[10][10];
int avail[10], work[10], finish[10];

// Safety Algorithm
int checkSafety() {
    int seq[10], count = 0;

    for (int i = 0; i < n; i++) finish[i] = 0;
    for (int i = 0; i < m; i++) work[i] = avail[i];

    while (count < n) {
        int found = 0;
        for (int i = 0; i < n; i++) {
            if (!finish[i]) {
                int j;
                for (j = 0; j < m; j++) {
                    if (need[i][j] > work[j]) break;
                }
                if (j == m)
... Continue reading "Banker's Algorithm Implementation in C" »

Classic Algorithm Solutions: Step-by-Step Examples

Posted by Anonymous and classified in Computers

Written on in English with a size of 5.78 KB

1) DIJKSTRA (SSSP) — STEP TABLE (PAST-PAPER INSTANCE A)

Given edges: a→b(2), a→c(7), a→e(10), b→d(2), c→d(1), c→g(2), d→f(2), e→g(1), f→g(2). Source = a.
Rule: Pick unsettled vertex with minimum dist; relax outgoing edges.

Vertices:   a   b   c   d   e   f   g

Init:
Dist      = 0   2   7   ∞  10   ∞   ∞
S = ∅

Step 1: Pick a (min=0), S={a}
Relax from a: already set b=2, c=7, e=10
Dist      = 0   2   7   ∞  10   ∞   ∞

Step 2: Pick b (min=2), S={a,b}
Relax b→d: dist(d) = dist(b)+2 = 2+2 = 4
Dist      = 0   2   7   4  10   ∞   ∞

Step 3: Pick d (min=4), S={a,b,d}
Relax d→f: dist(f) = 4+2 = 6
Dist      = 0   2   7   4  10   6   ∞

Step 4: Pick f (min=6), S={a,b,d,f}
Relax f→g: dist(g) = 6+2 = 8
Dist
... Continue reading "Classic Algorithm Solutions: Step-by-Step Examples" »

8051 Microcontroller Architecture and Flip-Flop Types

Posted by Anonymous and classified in Computers

Written on in English with a size of 288.82 KB

SR Flip-Flop (Set-Reset Flip-Flop)

The SR flip-flop is one of the simplest sequential circuits and serves as a fundamental building block for more complex flip-flops. It is a 1-bit memory device with two inputs: Set (S) and Reset (R). It has two outputs, Q and its complement (Q with overline).

Logic Diagram and Working

An SR flip-flop can be constructed using two cross-coupled NAND gates (or NOR gates). Below is the working principle for the NAND-gate implementation:

  1. Set Condition (S = 0, R = 1):

    • When S = 0, the output of the top NAND gate (Q) is forced to 1 (since NAND is the inverse of AND).

    • This Q = 1 is fed into the bottom NAND gate with R = 1; the bottom gate's inputs become 1 and 1, so its output () becomes 0.

    • The circuit is now in the

... Continue reading "8051 Microcontroller Architecture and Flip-Flop Types" »