Algorithms in Java

Trapping Rain WaterUnique Paths IIWord Ladder
public int trap(int[] height) {
    if (height == null || height.length == 0) {
        return 0;
    }

    int n = height.length;
    int left = 0, right = n - 1;
    int leftMax = 0, rightMax = 0;
    int waterTrapped = 0;

    while (left <= right) {
        if (height[left] <= height[right]) {
            if (height[left] >= leftMax) {
                leftMax = height[left];
            } else {
                waterTrapped += leftMax - 
Read More

Communication Channels: Types and Applications

Communication Channels

A communication channel is used to route messages from the sender to the receiver’s transmission components. A physical medium can support one or more communication channels. These can be:

  • Guided: Such as copper wires or optical fiber (e.g., coaxial cable).
  • Unguided: Such as air or a vacuum (e.g., wireless communications).

To establish a communication channel, the following are used:

  • Dedicated Links: Establish an exclusive channel between two interlocutors.
  • Point-to-Point: There
Read More

Data Transmission and Encoding Techniques

Data Elements and Signals

A data element is an entity that can represent one bit. A signal element is the short, in time, digital signal of 1A. Data elements need signals to send data; the signal is what sends these elements. Data rate is the number of data elements (bits) sent in one second. Modulation rate, or baud rate, is the number of signal elements sent per second.

Signal Characteristics and Coding

Bandwidth: The theoretical bandwidth of a digital signal is infinite; the effective bandwidth

Read More

Numerical Methods: Applications, Algorithms, and Code

The Importance of Numerical Methods

Numerical methods are crucial for solving complex mathematical problems that lack exact solutions, making them indispensable across various fields:

  • Engineering: Used in simulations like structural analysis, fluid dynamics, and heat transfer.
  • Physics: Models quantum mechanics, astrophysics, and thermodynamics.
  • Finance: Helps with risk analysis, options pricing, and portfolio optimization.
  • Biology/Medicine: Assists in drug modeling, population dynamics, and medical imaging.
Read More

Understanding Network Layers: Functions and Protocols

Network Layers Explained

The data link layer is responsible for establishing error-free communication. It ensures reliable data transfer to the upper layers. This layer operates at the physical level, managing data packets and ensuring their integrity. It divides messages into manageable fragments.

The data link layer handles tasks such as establishing and maintaining data flow, notifying users of errors, managing re-transmission requests, discarding duplicate data, and ensuring rapid transmission.

Read More

Signal Processing: Convolution, DFT, Filters, and Signals

Linear and Circular Convolution Using Circshift

This section demonstrates linear and circular convolution using the circshift function in MATLAB.

clc;
clear all;
close all;
x = [1 2 3];
h = [4 5];
L = length(x);
M = length(h);
N = L + M - 1;
x_padded = [x, zeros(1, N - L)];
h_padded = [h, zeros(1, N - M)];
for i = 1:N
    c = circshift(h_padded', i - 1);
    d(:, i) = c;
end
o = d * x_padded.';
disp('Linear convolution without function');
disp(o');
subplot(3, 1, 1);
stem(x, '*');
xlabel('n');
ylabel(
Read More