Posts

Showing posts from November, 2025

Doubly linked list

Image
Aim: To implement a Doubly Linked List (DLL) and perform operations like creation, insertion, deletion, and display. Objectives: Understand the concept of a doubly linked list. Perform dynamic memory allocation for nodes. Implement insertion at the beginning, end, and at a given position. Implement deletion from the beginning, end, and specific position. Traverse and display the list in forward direction. Algorithm: 1. Create Node: Allocate memory using malloc. Assign data. Set prev and next pointers. 2. Insert: At beginning: Adjust prev and next pointers. At end: Traverse to last node and insert. At position: Traverse to that position and insert node. 3. Delete: Beginning: Update head pointer. End: Update last node’s pointer. Specific position: Adjust pointers of neighbors. 4. Display: Traverse from head to end. Print each node’s data. Flowchart: C Program (Doubly Linked List Implementation) #include <stdio.h> #include <stdlib.h> struct Node {     i...

Graph using adjacency Matrix with BFS and DFS traversals.

Image
  Aim To implement a Graph using Adjacency Matrix and perform Breadth First Search (BFS) and Depth First Search (DFS) traversals. Objective Represent a graph using Adjacency Matrix . Perform BFS traversal using a queue . Perform DFS traversal using recursion (stack concept) . Understand the difference between BFS and DFS in exploring nodes. Algorithm 1. Graph Representation Start Initialize adj[n][n] to 0 (no edges). For each edge (u, v), set adj[u][v] = 1 and adj[v][u] = 1 (for undirected graph). End. 2. BFS Traversal Start Mark the starting vertex as visited and insert into queue. Repeat until queue is empty: Dequeue a vertex u and print it. For each adjacent vertex v of u, if not visited, mark visited and enqueue it. End. 3. DFS Traversal Start Mark the current vertex as visited and print it. For each adjacent vertex v of current node: If v is not visited, recursively call DFS on v. End. Flowchart C Program: Graph using Adjacency Matrix with BFS and DFS #include <stdio....