0% found this document useful (0 votes)
73 views9 pages

Tim Sort

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

Tim Sort

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

TIM SORT

- An Efficient Hybrid Sorting Algorithm


WHAT IS TIM SORT ?

Timsort is an hybrid algorithm derived from merge sort and


insertion sort.
Timsort is designed by Tim peters in the year 2002 for the python
programming language.
The main idea of tim sort is to exploit the existing order in the data
to minimize number of swaps and comparisons.
 It achives this by dividing array into small array called runs which
are already sorted and then merge it.
It is used in python’s sorted function.
ALGORITHM FOR TIMSORT

STEP1 : DEFINE THE SIZE OF THE RUN

STEP2 : DIVIDE THE ARRAY INTO RUNS

STEP3 : MERGE THE RUNS

STEP4 : ADJUST THE RUN SIZE

STEP5 : CONTINUE RUNS


CODE FOR TIMSORT ALGORITHM

USING MERGE SORT AND INSERTION SORT


CODE
TIME COMPLEXITY ANALYSIS FOR TIMSORT

• BEST CASE :O(N)

• AVARAGE CASE : O(N*LOG(N))

• WORST CASE : O(N*LOG(N))

• STABLE : YES
Tim Sort

Advantages Disadvantages
Efficiency on real world data It takes additional memory for
particularly on partially sorted temporary arrays while merging
data sort
Stability : It is a stable sort which While handling certain edge cases
means after an swap element such as nearly sorted data with
position is fixed few elements out of order
It is adaptive ,when data is Not always the fastest algorithm
partialy sorted it performs better there are more fast algorithm than
that O(nlog(n)) time timsort
conclusion

Hybrid algorithm : combines two sort as merge sort


and insertion sorting

Stable sorting : It maintains relative order of equal


elements

Versatility : It is designed to handle the wide range of


data types
THANK YOU

BY CB.SC.U4CSE23202
CB.SC.U4CSE23212
CB.SC.U4CSE23223
CB.SC.U4CSE23229

You might also like