Engrain by ByteRush

DSA.13.01 Mid-levelCore — asked often

DOM trees as data structures

Comes up in: DSA, Coding, JavaScript

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • DOM as an n-ary tree
  • DFS/BFS over children
  • find elements by predicate
  • nearest common ancestor of two DOM nodes
  • corresponding node in an identical tree (path of indices)
  • depth of the DOM
  • TreeWalker

Words you will know

n-ary treeDOM traversal

What you will practise

  • dom-find-by-class (M)
  • dom-common-ancestor (M)
  • dom-corresponding-node (M)
  • dom-max-depth (E)

Interview questions this answers

  • Given two identical DOM trees and a node in the first, find the matching node in the second.