• Level Up Coding
  • Posts
  • LUC #15: The Role of Heuristics in Efficient Algorithms

LUC #15: The Role of Heuristics in Efficient Algorithms

Plus, how Linux permissions work, components of URL explained, and adaptive streaming algorithms

Hello, coding enthusiasts! We’re back with another exciting edition of Level Up Coding’s newsletter.

In today’s issue:

Read time: 6 minutes

Streamlining Complex Algorithms with Heuristics

Programming solutions vary in complexity, and the most complex ones tend to require a little help to keep them efficient. Heuristics is one powerful approach that is often overlooked by many.

Heuristics is more commonly known in the field of Psychology. They are cognitive shortcuts we use to speed up decisions and judgments.

As you can imagine, this may sometimes lead to incorrect conclusions. But it’s appropriate when we lack the time or information to make fully informed judgments.

Heuristics is not about finding the perfect solution.

It’s about finding a good enough solution in a reasonable amount of timeefficiency over perfection.

By breaking down complex problems into more manageable tasks, the problem becomes far simpler and faster to solve than tackling the entire task as a whole.

Pre-defined criteria (or rules of thumb) allow algorithms to make educated guesses as to which path to explore further or which to disregard.

An example of this in action is with the A* search algorithm where a heuristic function is used to estimate the remaining distance between points and prioritize paths based on that information.

Effectively applying heuristics requires a deep understanding of the problem’s nuances. Experiment with different solutions and continuously learn and adjust your approach. By applying what you've learned in each iteration, you'll fine-tune your heuristic strategies and construct efficient solutions to complex problems. Most importantly, remember the goal is to create a solution that produces a good enough output; not a perfect output.

Heuristics has many applications. For example in machine learning, heuristics can speed up the learning process by guiding initial model structures or prioritizing certain paths during training.

The wide use of heuristics in programming highlights one very important principle — performance is far more important than perfection. There are many cases where a good enough output is preferred when a considerable performance gain can be achieved.

How Do Linux Permissions Work? (recap)

Linux permissions provide the ability to limit who has access to a file or directory and what actions (read, write, or execute) they are allowed to perform.

There are three permission types for each file and directory:
🔸 Read (r): Allows reading of a file or listing of the directory's contents.
🔸 Write (w): Allows you to modify the contents of a file or create or delete files from a directory.
🔸 Execute (x): Allows a file to be run as a program, or a directory to be entered into.

There are three types of users to whom permissions are assigned:
🔸 User (u): The owner of the file or directory.
🔸 Group (g): Other users who are members of the file's group.
🔸 Others (o): All other users who are not the owner or members of the group.

🔹 View permissions with the ls-l command
🔹 Change a file or directory’s permissions with the chmod command
🔹 Change a file or directory’s ownership using the chown and chgrp commands

Every Component of a URL Explained (recap)

🔸 Protocol/scheme: this represents the method used to fetch the resource. E.g. HTTP, HTTPS, or FTP.
🔸 Subdomain: it comes before the domain and is optional. It’s used to organize different sections of the website.
🔸 Domain name: the location of the server that stores the website or resource. This is used in place of the server’s IP address for readability.
🔸 Port: specifies the communication endpoint at which a web service listens for incoming requests from a client. When you access a website using a standard protocol, the browser automatically assumes these default ports.
🔸 Path: specifies the specific resource on the web server.
🔸 Query string: used to send additional info to the server. Starts with “?”, and consists of key-value pairs (eg; ?search=hat&color=blue).
🔸 Fragment/anchor: this is optional and comes after the “#”. It is used to let the browser know to scroll to that specific part of the webpage once it is loaded.

Adaptive Streaming Algorithms (recap)

How do companies like Netflix and YouTube manage to deliver such a smooth streaming experience? Adaptive streaming algorithms.

To deliver a smooth and buffer-free streaming experience, adaptive streaming algorithms are used to make real-time adjustments to the video quality based on factors such as network conditions. This approach allows the streaming provider to deliver the best video quality possible given the streaming conditions, without hindering performance and end-user experience.

The process behind adaptive streaming algorithms involves six steps:

  1. Preparing the content

  2. Creating the manifest file

  3. Client-server communication

  4. Buffer management

  5. Adjusting quality

  6. Request segments

That wraps up this week’s issue of Level Up Coding’s newsletter!

Join us again next week where we’ll explore monolithic vs microservices, How CORS works, and TLS vs SSL.