Data Structures and Algorithms in Java

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/27

flashcard set

Earn XP

Description and Tags

Flashcards about Trees, Binary Trees, and Binary Search Trees

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

What is a Tree in computer science?

An abstract model of a hierarchical structure consisting of nodes with a parent-child relation.

2
New cards

What is the Root of a tree?

Unique node without a parent.

3
New cards

What is an Internal node?

Node with at least one child.

4
New cards

What is an External (leaf) node?

Node without children.

5
New cards

What are Ancestors of a node?

Parent, grandparent, great-grandparent, etc.

6
New cards

What are Descendants of a node?

Child, grandchild, great-grandchild, etc.

7
New cards

What is the Level of a node?

The level of the root is 1. If a father has level i then its children has level i+1.

8
New cards

What is the Height of a tree?

Maximum level in a tree. A single node is a tree of height 1. The height of an empty tree is 0.

9
New cards

What is the Degree (order) of a node?

Number of its non-empty children.

10
New cards

What is a Path in a tree?

Each node has to be reachable from the root through a unique sequence of arcs (edges).

11
New cards

What is Tree traversal?

Visiting each node in the tree exactly one time.

12
New cards

What happens during a Pre-order Traversal?

Visit a node before its descendants.

13
New cards

What happens during a Postorder Traversal?

Visit a node after its descendants.

14
New cards

What happens during a Breadth-first Traversal?

Visit a node first, then all its children, then all its grandchildren,…

15
New cards

What is a Binary tree?

A tree in which each node has at most two children.

16
New cards

What is a Proper binary tree?

Every node other than the leaves has two children.

17
New cards

What is a Complete Binary Tree?

All non-terminal nodes have both their children, and all leaves are at the same level.

18
New cards

What is Breadth-first traversal?

Visiting each node starting from the lowest (or highest) level and moving down (or up) level by level, visiting nodes on each level from left to right (or from right to left)

19
New cards

What is Pre-order (NLR)?

Node, Left, Right

20
New cards

What is In-order (LNR)?

Left, Node, Right

21
New cards

What is Post-order (LRN)?

Left, Right, Node

22
New cards

Inorder sequence example

D B E A F C

23
New cards

Preorder sequence example

A B D E C F

24
New cards

How can Binary trees be implemented?

Implemented as arrays or as linked structures.

25
New cards

What are the properties of a Binary Search Tree (BST)?

The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees.

26
New cards

What are the three cases of deleting a node from the binary search tree?

The node is a leaf; it has no children. The node has one child. The node has two children.

27
New cards

What is Deleting by merging?

Making one tree out of the two subtrees of the node and then attaching it to the node’s parent

28
New cards

What is Deletion by Copying?

Replace the key being deleted with its immediate predecessor (or successor)