I am trying to improve the running time of my algorithm that counts the total number of 0s in an input array. The input array has a length n and consisting of 0s and 1s which are arranged in sorted order. My algorithm so far is : Algorithm : zeroCoun

I was looking at a problem which stated to convert strings as below. s = "3[a]2[bc]", return "aaabcbc". s = "3[a2[c]]", return "accaccacc". s = "2[abc]3[cd]ef", return "abcabccdcdcdef". I was abl

This question already has an answer here: Counting integer points inside a sphere of radius R and dimension D 3 answers I am writing a computer program/algorithm to count the number of integer points inside a sphere of radius R and Dimension D center

I am implementing the quick sort algorithm from Cormen's Algorithm book(CLRS), but it always prompt "offset out of range", and I don't know how to fix it. Here's my code. template<typename Iterator> void quick_sort(Iterator first, Iterator

I have two IEnumerable collections of generic objects. Each object has a name and value property. The name is a string and the value is a double. I would like to merge the two into one and add the value properties. For example, say an object that is

This question haskell fold rose tree paths delved into the code for folding a rose tree to its paths. I was experimenting with infinite rose trees, and I found that the provided solution was not lazy enough to work on infinite rose trees with infinit

list split(int size,list l){ ........... } needed to write a routine, so that it can divide the original linked-list into multiple smaller linked-list of size (provided as a function argument). is it possible to do this better than o(n) complexity. a

Is there a more efficient way to walk a directory tree that contains link cycles than tracking which files have already been visited? For example consider walking a directory containing these files: symlink "parent" -> ".." symlink

The following code counts inversions in an array nums (pairs i,j such that j>i && nums[i] > nums[j]) by merge sort. Is it possible to use the same approach to count the number of special inversions like j>i && nums[i] > 2*nums[

I've seen a lot of techniques for swapping two variables without using a third. Swap two variables without using a temp variable How to swap two numbers without using third variable? [duplicate] Swap 2 values of 2 variables without using a third vari

I have an array of string say A=["hello", "you"] I have a string, say s="hello, hello you are so wonderful" I need to count the number of occurrence of strings from A in s. In this case, the number of occurrences is 3 (2 &quo

I was asked to give an algorithm that was supposed to be O(n(log(k))) k is the number of arrays and n is the total number of elements in all of these. I had to sort the arrays. Minus the details I came up with an algorithm that does the job for in kl

Forgive me if what I'm about to ask is obvious, but I've been thinking about it for 2 hours now! I just can't figure it out.... Well, I had something similar to this : for(int i=0;i<N;i++) for(int j=0;j<i;j++) I can certainly say that the complexity

This is essentially the problem of connecting n destinations with the minimal amount of road possible. The input is a set of vertices (a,b, ... , n) The weight of an edge between two vertices is easily calculated (example the cartesian distance betwe

I am trying to detect cycles with BFS algoritm in a directed graph. My main idea to detect the cycles is: since BFS visites each node (and edge) only once, if I encounter an already visited node again; it causes a cycle. However, my code sometimes fi

I have the task of creating two seperate programs, one linear search program, which I have already completed, and a binary search program. These programs must also count the number of comparisons made during the search process. My linear search progr

Have an array of hashes, my @arr = get_from_somewhere(); the @arr contents (for example) is: @arr = ( { id => "id2", requires => 'someid', text => "another text2" }, { id => "xid4", requires => 'id2', text =>

What are the time complexities of (1) randomly shuffling a list of length N? (2) randomly choosing an item from a set of N items N times?Depends on your shuffle algorithm and intended behavior. For instance, iTunes shuffle creates an alternate playli

How to implement CCL in c++ for a binary matrix of large size ? I have checked the algorithm in Wikipedia but I cannot understand how to go about solving it and also implementing the data structure to store the equivalance !! Any help would be highly

I'm having trouble understanding how any data structure can be "nonblocking". Say you're making a "nonblocking" hashtable. At some point or another, your hashtable gets too full, so you have to re-hash into a larger table. This implies

I am developing a simple quiz app on Android. The questions in the quiz should become more difficult as advancing in the quiz. Now, I am trying to implement a static method that takes a list of Question objects and produces (pick) a sub-list of the a

How to find intersections between two (or more) 3D planar polygons (for the simplest case they are all convex)? Seeking algorithms able to provide the intersection line if there is any. Note the methods proposed for infinite Plane-Plane cases are not

This question already has an answer here: What is the best algorithm for an overridden System.Object.GetHashCode? 16 answers As you know, GetHashCode returns a semi-unique value that can be used to identify an object instance in a collection. As a go

I have the following two questions. I'm aware of the concept of a linked list. What is a linked list of intervals? I need to store a very huge (more than 100 bits) number in C/C++ and perform bitwise operations on it. Without using any big number lib

I need to compare a value to a set of array. However, I need to compare multiple values in foreach. If using in_array, it can be slow, real slow. Is there any faster alternative? My current code is foreach($a as $b){ in_array($b, $array); } Thank you

I have to implement an algorithm that generates a timetable for a university. I've searched and found a lot of algorithms. But here is the problem. I need an algorithm that generates a timetable for the whole semester, not on a weekly base. It should

Okay, here is my problem: Im implementing an algorithm in Java and part of it will be following: The Question is to how to do what I will explain now in an efficient way. given: array a of length n integer array perm, which is a permutation of [1..n]

I am working with Dundas maps and need to overlay the map with bubbles depicting some data. I want to add shapes to the map in order to achieve this. I can add a triangle (or any straight-line-polygon) like this: public static void AddShape(this MapC

just looking for a bit of help in terms of the best way to proceed with the following problem: I have a list of a bunch of dialled numbers, don't think you need me to show you but for e.g. 006789 1234 006656 1234 006676 1234 006999 1234 007000 1234 0

Not strictly a question, more of a puzzle... Over the years, I've been involved in a few technical interviews of new employees. Other than asking the standard "do you know X technology" questions, I've also tried to get a feel for how they appro