
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- Data Structures
- DSA - Data Structure Basics
- DSA - Data Structures and Types
- DSA - Array Data Structure
- DSA - Skip List Data Structure
- Linked Lists
- DSA - Linked List Data Structure
- DSA - Doubly Linked List Data Structure
- DSA - Circular Linked List Data Structure
- Stack & Queue
- DSA - Stack Data Structure
- DSA - Expression Parsing
- DSA - Queue Data Structure
- DSA - Circular Queue Data Structure
- DSA - Priority Queue Data Structure
- DSA - Deque Data Structure
- Searching Algorithms
- DSA - Searching Algorithms
- DSA - Linear Search Algorithm
- DSA - Binary Search Algorithm
- DSA - Interpolation Search
- DSA - Jump Search Algorithm
- DSA - Exponential Search
- DSA - Fibonacci Search
- DSA - Sublist Search
- DSA - Hash Table
- Sorting Algorithms
- DSA - Sorting Algorithms
- DSA - Bubble Sort Algorithm
- DSA - Insertion Sort Algorithm
- DSA - Selection Sort Algorithm
- DSA - Merge Sort Algorithm
- DSA - Shell Sort Algorithm
- DSA - Heap Sort Algorithm
- DSA - Bucket Sort Algorithm
- DSA - Counting Sort Algorithm
- DSA - Radix Sort Algorithm
- DSA - Quick Sort Algorithm
- Matrices Data Structure
- DSA - Matrices Data Structure
- DSA - Lup Decomposition In Matrices
- DSA - Lu Decomposition In Matrices
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- DSA - Spanning Tree
- DSA - Topological Sorting
- DSA - Strongly Connected Components
- DSA - Biconnected Components
- DSA - Augmenting Path
- DSA - Network Flow Problems
- DSA - Flow Networks In Data Structures
- DSA - Edmonds Blossom Algorithm
- DSA - Maxflow Mincut Theorem
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Red Black Trees
- DSA - B Trees
- DSA - B+ Trees
- DSA - Splay Trees
- DSA - Range Queries
- DSA - Segment Trees
- DSA - Fenwick Tree
- DSA - Fusion Tree
- DSA - Hashed Array Tree
- DSA - K-Ary Tree
- DSA - Kd Trees
- DSA - Priority Search Tree Data Structure
- Recursion
- DSA - Recursion Algorithms
- DSA - Tower of Hanoi Using Recursion
- DSA - Fibonacci Series Using Recursion
- Divide and Conquer
- DSA - Divide and Conquer
- DSA - Max-Min Problem
- DSA - Strassen's Matrix Multiplication
- DSA - Karatsuba Algorithm
- Greedy Algorithms
- DSA - Greedy Algorithms
- DSA - Travelling Salesman Problem (Greedy Approach)
- DSA - Prim's Minimal Spanning Tree
- DSA - Kruskal's Minimal Spanning Tree
- DSA - Dijkstra's Shortest Path Algorithm
- DSA - Map Colouring Algorithm
- DSA - Fractional Knapsack Problem
- DSA - Job Sequencing with Deadline
- DSA - Optimal Merge Pattern Algorithm
- Dynamic Programming
- DSA - Dynamic Programming
- DSA - Matrix Chain Multiplication
- DSA - Floyd Warshall Algorithm
- DSA - 0-1 Knapsack Problem
- DSA - Longest Common Sub-sequence Algorithm
- DSA - Travelling Salesman Problem (Dynamic Approach)
- Hashing
- DSA - Hashing Data Structure
- DSA - Collision In Hashing
- Disjoint Set
- DSA - Disjoint Set
- DSA - Path Compression And Union By Rank
- Heap
- DSA - Heap Data Structure
- DSA - Binary Heap
- DSA - Binomial Heap
- DSA - Fibonacci Heap
- Tries Data Structure
- DSA - Tries
- DSA - Standard Tries
- DSA - Compressed Tries
- DSA - Suffix Tries
- Treaps
- DSA - Treaps Data Structure
- Bit Mask
- DSA - Bit Mask In Data Structures
- Bloom Filter
- DSA - Bloom Filter Data Structure
- Approximation Algorithms
- DSA - Approximation Algorithms
- DSA - Vertex Cover Algorithm
- DSA - Set Cover Problem
- DSA - Travelling Salesman Problem (Approximation Approach)
- Randomized Algorithms
- DSA - Randomized Algorithms
- DSA - Randomized Quick Sort Algorithm
- DSA - Karger’s Minimum Cut Algorithm
- DSA - Fisher-Yates Shuffle Algorithm
- Miscellaneous
- DSA - Infix to Postfix
- DSA - Bellmon Ford Shortest Path
- DSA - Maximum Bipartite Matching
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Selection Sort Interview Questions
- DSA - Merge Sort Interview Questions
- DSA - Insertion Sort Interview Questions
- DSA - Heap Sort Interview Questions
- DSA - Bubble Sort Interview Questions
- DSA - Bucket Sort Interview Questions
- DSA - Radix Sort Interview Questions
- DSA - Cycle Sort Interview Questions
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Range Queries
Range Query is a question that asks for the sum, minimum, maximum, or average of the values between the two indices of a dataset. It is a common operation in data structures and is used in various applications.
For example, suppose you have to know the sum of all the values between the 3rd and 7th index of an array. This is a sum range query.
Let's assume you have a list of numbers : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Now, someone asks you to find the sum between the 3rd and 7th index. You will have to add the values at the 3rd, 4th, 5th, 6th, and 7th index. Let's do it.
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 3rd index = 4 4th index = 5 5th index = 6 6th index = 7 7th index = 8 Sum = 4 + 5 + 6 + 7 + 8 = 30
We got the sum of the values between the 3rd and 7th index. This is a range query, where we have to find the sum of the values between the start and end index.
Range Queries in Data Structures
Now, let's understand what and how range queries are used in data structures.
Range Queries are mostly used for finding the sum of the values between the start and end index. But, it can be used for other operations like finding the minimum, maximum, or average of the values between the start and end index.
For example, you might have a large dataset (like an array, a list, or a tree), and you want to quickly access the range of values. In this case, instead of iterating through the entire dataset, you can use a data structure that supports range queries.
There are many data structures that support range queries, and those are listed below:
- Segment Trees
- Fenwick Trees / Binary Indexed Trees
- Priority Search Trees
- kd-Trees
- Interval Trees
- Range Trees
- Wavelet Trees
- Quad Trees
Types of Range Queries
There are different types of range queries that can be performed on a dataset. Some of the common types are:
- Range Sum Query :
- Range Minimum/Maximum Query :
- Range Update Query :
- Range Count Query :
It is used for calculating the sum of the values between the start and end index.
It calculates the minimum or maximum value between the start and end index.
It updates the values between the start and end index.
It counts the number of values between the start and end index.
Applications of Range Queries
Range Queries are used in various applications, such as:
- Database Management Systems
- Geographical Information Systems
- Image Processing
- Computer Graphics
- Machine Learning
- Web Search Engines
- Network Traffic Analysis
- Statistical Analysis
- Genomic Data Analysis
- Financial Analysis
- Scientific Computing
- Game Development
These are some of the applications where range queries are used to efficiently access and process the data.
Conclusion
Range queries are important concept in data structures. You can use it for various operations and also it is useful in competitive programming. You can use range queries to solve many problems efficiently.