About Algorithm: Difference between revisions

From My Limbic Wiki
Line 10: Line 10:
=Sorting Algoritms=
=Sorting Algoritms=
* Two Pass -  
* Two Pass -  
<pre class="code java">
class Solution {
class Solution {
     public int[] productExceptSelf(int[] nums) {
     public int[] productExceptSelf(int[] nums) {
Line 30: Line 31:
     }
     }
}
}
</pre>
* [[Index.php?title=Binary Search|Binary Search]] - Binary search exploit "sorted and rotated" structure. At every iteration, it divide the space by 2 using left or right.
* [[Index.php?title=Binary Search|Binary Search]] - Binary search exploit "sorted and rotated" structure. At every iteration, it divide the space by 2 using left or right.
<pre class="code java">
<pre class="code java">

Revision as of 23:00, 5 October 2025

Tips

Sorting Algoritms

  • Two Pass -
class Solution {
    public int[] productExceptSelf(int[] nums) {
        int length = nums.length;
        int[] answer = new int[nums.length];

        int leftProduct = 1;
        for (int i = 0; i < length; i++) {
            answer[i] = leftProduct;
            leftProduct *= nums[i];
        }

        int rightProduct = 1;
        for (int i = length - 1; i >= 0; i--) {
            answer[i] *= rightProduct;
            rightProduct *= nums[i];
        }

        return answer;
    }
}
  • Binary Search - Binary search exploit "sorted and rotated" structure. At every iteration, it divide the space by 2 using left or right.
    private int binarySearch(
        int[] nums,
        int leftBoundary,
        int rightBoundary,
        int target
    ) {
        int leftIndex = leftBoundary;
        int rightIndex = rightBoundary;

        while (leftIndex <= rightIndex) {
            int midIndex = (leftIndex + rightIndex) / 2;
            int midValue = nums[midIndex];

            if (midValue == target) {
                return midIndex;
            } else if (midValue > target) {
                rightIndex = midIndex - 1;
            } else {
                leftIndex = midIndex + 1;
            }
        }
        return -1;
    }

Graphs

  • Dijkstra
  • Topologic sorting

Cryptography & Compression

  • Shannon-Fano
  • Huffman
  • Diffie-Hellman
  • RSA

Prime Numbers

  • ?

Most beautiful Equation