Programming Articles

Page 571 of 2547

Kth Smallest Element in a BST in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Finding the Kth smallest element in a Binary Search Tree (BST) is a common problem that leverages the BST property where in-order traversal visits nodes in sorted order. We can use in-order traversal to collect elements and return the Kth smallest one. 10 5 15 2 7 13 ...

Read More

Implement Trie (Prefix Tree) in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 5K+ Views

A Trie (prefix tree) is a tree data structure used to efficiently store and search strings. It's particularly useful for autocomplete features and prefix matching. Each node represents a character, and paths from root to nodes represent prefixes. Trie Structure Overview A Trie supports three main operations ? insert(word) − Adds a word to the trie search(word) − Returns True if the complete word exists startsWith(prefix) − Returns True if any word starts with the given prefix Implementation We'll use a ...

Read More

Number of Islands in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 2K+ Views

The Number of Islands problem involves counting connected components of land (represented by 1s) in a 2D grid surrounded by water (represented by 0s). An island is formed by connecting adjacent lands horizontally or vertically. Consider this grid example ? 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 This grid contains three islands: one large island (blue), one single-cell island (orange), and one small island (pink). Algorithm Overview The solution uses Depth-First Search ...

Read More

Find Peak Element in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 5K+ Views

A peak element in an array is defined as an element that is greater than its neighbors. We can use some common approaches such as binary search to efficiently locate a peak element and linear search algorithm which involves iterating through an array. What is a Peak Element? A peak element is an element that is greater than or equal to its adjacent neighbors. For elements at the edges of the array, we only consider the existing neighbor ? # Example array with peak elements nums = [1, 3, 20, 4, 1, 0] # Here, 20 ...

Read More

Analyzing Census Data in Python

Yaswanth Varma
Yaswanth Varma
Updated on 25-Mar-2026 895 Views

Census data is information collected by the government to understand population characteristics including age, gender, education, and housing. This data helps governments understand current scenarios and plan for the future. In this article, we will learn how to analyze census data in Python using libraries like pandas, numpy, and matplotlib. Sample Census Dataset We'll use sample census data with the following structure: age ...

Read More

Maximum Product Subarray in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

The Maximum Product Subarray problem asks us to find a contiguous subarray within an integer array that has the largest product. For example, in the array [2, 3, -2, 4], the subarray [2, 3] gives the maximum product of 6. This problem is tricky because negative numbers can turn a small product into a large one when multiplied by another negative number. We need to track both maximum and minimum products at each position. Algorithm We use dynamic programming to solve this problem ? Create two arrays: max_products and min_products to track maximum and minimum ...

Read More

Construct Binary Tree from Inorder and Postorder Traversal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 334 Views

Building a binary tree from its inorder and postorder traversal sequences is a classic tree construction problem. The key insight is that the postorder traversal gives us the root node (last element), while the inorder traversal helps us identify left and right subtrees. 3 9 20 15 7 ...

Read More

Construct Binary Tree from Preorder and Inorder Traversal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Constructing a binary tree from preorder and inorder traversal sequences is a classic problem in tree algorithms. The key insight is that the preorder traversal gives us the root nodes in order, while the inorder traversal helps us determine the left and right subtrees. 3 9 20 15 7 ...

Read More

Word Search in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 7K+ Views

In Python, word search refers to finding if a given word exists in a 2D grid. The word can be formed by sequentially connecting adjacent cells horizontally or vertically. This problem is commonly solved using backtracking and Depth-First Search (DFS) algorithms. Algorithm Overview The word search algorithm follows these key steps: Iterate through each cell in the 2D grid For each cell matching the first character, start a DFS search Use backtracking to explore all four directions (up, down, left, right) ...

Read More

Subsets in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Generating all possible subsets of a given set is a fundamental problem in computer science, also known as finding the power set. For a set like [1, 2, 3], the power set contains all combinations: [[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]. We can solve this using a recursive backtracking approach where each element can either be included or excluded from a subset. Recursive Backtracking Approach The algorithm works by making binary choices for each element − include it (1) or exclude it (0) from the current subset. Algorithm Steps ...

Read More
Showing 5701–5710 of 25,466 articles
« Prev 1 569 570 571 572 573 2547 Next »
Advertisements