newton-peixoto

newton-peixoto

Is it possible to implement all known algos within elixir?

Hello everyone, I’d like to know if is possible to execute all “populary known” algorithms in elixir. I’m asking that because most of algorithms use arrays for example and as far as I known elixir does not implement those so my question is if is possible to implement such algorithms with the same performance as in those languages that implement such data-structures.

First 7 of 7 Posts! Switch mode

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Algorithms designed around mutable datastructures will not translate directly into Elixir, nor will they perform the same. If you’re trying to get things done in Elixir this generally isn’t an issue as it just pushes you to reframe the problem into something more amenable to immutable datastructures, which gets you some side benefits along the way.

If your goal is to practice algorithms on mutable datastructures however then I’d pick a language that has those natively.

hauleth

hauleth

Possible to implement - yes. Will these perform equally well as in other languages? It depends on the algorithm. If such algorithm requires random access structures that can be cheaply updated, then implementing them in performant manner in Elixir will be hard, but you still will be able to do so (as per Church-Turing thesis).

newton-peixoto

newton-peixoto

I don’t think I get it. Talking about leetcode problems some of them has big O constraints and the solution to achieve such constraint is to use specific data structures those sometimes dont exist in functional languages so those kind of problems cant be solved in a “good time complexity”?

hauleth

hauleth

Complexity analysis is always constrained. For example in C++ you can do:

auto l = std::list{1,2,3,4,5};

std::cout << std::binary_search(l.begin(), l.end(), 1) << '\n';

[link]

And it will have O(n log n) “real” complexity despite the fact that std::binary_search is (by the standard) defined to have O(log n) complexity (the reason why there is such complexity and how C++ standard committee slipped that stuff there is left for the curious reader).

arcadian

arcadian

If you’re just doing it for educational purposes, sure. I came across a project like that in ruby a while back - implementations of pure ruby data structures like a red-black tree, a priority queue, etc. If you want actually useful data structures though, you’ll need to build them in C / C++ or something similar and then import the library as a nif.

cjbottaro

cjbottaro

Ok, I’m curious… :slight_smile:

If an array is already sorted, how is binary searching it not O(log n)?

Is it because in your example it’s a list and not an array where elements can be accessed in constant time?

hauleth

hauleth

Indeed. Because it is list, and advancing iterator over list is O(n) not O(1)

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement