SShortSingh.
Back to feed

How to Find the Left View of a Binary Tree Using BFS

0
·1 views

The left view of a binary tree consists of the first node visible at each level when the tree is observed from the left side. This can be solved efficiently using level-order traversal, also known as BFS, which processes nodes level by level from left to right. At each level, only the first node encountered is recorded as part of the left view. The approach uses a queue to push the root, then iterates through each level by tracking its size and capturing the node at index zero. Both the time and space complexity of this solution are O(N), where N is the total number of nodes in the tree.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Single-point uptime monitors miss network path failures in hybrid cloud setups

Traditional uptime tools check service availability from a single monitoring server, which can misrepresent connectivity in hybrid cloud environments where network paths vary across virtual networks. A service may appear fully operational from one vantage point while remaining unreachable from other parts of the infrastructure due to broken routes or misconfigured network security groups. The proposed solution involves deploying lightweight agents inside each network location — such as Azure Functions, AWS Lambda, or on-premises VMs — that push results outbound to a central hub, building a source-by-destination connectivity matrix. To manage the data volume from distributed monitoring, hourly pre-aggregation of heartbeat data reduces per-request row counts significantly while keeping dashboards updated in near real time via push-based status transitions. The core takeaway is that in multi-network infrastructure, meaningful uptime measurement requires asking not just whether a service is up, but whether it is reachable from each specific source that depends on it.

0
ProgrammingDEV Community ·

Morris Preorder Traversal Achieves O(1) Space Without Stack or Recursion

Morris Preorder Traversal is an algorithm that performs binary tree preorder traversal without using a call stack or auxiliary stack, achieving O(1) extra space. It works by temporarily linking a node's inorder predecessor back to the current node, creating a structure known as a thread. Unlike the recursive or stack-based approaches that use O(H) space, this method traverses each edge at most twice, keeping time complexity at O(N). The key distinction from Morris Inorder Traversal is that the node is visited before the thread is created, rather than when the thread is removed. Once traversal of a subtree is complete, the temporary thread is deleted to restore the original tree structure.

0
ProgrammingDEV Community ·

Developer launches auto-verified free proxy list refreshed every 30 minutes

A developer has published an open-source proxy list on GitHub called gproxynet/free-proxy-list, designed to address the common problem of stale, unverified public proxy lists. The repository is automatically regenerated every 30 minutes, with each proxy validated and tagged by protocol (HTTP, SOCKS4, SOCKS5), country, and latency. Proxies are available in plain-text and structured JSON formats, making them easy to integrate into scrapers or testing tools. The maintainer cautions that these are shared public proxies unsuitable for sensitive tasks, and recommends dedicated proxies for serious scraping or account-related work. The list is intended for lightweight use cases such as testing, learning, and one-off requests where a small, freshly checked pool is sufficient.

0
ProgrammingDEV Community ·

Ex-Amazon Warehouse Worker Shares 12 Years of Barcode Lessons in Free Tool

A former Amazon inbound dock worker with 12 years of experience has shared key insights into barcode specifications drawn from observing real-world shipment failures. Common formats like EAN-13, UPC-A, ITF-14, and Code 128 each serve distinct purposes, from retail products to warehouse bins and shipping cartons. A critical and frequently overlooked requirement is the mandatory quiet zone — empty white space on both sides of any barcode — which caused thousands of shipment rejections when label designers cropped too close to the edge. ITF-14 barcodes require an additional thick bearer bar to prevent ink bleed on corrugated cardboard surfaces. After leaving Amazon, the author built genbarcode.org, a free client-side barcode generator supporting six formats using the Canvas API.