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.
Join 28,501+ readers of our free newsletter: https://t.co/kPG9KUxfy6
Where do we cache data?
Data is cached everywhere, from the front end to the back end!
This diagram illustrates where we cache data in a typical architecture.
There are multiple layers along the flow.
Client apps: HTTP responses can be cached by the browser. We request data over HTTP for the first time, and it is returned with an expiry policy in the HTTP header; we request data again, and the client app tries to retrieve the data from the browser cache first.
CDN: CDN caches static web resources. The clients can retrieve data from a CDN node nearby.
Load Balancer: The load Balancer can cache resources as well.
Messaging infra: Message brokers store messages on disk first, and then consumers retrieve them at their own pace. Depending on the retention policy, the data is cached in Kafka clusters for a period of time.
Services: There are multiple layers of cache in a service. If the data is not cached in the CPU cache, the service will try to retrieve the data from memory. Sometimes the service has a second-level cache to store data on disk.
Distributed Cache: Distributed cache like Redis hold key-value pairs for multiple services in memory. It provides much better read/write performance than the database.
Full-text Search: we sometimes need to use full-text searches like Elastic Search for document search or log search. A copy of data is indexed in the search engine as well.
Database: Even in the database, we have different levels of caches:
- WAL(Write-ahead Log): data is written to WAL first before building the B tree index
- Bufferpool: A memory area allocated to cache query results
- Materialized View: Pre-compute query results and store them in the database tables for better query performance
Transaction log: record all the transactions and database updates
Replication Log: used to record the replication state in a database cluster
Over to you: With the data cached at so many levels, how can we guarantee the sensitive user data is completely erased from the systems?
--
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/FIzCeaWsZV
A Brief Overview of Kubernetes
Kubernetes, often referred to as K8S, extends far beyond simple container orchestration. It's an open-source platform designed to automate deploying, scaling, and operating application containers.
Where Docker Lags, Kubernetes Excels
Docker revolutionized containerization, making it accessible and standardized. However, when it comes to managing a large number of containers across different servers, Docker can fall short. Kubernetes steps in here, providing a more robust, cluster-based environment for managing containerized applications at scale. It offers high availability, load balancing, and a self-healing mechanism, ensuring applications are always operational and efficiently distributed.
Solving the Container Management Puzzle
The primary problem Kubernetes solves is the complexity of managing multiple containers across various servers. It automates the distribution and scheduling of containers on a cluster, handles scaling requirements, and ensures a consistent environment across development, testing, and production.
Kubernetes' Container Runtime Interface (CRI) is a significant leap forward, enabling users to plug in different container runtimes without recompiling Kubernetes. This flexibility means organizations can choose from a variety of runtimes like Docker, containerd, CRI-O, and others, depending on their specific needs.
โ
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/uc5M7CdXXC
Hello, everyone.
For ease of reference, you can now use these links:
Grammar Point
https://t.co/iQDwmyRyJg
Vocabulary Builder
https://t.co/iNpBNi4BAe
Idioms
https://t.co/FCUM0x0fFh
Phrasal Verbs
https://t.co/nz3dRTr0MP
Happy learning.
@66l86 If it was 0-0 Goals difference. Maxico had more yellow cards than Poland so even if Arabia would not score that goal, still Poland would go through
Java Backend Development is One of the Highly In Demand and Top Paying Jobs in Tech.
Here's a Simple and Structured Roadmap to Becoming One (with youtube videos):