Two Sum

Problem https://leetcode.com/problems/two-sum/ Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. Examples Example 1: Input: nums = [2,7,11,15], target = 9 Output: [0,1] Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]....

June 8, 2024 · 3 min · 532 words · Xavier Loera Flores

In Place Algorithms

In Place Algorithms In place algorithms are algorithms that are executed without needing extra memory. They will modify the input data directly and work within the same memory space. In place algorithms can use a amount of extra memory and still be considered in place. As long as the output is stored in the same memory space as the input, the algorithm is considered in place. Algorithms that don’t modify the input data directly and require extra memory are considered out of place or not in place....

June 8, 2024 · 2 min · 321 words · Xavier Loera Flores

Stable Sorting Algorithms

Stable Sorting Algorithms Stable sorting algorithms are algorithms that maintain the relative order of equally valued elements in its sorted output. This means that if two elements are equal in value, the element that appears first in the original list will appear first in the sorted list. Use Case One use case when sorting a list of objects by multiple keys. If the list is sorted by one key and then sorted by another key, the relative order of the first key will be maintained in the second sort....

June 4, 2024 · 2 min · 227 words · Xavier Loera Flores

Merge Sort

Merge Sort Merge Sort is a divide-and-conquer algorithm that divides the input list into two halves, recursively sorts the halves, and then merges the sorted halves. This algorithm is efficient for larger lists and is a stable sorting algorithm that guarantees $O(n \log n)$ time complexity. Key Points Time Complexity: $O(n \log n)$ Space Complexity: $O(n)$ Process: Divide: The input list is divided into two halves Conquer: The two halves are recursively sorted Merge: The sorted halves are merged back together in sorted order Features:...

June 2, 2024 · 3 min · 531 words · Xavier Loera Flores

Bubble Sort

Bubble Sort Bubble Sort is a simple sorting algorithm which repeatedly compares and swaps adjacent elements in place. By swapping elements into the correct order, larger elements will be bubbled towards the end of the list. Effectively, the algorithm bubbles the current largest element to the end of the list in each phase of the algorithm. Although this algorithm is simple, it is not efficient for larger lists. Key Points Time Complexity: $O({n}^{2})$...

June 1, 2024 · 2 min · 380 words · Xavier Loera Flores

Theory of Computation & Computational Models

When solving problems in computer science, it can help to abstract the problem to gain a better understanding of what we can possibly achieve. This can especially be seen when analyzing algorithms since we usually care more about how algorithms would perform on abstract computers (machines) rather than specific hardware. Computation any type of calculation that may include both arithmetical & non-arithmetical steps to provide a solution to a problem. Computational Models abstract models that allow us to reason about what can and can’t possibly be computed by a particular device....

November 27, 2023 · 3 min · 545 words · Xavier Loera Flores

Primality Testing

RSA Algorithm Rivest-Shamir-Aldeman Algorithm an asymmetric cryptography algorithm utilizes public and private generated from large prime numbers used to encrypt and decrypt data. The public key consists of two numbers where one number is a multiplication of two prime numbers. The private key is also derived from the same two prime numbers meaning if the public key primes are compromised, then so is the private key. Φ Φ(Phi) counts the number of numbers that are less than or equal to n and only share the factor of 1 with n Geeks for Geeks example: Geek For Geeks: RSA Algorithm Cryptography...

November 25, 2023 · 2 min · 406 words · Xavier Loera Flores