The document covers various data structures and algorithms, including the concepts of indegree and outdegree in graphs, AVL trees, binary search trees, and minimum spanning trees using Kruskal's algorithm. It also discusses hash tables with linear and quadratic probing, tree vs. graph structures, and the differences between B and B+ trees. Additionally, it explains traversal methods for trees and Dijkstra's algorithm for finding the shortest path in graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views1 page
Dsa Edit 2
The document covers various data structures and algorithms, including the concepts of indegree and outdegree in graphs, AVL trees, binary search trees, and minimum spanning trees using Kruskal's algorithm. It also discusses hash tables with linear and quadratic probing, tree vs. graph structures, and the differences between B and B+ trees. Additionally, it explains traversal methods for trees and Dijkstra's algorithm for finding the shortest path in graphs.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
1. Indegree and Outdegree of Each Vertex (given 9.
Operations on AVL Tree:
adjacency matrix): Insertion: Insert a node and rebalance. Indegree is the number of incoming edges to a Deletion: Remove a node and rebalance. vertex. Rotations: Left and right rotations to maintain Outdegree is the number of outgoing edges from balance. a vertex. 11. Construct AVL Tree for Data (70, 50, 30, For an adjacency matrix, you calculate the 90, 80, 130, 120): indegree and outdegree for each vertex by Insertion happens as in a standard BST, counting the occurrences of 1s in the followed by rotations to ensure balance: corresponding row (outdegree) and column Insert 70 (root). (indegree). Insert 50 (left of 70). Insert 30 (left of 50). 2. Store Values in Hash Table (Linear Probing): Insert 90 (right of 70). Division method of hashing uses hash = key % Insert 80 (left of 90). table_size. Insert 130 (right of 90). For keys = {13, 45, 24, 113, 161, 207, 211}, and Insert 120 (left of 130). table size 11, you apply linear probing to handle collisions. 12. Minimum Spanning Tree using Kruskal's For example, 13 % 11 = 2, so 13 is stored at Algorithm: index 2. Kruskal's Algorithm: Greedy algorithm that finds If a collision occurs, move to the next available the MST by sorting edges in increasing order slot. of weights and adding edges to the MST, 3. Steps to Create a Binary Search Tree: avoiding cycles. Insert elements into the BST: 13. Preorder, Inorder, and Postorder Traversal: Insert 15 (root). Preorder: Visit root, then left subtree, then Insert 30 (goes to the right of 15). right subtree. Insert 20 (goes to the left of 30). Inorder: Visit left subtree, then root, then right Insert 5 (goes to the left of 15). subtree. Insert 10 (goes to the right of 5). Postorder: Visit left subtree, then right subtree, Insert 2 (goes to the left of 5). then root. Insert 7 (goes to the right of 5). 14. Shortest Distance using Dijkstra’s 4. Complete Binary Tree: Algorithm:Dijkstra’s Algorithm is a greedy A Complete Binary Tree is a binary tree where all algorithm for finding the shortest path from a levels are fully filled except possibly the last level, source vertex to all other vertices in a graph and all nodes are as far left as possible. with non-negative weights. 1 15. Hash Table (Quadratic Probing): / \ Quadratic Probing resolves collisions by 2 3 checking at positions (index + i^2) % table_size /\ / for i = 1, 2, 3, .... 4 5 6 16. Two Representations of a Tree: 5. Compare Tree and Graph Data Structures: Static Representation: Tree:Hierarchical structure. Uses an array or matrix. Each node has exactly one parent, except the root. Example: In a binary tree, the parent-child No cycles (acyclic). relationships are calculated using array indices. Graph:Non-hierarchical structure. Advantage: Simple to implement. A node can have multiple parents. Disadvantage: Not memory-efficient for sparse Can have cycles (cyclic). trees. Edges can be directed or undirected. Dynamic Representation: 6. Weighted Undirected Graph and Adjacency List: Uses pointers or references (linked nodes). For an undirected graph, an adjacency list stores Each node stores data and pointers to its each vertex and its connected vertices (along with children. edge weights if weighted). Advantage: More flexible and memory-efficient. Example (Adjacency List for a graph with vertices 1 Disadvantage: Slight overhead due to , 2, 3):1: [(2, 4), (3, 5)] 17. Difference between B and B+ Trees: 2: [(1, 4), (3, 3)] B Tree: Internal nodes store keys and data, 3: [(1, 5), (2, 3)] with a variable number of children per node. 8. Close Addressing Concept in Hash Tables: B+ Tree: Internal nodes store keys only, and all data Close addressing (separate chaining) resolves is stored in leaf nodes, which are linked collisions by storing multiple elements that hash in a sequential order to the same index in a linked list or another data B Tree: Stores data in both internal and leaf nodes.B+ Tree: Stores data only in leaf nodes, and structure at that index. leaf nodes are linked in a sequential order.