Data Structures Exam 3

Ace your homework & exams now with Quizwiz!

How do you conduct Breadth - First Search (BFS) for graphs?

*BFS finds the shortest path from s to each vertex (in terms of number of edges) 1. Choose a starting vertex 2. Search all adjacent vertices 3. Return to each adjacent vertex in turn and visit all of its adjacent vertices

What does an adjacency matrix look like?

*if need to review, look at graphs slide 15

Considerations when encoding?

- Frequency of character use

What are graphs?

- Generalized trees - There is typically no limitation on the number of vertices or edges

What is the format for storing values in a BST?

- Values stored in the left subtree of a given node are less than the value stored in that node - Values stored in the right subtree of a given node are greater than the value stored in that node

Drawbacks of implementing binary tree arrays?

- You have to keep track of the locations of each node - Deletions are difficult

What is depth first search?

1. Choose a starting vertex 2. Do a depth-first traversal on each adjacent vertex * for pseudocode, you need to create a variable to keep track of which vertex's have been visited, because once they are visited DFS no longer needs to be performed on them

What is the algorithm for locating a specific value in a binary tree?

1. For each node, compare the value to the target value; if they match the search is done 2. If the target is smaller, we branch to the left subtree; if larger, we branch to the right 3. If at any point we cannot proceed further, then the search has failed and the target isn't in the tree

What is Dijkstra's algorithm?

1. Have a set of visited vertices that is initially empty 2. Set a queue that initially contains all vertices 3. While the queue is not empty, select the element of Q with the min. distance 4. Add u to the list of visited vertices 5. IF new shortest path found, set new value of shortest path

What is depth first traversal?

1. Proceeds by following left-hand or right-hand branches as far as possible 2. The backtracking to the most recent fork and takes the right-hand or left-hand branch to the next node 3. It then follows branches to the left (or right) again as far as possible 4. This process continues until all nodes have been visited

What is a complete binary tree?

A binary tree in which every level, except possibly the last, is completely filled and all nodes are as far left as possible

What is a perfect binary tree?

A full binary tree in which all leaves have the same depth or same level

What is a cycle in a graph? What is the difference between cyclic and acyclic?

A path of length 1 or more that begins and ends at the same node Acyclic - no cycles Cyclic - graph has one or more cycles

For graphs, what is a path?

A sequence of vertices with each adjacent pair connected by an edge. If graph is directed edges must be aligned with direction of path

What is a full binary tree? (also known as a proper binary tree or strictly binary tree)

A tree in which every node other than the leaves has two children

What is a binary tree?

A tree where each node has at most two children, designated as the left child and the right child (these children can be empty)

Time complexity for highly unbalanced or elongated trees that resemble linear linked lists?

Approaches sequential search time O(n)

What does a weighted graph do?

Assigns a value to each edge based on the application (for ex. - distance between cities)

How much time is needed to answer if there is an edge between vertex u and v? What is the memory required?

O(1) O(|V|^2)

General rule for the time complexity for searching in a binary tree?

O(log n) - the length of the path plus 1

Time complexity of decoding ABRACADABRA?

O(n)

Huffman time complexity if symbols are already sorted by frequency? Otherwise?

O(n) O(nlogn)

For an adjacency list, what is the time complexity? What is the storage needed?

O(n) O(|V| + |E|)

What is the time complexity for BFS for graphs?

O(|V| + |E|)

What is the time complexity for DFS for graphs?

O(|V| + |E|)

How much storage does the adjacency matrix require? What is the adjacency of an undirected graph?

O(|V|^2) Symmetric.

What is a complete graph?

One that has exactly one edge between each pair of vertices Denoted by Kn

What is breadth first traversal?

Proceeding level-by-level from top-down or bottom-up visiting each level's nodes left-to-right or right-to-left (easily implemented using a queue)

What is a node's level?

The length of the path to that node, plus 1

For trees, what is the path's length?

The number of arcs in the path

For a directed graph, What is out-degree?

The number of edges directed away from vertex

For a directed graph, What is in-degree?

The number of edges directed toward vertex

For graphs, What is the length of a path?

The number of edges in the path

What is the height of a node?

The number of edges on the longest downward path between the node and a leaf

What is the cardinality of V?

The number of vertices called the order of graph and devoted by |V|

What is tree traversal?

The process of visiting each node in a tree data structure exactly one time

What is the cardinality of E?

The size of graph Denoted by |E|

What are the 6 possible depth-first traversal arrangements? And what is the general rule of traversing?

VLR, VRL, LVR, LRV, RVL, and RLV Traverse left to right - which narrows this down to three traversals: VLR (preorder), LVR (inorder), and LRV (postorder)

What is the maximum number of edges in a directed graph?

|E| = O(|V|^2)

What is the maximum number of edges in an undirected graph?

|E| = O(|V|^2)


Related study sets

Chapter One: The Human Body: An Orientation Quiz

View Set

Search and Display Marketing MKTG 2220

View Set

The eye and ears mastering for test

View Set

Chp 4 - Contract of sales & leases

View Set