BST

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What are the characteristics of a general tree

-either empty or consists of a finite set of nodes T -node R is called the root -The set T-{r} is partitioned into disjoint subsets, each of which is a general tree

The number of nodes, N, contained in a full binary tree of height H is...

2^h +1 -1

Add the following numbers, in the order given to a binary search tree. 3,14,15,20,25,33, 62,200 Is this tree balanced? Why not? What is the execution time for searching for a value in this? What is the height of the tree?

3 14 15 20 goes down into a linear tree Not balanced. Execution time is O(n) 7

Child

A node immediately below and directly connected to a given node

Interior Node

A node that has at least one child

Descendant

A node's children, its children's children, and so on, down to the leaves

Ancestor

A node's parent, its paren'ts parent, and so on, up to the root

In an expression tree, each leaf node represents what?

A numeric operand

why does the shape of a binary tree matter?

A vine-like tree would be a more expensive path if you are looking for a node and had to go through each node

What are the 3 common applications of binary trees

Heaps, binary search trees, expression trees

Is implementing a preorder better externally or internally?

Interally because you very rarely want to just traverse the tree, in most cases you want to accomplish something else.

Siblings

The children of a common parent

Height

The length of the longest path in the tree -the maximum level number among leaves in the tree

Edge/Branch/Link

The line that connects a parent to its child

Postorder Traversal

Traverses left subtree, traverse right subtree, and visit root node -LRP

Inorder traversal

Traverses left subtree, visits root node, and traverses right subtree -LPR

Children are viewed from left to right. True or False?

True

Preoder traversal

Visits root node, and then traverses left subtree and right subtree In similar way -PLR

Are traversals written recursively?

Yes

Can you move subtrees (entire sections of a tree) to a different position in the tree without affecting the lower levels of the hierarchy?

Yes

What is the height of a tree containing one node

Zero

A tree has the following properties..

-One node of the tree is designated as the root node. -Every node n, except the root node, is connected by an edge from exactly one other node p, where p is the parent of n -A unique path traverses from the root to each node -If each node in the tree has a maximum of two children, it is a binary tree

Why use a tree?

-Parse tree -used for decision making -can support logarithmic searches and insertions -

Different shapes of binary trees

-Unbalanced -Perfectly balanced -Complete -Full

Heap property

constraint on the order of nodes

Operands of higher precedence usually appear near....

the bottom of the tree, unless override in source expression by parentheses

What is the root depth or level

the root is 0

In a binary tree, each node has at most...

two children, left and right child

What is the height of an empty tree

-1

Level order traversal

Beginning with level 0, visits the nodes at each level in left-to-right order

Heap sort

builds a head from data and repeatedly removes the root item and adds it to the end of a list

In worst case shape of a binary tree, they become

linear and support linear searches

Max heap-

places larger nodes nearer to the root

Add the following numbers in the order given to a binary search tree. 45,67,22,100,75,12,11,64,30 What is the height of the tree from number 1? What is the height of the subtree rooted at the node holding the value 22? If you remove 67, what would replace it?

45 22 67 13 30 | 64 100 11 75 height=3, starts from 0 Height of subtree holding the value 22= 2 64 would replace 67 because it is the largest subtree node of 67

Create a binary search tree and insert the following elements in the following order: 8,10,3,5,7,9,1,2,0 What is the depth? How many leaves? Give the preorder traversal of this tree? Give the inorder traversal of this tree Give the post order traversal of this tree.

8 3 \ 10 1/ \ 5 9/ 0/ \2 \ 7 depth=3 leaves=4 preorder=8,3,1,0,2,5,7,10,9 inorder=0,1,2,3,5,7,8,9,10 postorder=0,2,1,7,5,3,9,10,8

Parent

A node immediately above and directly connected to a given node. A node can have only one parent

Can an expression tree be empty?

An expression tree is NEVER empty

Node

An item stored in a tree

Expression Tree is..

Another way to process expressions to build a parse tree during parsing

What is a parse tree

Describes the syntactic structure of a particular sentence in terms of its component parts

What are the 2 main characteristics of trees?

Each item can have multiple children -except for root, root has exactly one parent

Definition of a binary tree

Either empty or consists of a root plus a left subtree and a right subtree, each of which are binary tress

A binary tree can have more than two children coming off of it

False

is a file system structure a binary tree or general tree

General tree because it has more than 2 children per node

When to use inorder traversal

Good for visiting items in a BST sorted order

What is a node that has no children?

Leaf

What is the leftmost and rightmost child called?

Leftmost=first rightmost= last child

A bst imposes a sorted ordering on its nodes. Nodes in left subtree of a node are _ node Nodes in right subtree of a node are _ node

Nodes in left subtree of a node are < node Nodes in right subtree of a node are > node

When shape approaches that of a perfectly balanced binary tree, searches and insertions are ____ in the worst case

O( log n)

The max amount of work that it takes to access a given node in a full binary tree is..

O(log N)

Where are trees used in computer science?

Operating systems, graphics, database systems, and computer networkin

What are the 4 standard types of traversals for binary trees

Preorder, inorder, postorder, level order

With every traversal, where do we start?

Root node

Path length

The number of edges in a path

Path

The sequence of edges that connect a node and one of its descendants

Root

The topmost node in a tree. It is the only node without a parent

Subtree

The tree formed by considering a node and all its descendants

Min heap-

each node is <= to both of its children

Depth or level

equals the length of the path connecting it to the root.

The height, H, of a full binary tree with N nodes is..

log v2 (N +1) -1

A BST imposes a special ordering on the nodes in a binary tree, so as to support___

logarithmic searches and insertions

A node can have how many children..

multiple

In a tree, the ideas of predecessor and successor are replaced with those of ___ and ___

parent and child

A node can have additional information called...

payload

Heaps are also used to implement...

priority queues

In an expression tree, an interior node represents a ______ _____, consisting of an _____

represents a compound expression, consisting of an operator and its operands


संबंधित स्टडी सेट्स

Health Assessment Chapter 15 Ears

View Set

Lewis Ch. 51 & 52 STIs, Breast Disorders

View Set

basic techniques in microbiology final

View Set

Slope Intercept Form Graphing, Slope-Intercept, Slope

View Set

AP Psychology Unit 12 Extra Definitions

View Set

Combo with AP Chem 1984 MC and 4 others

View Set

Chapter 18: The International Financial System

View Set