About Algorithm: Difference between revisions

From My Limbic Wiki
Line 11: Line 11:
* [[Index.php?title=Binary Search|Binary Search]]
* [[Index.php?title=Binary Search|Binary Search]]
<pre class="code java">
<pre class="code java">
     private int searchPivot(int[] nums){
     private int binarySearch(
         int size = nums.length;
        int[] nums,
         int rightIndex = size - 1, leftIndex = 0;
         int leftBoundary,
         int lastIndex = size - 1, lastValue = nums[lastIndex];  
         int rightBoundary,
         int midIndex = 0, midValue = 0;
         int target
    ) {
        int leftIndex = leftBoundary;
         int rightIndex = rightBoundary;


         while (leftIndex <= rightIndex) {
         while (leftIndex <= rightIndex) {
             midIndex = (leftIndex + rightIndex) / 2;
             int midIndex = (leftIndex + rightIndex) / 2;
             midValue = nums[midIndex];
             int midValue = nums[midIndex];
              
 
             if (midValue > lastValue) {
             if (midValue == target) {
                return midIndex;
             } else if (midValue > target) {
                rightIndex = midIndex - 1;
            } else {
                 leftIndex = midIndex + 1;
                 leftIndex = midIndex + 1;
            } else {
                rightIndex = midIndex - 1;
             }
             }
         }
         }
         return leftIndex;
         return -1;
     }
     }
</pre>
</pre>

Revision as of 22:58, 5 October 2025

Tips

Sorting Algoritms

    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