The question is quite vague
Now there are multiple ways for the front end to connect to the backend. Let's see. But first let's recap.
Front End: Refers to the client side. The UI that the users interact with.
Example frameworks: ReactJS(JS/TS), VueJS, Angular etc
Back End: Refers to the server side work like authentications, data fetching etc.
Example frameworks: NodeJs(JS/TS), Django, ASP.NET etc
HTML, CSS and JS are the building blocks of websites. As the time progressed we got frameworks like Sprint(Java), asp.net(c#), django(python) etc. They may differ in the language they are built on top off. But they all follow the same patterns. Some of the common design architectures are:
- Model–View–ViewModel (MVVM)
- Model-View-Controller (MVC)
- 3 Tier Architecture
For difference in MVC and MVVM check this answer
Now the developers depending on the project chooses any one of this patterns. But this are just architectures that can be implemented with any of the frameworks out there.
How the front end and backend communicates is a different story. Let's say you and I are both tasked with creating a school management system.
You chose Angular(front end) and asp.net(backend). On the other hand I chose ReactJS(front end) and Nodejs(backend). We can both achieve the same goal. But with different languages.
API vs Templating: This are two different ways we can have our application establish communication between frontend and backend.
- Templating:
A template engine enables you to use static template files in your application. At runtime, the template engine replaces variables in a template file with actual values, and transforms the template into an HTML file sent to the client. This approach makes it easier to design an HTML page.
- API: API stands for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other.
Let's say the user in your school portal inputs his name and password and hits login. That will send a post request to the backend and the backend which you wrote will check if the user is real or not. If the authentication is successful the backend will send a message and the user will navigate to the portal's dashboard.
For a better understanding of when to choose templating vs API refer to this post
Now about the example you provided i.e bubble sort. You actually don't need a backend and develop an API to show the sorted data. And usually the backend is required for the websites which handles authentication, authorization, protected data etc like an e-commerce.
That said you can have a backend for such a project. You'll have to send the data to the server side which will sort the array and send the sorted result back.
Refer to the section on API/Templating to choose you're preferred method. Hope you'll have a good understanding on how to work your application.