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

Sort by
Subject
Level

C Programming: Tokens, Operators, and Logic

Classified in Computers

Written on in English with a size of 2.55 KB

Tokens

In programming, a token is the smallest meaningful element in code. They are the building blocks of a language's syntax. Common token types include:

  • Keywords: Reserved words like if, else, while, and int (for declaring integers).
  • Identifiers: Names given to elements like variables (e.g., sum), functions, and arrays.
  • Constants: Unchanging values during program execution (e.g., 3.14 for pi).
  • Operators: Symbols for mathematical or logical operations (e.g., + for addition).
  • Separators: Punctuation like commas (,), semicolons (;), and braces ({}).

Example: int sum = 10 + 5;

In this line, int is a keyword, sum is an identifier, = is an operator, 10 and 5 are constants, and ; is a separator.

Arithmetic Operators

C has nine arithmetic operators for basic... Continue reading "C Programming: Tokens, Operators, and Logic" »

Dijkstra's Algorithm in C: Code & Explanation

Classified in Computers

Written on in English with a size of 3.5 KB

Dijkstra's Algorithm in C

This code implements Dijkstra's algorithm to find the shortest path from a source vertex to all other vertices in a graph represented as an adjacency matrix. The program reads graph data from an input.txt file and writes the results to an output.txt file.

Code Implementation


#include <stdio.h>
#include <limits.h>
#include <stdbool.h>

#define MAX_VERTICES 100

// Function to find the vertex with minimum distance
int minDistance(int dist[], bool visited[], int vertices) {
    int min = INT_MAX, min_index;

    for (int v = 0; v < vertices; v++)
        if (!visited[v] && dist[v] <= min) {
            min = dist[v];
            min_index = v;
        }

    return min_index;
}

// Dijkstra'
... Continue reading "Dijkstra's Algorithm in C: Code & Explanation" »

Data Structures: Queues, Trees, Graphs, and Searching Algorithms

Posted by Anonymous and classified in Computers

Written on in English with a size of 497.48 KB

Understanding Data Structures and Algorithms

8. Queues: FIFO Operations

A queue is a linear data structure that follows the First-In, First-Out (FIFO) principle. The element inserted first will be removed first, similar to people waiting in a line. It has two primary operations:

  • enqueue(): Adds an element to the rear of the queue.
  • dequeue(): Removes an element from the front of the queue.

Enqueue Operation Algorithm (Array-based):

  1. Check if the queue is full (rear == size - 1).
  2. If not full, increment rear.
  3. Insert the new element at queue[rear].

Example:

if (rear == size - 1)
    printf("Queue Overflow");
else {
    rear++;
    queue[rear] = value;
}

Dequeue Operation Algorithm:

  1. Check if the queue is empty (front > rear).
  2. If not empty, retrieve the element
... Continue reading "Data Structures: Queues, Trees, Graphs, and Searching Algorithms" »

Fundamental Computer Science Concepts & Algorithms

Classified in Computers

Written on in English with a size of 1.64 MB

Arithmetic Progressions (AP)

Sum of terms = n[(1st term + last term)]/2

Geometric Progressions (GP)

Sum of terms = [1st term(1 - quotientn)/(1 - quotient)] (Swap positions of 1 & quotient if quotient > 1)

Logarithms

  • loga(x/y) = logax - logay
  • logaxn = nlogax
  • logab = (logcb/logca)

Permutations

For a set of n objects: The total number of permutations is n!

For arranging 'r' objects from a set of 'n' objects: The number of permutations is nPr = n! / (n-r)!. (e.g., ways to arrange 3 objects from a set of 5 is 5 * 4 * 3, since there are 5 possibilities for the first object, followed by 4, then 3.)

Combinations

For selecting 'r' objects from a set of 'n' objects: The number of combinations is nCr = n! / (r! * (n-r)!). (Divide by r! since there are r! ways

... Continue reading "Fundamental Computer Science Concepts & Algorithms" »

Understanding Binary Adders and Race Conditions in Flip-Flops

Classified in Computers

Written on in English with a size of 4.17 KB

Binary Parallel Adder

A binary parallel adder is a digital circuit that adds two binary numbers in parallel, meaning all bits are added simultaneously. It typically consists of full adders arranged in parallel, with each full adder adding corresponding bits from the two input numbers.

BCD Adder

A BCD (Binary Coded Decimal) adder is a specific type of binary parallel adder designed to add two BCD numbers. BCD numbers are decimal digits encoded in binary, where each decimal digit is represented by its 4-bit binary equivalent.

Truth Table for a 4-bit BCD Adder

Here's the truth table for a 4-bit BCD adder:


Diagram


In the truth table:

  • A3 A2 A1 A0 represents the first BCD number (A).
  • B3 B2 B1 B0 represents the second BCD number (B).
  • Cin represents the carry-
... Continue reading "Understanding Binary Adders and Race Conditions in Flip-Flops" »

Essential Algorithms and Data Structures: A Quick Reference

Classified in Computers

Written on in English with a size of 580.94 KB

fUlQAAAABJRU5ErkJggg==

AOUNZyjQwEJMAAAAAElFTkSuQmCC


Essential Algorithms and Data Structures

Longest Increasing Subsequence (LIS):

  • Subproblem: dp[i] = length of LIS ending at index i
  • Recursion: dp[i] = max(dp[j] + 1 for j < i and arr[j] < arr[i])
  • Base case: dp[i] = 1 (every element is a subsequence of length 1)
  • Time Complexity: O(n^2), O(n log n) with binary search optimization.

Longest Alternating Subsequence (LAS):

  • Subproblem: dp[i][0] (increasing), dp[i][1] (decreasing)
  • Recursion: dp[i][0] = max(dp[j][1] + 1 for j < i and arr[j] < arr[i]), dp[i][1] = max(dp[j][0] + 1 for j < i and arr[j] > arr[i])
  • Base case: dp[0][0] = 1, dp[0][1] = 1
  • Time Complexity: O(n^2)

0/1 Knapsack Problem:

  • Subproblem: dp[i][w] = maximum value for the first i items and weight limit w
  • Recursion: dp[i][w] = max(
... Continue reading "Essential Algorithms and Data Structures: A Quick Reference" »

Network Fundamentals: Protocols, Addressing, Security

Posted by Anonymous and classified in Computers

Written on in English with a size of 17.78 KB

TCP Reliable Transfer and Connection Management

TCP Reliable Transfer

  1. Sequence Numbers

    • Each byte of data is assigned a sequence number. This number is used by the receiver to correctly order the data and ensure there are no missing segments.
  2. Acknowledgements

    • The receiver sends back an ACK to the sender for the sequence number of the next expected byte. If the sender receives the ACK before its timer expires, it knows everything up to that byte was received correctly.
  3. Retransmission

    • If the ACK is not received before the timer expires, the sender retransmits the data.

TCP Connection Management

Managing a TCP connection begins with a three-way handshake, which establishes a connection before any actual data is transmitted.

Steps in Three-Way Handshake

  1. SYN
    • The
... Continue reading "Network Fundamentals: Protocols, Addressing, Security" »

Core Web Development Concepts: Languages, Protocols, and Frameworks

Posted by Anonymous and classified in Computers

Written on in English with a size of 332.62 KB

JavaScript: The Heart of Interactive Web Development

JavaScript is a powerful and widely used programming language mainly used for making websites interactive and dynamic. It works on the client-side, which means it runs inside the user's web browser. JavaScript allows web pages to respond to user actions like clicking buttons, typing in text boxes, hovering over images, and more. It works together with HTML (for structure) and CSS (for design) to build modern and user-friendly websites. It is easy to learn and used by almost every website today.

Apart from the client-side, JavaScript is also used on the server-side using platforms like Node.js, which allows building full web applications using JavaScript alone. It is a platform-independent language,... Continue reading "Core Web Development Concepts: Languages, Protocols, and Frameworks" »

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" »

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" »