Shell Sort 1
Shell Sort 1
23I206- ATHISH S R
23I226- JOTHIPRAKASH K
23I228 - KAVIN A S
23I238 - MIDHUN M
23I246 – PRAGADEESH L A
23I264 – SHRIVISHNU R
Overview Of Problem Statement :
• The e-commerce platform needs to efficiently sort product prices in real-time to enable users to apply price filters
and sort products based on their price.
• This is crucial for a smooth shopping experience, especially as customers often interact with the product list
frequently.
Challenge:
1. Dynamic Updates:
• The product list is constantly changing, with products being added or removed.
• Each time a change occurs, the platform needs to re-sort the list to reflect the updated data.
2. Avoiding Full Re-sort:
• Re-sorting the entire list after every update is computationally expensive, especially when the list contains
hundreds or thousands of products.
• This would result in unnecessary delays and poor user experience.
Solution:
Shell Sort:
• The solution proposed is to implement Shell Sort, an optimization of Insertion Sort.
• Shell Sort improves the efficiency of sorting by comparing and swapping elements that are further apart,
which reduces the number of operations required as compared to traditional sorting algorithms like Insertion
Sort. Shell Sort’s gap sequence allows for larger jumps between elements in the early stages of sorting,
progressively reducing the gap to fine-tune the order.
• This provides better performance than standard insertion sort in practice, especially on larger lists.
Key Requirements:
1. Fast Sorting:
• The platform needs to sort prices quickly whenever users apply filters, ensuring a responsive user
experience.
2. Efficient Adaptation to Dynamic Changes:
• When products are added or removed, the system should be able to update the sorted list efficiently
without performing a full re-sort. Incremental sorting methods will be more efficient here.
3. Optimized Time and Space Complexity:
• The sorting algorithm must handle large product lists efficiently, with minimal computational overhead
and memory usage.
• This is especially important for an e-commerce platform with potentially high traffic and limited
resources.-
Shell Sort Algorithm:
1. Start with an initial gap, typically calculated as gap=⌊array size/2]
1. Compare the current element with the one that is gap positions behind.
2. If the two elements are out of order, swap them.
3. Continue this comparison and swapping within the gap sequence until the correct
position for the element is found.
4. End the process when gap=1 , and the array is fully sorted.
EXAMPLE:
Code:
Time and Space Complexity
1. Time Complexity
• 𝑂(1)
• Shell Sort is an in-place sorting algorithm, meaning it only uses a constant amount of
extra memory to store gap values and temporary variables during swaps.
Challenges
1. Frequent Price Updates and Real-Time Sorting:
The platform faces challenges in quickly sorting product prices after frequent updates (additions,
removals, price changes), which can lead to slow response times and poor user experience.
Shell Sort’s Efficiency: Shell Sort reduces the number of comparisons and swaps by progressively
decreasing the gap between compared elements, making it more efficient than standard Insertion
Sort.
The constant changes in the product catalog require efficient sorting mechanisms to avoid re-sorting
the entire list with each update, which would be computationally expensive and time-consuming.
Adaptive Handling of Updates: Shell Sort uses a partial sorting technique to efficiently update the list
by sorting only the affected region when products are added or removed, eliminating the need for full
re-sorting and optimizing update speed.
3. Limited Computational Resources:
The platform may struggle with limited server resources, where inefficient sorting algorithms could
lead to high memory usage, slower response times, and server overload during peak traffic.
Optimized for Space Efficiency: As an in-place algorithm, Shell Sort requires minimal additional
memory, making it space-efficient. Unlike algorithms like Merge Sort that need extra storage for
temporary data structures, Shell Sort operates directly on the original list, reducing memory usage
Benefits for Shell Sort
1. Faster than Insertion Sort: Shell Sort swaps distant elements earlier, reducing comparisons
and swaps.
2. Adaptive: Works better with nearly sorted data, speeding up sorting.
3. Efficient for Medium-Sized Data: Faster than basic algorithms like bubble sort for medium
datasets.
4. Reduces Time Complexity: Improves sorting time compared to insertion sort by using gap
sequences.
5. Space Efficient: It sorts in place, saving memory.
6. Easy to Implement: Simpler than advanced algorithms like quicksort but still efficient for smaller
datasets.
7. Good for Real-Time Sorting: Great for situations with frequent updates, as it can sort parts of
the data efficiently.
Conclusion
• Shell Sort helps optimize sorting on the e-commerce platform by reducing operations compared to
traditional methods.
• It quickly adapts to real-time price updates and handles product changes efficiently.
• This ensures fast performance, low-latency, and scalability, providing a smooth user experience
even with limited resources.
THANK YOU