DSA PPT
DSA PPT
2
Representation of Linked Lists
Linked lists are represented using nodes with two fields: data and a pointer
to the next node. The last node points to null, indicating the end of the list.
This structure allows for dynamic memory allocation and efficient insertion
and deletion operations.
Types of Linked
Lists
● Single Linked List
● Doubly Linked List
● Circular Linked List
4
Single Linked List
In a doubly linked list, each node contains two pointers: one to the next
node and one to the previous node. This facilitates bidirectional traversal,
enabling efficient operations such as insertion and deletion at both ends of
the list.
Circular Linked List
A circular linked list is a variation where the last node points back to the first
node, forming a loop. This structure is useful for applications requiring
continuous data access, such as round-robin scheduling and circular buffers.
It is of two types:
->Circular Singly Linked List
->Circular Doubly Linked List
Applications of Linked Lists
● Applications that have an MRU list ( a linked list of file
names)
● The cache in the browser that allows you to hit the BACK
button ( a linked list of URLs)
10
Tree
Terminologies
● Node : Fundamental unit of a tree that holds
data.
● Root : The topmost node in a tree, from which all
other nodes descend.
● Parent : A node that has child nodes connected
below it.
● Child : Nodes directly connected to another
node when moving away from the root.
● Leaf (External Node) : A node that has no
children.
● Internal Node : A node that has at least one
child.
● Depth : The level of a node in the tree relative to ● Subtree : A tree formed by a node
the root. Root has depth 0. and all its descendants.
● Height : The maximum depth of any node in the
11
tree.
Representation of Trees
● Array Representation :
.->Parent and child relationships are
defined by index calculations.
->Efficient for complete binary trees..
● Linked Representation :
->Each node stores data and
pointers/references to its children.
->Suitable for dynamic allocation
of memory and flexible tree structures.
Tree Traversals
● Depth-First Traversals :
Preorder Traversal:
Visit the root node first.
Recursively visit the left subtree.
Recursively visit the right subtree.
Inorder Traversal:
Recursively visit the left subtree.
Visit the root node. ● Breadth-First Traversal (Level-
Recursively visit the right subtree.
Order):
Postorder Traversal: Visit nodes level by level from left to
Recursively visit the left subtree. right.
Recursively visit the right subtree. Uses a queue to maintain the current
Visit the root node last. level of nodes.
Applications of Trees
1. Binary Search Trees (BST):
Efficient for searching, insertion, and deletion operations.
Used in databases, symbol tables, and dynamic sets.
2. Expression Trees:
Represent mathematical expressions for evaluation.
Used in compilers, calculators, and symbolic algebra.
3. Trie (Prefix Tree):
Store and retrieve strings efficiently.
Used in autocomplete features and dictionary implementations.
4. Huffman Trees:
Data compression through Huffman coding.
Used in file compression algorithms (e.g., ZIP files).
5. Decision Trees:
Represent decisions and their consequences.
Used in decision-making processes and
14 machine learning
algorithms.
ThankYou
Do you have any questions?
Tejaswi Pannala