﻿ DeveloperSite,exception,algorithm

## Find the shortest path between a given source and a set of destinations

You are given a weighted connected graph (20 nodes) with all edges having positive weight. We have a robot that starts at point A and it must pass at points B, D and E for example. The idea is to find the shortest path that connects all these 4 points. The robot also has a limited battery, but it can be recharged in some points. After researching on the internet I have two algorithms in mind: Dijkstra's and TSP. Dijkstra's will find the shortest path between a node and every other node and TSP will find the shortest path that connects all points. Is there any variant of the...

## Algorithm generating k-tuples of n items such that each is used at least once (k>n)

Given a set of n items, I'd like to generate all the ways we can select from this set (with replacement) k times such that order matters and each element is used as least once. So k>=n to have any valid arrangements. If k=n, this is just a permutation. So k>n is kind of like an extension of a permutation, but I do not know what it is called.It's of course easy to get an algorithm, albeit a horribly slow one: just iterate through all possible selections and toss the ones that don't have each element at least once. So to make something efficient will require tricks similar t...

## Easy interview question got harder: given numbers 1..100, find the missing number(s)

I had an interesting job interview experience a while back. The question started really easy: Q1: We have a bag containing numbers 1, 2, 3, …, 100. Each number appears exactly once, so there are 100 numbers. Now one number is randomly picked out of the bag. Find the missing number.I've heard this interview question before, of course, so I very quickly answered along the lines of: A1: Well, the sum of the numbers 1 + 2 + 3 + … + N is (N+1)(N/2) (see Wikipedia: sum of arithmetic series). For N = 100, the sum is 5050. Thus, if all numbers are present in the bag, the sum w...

## Given n-1*n array, find missing number

Here each row contains a bit representation of a number.These numbers come from 1..N Exactly one number is missing.Find the bit representation of the missing number.The interviewer asked me this question.I said: "We can find the sum of the given numbers and subtract it from the sum of first n numbers(which we know as (N*(N+1))/2)"He said that involves changing from base 10 to base 2.Can you give me a hint on how I can solve it without changing bases? You can XOR together all numbers from 0..N range, then XOR the numbers from the array. The result will be the missing numb...

## Merge the content of two tables (looking for Matlab or Pseudo Code)

THIS QUESTION IS NOT ONLY FOR MATLAB USERS - If you know an answer to the problem in PSEUDOCODE, then feel free to leave your answer as well!I have two tables Ta and Tb that have different number of rows and different number of columns. The content is all cell text, but maybe in the future it could also contain cell number.I want to merge the content of these tables together under the following set of rules:Take the value of Ta(i,j) if Tb(i*,j*) is empty and vice versa.If both are available, then take the value of Ta(i,j) (and optionally, check whether they are the same).Th...

## Can someone provide me a better proof and scenario for bubble sort compare to what i have proved

Give a list of unsorted elements.Initial condition is A=list of unsorted elements, p=1, N=total array size Bubble(A,p,N) if p>=N return for i=p to N-1 if A[i]>A[i+1] swap(A[i],A[i+1]) Bubble(A,p,N-1)Question 1: Prove the correctness of the algorithm by induction on N.My Problem:How can i use k+1 on Bubble(A,p,N-1)?I need someone explain and proof for me.Question 2:Prove that if an element once moves towards n, it will never move towards p for current and all forthcoming recursive calls.(unsolved)My problem: I know that after complete the first n-1 for loop of sorti...

## How can I use different encryption algorithms in OpenSSL for X.509 certificates?

I've been generating certificates for internal use at a company that may end up becoming more widespread as time progresses (rather than just on a single internal website). I've noticed that, when using OpenSSL, the certificates being generated show as using AES_256_CBC in Chrome, as shown below.I've been wondering, is it possible to use other encryption algorithms with OpenSSL? I've seen certificates for other websites showing up as using algorithms such as RC4_128, and CAMELLIA_256_CBC.If it helps, I have two versions of OpenSSL installed; 0.9.8l and 1.0.1c, and I'm using...

## Find permutations, that totally change the set of cumulative sums

I've got the following problem: Let N be a set of natural numbers with length n. Let S be the set of all cumulative sums, where a cumulative sum is the sum of the first k elements of a set. Now, given N, permutate its elements, so that S_i contains no element of S (i refers to the ith permutation). Find as many of these permutations, as possible.Could anyone help me with an idea? You don't have to give an algorithm, just an approach. Obviously, the last element in S_i (or S) is the sum of all elements. Regardless of how you permute the elements, this element w...

## Kalman Filter Prediction Implementation

I am trying to implement a Kalman filter in order to localize a robot.I am confused with the prediction step (excluding process noise) x = Fx + uIf x is a state estimation vector: [xLocation, xVelocity] and F is the state transition matrix [[1 1],[0 1]], then the new xLocation would be equal to xLocation + xVelocity + the corresponding component of the motion vector u.Why is the equation not x = x + u? Shouldn't the predicted location of the robot be the location + motion of the robot? Maybe there is some confusion with respect to what the matrices actually represent.Th...

## How do immutable languages implement set, concat, equals and such efficiently?

Certain array operations such as set, equals and concat would be considerably slow (mostly O(n)) if they needed complete structure copy on memory. I'm aware immutable languages such as Clojure use some tricks to avoid big complexity on those operations. What are those tricks? Because of the guarantees of persistent data structures "structural sharing " is used in Clojure. This means for example if you're adding to a list/vector with cons/conj the old data structure is shared between both the old and the new.Behind-the-scenes the data is stored in shallow trees with high...

## An algorithm for recomputation of marks on coordinate line depending on scale

I don't know how to formulate what the algorithm I need does in fewer words; it is highly possible that such question is already answered here, but I don't know how to search for it.What I need is the following.I'm writing kind of 2D graph plotting program. Obviously, drawing only main coordinate lines is not very good, since the graph can be located far from the origin, and the user will not have any reference for its size if only main lines are drawn.I decided to draw reference lines, that is, horizontal and vertical lines which appear periodically with constant interval,...

## All permutations in range with parameters

I am trying to find efficient algorithm to solve the following problem.Give a range of numbers from 1..N, and some arbitrary numbers K and M, find all possible permutation in given range. Where K represents the number of elements and M represents a minimum distance between elements. So let's look at the example:array = 1,2,3,4,5,6,7,8K = 2M = 2so the output then will be (3,5)(3,6)(4,6)so you can see how complexity increases if K and M getting bigger.Cheers. This problem is equivalent to finding subsets (combinations) of size k from set with n - (k-1)*(m-1) elements. Numb...

## Implementation of short bubble and bubble sort

Bubble sortIn the above URL it is clearly written that short bubble is a modification in bubble sort to reduce the number of passes.So in my implementation of both the algorithms i have added a counter which counts the number of passes and surprisingly both are having same no. of passes.Here is my code:def bubbleshort(mylist): flag= True passnum= len(mylist) -1 counter = 0 while flag and passnum > 0: flag = False for element in range(passnum): if mylist[element] > mylist[element + 1]: flag = True ...

## How to find the lowest common ancestor of two nodes in any binary tree?

The Binary Tree here is may not necessarily be a Binary Search Tree.The structure could be taken as -struct node { int data; struct node *left; struct node *right;};The maximum solution I could work out with a friend was something of this sort -Consider this binary tree :Binary Tree http://lcm.csa.iisc.ernet.in/dsa/img151.gifThe inorder traversal yields - 8, 4, 9, 2, 5, 1, 6, 3, 7And the postorder traversal yields - 8, 9, 4, 5, 2, 6, 7, 3, 1So for instance, if we want to find the common ancestor of nodes 8 and 5, then we make a list of all the nodes which are betwe...

## How to map out a maze as a robot?

First - I've looked through similar looking questions but they did not solve my problem, this is no repetition (I hope). I'm building and programming a robot with an Arduino Nano that is supposed to solve a maze. It gets put somewhere in the maze and then has to find an item. The next time it is supposed to go straight to the item (it does not have to be the shortest way but no dead ends allowed). It is not necessary to know the whole maze because as long as he has one way to the item it is good. As I said, I don't need the shortest way. The maze is 2D, I just put black tap...

## How to determine if a sequence is bitonic?

A sequence is bitonic if it monotonically increases and then monotonically de- creases, or if it can be circularly shifted to monotonically increase and then monotonically decrease. For example the sequences (1, 4, 6, 8, 3, −2) , (9, 2, −4, −10, −5) , and (1, 2, 3, 4) are bitonic, but (1, 3, 12, 4, 2, 10) is not bitonic.How can it be determined if given sequence is bitonic?I have the following opinion. We can walk till n/2, where n is the length of the array, and check if (a[i] < a[i + 1]) and (a[n - i - 1] < a[n-1 - (i + 1)])Is this correct? A...

Page 1 of 129  |  Show More Pages:  Top Prev Next Last