-
Day 1 Linear alghoritm is a simple algorithm to find a specific key in an unordered array. It starts at the first element and checks each one sequentially until it either finds the key or reaches the end of the array. If the key is found, the algorithm returns its index; otherwise, it indicates that the key is not in the array. This approach is particularly useful when the array is unsorted, as it does not require any prior sorting. The time complexity of linear search is O(n), where n is the number of elements in the array. Binary algorithm is used when we have a sorted array. It works by repeatedly dividing the search range in half. The algorithm starts by selecting the middle element and compares it with the key. If the key matches, the algorithm stops. If not, it checks if the key is smaller or larger than the middle value. If the key is smaller, the search continues in the left half; if larger, the search continues in the right half. This process repeats until the key is found or the search range is exhausted. Hashing algorithm works by creating an array with a fixed number of empty slots. We then use a key to calculate an index using a hash function, typically by performing a modulo operation (key % array.length). The remainder of this division becomes the index where the data is stored. If two keys result in the same index (a collision), methods like chaining or open addressing are used to handle the collision. Hashing table works by creating an array with a fixed number of slots. We then create a function to add values, where each value has a key and data. The key is used to calculate the index by performing a modulo operation (key % arr.length). The key and its data are stored at the resulting index. A potential issue arises when two keys result in the same index (a collision). In this case, both values are stored in the same array slot. To retrieve the correct element, we use the key, which allows us to access the data. This is why both the key and the data are stored in the array. The main problem for both hashing algorithms and hash tables is collisions, where two different elements with the same key and data have the same hash. In this case, they are stored at the same index in the array. To resolve this, theopen addressing method is used. When calculating the index, we also check if the index is already occupied. If it is, the element is placed at the next available index.
-
Day 2 i continue to learn ways to minimized collisions in hash tabs and there is some simple ways to minimize: In Separate chainig method, we can store multiple pairs of
key
+data
in the same storage location by creating an array (or linked list) at each index to hold all the pairs that map to that index.
Double hashing method little bit similar with a open address method where we use ahashKey + 1
for finding an empty storage location, but in double hashing we use secondary hashing method which we set ourselves with any available and quick formula for finding a new empty socket. Rehashing is a very simple way to minimize collision but function must always check occupancy condition of our array and resize array in case of hit a critical point, while rehashing is an effective way to reduce collisions, it is not the most efficient method because each resize allocates more memory, leaving a large portion of the table unused. This leads to a less efficient utilization of space as the table grows over time. -
Day 3-4 learn deeper how 1D massives work, column massives and find duplicate. Learn and understanding what is 2D and nD massives. Singly linked and Doubly linked list has difference only in bilateral nodes which is help us to move in both side.
-
Day 5-7 A Double-ended queue is simple and works with a FIFO (First In First Out) principle, but with a small difference from a simple queue: we can add or remove data (items) from both ends of the queue. A Priority queue works like a separate array, where we look for priorities and shift all elements if needed to add a new element to the queue. A Stack works with the LIFO (Last In First Out) principle.
-
Notifications
You must be signed in to change notification settings - Fork 0
Vantana1995/Algorithms
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
my study process
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published