{"id":22513964,"url":"https://github.com/emahtab/check-completeness-of-a-binary-tree","last_synced_at":"2026-01-07T05:07:13.747Z","repository":{"id":79525354,"uuid":"237645602","full_name":"eMahtab/check-completeness-of-a-binary-tree","owner":"eMahtab","description":"Checking whether a binary tree is Complete binary tree or not","archived":false,"fork":false,"pushed_at":"2020-05-30T05:55:18.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-02T03:26:14.670Z","etag":null,"topics":["bfs","complete-binary-tree","leetcode","problem"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-01T16:47:51.000Z","updated_at":"2020-05-30T05:55:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"f76a120b-2d5a-4eef-9eae-74a751659d05","html_url":"https://github.com/eMahtab/check-completeness-of-a-binary-tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcheck-completeness-of-a-binary-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcheck-completeness-of-a-binary-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcheck-completeness-of-a-binary-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fcheck-completeness-of-a-binary-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/check-completeness-of-a-binary-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245952314,"owners_count":20699467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bfs","complete-binary-tree","leetcode","problem"],"created_at":"2024-12-07T03:15:17.809Z","updated_at":"2026-01-07T05:07:08.728Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Check Completeness of a Binary tree\n## https://leetcode.com/problems/check-completeness-of-a-binary-tree\n\nGiven a binary tree, determine if it is a complete binary tree.\n\nDefinition of a complete binary tree from Wikipedia:\nIn a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.\n\n**Note: The tree will have between 1 and 100 nodes.**\n\n## Implementation :\n\n```java\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n    public boolean isCompleteTree(TreeNode root) {\n        if(root == null)\n            return true;\n        Queue\u003cTreeNode\u003e queue = new LinkedList\u003c\u003e();\n        queue.offer(root);\n        boolean nullSeen = false;\n        while(!queue.isEmpty()){\n            TreeNode current = queue.poll();\n            if(current == null){\n              nullSeen = true;  \n            } else {\n                // If we already saw a null node \n                // and then If we see a non null node, that means its not a complete binary tree \n                if(nullSeen)\n                    return false;\n                queue.offer(current.left);\n                queue.offer(current.right);\n            }\n        }\n        return true;\n    }\n}\n```\n## Little Refactoring\n```java\nclass Solution {\n    public boolean isCompleteTree(TreeNode root) {\n        if(root == null)\n            return true;\n        Queue\u003cTreeNode\u003e q = new LinkedList\u003c\u003e();\n        q.add(root);\n        boolean nullSeen = false;\n        while(!q.isEmpty()) {\n            TreeNode node = q.poll();\n            if(node == null)\n                nullSeen = true;\n            else if(nullSeen)\n                return false;\n            else {\n                q.add(node.left);\n                q.add(node.right);\n            }\n        }\n        return true;\n    }\n}\n```\n\n\n# References :\nhttps://www.youtube.com/watch?v=j16cwbLEf9w\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcheck-completeness-of-a-binary-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fcheck-completeness-of-a-binary-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fcheck-completeness-of-a-binary-tree/lists"}