-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added Theory (Complexity Analysis and Data Structures) #13
Changes from all commits
b0dfcd3
7d2e8bc
1fa28e2
b0d0de3
ed7e4e1
1c40af8
b6dd513
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Complexity Analysis | ||
|
||
Complexity analysis evaluates the efficiency of algorithms in terms of time and space. The goal is to understand how an algorithm performs as input size grows, using Big O, Big Θ, and Big Ω notations. | ||
|
||
## 1. Time Complexity | ||
Time complexity measures the time taken by an algorithm to run as a function of the input size \(n\). | ||
|
||
- **Big O (O)**: Upper bound. Worst-case scenario. | ||
- **Big Θ (Θ)**: Tight bound. Average-case scenario. | ||
- **Big Ω (Ω)**: Lower bound. Best-case scenario. | ||
|
||
### Common Time Complexities | ||
| Complexity | Description | Example | | ||
|-----------------|--------------------------------------|------------------------------| | ||
| **O(1)** | Constant time | Accessing an array element | | ||
| **O(log n)** | Logarithmic | Binary search | | ||
| **O(n)** | Linear | Linear search | | ||
| **O(n log n)** | Linearithmic | Merge sort, heapsort | | ||
| **O(n^2)** | Quadratic | Bubble sort, insertion sort | | ||
| **O(2^n)** | Exponential | Recursive Fibonacci | | ||
| **O(n!)** | Factorial | Permutation generation | | ||
|
||
## 2. Space Complexity | ||
Space complexity measures the amount of memory required by an algorithm as a function of input size. | ||
|
||
- Includes both auxiliary space and input space. | ||
- Important for memory-intensive applications. | ||
|
||
## 3. Asymptotic Notations | ||
These notations describe the growth rate of functions: | ||
|
||
- **Big O (O)**: Upper limit; worst-case behavior. | ||
- **Big Θ (Θ)**: Average or "tight" bound; commonly expected performance. | ||
- **Big Ω (Ω)**: Lower limit; best-case behavior. | ||
|
||
## 4. Trade-offs | ||
- **Time vs Space**: Faster algorithms often use more memory, and vice versa. | ||
- **Amortized Analysis**: For operations like dynamic array resizing, considers average time per operation over a sequence. | ||
|
||
Understanding complexity is key to choosing the most efficient algorithm for a given problem. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make any ONE of the following changes,
Note But I strongly suggest you to go with second option for now, The automations will work properly when you place all directories/folders without any complex hierarchies like have sub-folders under sub-folders. Important Please make sure you make sure the same is being reflected with all the files & directories/folder present within
Tip Please read the CONTRIBUTING.md file at the file structure section. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## 5. Graphs | ||
A **Graph** is a collection of vertices (nodes) and edges (connections between nodes) representing networks. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a Table of content as described on Instructions and Guidelines. |
||
### Key Characteristics | ||
- **Directed** vs **Undirected**: Directed graphs have edges with direction. | ||
- **Weighted** vs **Unweighted**: Weighted graphs assign values to edges. | ||
|
||
### Common Representations | ||
- **Adjacency Matrix**: A 2D array where cells indicate edge presence. | ||
- Space Complexity: \(O(V^2)\) | ||
- **Adjacency List**: Each vertex has a list of adjacent vertices. | ||
- Space Complexity: \(O(V + E)\) | ||
|
||
### Common Operations | ||
- **Traversal**: | ||
- **Breadth-First Search (BFS)**: Level-order traversal, useful for finding shortest paths in unweighted graphs. | ||
- **Depth-First Search (DFS)**: Visits nodes as deep as possible before backtracking, useful for pathfinding. | ||
- **Shortest Path Algorithms**: | ||
- **Dijkstra's Algorithm**: Finds shortest paths from a single source in a weighted graph. | ||
- **Floyd-Warshall**: All-pairs shortest paths. | ||
- **Minimum Spanning Tree (MST)**: | ||
- **Kruskal's and Prim's Algorithms**: Find the minimum cost to connect all nodes in a weighted graph. | ||
|
||
### Applications | ||
- **Networks**: Routing algorithms in communication networks. | ||
- **Social Networks**: Representing and analyzing relationships. | ||
- **Web Crawling**: Link structure of websites. | ||
- **Pathfinding**: Navigation systems and game AI. | ||
- **Scheduling**: Task scheduling with dependencies. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## 3. Linked Lists | ||
A **Linked List** is a linear data structure consisting of nodes, where each node contains a data part and a reference (or link) to the next node in the sequence. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a Table of content as described on Instructions and Guidelines. |
||
### Key Characteristics | ||
- Nodes are stored non-contiguously in memory. | ||
- Elements are linked using pointers, allowing efficient insertion and deletion. | ||
|
||
### Types of Linked Lists | ||
- **Singly Linked List**: Each node has a single link to the next node. | ||
- **Doubly Linked List**: Each node has links to both the previous and next nodes. | ||
- **Circular Linked List**: Last node links back to the first node. | ||
|
||
### Common Operations | ||
- **Insertion**: | ||
- At the head, tail, or a specific position. | ||
- Complexity: \(O(1)\) for head or tail (if tail pointer exists), \(O(n)\) for arbitrary position. | ||
- **Deletion**: | ||
- Removing an element from head, tail, or specific position. | ||
- Complexity: \(O(1)\) for head or tail, \(O(n)\) for arbitrary position. | ||
- **Traversal**: Accessing elements sequentially. | ||
- Complexity: \(O(n)\) | ||
- **Searching**: | ||
- Finding an element. | ||
- Complexity: \(O(n)\) | ||
|
||
### Applications | ||
- **Dynamic Memory Management**: Efficient for varying data sizes. | ||
- **Implementing Stacks and Queues**: Using linked lists as the underlying data structure. | ||
- **Sparse Matrices**: Efficiently storing and accessing non-zero elements. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
## 2. Queues | ||
A **Queue** is a linear data structure that follows the First-In-First-Out (FIFO) principle. The first element added is the first to be removed. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a Table of content as described on Instructions and Guidelines. |
||
### Key Characteristics | ||
- Operates in a **FIFO** order. | ||
- Can be implemented using arrays, linked lists, or circular buffers. | ||
|
||
### Types of Queues | ||
- **Simple Queue**: Basic FIFO queue. | ||
- **Circular Queue**: The last position is connected back to the first. | ||
- **Priority Queue**: Elements are dequeued based on priority. | ||
- **Deque**: Double-ended queue, allowing insertion and deletion at both ends. | ||
|
||
### Common Operations | ||
- **Enqueue(x)**: Adds element `x` at the end of the queue. | ||
- Complexity: \(O(1)\) | ||
- **Dequeue()**: Removes and returns the front element. | ||
- Complexity: \(O(1)\) | ||
- **Front()**: Returns the front element without removing it. | ||
- Complexity: \(O(1)\) | ||
- **isEmpty()**: Checks if the queue is empty. | ||
- Complexity: \(O(1)\) | ||
|
||
### Applications | ||
- **CPU Scheduling**: Round-robin scheduling. | ||
- **Breadth-First Search (BFS)**: Used in graph traversal. | ||
- **IO Buffers**: Handling asynchronous data. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## 1. Stacks | ||
A **Stack** is a linear data structure that follows the Last-In-First-Out (LIFO) principle. This means the last element added is the first one to be removed. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a Table of content as described on Instructions and Guidelines. |
||
### Key Characteristics | ||
- Operates in a **LIFO** order. | ||
- Can be implemented using arrays or linked lists. | ||
|
||
### Common Operations | ||
- **Push(x)**: Adds element `x` to the top of the stack. | ||
- Complexity: \(O(1)\) | ||
- **Pop()**: Removes and returns the top element. | ||
- Complexity: \(O(1)\) | ||
- **Peek/Top()**: Returns the top element without removing it. | ||
- Complexity: \(O(1)\) | ||
- **isEmpty()**: Checks if the stack is empty. | ||
- Complexity: \(O(1)\) | ||
|
||
### Applications | ||
- **Expression Parsing**: Evaluating postfix and infix expressions. | ||
- **Function Calls**: Recursive calls use a call stack. | ||
- **Backtracking**: Helps in scenarios where previous states are revisited, like maze solving or browser history. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## 4. Trees | ||
A **Tree** is a hierarchical data structure consisting of nodes with a parent-child relationship. It starts with a **root** node and expands into subtrees of children, representing various hierarchical levels. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a Table of content as described on Instructions and Guidelines. |
||
### Key Characteristics | ||
- Each node has data and links to child nodes. | ||
- Commonly represented as a **rooted tree** with a single root node. | ||
|
||
### Types of Trees | ||
- **Binary Tree**: Each node has at most two children. | ||
- **Binary Search Tree (BST)**: A binary tree with the left child <= root <= right child. | ||
- **Balanced Trees**: Trees like AVL, Red-Black Trees keep balance for efficient operations. | ||
- **Heap**: A complete binary tree used for priority queues. | ||
- **Trie**: A tree for storing strings, useful in search applications. | ||
- **B-Trees**: Balanced trees used in databases and filesystems. | ||
|
||
### Common Operations | ||
- **Insertion**: | ||
- Adds nodes based on tree type (e.g., BST properties). | ||
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced. | ||
- **Deletion**: | ||
- Removes a node while maintaining tree properties. | ||
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced. | ||
- **Traversal**: | ||
- **In-order**: Left, Root, Right (BST sorted order). | ||
- **Pre-order**: Root, Left, Right (used for copying). | ||
- **Post-order**: Left, Right, Root (used for deletion). | ||
- Complexity: \(O(n)\) | ||
- **Searching**: | ||
- Complexity: \(O(\log n)\) for balanced trees; \(O(n)\) for unbalanced. | ||
|
||
### Applications | ||
- **Hierarchical Data Representation**: File systems, organizational structures. | ||
- **Binary Search Trees (BSTs)**: Efficient searching, insertion, and deletion. | ||
- **Priority Queues**: Implemented using heaps. | ||
- **Trie**: Used for autocomplete and dictionary implementations. | ||
- **Databases and Filesystems**: B-trees provide efficient data retrieval. | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,14 +14,23 @@ Welcome to **DSA's Theory**, this very directory serves as a treasure trove of w | |||||||||||||||||||
## Table of Content | ||||||||||||||||||||
|
||||||||||||||||||||
<!-- TABLE OF CONTENT BEGINS --> | ||||||||||||||||||||
- **Complexity Analysis** | ||||||||||||||||||||
- [Complexity Analysis](./Complexity-Analysis/README.md) | ||||||||||||||||||||
|
||||||||||||||||||||
- **Data Structures** | ||||||||||||||||||||
- [Stacks](./Data-Structures/Stacks/README.md) | ||||||||||||||||||||
- [Queues](./Data-Structures/Queues/README.md) | ||||||||||||||||||||
- [Linked Lists](./Data-Structures/Linked-Lists/README.md) | ||||||||||||||||||||
- [Trees](./Data-Structures/Trees/README.md) | ||||||||||||||||||||
- [Graphs](./Data-Structures/Graphs/README.md) | ||||||||||||||||||||
Comment on lines
+17
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove manually entered content, these details will be updated manually.
Suggested change
|
||||||||||||||||||||
<!-- TABLE OF CONTENT ENDS --> | ||||||||||||||||||||
|
||||||||||||||||||||
## Table of Contribution | ||||||||||||||||||||
|
||||||||||||||||||||
<!-- TABLE OF CONTRIBUTORS BEGINS --> | ||||||||||||||||||||
| Contribution Title | Contributor Names | Pull Requests | Demo | | ||||||||||||||||||||
| --- | --- | --- | --- | | ||||||||||||||||||||
| - | - | - | - | | ||||||||||||||||||||
| Complexity Analysis and Data Structures| ghruank | #13 | - | | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove manually entered content, these details will be updated manually.
Suggested change
|
||||||||||||||||||||
<!-- TABLE OF CONTRIBUTORS ENDS --> | ||||||||||||||||||||
|
||||||||||||||||||||
## Thank you Contributors | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -6,14 +6,23 @@ Welcome to **DSA's Theory**, this very directory serves as a treasure trove of w | |||||||||||||||||||
# Table of Content | ||||||||||||||||||||
|
||||||||||||||||||||
<!-- TABLE OF CONTENT BEGINS --> | ||||||||||||||||||||
- **Complexity Analysis** | ||||||||||||||||||||
- [Complexity Analysis](./Complexity-Analysis/README.md) | ||||||||||||||||||||
|
||||||||||||||||||||
- **Data Structures** | ||||||||||||||||||||
- [Stacks](./Data-Structures/Stacks/README.md) | ||||||||||||||||||||
- [Queues](./Data-Structures/Queues/README.md) | ||||||||||||||||||||
- [Linked Lists](./Data-Structures/Linked-Lists/README.md) | ||||||||||||||||||||
- [Trees](./Data-Structures/Trees/README.md) | ||||||||||||||||||||
- [Graphs](./Data-Structures/Graphs/README.md) | ||||||||||||||||||||
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove manually entered content, these details will be updated manually.
Suggested change
|
||||||||||||||||||||
<!-- TABLE OF CONTENT ENDS --> | ||||||||||||||||||||
|
||||||||||||||||||||
# Table of Contribution | ||||||||||||||||||||
|
||||||||||||||||||||
<!-- TABLE OF CONTRIBUTORS BEGINS --> | ||||||||||||||||||||
| Contribution Title | Contributor Names | Pull Requests | Demo | | ||||||||||||||||||||
| --- | --- | --- | --- | | ||||||||||||||||||||
| - | - | - | - | | ||||||||||||||||||||
| Complexity Analysis and Data Structures| ghruank | #13 | - | | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove manually entered content, these details will be updated manually.
Suggested change
|
||||||||||||||||||||
<!-- TABLE OF CONTRIBUTORS ENDS --> | ||||||||||||||||||||
|
||||||||||||||||||||
# Thank you Contributors | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a Table of content as described on Instructions and Guidelines.