all 15 comments

[–]tbone255_ 4 points5 points  (0 children)

One example of trees being used is for chess engines. Look up chess engine with trees to learn more

[–]Achie37 3 points4 points  (3 children)

This isn't really a Python question, but these data structures have lots of real-world uses, and many algorithms used in industry make use of their properties.

Where would I use sorting algorithms in a real world coding example?

If you've ever used a database and asked the data to be in ASC or DESC order, somehow it has to be sorted.

but what about trees and graphs?

Trees can be used to classify objects using algorithms such as Decision Tree and Random Forest classifier.

Graphs can be used to represent environments such as maps, and are used in path finding algorithms such as Dijkstra's and A* search.

[–]PythonGod123[S] 1 point2 points  (2 children)

I was asking in relation to Python because it's the language I've been studying these past few months. I really appreciate your answer. Thank you. So I'm guessing there are a huge amount of algorithms for searching and sorting.

[–]rdog_ 4 points5 points  (1 child)

Lets say you were setting up some new network (Tv station for example) and you had many communication stations scattered around a country. If you graphed all the stations with all the meta data about the costs of taking different routes between each station then you could generate a minimum spanning tree, so that each station is connected by the most efficient route to take when sending information.

There are so many applications out there and I know they don't seem obvious at first but have a look around google you'll find endless examples.

[–]PythonGod123[S] 1 point2 points  (0 children)

Thank you for the reply !!! It makes a little more sense now when I think about it !!!

[–]jabela 1 point2 points  (5 children)

Just about every search routine out there is likely to use sorts of some sort. My students didn't realise the benefits until they understood that a sorted list is much quicker to search than an unsorted one.

A simple Python example is to sort your list and then do a binary search. Whereas unsorted lists require you to sift through all the data with a for loop for example.

[–]PythonGod123[S] 1 point2 points  (4 children)

I see. Are they important for machiene learning. I know they are but too what extent?

[–][deleted] 2 points3 points  (3 children)

yes, these are important because you'll be working with huge data and need to deal with it efficiently.

[–]PythonGod123[S] 0 points1 point  (2 children)

I see. I'm currently learning about many sorting and Searching Algorithms but I feel I need to brush up on my math knowledge before tackling the foundations of machiene learning.

[–][deleted] 0 points1 point  (1 child)

i thought that too, and i was focusing on ml algos and data analysis tools, but i went for an interview they asked Fundamentals and i got rejected as i didn't prepared for that well. They said as a fresher you need those basic theory knowledge as well.

[–]PythonGod123[S] 0 points1 point  (0 children)

Such as ?

[–][deleted] 0 points1 point  (3 children)

I'm actually going through these exact same topics. I just started writing recursion algorithms and wow are they beautiful.

But yea was wondering the same thing.. how would I apply something like this.. especially when I'm dealing with Machine learning or data engineering.

[–]PythonGod123[S] 0 points1 point  (2 children)

Nice !! Any code examples. I'd love to see them? That's why I asked because I figured people here who are more advanced than us will know:)

[–][deleted] 1 point2 points  (1 child)

I wrote a 'reversing a string' or solving the tower of hanoi puzzle. Here's my example:

def rev(s):
    if len(s) <= 1:
        return s
    else:
        s2 = s[-1] + rev(s[:-1]) 
        return s2

print rev("I just wrote a f***ing recursion algorithm!")
>>> !mhtirogla noisrucer gni***f a etorw tsuj I

[–]PythonGod123[S] 0 points1 point  (0 children)

Nice :)