# Insert Operation - 2-3 Tree

## Insert into 2-node at bottom

* Search for key as usual
* Replace 2-node with 3-node

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-1e5e09691d424d4e26b2cb0a3b98722e1f30bdee%2Fimage%20\(49\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-56d9cab8172632a78eecad5e668547ae622b677e%2Fimage%20\(73\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-12e40e659e47ed5659296219da8341583f97e793%2Fimage%20\(41\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-17b7cae981aa44b89c8c9c7c50f12b6b9daad9bf%2Fimage%20\(80\).png?alt=media)

## Insert into 3-node at bottom

* Add new key to 3-node to make it to 4-node
* Move middle key of 4-node to parent
* Repeat up the tree as necessary
* if you reach the root, and it is 4-node then split it into three 2-nodes.

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-8dc168f10d68c9821e5360b773b0f0d6cc5b6cc1%2Fimage%20\(68\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-73190c7a238ac18bcce38553c33b2bc9bc452e31%2Fimage%20\(77\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-fab3b040912e6b5fe97e3fd3356425227377fbfc%2Fimage%20\(72\).png?alt=media)

## Root Having 3-node

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-4987f7ab64057b8b3f2ae2f0e8af93d5d2650559%2Fimage%20\(70\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-3361f5197b455b84f2c7bfaa0f01c46f4f2fb285%2Fimage%20\(58\).png?alt=media)

![](https://1133441777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP3gpNOfmHBf90k26iY%2Fuploads%2Fgit-blob-2080ffabdf3e6a0cf14b5f5ce4330e6f762c6a1b%2Fimage%20\(33\).png?alt=media)
