Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 8404

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 28, 20242024-11-28T12:48:09+00:00 2024-11-28T12:48:09+00:00

Data Structures: Trees I

  • 60k

This 2-part article will be on Tree data structures. In this first part we are going to look at what a tree data structure is, types of tree data structures, and some applications/use cases of tree data structures. In the second part we will look at implementing a tree data structure in Javascript; lets get into it.

root meme

 

Trees

A tree is a non-linear data structure that is used to store hierarchal data, e.g. a family tree, a company employee structure. Similar to Linked Lists, a Tree is made up of nodes that store a value and pointers to other related nodes. Trees make it fast to retrieve and organize data on a computer.

 

Structure Of A Tree Data Structure

All Trees have a node at the top known as the root; all other nodes are descendants of the root node.

Root node image

 

Tree Terminologies

Some of the terms used to describe the relationship between nodes in a tree are:

 

Parent and Child

parent node tree data structure

A parent node refers to the node that directly precedes another node. In the above image we can see that node [2] is a parent of nodes [5, 6, 7], which would also make nodes [5,6,7] children / child nodes of node [2]. similarly, nodes [9, 10] are children of node [4] and node [3] is the parent of node [8].

 

Sibling

sibling nodes

Nodes that share a parent node are referred to as siblings. Note all nodes in a tree can only have 1 parent except the root node which has no parent. In the above image we can see that nodes [5, 6, 7] are siblings; so are nodes [9, 10].

 

Leaf

Leaf node

A node with no child nodes is called a leaf node. Nodes [5, 6, 7, 8, 9, 10] are all leaf nodes.

 

Ancestor and Descendant

ancestors and descendants in tree data structure

An ancestor of a node refers to nodes that share a direct reverse connection between a given node and the root node; you can think of them as grand parents. In the above image we can see that nodes [6, 2, 1] are ancestors of node [11], though node [6] is technically an ancestor of node [11] it is more clear to call it a parent node.

Descendants are the same principle, but backwards. Node [11] is a descendant of nodes [6, 2, 1]. As we mentioned before, all nodes are descendants of nodes [1] aka the root nodes.

 

Subtree

Subtree

Any node in a tree that has descendants can be considered a subtree. All subtrees are descendants of the root node e.g. node [2] and it's child nodes.

 

Height Of A Tree

Height of node

The height of a tree refers to the number of nodes/edges between the root node and its last descendants or farthest leaf nodes. The height of the above tree is 3.

 

Depth Of A Node

Depth of a node

The depth of a node refers to the number of nodes/edges between a given node and the root node. In the above image, the depth of node [10] is 2.

 

Types Of Tree Data Structure

There are a lot of tree type data structures, but we are just going to look at a few.

 

General Tree

A general tree is a tree that has no restrictions on the number of child nodes a parent node can have, including the root node.

general tree

 

Binary Tree

A binary tree is a tree whose nodes can have no more than 2 child nodes per parent node including the root node. The child nodes in a binary tree are called left and right child

Binary tree

 

Binary Search Tree (BST)

A BST is a tree whose nodes are sorted when created. The nodes are sorted based on whether they are greater than or less than their parent node. Nodes greater than their parent node are placed to the right, while nodes less than are placed to the left.

binary search tree

 

if you would like to know what other tree type data structures there are check out this article.

 

Uses/Application Of Tree Data Structures

  • Trees are used in computer file systems to keep track of folder structure.

  • BST are often used in search and sorting algorithms.

  • Domain name space (DNS) uses tree data structures to manage domain names.

  • Trees are used when rendering computer graphics.

  • Dictionary applications, autocomplete and spell check use trees.

 

Trees are a very complex data structure, so if you have any questions please leave a comment and i will try my best to answer it. In the next part of this article we will look at how to create a BST in Javascript. Thank you for reading.

Part 2

see you later

beginnerscomputerscienceprogrammingwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.