Relational Data Structures - Week 4

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/21

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.

22 Terms

1
New cards
<p>For this graph, show the adjacency matrix. And how would this be different if it was weighted?</p>

For this graph, show the adjacency matrix. And how would this be different if it was weighted?

If weighted, the 1s would be changed to the weight.

<p>If weighted, the 1s would be changed to the weight.</p>
2
New cards
<p>For this graph, give the adjacency list and edge list.</p>

For this graph, give the adjacency list and edge list.

knowt flashcard image
3
New cards

If a graph is undirected, how does this alter the edge list?

Only list the pairs once.

4
New cards

What is a tree?

A graph with no loops. It has vertices and edges.

5
New cards

What is the weight of the graph?

The length of the path back to the root.

6
New cards

What is a subtree?

Any collection of vertices and
edges from the tree which remains a tree.

7
New cards

Parial orders and total orders in trees. How are they defined?

Vertex orders are defined using the height.

A =< B because height(A) =< height(B).

This is only a partial order; doesn’t allow comparisons at the same level.

To get a total order, we must arbitrarily define the order of the children of a vertex.

8
New cards

What does a partial order mean about a tree and what does a total order allow?

Partial order means it is not linear.

Total order allows to sort the vertices of a tree.

9
New cards

How many edges does a tree have?

A tree with n vertices has n-1 edges.

10
New cards

Prove a tree with n vertices has n-1 edges.

→ Every edge joins a parent to 1 child. Take the edge joining parent to child and associate with the child.

→ Each vertex, except the root, has exactly one edge associated, hence n-1 edges.

11
New cards

What is the size of data for a tree?

O(1)

12
New cards

Why is an adjacency matrix not used for trees?

Highly redundant, has size O(n²)

13
New cards

What is a binary tree?

A tree where each vertex has at most 2 children.

14
New cards

What representation is used in binary trees?

Array.
At each level k, at most 2k vertices. Requires array size: 2h+1-1

15
New cards
<p>What is the adjacency list for this tree?</p>

What is the adjacency list for this tree?

A(B,C,D)
B(E,F)
C(G)
D()
E()
F()
G()

16
New cards

What is the purpose of a heap?

In some problems, we have data where the ordering ‘=<' represents a priority. The highest priority item is the minimum in regards to (w.r.t) =<.

We would like to represent this data in an efficient data structure that allows us to recover the minimum item and insert new data.

This is the purpose of a heap.

17
New cards

How can heaps be defined as binary trees?

→ It is complete - every level is full, except for (possibly) the last one. Items on the last row are left justified.

→ Each vertex represents 1 item of data.

→ The value on a vertex is no more than that of any of its descendants.

→ Therefore, any subtree is also a heap.

18
New cards

Properties of binary heaps

Since the tree is binary and complete, we represent it efficiently with an array with 2h+1-1, with h = O(log2n) number of items.

The root is the smallest element and can be found in O(1) time.

A new item is inserted in the next position in the final row, done in O(1) time.

19
New cards
<p>Show the steps to insert the number ‘4’ into a tree with a binary heap property.</p>

Show the steps to insert the number ‘4’ into a tree with a binary heap property.

knowt flashcard image
20
New cards
<p>Show the steps to extract the minimum vertex in this binary tree with a heap function.</p>

Show the steps to extract the minimum vertex in this binary tree with a heap function.

knowt flashcard image
21
New cards

What are the steps to perform a heap sort on an unsorted array O(n)

  1. Build a heap from unsorted array O(n)
    → Convert unsorted array into a binary tree.
    → Convert tree to binary (max) heap.

  2. Sorting:
    → Swap root elements with last element. It will be ordered and not considered further.
    → Rebuild heap for remaining.
    → Repeat a and b until the heap is of size 1.
    → Array is sorted.

22
New cards
<p>Show the performing of a heap sort on this unsorted array: </p>

Show the performing of a heap sort on this unsorted array:

knowt flashcard image