Skip to content

Commit

Permalink
formatting and fix list in load balancers post
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoaguirre committed Oct 9, 2024
1 parent f2035b4 commit 47b40f8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions content/posts/fast-slow.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ draft = false
+++

This is a pattern that uses two pointers approach, however there's a special thing about this pattern:

- One pointer moves faster than the other.

The Fast and Slow pattern follows the [Hare and Tortoise algorithm](https://en.wikipedia.org/wiki/Cycle_detection).
Expand Down Expand Up @@ -37,6 +38,7 @@ def hasCycle(head: Node) -> bool:

return False
```

<br>
Also the algorithm helps us to find the middle Node of a linked list in `O(N)` time complexity and time `O(1)` constant space

Expand All @@ -61,6 +63,7 @@ def findMiddle(head: Node) -> Node:

return slow
```

<br>
So, with this said, we can calculate the node that starts the cycle in a linked list

Expand Down Expand Up @@ -121,6 +124,5 @@ def getCycleStart(head: Node, cycle_length: int) -> Node:

return slow
```
<br>


<br>
20 changes: 9 additions & 11 deletions content/posts/load-balancers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ Load Balancers (LB) are a crucial component for System Design. They are basicall

## How does a request get processed by a Load Balancer?

- Request is received
- Request then is evaluated:
- LB determines which server or resource should handle the request
- At this point, the Load Balancer Algorithm takes into account the following things:
- Server capacity and response time
- Number of active connections
- Geographic location

- LB forwards request to the server
- Server responds back to the LB
- LB processes response and sends it back to the user/client
1. Request is received
2. Request then is evaluated:
LB determines which server or resource should handle the request using a balancing algorithm taking in consideration the following things:
- Server capacity and response time
- Number of active connections
- Geographic location
3. LB forwards request to the server
4. Server responds back to the LB
5. LB processes response and sends it back to the user/client

## Load Balancer Algorithms

Expand Down
8 changes: 6 additions & 2 deletions content/posts/two-pointers.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ Two Pointer is basically what the name says. You've got to use two variables to
This approach excels in the following:

## Data structures

- Arrays (sorted or unsorted)
- Linked lists

## Problem types

- Find a set of elements that fulfill certain constraints
- Pairs, Triplets, Sub-arrays.

Expand All @@ -23,15 +25,17 @@ The most common problem types you'll encounter are something like this:
> Given an array of unsorted numbers and a target number, find a triplet in the array whose sum is as close to the target number as possible.
## Tips and observations

I think the idea is pretty clear right? Either the array is sorted or not, you could always sort it with a pre-built in function and start manipulating the pointers at your wish.

A rule of thumb that I've been telling myself to follow is to **never name those pointers `i` and `j`**. Instead, name them `left` and `right`. Those names are much clear and will simplify things in your head.

## Common code structure
For simplicity sake, I'll write things in Python.

For simplicity sake, I'll write things in Python.

### Pointer at the beginning and end of an array

```python
from typing import List

Expand All @@ -58,6 +62,7 @@ def bothSides(arr: List[int]):
```

### One main index and pointers at both ends

```python
from typing import List

Expand Down Expand Up @@ -106,7 +111,6 @@ def rightPullsLeft(arr: List[int]):
right += 1
```


Alright, that's it for Two Pointers.

Keep grinding!

0 comments on commit 47b40f8

Please sign in to comment.