DEV Community

Cover image for TimSort Algorithm in C with doubly Linked List
Traky Richard BLM
Traky Richard BLM

Posted on

1

TimSort Algorithm in C with doubly Linked List

Have you already chosen a sorting #algorithm?

I admit that the exercise is not one of the least, the sorting algorithms, there are dozens of them and everyone has their say.

Having almost all studied, one of the choices that I retain is the algo of #TimSort.

Timsort is an efficient sorting algorithm for real-world data. Created by Tim Peters and adopted in 2001 as the default sorting algo in the #Python programming language. Timsort first analyzes the list it is trying to sort, then chooses an approach based on the analysis performed.

The initial array is divided into sub-arrays called #RUN on which insertion sort is applied (insertion sort); and then merge sort on each of its RUNs to return to the initial array.

NB: The value of RUN may vary depending on the size of the initial array.

This algo allows you to have an order #complexity of O(n log n) in a worse case and a complexity of O(n) in a best case.

An implementation in C using the double linked lists that I made of this algo can be found in the Link

Your feedback is welcome in the comments.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay