0% found this document useful (0 votes)
83 views18 pages

Understanding Strand Sort Algorithm

The document describes the strand sort algorithm. Strand sort is a comparison-based sorting algorithm that works by repeatedly pulling sorted sublists out of the unsorted list and merging them together. It begins by examining the first element of the list to start a new sublist, then iterates through the rest of the list adding larger elements to the sublist until it is fully sorted. The sublist is then merged into the main output list. This process repeats until the main list is empty and all elements have been sorted. The time complexity is O(n) in the best case, O(n^2) in the average and worst cases. Advantages include better efficiency than selection sort and lower cache miss ratio than shell sort, while disadvantages are lower

Uploaded by

Arham Siddiqui
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views18 pages

Understanding Strand Sort Algorithm

The document describes the strand sort algorithm. Strand sort is a comparison-based sorting algorithm that works by repeatedly pulling sorted sublists out of the unsorted list and merging them together. It begins by examining the first element of the list to start a new sublist, then iterates through the rest of the list adding larger elements to the sublist until it is fully sorted. The sublist is then merged into the main output list. This process repeats until the main list is empty and all elements have been sorted. The time complexity is O(n) in the best case, O(n^2) in the average and worst cases. Advantages include better efficiency than selection sort and lower cache miss ratio than shell sort, while disadvantages are lower

Uploaded by

Arham Siddiqui
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Strand Sort

Date: December 20, 2023


Prepared by: Arham Siddiqui, Muhammmad Abdullah
In this presentation:
1. Introduction
a. What is Strand sort?
b. How does the strand sort algorithm work?
2. Implementation
a. Example with animation

b. C++ code
3. Particulars
a. Time complexity (Best, Average and Worst cases)
4. Advantages
5. Disadvantages
Introduction
What is Strand Sort?
Strand Sort is a comparison-based sorting algorithm. It operates by
dividing the original unsorted list into smaller sorted sublists, and then
repeatedly merging these sublists together until the entire list is sorted.

The name 'Strand Sort' comes from the way the algorithm 'strands' or
isolates sorted sequences from the unsorted list.

The Strand Sort algorithm works by repeatedly pulling sorted sublists


out of the unsorted list and merging them together.

Strand sort is a recursive sorting algorithm that sorts items of a list into
increasing order.
How does the strand sort algorithm work?
The algorithm begins by examining the first element in the list. This element
forms the beginning of a new sublist. The algorithm then continues through the
rest of the list, checking each element in turn.

If an element is found that is larger than the last element in the current sublist, it
is removed from the main list and added to the end of the sublist. This process
continues until the end of the list is reached, at which point the sublist is fully
sorted and is merged back into the main list.

The merging process is also straightforward. The algorithm compares the first
elements of the main list and the sublist. The smaller element is removed from its
list and added to the end of the output list. This process continues until one of the
lists is empty, at which point all remaining elements from the non-empty list are
added to the end of the output list.

The algorithm then repeats this process, creating a new sublist from the
remaining unsorted elements in the main list, and merging it into the output list,
until the main list is empty and all elements have been sorted.
Example

An Unsorted Array
This example is based on the description of the algorithm provided in the book,
IT Enabled Practices and Emerging Management Paradigms.
Step 1: Start with a list of numbers: {5, 1, 4, 2, 0, 9, 6, 3, 8, 7 }

Step 2: Next move the first element of the list into a new sub-list: sub-list
contains {5}

Step 3: Then iterate through the original list and compare each number to 5
until there is a number greater than 5.
1 < 5 so 1 is not added to the sub-list.
4 < 5 so 4 is not added to the sub-list.
2 < 5 so 2 is not added to the sub-list.
0 < 5 so 0 is not added to the sub-list.
9 > 5 so 9 is added to the sub-list and removed from the original list.
Step 4: Now compare 9 with the remaining elements in the original list until
there is a number greater than 9.
6 < 9 so 6 is not added to the sub-list.
3 < 9 so 3 is not added to the sub-list.
8 < 9 so 8 is not added to the sub-list.
7 < 9 so 7 is not added to the sub-list.

Step 5: Now there are no more elements to compare 9 to so merge the sub-list
into a new list, called solution-list.
After step 5, the original list contains {1, 4, 2, 0, 6, 3, 8, 7}
The sub-list is empty, and the solution list contains {5, 9}

Step 6: Move the first element of the original list into sub-list: sub-list contains
{1}
Step 7: Iterate through the original list and compare each number to 1 until
there is a number greater than 1.
4 > 1 so 4 is added to the sub-list and 4 is removed from the original list.

Step 8: Now compare 4 with the remaining elements in the original list until
there is a number greater than 4.
2 < 4 so 2 is not added to the sub-list.
0 < 4 so 0 is not added to the sub-list.
6 > 4 so 6 is added to the sub-list and is removed from the original list.

Step 9: Now compare 6 with the remaining elements in the original list until
there is a number greater than 6.
3 < 6 so 3 is not added to the sub-list.
8 > 6 so 8 is added to the sub-list and is removed from the original list.
Step 10: Now compare 8 with the remaining elements in the original list until there is
a number greater than 8.
7 < 8 so 7 is not added to the sub-list.

Step 11: Since there are no more elements in the original list to compare {8} to, the
sub-list is merged with the solution list. Now the original list contains {2, 0, 3, 7}, the
sub-list is empty and the solution-list contains: {1, 4, 5, 6, 8, 9}.

Step 12: Move the first element of the original list into sub-list. Sub-list contains {2}

Step 13: Iterate through the original list and compare each number to 2 until there is
a number greater than 2.
0 < 2 so 0 is not added to the sub-list.
3 > 2 so 3 is added to the sub-list and is removed from the original list.
Step 14: Now compare 3 with the remaining elements in the original list until there is
a number greater than 3.
7 > 3 so 7 is added to the sub-list and is removed from the original list.

Step 15: Since there are no more elements in the original list to compare {7} to, the
sub-list is merged with the solution list. The original list now contains {0}, the sub-
list is empty, and solution list contains: {1, 2, 3, 4, 5, 6, 7, 8, 9}.

Step 16: Move the first element of the original list into sub-list. Sub-list contains {0}.

Step 17: Since the original list is now empty, the sub-list is merged with the solution
list. The solution list now contains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. There are now no more
elements in the original list, and all of the elements in the solution list have
successfully been sorted into increasing numerical order.
Animation
Code
C++
Time complexity

Best Average Worst


case Case Case
O(n) O(n^2) O(n^2)
Advantages of Strand Sort
It is more efficient than the selection sort algorithm
The cache miss ratio for strand sort is less than that of shell sort

Disadvantages of Strand Sort


It is not as efficient in performance as quick sort or merge sort
It has a complex algorithm
Thank you.

Common questions

Powered by AI

The Strand Sort algorithm starts by examining the first element of the list, forming a new sublist with it. As the algorithm iterates through the list, it compares each subsequent element with the last element of the current sublist. If an element is larger, it is removed from the main list and appended to the sublist. This process continues until the end of the list is reached, resulting in a sorted sublist. The sorted sublist is then merged back into the main list.

The animation code in C++ for Strand Sort would demonstrate visually how the algorithm identifies and isolates sublists from the main list, removes them, and sequentially merges them back into the solution list. This dynamic illustration would help in understanding the iterative process of comparing and merging elements.

Strand Sort achieves its best time complexity, O(n), in an already sorted list. In this scenario, each iteration of stranding results in immediate merging as the elements naturally form sorted subsequences, minimizing the number of comparisons and operations.

Strand Sort is less preferable due to its recursive nature and larger time complexity in average and worst cases (O(n^2)) compared to the more efficient quicksort (O(n log n) on average). Its complex algorithmic steps in managing sublists can also make it cumbersome to implement and less intuitive than simpler, divide-and-conquer methods used by quicksort.

In Strand Sort, merging involves comparing the first elements of the main list and the sorted sublist. The smaller element is removed from its list and added to the end of the output list. This continues until one list is empty, after which remaining elements from the non-empty list are added to the output list. This newly merged list becomes the main list, and the process repeats with new sublists until all elements are sorted.

In a sequence like {5, 1, 9}, strand sorting begins by forming a sublist starting with 5. As we progress, 9 is identified as greater and is added to the sublist. The sublist is {5, 9}. When merging, this sublist is compared with elements already in the solution list or merged into it directly if it is the first iteration. For succeeding rounds, continue until all elements join the sorted sequence in the solution list.

The 'stranding' concept in Strand Sort refers to isolating sequences from the unsorted list that can consecutively form a sorted subsequence. This means selectively building a sublist that adheres to the order requirement, effectively 'stranding' or separating these elements from the rest, which allows the sorting process to focus on optimally building sorted sublists for merging.

The iterative aspect of Strand Sort allows for the formation of multiple ordered sublists that can be merged efficiently, improving upon the selection sort which handles elements more sequentially with constant comparisons, making Strand Sort more adaptable to partially ordered lists and overall more efficient in such cases.

Recursion in Strand Sort allows the algorithm to manage the stranding and merging processes in a systematic, backward-tracking manner. It efficiently organizes sublists for merging. However, recursion can also lead to higher memory usage and stack overflow for very large lists, potentially slowing down performance when managing multiple recursive calls.

Advantages of Strand Sort include its efficiency over selection sort and a lower cache miss ratio than shell sort. However, it is less efficient in performance compared to algorithms like quick sort or merge sort and is considered complex.

You might also like