BINARY TREES Flashcards

1
Q

Define and illustrate a tree

A

•A tree (in data structure terms)
is defined as a structure in which a set of nodes are connected together by their edges, in a parent-child relationship.

*See notes for pic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the different applications of tree structures

A
  • Databases
  • File systems
  • Web sites
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the characteristics of trees

A

• Consists of nodes connected by edges.
• Edges between the nodes represent the way the nodes are
related.
• The only way to get from node to node is to follow a path
along the edges.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a rooted tree

A

•A rooted tree is one where there is one distinguished node called the root, and every other node is connected to only one parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is binary tree?

A

•A binary tree is one in which each node has at most two children, each called the left and right child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the following terminologies: path root and parent

A

• Path: Traversal from node to node along the edges results in a
sequence called path.
• Root: Node at the top of the tree.
• Parent: Any node, except root has exactly one edge running
upward to another node. The node above it is called parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the following terminologies: child, lead and subtree

A

• Child: Any node may have one or more lines running
downward to other nodes. Nodes below are children.
• Leaf: A node that has no children.
• Subtree: A subtree of a tree, rooted at a particular node, is a tree consisting of that node and all its descendants.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the following terminologies: external, internal node, siblings, ancestor and descendant

A

• Nodes with the same parent are called siblings
• An external (leaf, or terminal) node has no children
• An internal (non-terminal) node has one or more children
• If there is a path from node A to node B, then A is an ancestor of B, and B is a
descendant of A.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Describe the following terminologies: visiting, traversing, levels and keys

A

• Visiting: A node is visited when program control arrives at the
node, usually for processing.
• Traversing: To traverse a tree means to visit all the nodes in
some specified order.
• Levels: The level of a particular node refers to how many
generations the node is from the root. Root is assumed to be
level 0.
• Keys: Key value is used to search for the item or perform
other operations on it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the depth height and size of a tree

A

• The depth of a node is the length of the path from the root to the node (The root has a depth of 0.)
• The height of a node is the length of the path from the node to the deepest leaf.
• The size of a node is the number of
nodes in the subtree rooted at that node (including itself.)

*See notes for illustration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between a general tree and a binary tree

A

• A general tree is a data structure in that each node can
have infinite number of children.
• Every node in a binary tree can have at most two
children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Define a balanced binary/AVL tree

A

A binary tree is balanced if and only if, for every node, the height of its left and right subtree differ by at most 1.

*See notes for illustration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define a binary search tree

A

This is a binary tree in which the left child is always less

that its parent, while right child is greater than its parent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two ways of representing trees

A

1.Linked list
• Similar to Linked List but with two Links
• Store the nodes at unrelated locations in memory and
connect them using references in each node that point to its
children.

2.Arrays
• Can also be represented as an array, with nodes in specific
positions stored in corresponding positions in the array.

*See notes for illustrations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are different ways to traverse a tree

A

– Inordertraversal: Left subtree, Node, Right subtree
– Preordertraversal: Node, Left subtree, Right subtree
– Postordertraversal: Left subtree, Right subtree, Node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Using relevant examples, distinguish between linear and non-linear data structures

A

In a linear data structure, data elements are arranged in a linear order where each and every element is attached to its previous and next adjacent eg arrays stacks and queues while in a non-linear data structure, data elements are attached in hierarchically manner eg
trees and graphs.

17
Q

Write the different algorithms for the different traversals

A

*See EDNAH CHAT for link

18
Q

Discuss any application of binary search trees in real life programming.

A

BSTs are used for indexing and multi-level indexing.
They are also helpful to implement various searching algorithms.
It is helpful in maintaining a sorted stream of data.
TreeMap and TreeSet data structures are internally implemented using self-balancing BSTs

19
Q

List and explain any three applications of the tree data structure in computing technology.

A

Store hierarchical data, like folder structure, organization structure, XML/HTML data.
Binary Search Tree is a tree that allows fast search, insert, delete on a sorted data. It also allows finding closest item
Heap is a tree data structure which is implemented using arrays and used to implement priority queues

20
Q

Discuss how space and time is understood and studied in computing in relation to algorithms

A

Space complexity :

Space complexity is defined as the process of determining a formula for the production of how much memory space will be required for the successful execution of an algorithm. The memory space we consider is the space of primary memory.

Time complexity :

The time complexity is defined as the process of determining a formula for total time required towards the execution of that algorithm. This calculation will be independent of implementation details and programming language.