Data Stucture
Data Stucture
3. Explain String.
A string is a sequence of characters stored in a contiguous memory location. strings are
treated as an array of characters with additional functionalities like concatenation,
slicing, and searching.
Example: Initialize a head node with NULL values for prev and next.
Insertion:
• At the Beginning: Create a new node, set its next to point to the current head, and update the
head's prev to point to the new node.
• At the End: Traverse to the last node, create a new node, set the last node's next to the new
node, and the new node's prev to the last node.
• In the Middle: Traverse to the desired position, update pointers of adjacent nodes, and link the
new node.
• Deletion:
• From the Beginning: Update the head to point to the next node and set the new head's prev to
NULL.
• From the End: Traverse to the last node, update the second-last node's next to NULL, and free
the last node.
• From the Middle: Adjust the prev and next pointers of adjacent nodes to bypass the node to
be deleted, and then free the node.
Tree traversal is the process of visiting all nodes in a tree in a systematic order. The common
techniques are: Depth-First Traversals
Traverse nodes level by level from top to bottom, left to right.Implemented using a queue.