PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

DSA · Theory

Floor and Ceil from a BST

← All stacks

Theory

635/810

Floor and Ceil from a BST

Asha only reaches for Floor and Ceil from a BST when folder on disk has to stay correct in a file explorer.

For Floor and Ceil from a BST, a dry-run table is in play. Don’t blame it until you have traced folder on disk.

Floor and Ceil from a BST exists so Asha can keep folder on disk correct in a file explorer.

Floor and Ceil from a BST shows up in a file explorer. Name folder on disk, not “a real-world scenario”.

Don’t do this with Floor and Ceil from a BST: unbalanced BST becoming a list. Interviewers spot it in ten seconds.

Place Floor and Ceil from a BST next to nearby DSA work — left < root < right is the link.

Viva for Floor and Ceil from a BST — what it is → left < root < right → the mistake (unbalanced BST becoming a list).

Diagram
      8
     / \
    3   10
   / \
  1   6
Exam tip

Board: folder on disk. Dry-run Floor and Ceil from a BST. Name the trap: unbalanced BST becoming a list.

Example

class Node:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None

def insert(root, val):
    if root is None:
        return Node(val)
    if val < root.val:
        root.left = insert(root.left, val)
    elif val > root.val:
        root.right = insert(root.right, val)
    return root

root = None
for v in [5, 2, 7, 1]:
    root = insert(root, v)
print(root.val, root.left.val, root.right.val)

Floor and Ceil from a BST — bST invariant: left < node < right — enables log-time search when balanced.

Short notes

  • DefFloor and Ceil from a BST — Asha uses it for folder on disk in a file explorer.
  • RuleFloor and Ceil from a BST → left < root < right.
  • RememberFloor and Ceil from a BST + a dry-run table (a file explorer).
  • UseFloor and Ceil from a BST in a file explorer (folder on disk).
  • TrapFloor and Ceil from a BST — unbalanced BST becoming a list.
  • ExFloor and Ceil from a BST → folder on disk.

Questions

1

What is Floor and Ceil from a BST? Teach it with folder on disk.

2

Name one DSA screen/job that needs Floor and Ceil from a BST.

3

What trap does Asha hit with Floor and Ceil from a BST?

4

Change one input on folder on disk. Predict the new result.

Previous← Applications, Advantages and Disadvantages of StacksNextIndia Stack →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.