Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/fogonthedowns/convert-binary-search-tree-to-sorted-doubly-linked-list

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/fogonthedowns/convert-binary-search-tree-to-sorted-doubly-linked-list

  • v0.0.0-20200722222549-b0725000d04d
  • Source
  • Go
  • Socket score

Version published
Created
Source

Convert Binary Search Tree to Sorted Doubly Linked List

Time complexity: O(N). Each node is processed exactly once. Space complexity: O(N). We have to keep a recursion stack of the size of the tree height

We use Depth First Search In Order Traversal.

  • inOrder(node.Left) node.Val inOrder(node.Right)

Here is the algorithm :

  • Initiate the first and the last nodes as nulls.
  • Call the standard inorder recursion helper(root) :
    • If node is not null :
      • Call the recursion for the left subtree helper(node.left).
      • If the last node is not null, link the last and the current node nodes.
      • Else initiate the first node.
      • Mark the current node as the last one : last = node.
      • Call the recursion for the right subtree helper(node.right).
      • Link the first and the last nodes to close DLL ring and then return the first node.

FAQs

Package last updated on 22 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc