algorithm

c algorithm - question

What kind of algorithm should i use to calculate 2^n . . Where n is always greater than 100 . . Suggest a good algorithm using c :) ...

Connect the dots - connect the line between contour points

I have a gray scale image of 64x64. I found the dots of the contour by a simple algorithm: find brightest spot (Example: 100) divide by 2 (100/2 = 50) define a band around the result (50-5=45 to 50+5=55) mark all dots that have value in the band (between 45 to 55) The question now is, how do I decide of the order of connecting the d...

How to convert a binary file into a Long integer?

In python, long integers have an unlimited range. Is there a simple way to convert a binary file (e.g., a photo) into a single long integer? ...

Where shall I find Questions to be put up in a Coding contest?

Err....I guess this aint correct place to ask this question... But i couldn't find any place where i could get the desired coding problems, that i should put up in a Coding contest, which we are organizing as a part of our college function & I really want the Problems to be Advanced! ...

nth root of a number

I wrote a program to calculate nth root of a number upto 2 decimal places. eg 4th root of 81 is 3., 3rd root of 125 is 5.Its working nicely except for the 2nd root of 4. It's giving the output 1.99 instead of 2. Here is the code. #include<stdio.h> int main(int argc, char **argv) { double root1(int,int); int n; int num1; ...

Algorithm to check whether one set is a proper set from another set

Write an algorithm to check whether a set A is proper set from B or not. (Hint: proper set is that set A is subset from B but they should not be equal, the result should be either True or False, if true that means A is proper set else it is not proper set) ...

Help with understanding this algorithm

I would like to implement the Ramer–Douglas–Peucker_algorithm in C++. The pseudo code looks like this: function DouglasPeucker(PointList[], epsilon) //Find the point with the maximum distance dmax = 0 index = 0 for i = 2 to (length(PointList) - 1) d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) if d > ...

Minimize price for volume discount orders

Hi all – I’m trying to put together a system to suggest consumable kits based on a requested quantity. The challenge I’m running into is that the kits have volume/bulk discounts, so it may be cheaper for the customer to order a larger quantity because the price may be less. For example, let’s say the available kits are: 25 widgets fo...

Implementing a question analyzer for auto tagging

What are good resources to go to for implementing a question analyzer? I am trying to figure out how to auto-tag questions to make it easier for non-technical users to ask questions. I've found that using Bayes Theorem I can achieve this, but I have no idea how to implement it. Any open source libraries or research papers on this? ...

How to implement substring algorithm

I am trying to implement an algorithm to take a string of length n and returns all substrings with a length of 2 or greater. If the user inputs a string e.g "abcd", then the output should be ab, bc, cd, abc, bcd, abcd. a=input("Ente the input") list=[] com="" for k in range(2,len(a)+1): for x in range(k,len(a)+1): com="" ...

Simplifying a cubic bezier path?

I'm trying to achieve something close to what Adobe Illustrator does with the brush tool. It correctly analyzes and simplifies the path, including its bezier handles. I implemented the Ramer–Douglas–Peucker_algorithm however, it wound up not really being what I needed. It works very well for line segments, but doesn't factor in bezier ha...

Treap with implicit keys

There's a data structure called treap: that's a randomized binary search tree, which is also a heap on randomly generated so-called "priorities". There's a variation of this structure, where keys are implicit, they aren't stored in the tree, but we consider the ordered index of the node in the tree as this node's key. We need to store s...

Need help with a word-packing algorithm

I have a list of sub-lists of letters, where the number of letters in each sub-list can vary. The list and sub-lists are ordered. This structure can be used to produce words by choosing a number X, taking a letter from position X in every sub-list and concatenating them in order. If the number X is larger than the length of the sub-list,...

Why use binary search if there's ternary search?

Hello, I recently heard about ternary search in which we divide an array into 3 parts and compare. Here there will be two comparisons but it reduces the array to n/3. Why don't people use this much? ...

Find the nearest dot in a 2D space

Yesterday I read a problem which can be translated into the following problem with slight modification: The coordinate of a dot is expressed by (x, y) in a 2D space. Input : An array of dots ARRAY = (x1, y1), (x2, y2), (x3, y3), ..., (xn, yn) and another dot D = (xi, yi) Find the dot in the ARRAY which is nearest to D. By sa...

What situations require me to store different versions of the same data in a database?

This is a shot from Google BigTable paper What can be the kind of scenarios in which instead of having something like Oracle's redo logs, I will need to store multiple versions of the same data within the database? Coming specifically to this example, why do I need to store multiple versions of a html page in my database? It cannot ...

Compress two or more numbers into one byte

Hi, I think this is not really possible but worth asking anyway. Say I have two small numbers (Each ranges from 0 to 11). Is there a way that I can compress them into one byte and get them back later. How about with four numbers of similar sizes. What I need is something like: a1 + a2 = x. I only know x and from that get a1, a2 For the...

Is it possible to have only one comparison per iteration of a binary search algorithm?

In binary search algorithm we have two comparisons: if (key == a[mid]) then found; else if (key < a[mid]) then binary_search(a[],left,mid-1); else binary_search(a[],mid+1,right); Is there a way by which I can have only one comparison instead of the above two. -- Thanks Alok.Kr. ...

How to improve this algorithm which fills up a calendar grid?

I have Grid which will render a calendar, and I'm provided with an ArrayList<CalendarEventEntity> which contains events. Those events have to be highlighted in the grid. As I have to fill the grid by my self I have something like this: for( loop through the days of the month ){ Calendar eventDate = event.getDate(); // look for ...

How do I detect memory access violation and/or memory race conditions?

I have a target platform reporting when memory is read from or written to as well as when locks(think mutex for example) are taken/freed. It reports the program counter, data address and read/write flag. I am writing a program to use this information on a separate host machine where the reports are received so it does not interfere with ...