newton-peixoto

newton-peixoto

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.

Showing Posts 1 to 7

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 OP

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)

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews