Algorithms – Google Information Providers (example for setting the current time)

I want you to guide me on how to create something similar to the following image, but with my own information.

This page displays specific information that is updated daily. I would like them to look similar if you are looking for "current weather" or any other information provider, eg. For example, if you enter "$ 13 in Argentine pesos." Thanks in advance

Search for the current time on Google

Algorithms – retrieve the alphabet – Huffman code

Keep in mind that it is necessary to use the Huffman algorithm to obtain the encoding of the alphabet {p, q, r} with the frequencies fp, fq, fr. In each of the following cases, give an example of the frequencies fp, fq, fr that would yield the given code. If you can not get the given code, what is the reason?

        (a) p = 0, q = 10,  r = 11          
        (b) p = 0, q = 1,  r = 00 
        (c) p = 10, q = 01,  r = 00

Algorithms – Achieving Local Optimality in Simulated Annealing

I am currently reading about local search techniques. I understand that local search algorithms tend to be in local optima and therefore usually do not find globally optimal solutions. Therefore, there are more sophisticated approaches that allow us to maintain local optima and improve overall solution quality (eg, simulated annealing or genetic algorithms).

What I'm thinking of is this: As far as I understand, the simplest approaches, such as mountaineering (best-fit), will at least be guaranteed to find locally optimal solutions to the given neighborhood. Do not we lose this property when we use simulated annealing or genetic algorithms? Even for the first version of mountaineering, it is no longer guaranteed to find a local optimum and at the same time to have the advantage of a possible runtime shortening.

Is it a compromise between an increased ability to achieve globally optimal solutions (or a reduced runtime in the first-fit case of mountaineering) and a higher risk of not even getting a locally optimal solution?

Algorithms – Improve algorithmic complexity

We have an array of N size. We need to perform Q queries that include each query, and Index I, for which we do the following:

for j=I+1 to N:
  if A(j)

The queries are not independent of each other, so we have to use the modified array every time.

I've thought a lot, but could only find a brute-force solution with the complexity of O (Q * N). Can someone tell me a better solution?

E.g: -

Array- 4 3 4 3 2, Query-3 2
After Query 1(Index 3, element 3)- 4 3 4 3 0
After Query 2(Index 2,element 4)-4 3 4 0 0

Algorithms – Minimal changes to obtain an alternating sequence

I have recently studied DP and have encountered a problem that I think (possibly wrongly) is a modification of the classic LAS problem (Longest Alternating Subsequence).

However, instead of asking you for the maximum length, this issue asks you how many changes should be made at least V(i) Element so that the entire input array becomes an alternating sequence. Changes can only be subtractions, no additions.

Example: 2 5 8 6 1 2

In this case, the minimum number 1: You can do that 8 one 4, for example.

The answer could be 0 even if the entire sequence already alternates.

I know that we have to stick to the solution of the LAS DP(i)(0) the size of the longest alternating sequence that ends in i for which the last element is larger than the previous one and in DP(i)(1) the same if the last element is smaller than the previous one. And we build this up by iterating from 1 to i-1,

But how do I find the changes I need to make to turn the entire sequence into an alternate one?

Algorithms – Start with an initially empty AVL tree and draw the resulting AVL tree after pasting

Start with an initially empty AVL tree and draw the resulting AVL tree after inserting the following elements one at a time. 50, 70, 30, 10, 20, 15.

I'm not sure if I'm doing it right, since I'm new to AVL trees. Do I turn if there is an inequality after inserting, or do I insert everything, then just rotate the AVL tree?

Here is my attempt:

  1. First I add 50, 70, 30, 10, 20.
    30  70

Then I realize that there is an imbalance, so I turn and get

    20  70
  10  30

There is another element to insert, namely 15. So I put it in the tree

    20  70
  10  30

and there is an imbalance again. So I turn it

  10    50
    15 30  70

My question here is if I insert everything and then just turn or rotate if there is an imbalance in the paste. I did the latter. Can I know if my approach is correct? I am new to AVL trees. thanks

Search algorithms – Minimum number of tree sections, so that every pair of trees changes from strictly decreasing to strictly increasing

I want to find the minimum number of tree trims so that each tree pair in a tree sequence alternates between a strict decrease and a strict increase. Example: In (2, 3, 5, 7) the minimum number of tree sections is 2 – a possible final solution is (2, 1, 5, 4).

My search model is a graph in which each node is a possible configuration of all tree heights and each edge is a tree cut (= a reduction in the height of a tree). In this model, one possible path from the starting node to the destination node in the above example would be (2,3,5,7) – (2,1,5,7) – (2,1,5,4). , I used a breadth first to find the destination node. Since BFS does not cross traversed nodes, the part of the diagram I traverse during the search is actually a tree data structure.

The only improvement to this algorithm that I was able to think about was the use of a priority queue that lists the possible nodes in ascending order one by number of cuts (as the conventional BFS already does) and two by the number of strikes increasing / decreasing knot orders triplets. This increases the likelihood that a target node with the minimum number N of slices will be within the first node of all nodes with N slices to be evaluated and the search can be completed somewhat faster.

The time required to execute this algorithm grows exponentially with the number of trees and the height of the trees. Is there any other algorithm / idea that could be used to speed this up?

Algorithms – Same partition up to an integer

For the partition problem, a set of positive integers with the same sum must be split into two subsets. This problem is known to be NP-hard. But the following variant is simple:

Partition a set of integers into two subsets so that the difference between their sums is at most the largest integer.

There is always a solution that can be found with the following algorithm:

  • Arrange the integers by decreasing value.
  • Enter the largest integer in subset A, the second in subset B, the third in subset A, and so on.

The sum in subset A is always at least as large as the sum in subset B, but when we remove the largest integer from subset A, the sum in subset B is at least as large as the remainder. Therefore, the partition is equal to one integer.

MY QUESTION IS: What happens if the subsets have cardinality constraints? Suppose there is $ 4 million Integers, subset A must be included $ m $ and subset B must be included $ 3m $ whole numbers. The above algorithm does not work, and in fact, there may not be a partition with an integer of up to one. What is an algorithm to decide if such a partition exists?

Algorithms – Uniformly distributed UVs on Bezier curves without lookup table

I have a network that is straight and I change it to follow along a Bezier curve. The problem is that mesh textures are stretched / contracted depending on the shape of the curve. Since Bezier curves do not have a constant slope, I had to use a lookup table for every net I want to bend.

The lookup table distributes the vertices and UVs evenly along the curve so that the textures look correct. But I was wondering if there was any way to do this without using a lookup table, because I would like to use a shader and would prefer not having to create arrays of spaces in my shader for each curve myself.

Is that even possible? I could not imagine an algorithm for it, so I wondered if anyone knew of a way to do it without a look-up table.

This is my current LUT approach in C #:

    private static void SetDistances(CubicBezier cb)
        _LUT(0) = 0;
        Vector3 prevPoint = cb.A;
        float precisionm1 = Precision - 1;

        for (int i = 1; i < _LUT.Length; i++)
            float t = i / precisionm1;
            var pos = cb.Evaluate(t);
            var delta = (prevPoint - pos).magnitude;
            _LUT(i) = _LUT(i - 1) + delta;
            prevPoint = pos;

    public static float Percentage(float t, CubicBezier cb)

        float iFloat = t * (Precision - 1);
        int idLower = (int)iFloat;
        int idUpper = idLower + 1;

        if (idUpper >= _LUT.Length)
            idUpper = _LUT.Length - 1;
        if (idLower < 0)
            idLower = 0;

        float result = Mathf.Lerp(_LUT(idLower), _LUT(idUpper), iFloat - idLower) / cb.Length;
        return result;

Code that changes the network:

    for (int i = 0; i < _vertices.Length; i++)
        Vector3 v = _vertices(i);
        float t = v.z / _subDivisions;
        Vector3 pos = _cb.Evaluate(t);
        Vector3 perp = _cb.Perp(t);
        if (Mathf.Abs(v.x) <= Mathf.Epsilon)
            _newVerts(i) = pos;
            _newVerts(i) = pos + perp * v.x;
        _newVerts(i).y = v.y + pos.y;
        _newuvs(i) = new Vector2(_uvs(i).x, Bezier.Percentage(t,_cb) * _cb.Length);

Greedy Algorithms – activity selection with changeable start time

I investigated a problem in my work and reduced my problem to the problem of activity selection. It is a problem that I know and that I know with the greedy solution.

However, with my problem, the start time of my activities may shift to some extent (forward or backward) while the duration is still the same. Let's say 15 minutes. I assume that this results in better optimization than a conventional problem.

On the other hand, I am not sure how to solve this problem. I think of an idea like this:

 - Create 30 more activity from -15 min to +15 min for each single original activity which they forms a set of 31
 - Run the original greedy search
 - Chose only one of each set of 31 item.

In this sense, there is another question: how to choose as in the third step of the algorithm?

I would like to receive your comments on my approach. Is it efficient? Is there a better solution?

thank you in advance