Skip to content

Commit 36d92b3

Browse files
Added Data Structure & Algorithm in C-Programming πŸ‘¨β€πŸ’»
1 parent e4dc920 commit 36d92b3

File tree

3 files changed

+182
-0
lines changed

3 files changed

+182
-0
lines changed

β€ŽLICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2022] [Mahendra]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

β€ŽREADME.md

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Data Structures and Algorithms in C Programming
2+
3+
Welcome to the Data Structures and Algorithms in C Programming repository! This repository contains implementations of various data structures and algorithms in the C programming language. Whether you're learning about fundamental data structures or exploring advanced algorithms, you'll find practical examples and explanations here...
4+
5+
## Quick Access
6+
7+
1. [Circular Linked List](./CIRCULAR-LINKED-LIST)
8+
2. [Doubly Linked List](./DOUBLY-LINKED-LIST)
9+
3. [Graph](./GRAPH)
10+
4. [Linked List](./LINKED-LIST)
11+
5. [List](./LIST)
12+
6. [Queue](./QUEUE)
13+
7. [Recursion](./RECURSION)
14+
8. [Searching](./SEARCHING)
15+
9. [Sorting](./SORTING)
16+
10. [Stack](./STACK)
17+
11. [Tree](./TREE)
18+
12. [DSA Learning Resources](./DSA-LEARNING-RESOURCES)
19+
20+
## Table of Contents
21+
22+
1. [Introduction](#introduction)
23+
2. [Data Structures](#data-structures)
24+
- [Linked Lists](#linked-lists)
25+
- [Stacks](#stacks)
26+
- [Queues](#queues)
27+
- [Trees](#trees)
28+
- [Graphs](#graphs)
29+
3. [Algorithms](#algorithms)
30+
- [Searching](#searching)
31+
- [Sorting](#sorting)
32+
- [Recursion](#recursion)
33+
- [Dynamic Programming](#dynamic-programming)
34+
- [Greedy Algorithms](#greedy-algorithms)
35+
- [Graph Algorithms](#graph-algorithms)
36+
4. [Contributing](#contributing)
37+
5. [License](#license)
38+
39+
## Introduction
40+
41+
Understanding data structures and algorithms is fundamental to becoming a proficient programmer. This repository aims to provide a comprehensive collection of C implementations for various data structures and algorithms. Whether you're a student, a software engineer, or an enthusiast, you'll find valuable resources here to deepen your understanding and improve your coding skills.
42+
43+
## Data Structures
44+
45+
### Linked Lists
46+
47+
Linked lists are linear data structures where elements are linked using pointers. They come in various forms, such as singly linked lists, doubly linked lists, and circular linked lists. In this repository, you'll find implementations of these linked list variants along with operations like insertion, deletion, and traversal.
48+
49+
### Stacks
50+
51+
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle. It supports two main operations: push (to add an element) and pop (to remove the top element). Implementations of stack data structure with various functionalities are available here.
52+
53+
### Queues
54+
55+
A queue is a linear data structure that follows the First In, First Out (FIFO) principle. It supports operations like enqueue (to add an element) and dequeue (to remove the front element). This repository contains implementations of queue data structures and their associated operations.
56+
57+
### Trees
58+
59+
Trees are hierarchical data structures consisting of nodes connected by edges. Common types of trees include binary trees, binary search trees (BSTs), AVL trees, and B-trees. You'll find implementations of these tree variants and their operations like insertion, deletion, and traversal.
60+
61+
### Graphs
62+
63+
Graphs are non-linear data structures consisting of nodes (vertices) and edges connecting these nodes. They are widely used to model relationships between objects. This repository includes implementations of various graph algorithms like breadth-first search (BFS), depth-first search (DFS), Dijkstra's algorithm, and more.
64+
65+
## Algorithms
66+
67+
### Searching
68+
69+
Searching algorithms are used to find a particular element in a data structure. Common searching algorithms include linear search, binary search, and interpolation search. You'll find C implementations of these algorithms along with their explanations and complexities.
70+
71+
### Sorting
72+
73+
Sorting algorithms are used to arrange elements in a specific order, such as ascending or descending. Common sorting algorithms include bubble sort, insertion sort, selection sort, merge sort, quick sort, and heap sort. This repository provides C implementations of these sorting algorithms and their comparisons.
74+
75+
### Recursion
76+
77+
Recursion is a programming technique where a function calls itself to solve smaller instances of a problem. It is commonly used in algorithms like factorial calculation, Fibonacci sequence generation, and binary tree traversal. You'll find recursive implementations of various algorithms in this repository.
78+
79+
### Dynamic Programming
80+
81+
Dynamic programming is a method for solving complex problems by breaking them down into simpler subproblems and solving each subproblem only once. It is used to optimize algorithms by storing the results of subproblems to avoid redundant computations. This repository includes dynamic programming solutions to classic problems like the knapsack problem, longest common subsequence, and more.
82+
83+
### Greedy Algorithms
84+
85+
Greedy algorithms make locally optimal choices at each step with the hope of finding a global optimum. They are often used for optimization problems where a sequence of choices must be made. This repository contains C implementations of greedy algorithms like Kruskal's algorithm, Prim's algorithm, and Dijkstra's algorithm.
86+
87+
### Graph Algorithms
88+
89+
Graph algorithms are used to solve problems related to graphs, such as finding the shortest path, detecting cycles, and determining connectivity. This repository provides C implementations of fundamental graph algorithms like BFS, DFS, topological sorting, and more.
90+
91+
## Getting Started
92+
93+
To get started with using the scripts in this repository, follow these steps:
94+
95+
1. Clone this repository to your local machine using the following command:
96+
97+
```
98+
git clone https://github.com/mahendramahara/DSA-in-C-Programing.git
99+
```
100+
101+
2. Navigate to the directory containing the script you are interested in.
102+
3. Follow the instructions provided in the README.md file of that directory to set up and run the script.
103+
104+
105+
## License
106+
107+
This repository is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
108+
109+
---
110+
111+
Happy Coding! πŸš€

β€ŽTREE/BST-All-Traversal.c

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
struct Node {
4+
int data;
5+
struct Node *left, *right;
6+
};
7+
struct Node *newNode(int data) {
8+
struct Node *temp = (struct Node *)malloc(sizeof(struct Node));
9+
temp->data = data;
10+
temp->left = temp->right = NULL;
11+
return temp;
12+
}
13+
void inorder(struct Node *root) {
14+
if (root != NULL) {
15+
inorder(root->left);
16+
printf("%d ", root->data);
17+
inorder(root->right);
18+
}
19+
}
20+
void preorder(struct Node *root) {
21+
if (root != NULL) {
22+
printf("%d ", root->data);
23+
preorder(root->left);
24+
preorder(root->right);
25+
}
26+
}
27+
// Postorder traversal of the binary tree
28+
void postorder(struct Node *root) {
29+
if (root != NULL) {
30+
postorder(root->left);
31+
postorder(root->right);
32+
printf("%d ", root->data);
33+
}
34+
}
35+
int main() {
36+
// Constructing a binary tree
37+
struct Node *root = newNode(1);
38+
root->left = newNode(2);
39+
root->right = newNode(3);
40+
root->left->left = newNode(4);
41+
root->left->right = newNode(5);
42+
// Print the traversals
43+
printf("Inorder traversal: ");
44+
inorder(root);
45+
printf("\nPreorder traversal: ");
46+
preorder(root);
47+
printf("\nPostorder traversal: ");
48+
postorder(root);
49+
return 0;
50+
}

0 commit comments

Comments
Β (0)