Questions tagged [algorithms]

In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
203 views

K-nearest neighbors for friend recommendation system

I want to write algorithm that will find recommended friends for given user. I was wondering if K-nearest neighbors algorithm will work fine for that task? Firstly, I'm not sure if I understood this ...
  • 101
2 votes
1 answer
478 views

Running time for simple for loops - Big O notation

I am currently doing some exercises with algorithms and I find myself in a huge problem. It seems that everybody understands this type of problem but I have a really hard time figuring it out. For ...
-2 votes
2 answers
2k views

Is using nested try-except blocks problematic?

I've been seeing a lot of this construct throughout my application: def doSomething(): try: # setup some variables try: # do something that could throw an OSError ...
  • 1,017
0 votes
1 answer
58 views

Find concurrent users with timeranges

So my question is more algorithm based rather than code or architectural problem. I have a problem where I am given an array of object like this: [{joinedAt: <Timestamp>, leftAt:<Timestamp>...
1 vote
1 answer
95 views

Should exception-blocks handle only exceptions raised from try-blocks?

Should the exception blocks in a try-except sequence be specific only to those exceptions which may originate from the try? Or can they be inclusive of exceptions that may arise from handling the ...
  • 1,017
4 votes
1 answer
224 views

Mentorship schedule matchmaking algorithm

A while ago, I tried to help a fella to develop a mentorship matchmaking program given the answers of a questionnaire to match mentors and mentees according to their respective skills and available ...
0 votes
1 answer
121 views

how to store the data for function f(time,length)

I have a function which has discrete time step ,discrete length from origin . These two give height of the function. For example at time 1.2sec , and length 5.5cm from origin height is 10cm. The step ...
-1 votes
2 answers
232 views

How to tell if a group of items is stacked horizontally or vertically based only on their positions?

How do you tell if a group of items is stacked horizontally or vertically given only the items x and y positions? Vertical Group: item 1 item 2 item 3 Horizontal Group: • item 1 • item 2 • item 3 ...
-5 votes
1 answer
81 views

How to write algorithm of distribution amounts

I have an array of N integer values, and I need to sum elements and distribute these sums by equal parts in the range from 150 to 250, but without to mix indexes. For example {50,100,50,250,200,49, ...
  • 101
2 votes
2 answers
571 views

How to find the nearest integer number that when multiplied by a set of decimals still gives an integer number?

I do not know how to properly formulate this question, but I am trying to find the best algorithm to get the nearest integer number where every set of numbers (including decimals) give an integer ...
0 votes
1 answer
705 views

Find duplicate subgraphs in directed graph?

Is there a good way to search for duplicate subgraphs in an immutable directed graph, where edges and nodes may be labeled? I was thinking I could try to name the nodes according to their position in ...
0 votes
2 answers
734 views

Algorithm to find minimum number of elements that occur in all sets

I have n sets that each contain some elements, for example: {2, 3}, {6, 3}, {2, 7, 3}, {7} Now the goal is to find the minimum number of elements that occur in all sets. For this example it would be 2 ...
  • 109
0 votes
1 answer
151 views

Versioning of data handling pipeline elements

I have developed a custom-made Python package, which provides 2 classes to play with: Stage and Step. They operate based on a Chain of Responsibility design pattern, and behave in a way where: Both ...
  • 109
-4 votes
4 answers
2k views

Time efficient way to count pairs in an array whose sum is divisible by a specific number?

Given an array of integers, we want to find how many explicit pairs can be made such that their sum is divisible by 60. The pairs are not necessarily non-unique. For example, let's say the input into ...
  • 1,359
3 votes
1 answer
177 views

Nested loop complexity

I am working through MIT 6.006 OpenCourseWare as taught in Fall 2011. Problem 1.2c asks for the time complexity of an algorithm1 which finds a peak element (i.e. all neighbors are less than or equal) ...
0 votes
1 answer
73 views

Pubsub model - publisher broadcast to remote subscribers

With a single publisher(go-routine) and multiple subscribers(go-routine) on same machine, below message hub help create pubsub model: type PublisherHub struct { subscribers map[*subscribmediator....
  • 2,245
0 votes
1 answer
1k views

Efficient way to find Xor of pairs with given target X in a range 0 to K

I came across a problem: given an array (can be huge 10^8) and an integer, K, find the count of pairs in the array whose Xor equal to each value in the range 0 to K. eg: Arr = 1 2 3 K = 2 since K=...
12 votes
2 answers
975 views

Data structure for multi key range queries

I need a data structure that gives the best performance for multi-key range lookups. I do not need to update/insert/delete. This will be immutable. The use case is in-memory filtering of values over ...
20 votes
6 answers
4k views

Using a different algorithm depending on the size of the input

I recently finished a course on advanced algorithms, and another on complexity & computability theory, and in the past few days my mind has been somewhat preoccupied by this question. Why don't we ...
  • 335
0 votes
0 answers
71 views

Time-indexed "array" of time spans

I have a list of objects that have durations, ProcedurePart Start: double Stop: double Instructions: string they occur sequentially after each other: stepOne stepTwo ...
-4 votes
1 answer
568 views

Better way to process huge files

I have a huge csv file and I have to process that file and do some data manipulation. Right now I'm reading/loading the file in buffer and then doing the data processing work. I find this approach ...
-2 votes
2 answers
242 views

Is looping an array to compare to itself considered O(n^2)? [duplicate]

Often when I'm doing an operation comparing an array to itself, I write code along these lines: function operation (array) { for (let i = 0; i < array.length; i++) { for (let j = i + 1; j <...
4 votes
2 answers
464 views

How to show fluctuating data smoothly and accurately?

I am working on a project in which I have to read data from liquid level sensor installed in tank which measures fluid level and sends output in millivolt. The device has predefined ranges of voltage ...
1 vote
3 answers
2k views

Need help finding an efficient way to group the keys in a dictionary into buckets defined by the values in the dictionary?

I have a dictionary in the form of Dictionary<int, List<int>> The problem is that I need to group the keys together into buckets defined by the value (List<int>). It is easier to ...
  • 139
3 votes
5 answers
387 views

Applying function to file line by line or read entirely into structure first?

I've often found myself with the need to develop tools that process large files over a network and perform an operation to every element in that file. An element may be an individual line or an object ...
  • 1,017
-3 votes
2 answers
914 views

Which hash algorithm is best for speed and identical hashes. (a lot of collisions)

I'm searching an existing hash function or trying to make a hash function that has a lot of collisions. Regularly a hash is used for it's ability to create unique hashes for hash tables or security ...
1 vote
0 answers
152 views

Rectangle packing / Bin packing with multiple frames

I have multiple rectangular frames, with different fixed heights. The width should be minimized and there is a maximum width. Then there are many different smaller rectangles. These should be packed ...
-5 votes
1 answer
47 views

Choosing 2 or 3 values out 3 values after calculating their closeness

I want to find a specific algorithm to choose either 2 or 3 out of 3 given values. Like if I have a set of values 10,11,12 all three are close enough so I will calculate the mean of the value and ...
2 votes
2 answers
282 views

Collaborative graph exploration algorithm

Given a minimum spanning tree in an unweighted graph of (10 .. 500) vertices and (vertice_count .. 1000) edges. Each vertex can have up to 6 edges. Given K agents/bots/processes/etc.., all starting ...
4 votes
3 answers
266 views

How to return "debugging" information during the execution of an algorithm

I was recently tasked with thinking about returning optional tracing information about the execution of a complex algorithm. It's the kind of data you need to analyse the inner workings - a bit like ...
  • 157
5 votes
5 answers
849 views

How can billion integer ids be stored and specific ones checked for existence most efficiently? (persistent solution, not just in-memory)

Let me preface this by saying that I am familiar with RDBMS. I have a solution using mysql/mariadb but I am not happy with the efficiency of the solution so I'm looking for alternatives. I'm trying ...
-4 votes
2 answers
3k views

Booking Availability Algorithm

I've been tasked with creating a booking system and need to figure out when rooms are available at specific time slots on each day. There are 5 available meeting rooms that can be booked at fixed ...
user avatar
0 votes
2 answers
134 views

How to minimize size of data given the need for a null pointer?

So I don't know how to formulate this clearly, as it's quite confusing. Hence the reason for asking this question, to overcome the confusion. I will do my best to make it clear, but part of the ...
  • 2,447
2 votes
2 answers
220 views

Time complexity for a small code

I'm trying to find the time complexity for the following code. N= number of elements in array D= a constant: D>1 V= a constant: V>1000 counter=1; //the maximum value of the counter is N/D. ...
  • 37
-3 votes
2 answers
118 views

Recursion + Stack/Queue usage in practical life implementation [closed]

I am very new to Data Structures and Algorithms. I want to use recursion + stack/queue in a grocery store inventory program that I am making. However, I can't come up with any good ways of using ...
1 vote
2 answers
240 views

Algorithm for rule-based sorting?

I am trying to plant a garden. Certain plants are good for some plants and bad for others, and I am trying to find the best order of plants: most adjacent friends and no adjacent foes, as defined in ...
  • 119
-4 votes
1 answer
328 views

What is the worst case Time Complexity for only the Divide Portion of the Merge Sort Algorithm?

Please, consider the below merge sort algorithm. Here we start with a divide portion which splits the array into halves and we do recursive operation on each half separately. I have ignored the merge ...
-1 votes
1 answer
49 views

Resolving Dependencies and Incompatibilities Deterministically

Problem Description I'm working in Python and I've been having a problem designing something to handle the following (abstracted) system: I have some objects (lets call them Nodes) that can be in ...
  • 3
0 votes
0 answers
81 views

Assigning weights dynamically to ensure equal distribution

Scenario:- The load balancer distributes traffic to backends with a simple round-robin mechanism. With default config, each backend is assigned weight "1" so all backends are given equal chance of ...
-4 votes
1 answer
57 views

Choose a most probable value from the list based on some text [closed]

Im looking for a good way to find a value from the given list based on a text. Example: This computer has 16GB ram and with the best processor in it. Case is made from aluminium. And I have ...
  • 103
3 votes
4 answers
441 views

An algorithm for self picking teams

Say I have 100 users, each with varying strength, and each with a top 5 set of "preferred teammates" and a top 5 set of "preferred enemies". I want to sort the users into two teams. User { int Id;...
  • 602
0 votes
1 answer
81 views

Design Algorithms and Data Structures Around a Lack of Fast Integer Division

I had begun scouring my code for optimization opportunities (execution speed, data parallelism, workload parallelism) yesterday when I noticed that there are very few opportunities for speeding up ...
  • 145
1 vote
1 answer
83 views

Using Builtin Method vs Manual Implementation

I work in a DevOps role and mainly write glue code and OS-level automation. I've rarely needed to deviate from existing language implementations or "reinvent the wheel" in the small programs I've ...
7 votes
7 answers
2k views

Best algorithm to sort tasks by priorities by a human

I have developed a task management tool. And some task lists can be very large. (I have myself more than 300 tasks to do). I would like to do some task reviews from time to time as the tasks pile up ...
  • 205
-1 votes
1 answer
55 views

Algorithm for subjective ranking by many people

My friends and I are trying to figure out which one of our professor's would win in a fist fight. (ie, 2 profs would fight at a time, and the victors of those fights would then fight, etc. until there ...
-3 votes
1 answer
93 views

Shopping Cart Offers

I have been wondering about this issue for quiet some time now. I find interesting and I have not been able to come up with a solution. This must be seen in a context of a shopping cart where you can ...
-4 votes
1 answer
117 views

Is there any formula or trick to count how many times a statement inside a nested loop gets executed?

I am modifying a software which is for trash collection. While reading the code, I asked myself is there any formula or trick to quickly calculate the number of time the statement gets executed inside ...
3 votes
3 answers
1k views

What is the right algorithm to match regex on a stream?

I'd like to match a regex pattern on a stream, but I am not sure what algorithm to use. I certainly don't want to load the entire file into memory. I tried to figure out how to do this, but I have ...
  • 1,181
0 votes
1 answer
85 views

Transitive matching in streaming application

Problem A streaming application should perform matching transitively i.e. if A == B & B == C then A == C Current Implementation Application accepts domain objects in a streaming fashion and ...
0 votes
1 answer
78 views

Booking problem

The initial task was to find very quickly, free time for resources, let say - hotel rooms, services availability. I came with following model: Let say we have 24h in 1 day, and 365(366) days in a ...
  • 101

1 2
3
4 5
44