7 must-know runtime complexities for coding interviews:
1. 𝐎(1) - 𝐂𝐨𝐧𝐬𝐭𝐚𝐧𝐭 𝐭𝐢𝐦𝐞
- The runtime doesn't change regardless of the input size.
- Example: Accessing an element in an array by its index.
2. 𝐎(𝐥𝐨𝐠 𝐧) - 𝐋𝐨𝐠𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slowly as the input size increases. Typically seen in algorithms that divide the problem in half with each step.
- Example: Binary search in a sorted array.
3. 𝐎(𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫 𝐭𝐢𝐦𝐞
- The runtime grows linearly with the input size.
- Example: Finding an element in an array by iterating through each element.
4. 𝐎(𝐧 𝐥𝐨𝐠 𝐧) - 𝐋𝐢𝐧𝐞𝐚𝐫𝐢𝐭𝐡𝐦𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows slightly faster than linear time. It involves a logarithmic number of operations for each element in the input.
- Example: Sorting an array using quick sort or merge sort.
5. 𝐎(𝐧^2) - 𝐐𝐮𝐚𝐝𝐫𝐚𝐭𝐢𝐜 𝐭𝐢𝐦𝐞
- The runtime grows proportionally to the square of the input size.
- Example: Bubble sort algorithm which compares and potentially swaps every pair of elements.
6. 𝐎(2^𝐧) - 𝐄𝐱𝐩𝐨𝐧𝐞𝐧𝐭𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- The runtime doubles with each addition to the input. These algorithms become impractical for larger input sizes.
- Example: Generating all subsets of a set.
7. 𝐎(𝐧!) - 𝐅𝐚𝐜𝐭𝐨𝐫𝐢𝐚𝐥 𝐭𝐢𝐦𝐞
- Runtime is proportional to the factorial of the input size.
- Example: Generating all permutations of a set.
♻️ Repost to help others in your network.
Concepts every developer should know: concurrency is NOT parallelism.
Parallelism and concurrency are two terms that often create confusion.
One is about managing multiple tasks at once, intermixing them to optimize resource usage.
The other involves executing multiple tasks simultaneously.
As Rob Pike (one of the creators of Golang) succinctly put it: “Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once."
What is concurrency?
In modern systems, concurrency is driven by design principles that ensure tasks or processes run efficiently, whether the hardware has one or multiple processors.
Even with a single CPU, concurrency patterns allow tasks to share processor time effectively. This creates an illusion of parallel execution.
These patterns also enable parts of a program to be executed out of sequence or in partial order, while still preserving the intended behavior of the program.
What is parallelism?
While concurrency is about dealing with many tasks at once (task management). Parallelism is about doing many tasks at once (task execution).
Parallelism requires hardware support, such as multi-core or multi-processor systems, to allow different tasks to run at the same time.
This distinction between concurrency (task management) and parallelism (task execution) significantly impacts application performance and efficiency.
Parallelism is particularly beneficial for compute-intensive applications, where tasks can be distributed across multiple processors to be executed simultaneously, leading to faster and more efficient processing.
Asynchronous programming is used to achieve concurrency in single-threaded environments.
This approach enables a program to initiate tasks without waiting for previous ones to finish, managing multiple tasks in a non-blocking manner.
A great example is Node.js, which handles concurrency in a single-threaded model using callbacks and event loops.
Meanwhile, multi-threaded environments (eg; C#) facilitate both concurrency and parallelism.
They facilitate both concurrent task execution and true parallel execution across multiple processors or cores simultaneously.
Understanding concurrency and parallelism is an important distinction for building high-performing and efficient software solutions.
~~
Thanks to our partner Kestra who keeps our content free to the community.
Are repetitive manual tasks slowing you down?
Kestra’s intuitive UI makes it effortless to automate and manage your workflows visually.
Check it out: https://t.co/qR5j8TKEaW
Full Stack Developer is One of the Highly In Demand and Top Paying Jobs in Tech.
Here's a complete roadmap to be a excellent Full Stack JavaScript Developer (with youtube videos):
A Thread 🧵
“Transformers from scratch” by Brandon Rohrer 🤖
This is one of the best write ups, that starts from 0 and explains every single detail of the model architecture.
Even if you need a refresher or don’t, I would still highly recommend reading it:
https://t.co/D25bs6TP5X
20-year-old kids are making $10,000/m using AI and No-Code tools.
They are building money printing machines.
Here are 8 free AI and No-Code tools to start printing money online: