CMSC 256 Test 3 Comprehensive Study Guide on Sorting Algorithms and Tree Traversal

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

Root

In a tree, the topmost node of the tree. All other nodes in the tree are descendants

2
New cards

Leaf

In a binary tree, it is any node that has two empty children.

In general tree, any node can be this if it has no children

3
New cards

Parent

In a tree, the node P that directly links to a node A.

4
New cards

Child

In a tree, the set of nodes directly pointed to by a node R

5
New cards

Internal node(or inner node)

In a tree, any node that has at least one non-empty child

6
New cards

Siblings

Any other node with the same parent as a node A

7
New cards

Descendant

All of the nodes that can be reached from a node A by progressing downwards in tree

8
New cards

Subtree

Subset of the nodes of a binary tree that includes some node R of the tree as the root along with all the descendants of R

9
New cards

Height

One more than the depth of the deepest node in the tree

10
New cards

Bubble sort implementation/how it works

-need an array w/values to sort

-Inner for loop moves from left to right comparing adjacent elements

-Highest one placed at rightmost end

-Repeats process until data is sorted

11
New cards

Selection sort implementation/how it works

-finds the largest element in an unsorted list, then next largest, and so on

-goes from left to right through entire unsorted portion of array

-only one swap is required to put element into place

12
New cards

Insertion sort implementation/how it works

13
New cards

Bubble Sort BigO

Best efficiency: O(n)

Average efficiency: O(n^2)

Worst efficiency: O(n^2)

14
New cards

Selection sort BigO

Best efficiency: O(n^2)

Average efficiency: O(n^2)

Worst efficiency: O(n^2)

15
New cards

Insertion sort BigO

Best efficiency: O(n)

Average efficiency: O(n^2)

Worst efficiency: O(n^2)

16
New cards

Worst case for comparisons total in selection sort

n^2/2

17
New cards

When is selection sort a good choice to use for sorting an array?

When the cost of a swap is large, such as when the records are long

18
New cards

Total # of swaps required in selection sort

n-1

19
New cards

T or F

Insertion Sort is a stable sorting algorithm. Recall that a stable sorting algorithm maintains the relative order of records with equal keys.

True

20
New cards

Depth

The length of the path from root of the tree to node M

21
New cards

Preorder traversal

Root, left child, right child

22
New cards

Post-order traversal

Left child, right child, root

23
New cards

Inorder traversal

Left child, root, right child

24
New cards

Level order traversal

Process all nodes of a tree by depth: first the root, then the children of the root, etc.

25
New cards

How would you change the implementation of a binary heap(min heap) to be a max heap?

Change comparisons

26
New cards

General tree

A tree in which any given node can have any number of children. Tend to be harder to implement due to this reason

27
New cards

Binary tree

A tree with a finite set of nodes which is either empty, or else has a root node together of left and right subtree which are disjoint from each other and the root

28
New cards

General tree properties

Single parent: has precisely one parent except for the root which has no parent