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:

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

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

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

I'm trying to replace words that are passed in with the word "CENSORED" but I can't figure out where to account for the difference between the replaced word and censored. Here's an example of the input and output. ./a.out Ophelia draw or <poe

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

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

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

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

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

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

The number can range from 1 to 1015. I am using this code but it is running out of time. int distinct(long long int a) { int ele[10]={0},i,c=0; if(a==0) return 1; if(a<0) a=a*-1; while(a) { int t=a%10; ele[t]=1; a=a/10; } for (i=0;i<10;i++) if (ele[

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,

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

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

I have an N by N grid, with values in each box. I have to move from the top-left corner to the bottom-right corner (path 1) and from the top-right corner to the bottom-left (path 2). When I move from top-left to bottom-right I can only move down or t

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

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

I have an Java object (Object 1), which I cannot modify, with 25 ArrayLists in it. I have to consume another object (Object 2) and place it into one of the corresponding lists of Object 1 based on a String that is found in Object 2. Each list has one

This is a homework assignment. The goal is to present an algorithm in pseudocode that will search an array of numbers (doesn't specify if integers or >0) and check if the ratio of any two numbers equals a given x. Time complexity must be under O(nlog

Which algorithm you would recommend for fast solution of dense linear system of fixed dimension (N=9) (matrix is symmetric, positive-semidefinite)? Gaussian elimination LU decomposition Cholesky decomposition etc? Types are 32 and 64 bits floating po

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

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

std::set<std::string> setStrings; setString.insert("abc"); setString.insert("abcd"); setString.insert("babc"); Question> I would like to know how to check whether "bab" is one of the stored string's prefix?

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))

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

I want to round a DateTime to the nearest 5 seconds. This is the way I'm currently doing it but I was wondering if there was a better or more concise way? DateTime now = DateTime.Now; int second = 0; // round to nearest 5 second mark if (now.Second %

There is an array of size n (numbers are between 0 and n - 3) and only 2 numbers are repeated. Elements are placed randomly in the array. E.g. in {2, 3, 6, 1, 5, 4, 0, 3, 5} n=9, and repeated numbers are 3 and 5. What is the best way to find the repe

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

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'