Final Exam Answer Key

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Answer key

Part I:
1. A
2. D
3. C
4. C
5. D
6. A
7. D
8. B
9. B
10. C

Part II
1.
Binary Tree:
A binary tree is a hierarchical data structure where each node can have at
most two children, the left and right child.
There are no specific rules or constraints regarding the arrangement of
elements in a binary tree. Nodes can be arranged in any order, and the tree
can represent any arbitrary relationship between elements.
Binary trees are used for various purposes, including hierarchical data
representation, expression trees, and more.
Binary Search Tree (BST):
A binary search tree is a specific type of binary tree where the elements are
organized in a particular order that allows for efficient searching, insertion, and
deletion operations.
In a binary search tree, for any node:
The values in the left subtree are less than the value of the node.
The values in the right subtree are greater than the value of the node.
This ordering property of a binary search tree ensures that the elements are
arranged in a sorted manner, making it easier to perform binary search
operations.
Binary search trees are commonly used in applications where efficient
searching is crucial, such as in databases, symbol tables, and certain
algorithms like binary search.
2. Handl by yourself
3. Handl by yourself
4. ABCD-*+E/
5. a) 3
b) 1
c) 3
d)
inorder-> 5 10 12 20 22 25 28 30 36 38 40 48
Preorder -> 25 20 10 5 12 22 36 30 28 40 38 48
postorder-> 5 12 10 22 20 28 30 38 48 40 36 25

Part III
1. Check the attached image
2. Check the attached image
3. Check the attached image
4.
A)
. Initialize distances:
- A=0, B=∞, C=∞, D=∞, E=∞, F=∞, G=∞, H=∞

Start with vertex A; Adjacent vertices are B and C.


- Update distances: B (2), C (5)

Choose the next smallest distance; Vertex B with distance 2; Adjacent vertices are C
and D.
- Update distances: C (5), D (10)

Choose the next smallest distance; Vertex C with distance 5; Adjacent vertices are D
and G.
- Update distances: D (10), G (9)

Choose the next smallest distance; Vertex G with distance 9; Adjacent vertices are F
and H.
- Update distances: F (13), H (17)
Choose the next smallest distance; Vertex F with a distance of 13. No adjacent
unvisited vertices.

Choose the next smallest distance; Vertex D with a distance of 11. The adjacent
vertex is E.
- Update distances: E(10)
Choose the next smallest distance; Vertex E with a distance of 16. No adjacent
unvisited vertices.

Final shortest paths from A:


- A to B = 2
- A to C = 5
- A to D = 11
- A to E = 13
- A to F = 13
- A to G = 9
- A to H =17

B)

The lowest-cost path from vertex A to H in the given graph, as computed using
Dijkstra’s algorithm, is as follows:

1. Start at vertex A.
2. Move to vertex B (cost 2).
3. Move to vertex D (cost 10).
4. Move to vertex E (cost 13).
5. Move to vertex H (cost 17).

Therefore, the total cost of the path from A to H is 17 units.

You might also like