1. Home
  2. Explore
  3. Computer Science
  4. Introduction to Trees

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Introduction to Trees

  • 28Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Tree Fundamentals
Tree is a
data structure, unlike linked lists which are linear.

28 questions

  1. 1
    Tree is a
    _____
    data structure, unlike linked lists which are linear.
    Hint

    Consider how nodes can connect to multiple other nodes.

    Answer

    non-linear

  2. 2
    In a binary tree, each node can have at most
    _____
    children.
    Hint

    The prefix 'bi-' indicates this number.

    Answer

    two

  3. 3
    In an n-ary tree, multiple children of a node are typically stored in a
    _____
    of type node*.
    Hint

    A dynamic array-like structure for storing multiple elements.

    Answer

    list

  4. 4
    A binary tree node contains data, a left pointer, and a
    _____
    pointer.
    Hint

    The two pointers point to the two possible children.

    Answer

    right

  5. 5
    The topmost node from which the tree originates is called the
    _____
    .
    Hint

    It is the starting point of the tree.

    Answer

    root

  6. 6
    A node directly connected below another node is called its
    _____
    .
    Hint

    It is the opposite of parent.

    Answer

    child

  7. 7
    The node above a child is called its
    _____
    .
    Hint

    It is the node that is directly connected above.

    Answer

    parent

  8. 8
    Nodes that share the same parent are called
    _____
    .
    Hint

    They are like brothers/sisters in a family tree.

    Answer

    siblings

  9. 9
    All nodes that appear above a given node on the path to the root are called its
    _____
    .
    Hint

    Think of lineage; these are the nodes before the given node.

    Answer

    ancestors

  10. 10
    All nodes that appear below a given node are called its
    _____
    .
    Hint

    Think of future generations in a family tree.

    Answer

    descendants

  11. 11
    A node with no children is called a
    _____
    node.
    Hint

    It is at the end of a branch.

    Answer

    leaf

  12. 12
    In the recursive buildTree function, a base case returns NULL when the input data equals
    _____
    .
    Hint

    This value acts as a sentinel indicating no node.

    Answer

    -1

  13. 13
    In the recursive buildTree function, after creating the root node from input data, the function recursively builds the
    _____
    subtree first.
    Hint

    The function asks for data for left insertion before right.

    Answer

    left

  14. 14
    The buildTree function returns a pointer to the
    _____
    of the tree.
    Hint

    It is the topmost node.

    Answer

    root

  15. 15
    In level order traversal, a
    _____
    is used to process nodes level by level.
    Hint

    This data structure operates in FIFO order.

    Answer

    queue

  16. 16
    In level order traversal with level separation, a
    _____
    is pushed into the queue to mark the end of a level.
    Hint

    It is a special value indicating no node.

    Answer

    NULL

  17. 17
    In inorder traversal, the order of operations is: left subtree,
    _____
    , right subtree.
    Hint

    The 'N' in LNR stands for this.

    Answer

    node

  18. 18
    In preorder traversal, the node is visited
    _____
    the left and right subtrees.
    Hint

    In NLR, the node comes first.

    Answer

    before

  19. 19
    In postorder traversal, the node is visited
    _____
    both left and right subtrees.
    Hint

    In LRN, the node comes last.

    Answer

    after

  20. 20
    The recursive implementation of inorder traversal has a base case that checks if root is
    _____
    .
    Hint

    The condition to stop recursion.

    Answer

    NULL

  21. 21
    In level order traversal, after printing a node, its left child (if exists) is pushed into the queue first, followed by its
    _____
    child.
    Hint

    The order of pushing maintains left-to-right order within the level.

    Answer

    right

  22. 22
    In buildFromLevelOrder, after creating the root node from input, we push the root onto a
    _____
    .
    Hint

    This data structure is used to process nodes in FIFO order.

    Answer

    queue

  23. 23
    In buildFromLevelOrder, for each node taken from the queue, we read data for its left child; if the data is not
    _____
    , we create a new left node and push it onto the queue.
    Hint

    This value indicates no child.

    Answer

    -1

  24. 24
    In buildFromLevelOrder, after processing the left child, we read data for the
    _____
    child.
    Hint

    The next child after left.

    Answer

    right

  25. 25
    In counting leaf nodes, a node is considered a leaf if both its left and right children are
    _____
    .
    Hint

    A leaf has no children.

    Answer

    NULL

  26. 26
    The time complexity for counting leaf nodes in a tree with nnn nodes is
    _____
    .
    Hint

    It depends on the number of nodes visited.

    Answer

    O(n)O(n)O(n)

  27. 27
    The iterative implementations of inorder, preorder, and postorder traversal use an explicit
    _____
    instead of recursion.
    Hint

    This data structure follows LIFO order and is commonly used to simulate recursion.

    Answer

    stack

  28. 28
    To implement reverse level order traversal, one common method uses a queue for level order traversal and a
    _____
    to reverse the output.
    Hint

    This data structure reverses order (LIFO).

    Answer

    stack

1 of 28
Question 1 of 28

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent