dsa

Key Points for System Design Interviews

Key Points for System Design Interviews

A System Design Interview assesses your ability to design complex systems, scale them, and ensure they meet the requirements in terms of performance, reliability, and maintainability. It's a critical skill for software engineering roles, especially in senior positions. Here are key points and strategies to approach a system design interview: 1. Clarify Requirements Ask Questions: Always start by asking clarifying questions. Don’t jump into designing immediately. Understand the exact features, non-functional requirements, and constraints of the system.Identify Core Features: Pinpoint the most critical features and their priorities (e.g., user login, data storage, or high availability).Define Scope: Ensure that you are…
Read More
Using HashMaps, Coding Interview Pattern

Using HashMaps, Coding Interview Pattern

Hashmaps Hashmaps are a versatile data structure essential for many coding interview problems due to their average-case (O(1)) time complexity for insertions, deletions, and lookups. They allow you to efficiently store and retrieve key-value pairs by leveraging a hash function to distribute keys across an array. In interviews, hashmaps are frequently used to solve problems related to frequency counting, finding pairs that sum to a target value, grouping anagrams, and detecting subarrays with specific sums. Their ability to handle large datasets with minimal computational overhead makes them a valuable tool in optimizing solutions and tackling complex algorithmic challenges. Valid Anagram…
Read More
Approaching Various Tree Algorithm using Javascript

Approaching Various Tree Algorithm using Javascript

Simple Tree we need to always start with the simple one then step by step we can go to the complex Algorithm. class SimpleTree { constructor(value) { this.value = value; this.children = []; } insertChild(value) { const newChild = new SimpleTree(value); const lastElement = this.findLastChild(this); lastElement.children.push(newChild); return newChild; } findLastChild(root) { if (root.children.length == 0) { return root; } return this.findLastChild(root.children[0]); } traversal(root) { console.log(root.value + ' --> '); root.children.forEach(child => { this.traversal(child); }) } } const simpleTree = new SimpleTree('A'); simpleTree.insertChild('B'); simpleTree.insertChild('C'); simpleTree.insertChild('D'); simpleTree.insertChild('E'); simpleTree.insertChild('F'); console.log(simpleTree) simpleTree.traversal(simpleTree) /* { "value": "A", "children": [ { "value": "B", "children": [ {…
Read More
Approaching Brute Force Algorithm Using Javascript

Approaching Brute Force Algorithm Using Javascript

Below are few examples which is started with simple to advance level (Travelling Salesman Problem and 0/1 knapsack problem) These examples are based on brute force Algorithm My Note:- There are several downsides of this Brute Force Algorithm but before directly jumping into Dynamic programming and other approaches you should have ideas on this approach and you must find out why we need a Dynamic Programming pattern (Recursion + Memorization) If you closely observe the pattern for the brute force const wrapper = (value) => { const helper = (combinedArray, depth) => { if (depth == 3) { // operation…
Read More
Union-Find, Data Structures

Union-Find, Data Structures

Union-Find Data Structure class UnionFind { private: vector<int> parent; vector<int> rank; public: // Constructor to initialize Union-Find with n elements UnionFind(int n) { parent.resize(n); rank.resize(n, 0); for (int i = 0; i < n; ++i) { parent[i] = i; // Each element is its own parent initially } } // Find the representative or root of the set containing 'vertex' int find(int vertex) { if (parent[vertex] != vertex) { parent[vertex] = find(parent[vertex]); // Path compression } return parent[vertex]; } // Union the sets containing 'u' and 'v' void unite(int u, int v) { int rootU = find(u); int rootV =…
Read More
Bellman ford algorithm(Single Source Shorted Path in DAG)

Bellman ford algorithm(Single Source Shorted Path in DAG)

Bellman-ford algorithm Bellman ford algorithm works on directed graph only ( if you want to use it on undirected graph then you will have to convert the undirected graph into directed graph first) Bellman ford algorithm is used to find the single source shortest path even when the graph has negative cycle(inwhich case Dijkstra's fails) Bellman ford also helps us check if the graph(DAG) has negative edge cycle What needs to be done: Relaxation of edges: if(distance[u] + weight < distance[v]){ distance[v] = distance[u] + weight; } Enter fullscreen mode Exit fullscreen mode This above check needs to be done…
Read More
How I Befriended Segment Trees

How I Befriended Segment Trees

Last time, I talked about one advanced data structure that is useful for handling frequent range queries – Fenwick Tree. However, it's not very versatile as it is mostly used for sum queries, and I personally never used it for any other kind of problem. However, there is another player on the field, which has many more hats. Ladies and gentlemen, meet the Segment Tree, one of the most useful, yet often overlooked data structure. Why I decided to learn it So, what was my motivation behind learning Segment Trees? The answer is quite simple, actually. I got tired of…
Read More
Stacks, Data Structures

Stacks, Data Structures

Stacks A stack is a fundamental data structure in computer science that operates on a Last In, First Out (LIFO) principle. This means that the last element added to the stack is the first one to be removed. Stacks are analogous to a pile of plates where you can only add or remove the top plate. This simplicity and the constraint on how elements are added and removed make stacks particularly useful for certain types of problems and algorithms. Basic Concepts of Stacks Push Operation: This operation adds an element to the top of the stack. If the stack is…
Read More
Linked List, Data Structures

Linked List, Data Structures

Linked List A linked list is a fundamental data structure used in computer science to organize and store data efficiently. Unlike arrays, linked lists consist of nodes, where each node contains data and a reference (or link) to the next node in the sequence. This structure allows for dynamic memory allocation and efficient insertions and deletions, making linked lists highly versatile and useful for various applications. Comparison with Arrays Linked lists and arrays are both used to store collections of elements, but they have key differences that affect their performance and usage: Memory Allocation: Arrays: Use contiguous memory allocation. The…
Read More
No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.