The complexity of the time to find k successors in BST

Given a binary search tree (BST) of height h, it would take O(k+h) time to apply the BST InOrder Successor algorithm k times in succession, starting in any node, applying each next call on the node that was returned by the previous call. Pseudo code:

Minimax problem - connect four.

I'm struggling with a minimax exercise, I'm just trying to make a connect four ai with it. Mine works when only exploring one node deep but I can't figure out why it messes up once it goes deeper. private int minimax(Gameboard gameBoard, int alpha, i

Confusion about the complexity of Bubble sorting

From how to calculate Bubble sort Time Complexity on stack overflow i come to know that complexity of worst case of bubble sort is Big Oh = n^2 But my confusion is the way it has been derived is Big Oh = n + n - 1 + n - 2 ... + 1 = (n(n + 1))/2 = O(n

Best analyzer algorithm for lexical structure transfer?

As part of a bigger project I want to implement a machine translator from language A to language B. Since there are not available tools that automatically do machine translation over this set of languages, and the available corpus of language B is qu

Data Structure Project Ideas?

Firstly this question maybe a little bit broad, if so, is there any stackoverflow related site where this question would not get marked as broad? Anyway I have a project and for that project I need to use data structure(s). I am unable to think of an

Bilinear ladder algorithm strange effects

I wrote an algorithm to scale image by billinear scalling method but it doesn't work as expected. I really cannot find any bug in my code but it's producing wrong output: Process(context: ImageData): ImageData { var imageData = context; var w = image

Reverse the numbers of a whole number

how to reverse a number? Example1: x = 123, return 321 Example2: x = -123, return -321 this is my answer: public int reverse(int x) { int result = 0; while(x != 0){ result = result * 10 + x % 10; x = x / 10; } return result; } but when I input 153423

Python algorithm for the area contained in the table (graphic)

This question already has an answer here: Algorithm to solve for water accumulation given building heights 3 answers Setup: Visualize a large array of numbers where each number represents a height of a bar on a bar graph. Ex: [5, 4, 3, 7, 2, 3, 1, 12

Update the maximum stream after adding an edge

Consider we have a network flow and using Edmond-Karp algorithm, we already have the maximum flow on the network. Now, if we add an arbitrary edge (with certain capacity) to the network, what is the best way to update the maximum flow? I was thinking

How to calculate RPG level progress as a percentage

I'm designing an RPG game where a user may accumulate experience points (XP) and level up, based on XP. Calculating the current level is trivial; if else seems to be most efficent. I would like to calculate percent of progression for the current leve

prints all nodes at a distance of 'x' from a given node in BST

The detailed question is to find all the nodes with distance x( i.e. number of edges =x) from a given node . I was asked in an Amazon Interview today, void findNodeWithDistanceX(struct node* root,struct node * qnode, int value) { //root is root Node,

Find how many different floating values ​​I have in a table

In order to solve a section from a problem, in which I'm given n pairs of integers x and y, I need to find how many different x/y are there. (the precise value, with decimals) 1. Of course I could just iterate through all the previous pairs and see i

Is there an algorithm that does not depend on n (input size)?

I was just curious yet google couldn't help me much with this. Does there exist any algorithm which doesn't depend on size of inputs? Like, whose time complexity won't depend on n?Any constant time algorithm (hashing, array lookup and adding to or re

longer substring with string exclusion list

I am using this algorithm to find common substring between 2 strings. Please, help me to do this but with using Array of common substrings of this strings, which I should ignore in my function. My Code in Java: public static String longestSubstring(S

Which algorithm should I use to convert this

To convert the black wave to the red signal. Taking forward Jesse Craig's answer and dukeling's comment of spotting a switch between increasing and decreasing does yield a solution, at least in simple cases where there is no noise. E.g. with this inp

Is there an effective way to find colors like this?

In our project, we will try to use different color for different figures. These colors should satisfy the following condition: All colors should meets: abs(A.R - A.G) + abs(A.G - A.B) + abs(A.B - A.R) > 250 All colors should be different enough. If c

How to solve diophantine linear equations in programming?

I have read about Linear Diophantine equations such as ax+by=c are called diophantine equations and give an integer solution only if gcd(a,b) divides c. These equations are of great importance in programming contests. I was just searching the Interne

how is gcd calculated from 4 number?

does gcd(gcd(a,b),gcd(c,d)) equal gcd(a,b,c,d)?or how can i calculate gcd of 4 number?yes that is correct. If you are finding the gcd of (a,b,c,d) then any split should work. So gcd(a,b,c,d) = gcd(gcd (a,b) , gcd(c,d))

The fastest / easiest way to calculate average ARGB colors?

I have five colors stored in the format #AARRGGBB as unsigned ints, and I need to take the average of all five. Obviously I can't simply divide each int by five and just add them, and the only way I thought of so far is to bitmask them, do each chann

How to generate circles that do not overlap in a fixed region?

What's the best way to generate a known number of non overlapping fixed radius circles in a limited space?The way to do this with the least leftover space is to put the centers of the circles on a hexagonal grid, like the pattern you'd get if you wer

How can I multiply (and divide) BCD numbers by 10 ^ x

I have a large (12 digit) BCD number, encoded in an array of 6 bytes - each nibble is one BCD digit. I need to multiply it by 10^x, where x can be positive or negative. I know it can be done by shifting left or right by nibble instead of bit, but it'