Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Algorithms: Sorting and Searching Searching Names Sorting Names

Ernesto Salazar
Ernesto Salazar
21,555 Points

how is the algorithm sorting the list?

Hello everybody!, i would like to ask if some one knows how is this working under the hood so the programming language knows the correct order.

i have a suspicion that maybe the language is making a cohersion of the first letter of each string to something like a number to know if the string should be to right or left of the pivot. i don't know if i'm right so it would be awesome if someone could enlighten us.

2 Answers

Steven Parker
Steven Parker
231,269 Points

A typical sort method compares the first letters and orders the terms based on which one comes earlier in the alphabet. But if the first letters are the same, then it moves to the second letter and re-tries the comparison. This continues until it finds two letters that are different (or runs out of letters, in which case the order remains unchanged).

Ernesto Salazar
Ernesto Salazar
21,555 Points

Hello! thanks for your reply, i also did some research, and in addition to this i would also like to mention that most programming languages implements what is called ascii order, which compares the ascii representation of the characters.

there is another kind of sorting called natural order that you can find them used in things like the windows explorer file system and the Mac Finder, and it's apparently more complicated to implement.

i'll leave here some interesting posts so everyone can check them:

How do I do this in C#?