Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
Signed-off-by: Raj Patil <rajp152k@gmail.com>
  • Loading branch information
rajp152k committed Jan 27, 2025
1 parent 853407e commit 373a0c9
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 17 deletions.
18 changes: 9 additions & 9 deletions Content/20230715173535-data_structure.org
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

2. *Non-Primitive Data Structures*
- *Linear Structures*
- Arrays: Fixed-size collections of elements.
- [[id:ce5570cd-e6c4-4dcc-9146-860cbb11a15d][Arrays]]: Fixed-size collections of elements.
- Linked Lists: Collections of elements linked via pointers.
- Stacks: Last-in-first-out (LIFO) storage.
- Queues: First-in-first-out (FIFO) storage.
Expand All @@ -30,21 +30,21 @@
- Searching: Finding elements (e.g., linear search, binary search).
- Sorting: Arranging elements (e.g., quicksort, mergesort).
* [[id:c8a3e246-0f29-4909-ab48-0d34802451d5][Cache]] Friendliness: Overview
- /Definition/: Cache friendliness refers to how well a data structure or algorithm utilizes the CPU cache to minimize latency and improve performance.
- Definition: Cache friendliness refers to how well a data structure or algorithm utilizes the CPU cache to minimize latency and improve performance.

** Key Concepts
1. /Locality of Reference/
- /Temporal Locality/: If a data location is accessed, it is likely to be accessed again soon.
- /Spatial Locality/: If a data location is accessed, nearby data locations are likely to be accessed soon.
1. Locality of Reference
- Temporal Locality: If a data location is accessed, it is likely to be accessed again soon.
- Spatial Locality: If a data location is accessed, nearby data locations are likely to be accessed soon.

2. /Cache Hierarchy/
2. Cache Hierarchy
- Modern CPUs have multiple cache levels (L1, L2, L3).
- Data structures should fit within cache lines to leverage fast memory access.

** Characteristics of Cache-Friendly Data Structures
- /Contiguous Memory Allocation/: Arrays are generally more cache-friendly than linked lists as they store elements in contiguous memory locations.
- /Data Structure Size/: Smaller structures that fit in cache are preferable.
- /Access Patterns/: Sequential access patterns (e.g., traversing an array) are usually better than random access patterns.
- Contiguous Memory Allocation: Arrays are generally more cache-friendly than linked lists as they store elements in contiguous memory locations.
- Data Structure Size: Smaller structures that fit in cache are preferable.
- Access Patterns: Sequential access patterns (e.g., traversing an array) are usually better than random access patterns.

** Impact on Performance
- Efficient cache usage can reduce memory access time significantly, leading to overall faster program execution.
Expand Down
20 changes: 12 additions & 8 deletions Content/20250122095143-dsindex.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

Index into data structures of varying complexities and brief descriptions about their core aspects

| Data Structure | Desc |
|----------------+----------------------------|
| [[id:3821a4f5-998a-4903-970f-d95bf2ed8cd4][Binary Tree]] | forkable linked lists |
| [[id:1d703f5b-8b5e-4c82-9393-a2c88294c959][Graphs]] | Edges and Nodes |
| [[id:20240519T201001.324666][Merkle Tree]] | scalable data verification |
| [[id:4054ebe7-812f-4204-be63-bb7379d5b56b][Queue]] | FIFO/LILO |
| [[id:e20be945-5df7-4b35-aab5-a9a439b62de8][Stack]] | FILO/LIFO |
| [[id:9a7e1b83-9160-40a7-821b-0f0ada44e350][Linked lists]] | Fundamental data and glue |
| Data Structure | Desc |
|----------------+------------------------------------|
| [[id:ce5570cd-e6c4-4dcc-9146-860cbb11a15d][array]] | static contiguous blocks of memory |
| [[id:3821a4f5-998a-4903-970f-d95bf2ed8cd4][binary tree]] | forkable linked lists |
| [[id:1d703f5b-8b5e-4c82-9393-a2c88294c959][graphs]] | edges and nodes |
| [[id:9a7e1b83-9160-40a7-821b-0f0ada44e350][linked lists]] | fundamental data and glue |
| [[id:20240519t201001.324666][merkle tree]] | scalable data verification |
| [[id:4054ebe7-812f-4204-be63-bb7379d5b56b][queue]] | fifo/lilo |
| [[id:e20be945-5df7-4b35-aab5-a9a439b62de8][stack]] | filo/lifo |
| [[id:198d0435-df28-4af5-a687-3475ed78eadf][Heap]] | priority queues |
| [[id:a1958360-5d36-4994-a617-37c040f78812][Fibonacci Heap]] | heaps of trees |
| | |
5 changes: 5 additions & 0 deletions Content/20250127063511-array.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: ce5570cd-e6c4-4dcc-9146-860cbb11a15d
:END:
#+title: Array
#+filetags: :data:cs:
36 changes: 36 additions & 0 deletions Content/20250127063921-heap.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
:PROPERTIES:
:ID: 198d0435-df28-4af5-a687-3475ed78eadf
:ROAM_ALIASES: "Priority Queue"
:END:
#+title: Heap
#+filetags: :data:cs:

* Overview

- *Definition*: A heap is a specialized [[id:3821a4f5-998a-4903-970f-d95bf2ed8cd4][tree]]-based data structure that satisfies the heap property as described below:

- *Types*:
- *Max-Heap*: The parent node has a value greater than or equal to its children.
- *Min-Heap*: The parent node has a value less than or equal to its children.

- *Common Implementations*:
- *[[id:5ed05b89-71e5-423c-b51c-dc53133c3e91][Binary Heap]]*: Most common heap implementation which uses a complete binary tree structure.
- *[[id:a1958360-5d36-4994-a617-37c040f78812][Fibonacci Heap]]*: More advanced, allowing for more efficient merge operations.
- *[[id:addc4776-3f73-47a6-94b7-9cd9dd07b996][Binomial Heap]]*: Amalgamates multiple [[id:e7006647-efb9-4fce-8b3a-3bf6fabac685][binomial trees]] for optimized operations.

- *Operations*:
- *Insertion*: Adding a new element while maintaining the heap property.
- *Deletion*: Typically removing the root (max or min), followed by reorganizing to maintain heap integrity.
- *Peek*: Accessing the root element without modifying the heap.

- *Applications*:
- *Priority Queues*: Heaps are commonly used to implement priority queues.
- *Heap Sort*: An efficient sorting algorithm that utilizes a heap.
- *Graph Algorithms*: Utilized in algorithms like Dijkstra's shortest path.

- *Time Complexity*:
- Insertion: O(log n)
- Deletion (removing root): O(log n)
- Accessing the root: O(1)
- Building a heap: O(n)

30 changes: 30 additions & 0 deletions Content/20250127070013-binary_heap.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
:PROPERTIES:
:ID: 5ed05b89-71e5-423c-b51c-dc53133c3e91
:END:
#+title: Binary Heap
#+filetags: :data:cs:

* Key Properties and Characteristics

- *Definition*: A binary heap is a complete [[id:3821a4f5-998a-4903-970f-d95bf2ed8cd4][binary tree]] that satisfies the [[id:198d0435-df28-4af5-a687-3475ed78eadf][heap]] property.
- *Heap Property*:
- *Max-Heap*: The key of each node is greater than or equal to the keys of its children. The maximum key is at the root.
- *Min-Heap*: The key of each node is less than or equal to the keys of its children. The minimum key is at the root.

- *Structure*:
- Complete binary trees, meaning all levels are fully filled, except possibly for the last level.
- Efficiently stored in array format, where for a node at index =i=:
- Left child: =2*i + 1=
- Right child: =2*i + 2=
- Parent: =floor((i - 1) / 2)=

- *Time Complexity*:
- Insertion: O(log n)
- Deletion: O(log n)
- Find-min or Find-max: O(1)
- Building a heap: O(n)

- *Applications*:
- Priority Queues: Efficiently manage dynamically changing priority data.
- [[id:4a362cc7-3fe3-46b5-9038-c0e5d4af2eb5][Heapsort]]: An efficient sorting algorithm using binary heaps.
- [[id:1d703f5b-8b5e-4c82-9393-a2c88294c959][Graph]] algorithms: Such as [[id:e31f91e8-25d9-499b-9c55-10afcb086edb][Dijkstra]]’s and [[id:dd72e849-016c-4065-80fd-656fad075d4a][Prim]]’s for [[id:eeca3654-8525-4ce3-a135-a51e262094c3][minimum spanning trees]].
5 changes: 5 additions & 0 deletions Content/20250127070238-heapsort.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: 4a362cc7-3fe3-46b5-9038-c0e5d4af2eb5
:END:
#+title: Heapsort
#+filetags: :algo:cs:
5 changes: 5 additions & 0 deletions Content/20250127070324-dijkstra_s_algorithm.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: e31f91e8-25d9-499b-9c55-10afcb086edb
:END:
#+title: Dijkstra's Algorithm
#+filetags: :algo:cs:
5 changes: 5 additions & 0 deletions Content/20250127070400-prim_s_algorithm.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: dd72e849-016c-4065-80fd-656fad075d4a
:END:
#+title: Prim's Algorithm
#+filetags: :algo:cs:
5 changes: 5 additions & 0 deletions Content/20250127070419-minimum_spanning_trees.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: eeca3654-8525-4ce3-a135-a51e262094c3
:END:
#+title: minimum spanning trees
#+filetags: :data:cs:
44 changes: 44 additions & 0 deletions Content/20250127070737-fibonacci_heap.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
:PROPERTIES:
:ID: a1958360-5d36-4994-a617-37c040f78812
:END:
#+title: Fibonacci Heap
#+filetags: :data:cs:

* Overview
- *Definition*:
- A Fibonacci [[id:198d0435-df28-4af5-a687-3475ed78eadf][heap]] is a type of data structure that consists of a collection of trees following the properties of a min-heap (or max-heap). It allows for very efficient merging of heaps and is used in [[id:dd94cae5-96e2-4a46-9890-41c8c88059bc][network optimization algorithms]].

- *Structure*:
- The Fibonacci heap is composed of a collection of heap-ordered trees, structured in such a way that the minimum element is always accessible.
- Nodes within the trees can hold more than one child, forming a Fibonacci-like structure, hence the name.

- *Key Operations*:
- *Insertion*: Adds a new element to the heap in constant time, O(1).
- *Finding Minimum*: Provides access to the minimum element in O(1) time.
- *Union*: Merges two heaps in O(1) time; this is one of the highlights of Fibonacci heaps.
- *Decrease Key*: Decreases the key of a node, which takes [[id:b91e378d-b17a-43b2-b13e-19c02afe1558][amortized]] O(1) time.
- *Delete*: Removal of the minimum element within O(log n) time.

- *Applications*:
- Primarily used in graph algorithms such as [[id:e31f91e8-25d9-499b-9c55-10afcb086edb][Dijkstra's]] and [[id:dd72e849-016c-4065-80fd-656fad075d4a][Prim's]] algorithms, where efficient priority queue operations are paramount.
- Useful in scenarios where merge operations are frequent and optimized performance over several operations is needed.

* Operational Breakdown and Explanation

- Amortized Analysis:
- Fibonacci heaps leverage amortized analysis to ensure that while individual operations may seem costly, the average time per operation over a sequence of operations is efficient.
- This is particularly relevant for operations like decrease key and delete.

- Operational Complexity:
- *Insert*: O(1) - This operation simply adds the new element to the list of roots.
- *Find Minimum*: O(1) - Constant time access to the minimum element.
- *Union*: O(1) - Combining the root lists of two Fibonacci heaps.
- *Decrease Key*: O(1) amortized - The node is cut from its parent and added to the root list; potential restructuring happens lazily.
- *Delete*: O(log n) - Involves decreasing the key to negative infinity followed by removing the minimum element.

- Heuristic Characteristics:
- Lazy Merging: Allows for efficient merging of heaps and defers the restructuring to later operations.
- Tree Structure: Each tree is a min-heap, which guarantees that the minimum element is always accessible.

* Resources
- https://en.wikipedia.org/wiki/Fibonacci_heap
8 changes: 8 additions & 0 deletions Content/20250127070955-network_optimization.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:PROPERTIES:
:ID: dd94cae5-96e2-4a46-9890-41c8c88059bc
:END:
#+title: network optimization
#+filetags: :network:cs:

* Resources
- https://networkoptimization.dev/
5 changes: 5 additions & 0 deletions Content/20250127071821-binomial_heap.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:PROPERTIES:
:ID: addc4776-3f73-47a6-94b7-9cd9dd07b996
:END:
#+title: Binomial Heap
#+filetags: :data:cs:
31 changes: 31 additions & 0 deletions Content/20250127071830-binomial_trees.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:PROPERTIES:
:ID: e7006647-efb9-4fce-8b3a-3bf6fabac685
:END:
#+title: binomial trees
#+filetags: :data:cs:


* Overview

- *Definition of Binomial Trees*:
- A binomial tree is a data structure that is a recursive combination of binomial trees, each representing a set of potential states or values at each node.

- *Structure*:
- A binomial tree of order \( k \) consists of \( 2^k \) nodes.
- Each node has \( k \) children, corresponding to the structure of the binomial coefficient.

- *Properties*:
- The height of a binomial tree of order \( k \) is \( k \).
- There are \( C(k, i) \) ways to choose \( i \) children from \( k \).

- *Operations*:
- *Merge*: Merging two binomial trees is efficient, \( O(\log n) \).
- *Insert*: Inserting a new element is also \( O(\log n) \).
- *Delete*: Deletion can be done in logarithmic time as well.

- *Applications*:
- Commonly used in the implementation of priority queues, particularly in [[id:a1958360-5d36-4994-a617-37c040f78812][Fibonacci heaps]].
- Useful in algorithms for binomial queues and efficient algorithms in [[id:dd94cae5-96e2-4a46-9890-41c8c88059bc][network design]].

* Resources
- https://en.wikipedia.org/wiki/Binomial_heap

0 comments on commit 373a0c9

Please sign in to comment.