Search Results

Search found 5070 results on 203 pages for 'algorithm'.

Page 94/203 | < Previous Page | 90 91 92 93 94 95 96 97 98 99 100 101  | Next Page >

  • Efficient determination of which strings in an array are substrings of the others?

    - by byte
    In C#, Say you have an array of strings, which contain only characters '0' and '1': string[] input = { "0101", "101", "11", "010101011" }; And you'd like to build a function: public void IdentifySubstrings(string[] input) { ... } That will produce the following: "0101 is a substring of 010101011" "101 is a substring of 0101" "101 is a substring of 010101011" "11 is a substring of 010101011" And you are NOT able to use built-in string functionality (such as String.Substring). How would one efficiently solve this problem? Of course you could plow through it via brute force, but it just feels like there ought to be a way to accomplish it with a tree (since the only values are 0's and 1's, it feels like a binary tree ought to fit somehow). I've read a little bit about things like suffix trees, but I'm uncertain if that's the right path to be going down. Any efficient solutions you can think of?

    Read the article

  • Efficient way to get highly correlated pairs from large data set in Python or R

    - by Akavall
    I have a large data set (Let's say 10,000 variables with about 1000 elements each), we can think of it as 2D list, something like: [[variable_1], [variable_2], ............ [variable_n] ] I want to extract highly correlated variable pairs from that data. I want "highly correlated" to be a parameter that I can choose. I don't need all pairs to be extracted, and I don't necessarily want the most correlated pairs. As long as there is an efficient method that gets me highly correlated pairs I am happy. Also, it would be nice if a variable does not show up in more than one pair. Although this might not be crucial. Of course, there is a brute force way to finding such pairs, but it is too slow for me. I've googled around for a bit and found some theoretical work on this issue, but I wasn't able for find a package that could do what I am looking for. I mostly work in python, so a package in python would be most helpful, but if there exists a package in R that does what I am looking for it will be great. Does anyone know of a package that does the above in Python or R? Or any other ideas? Thank You in Advance

    Read the article

  • Length of Encrypted String

    - by Agnel Kurian
    I need to create a database column which will store a string encrypted using Triple DES. How do I determine the length of the encrypted string column? (Answers for algorithms other than Triple DES are also welcome.)

    Read the article

  • What are the core mathematical concepts a good developer should know?

    - by Jose B.
    Since Graduating from a very small school in 2006 with a badly shaped & outdated program (I'm a foreigner & didn't know any better school at the time) I've come to realize that I missed a lot of basic concepts from a mathematical & software perspective that are mostly the foundations of other higher concepts. I.e. I tried to listen/watch the open courseware from MIT on Introduction to Algorithms but quickly realized I was missing several mathematical concepts to better understand the course. So what are the core mathematical concepts a good software engineer should know? And what are the possible books/sites you will recommend me?

    Read the article

  • Recursion - Ship Battle

    - by rgorrosini
    I'm trying to write a little ship battle game in java. It is 100% academic, I made it to practice recursion, so... I want to use it instead of iteration, even if it's simpler and more efficient in most some cases. Let's get down to business. These are the rules: Ships are 1, 2 or 3 cells wide and are placed horizontally only. Water is represented with 0, non-hit ship cells are 1, hit ship cells are 2 and sunken ships have all it's cells in 3. With those rules set, I'm using the following array for testing: int[][] board = new int[][] { {0, 1, 2, 0, 1, 0}, {0, 0, 1, 1, 1, 0}, {0, 3, 0, 0, 0, 0}, {0, 0, 2, 1, 2, 0}, {0, 0, 0, 1, 1, 1}, }; It works pretty good so far, and to make it more user-friendly I would like to add a couple of reports. these are the methods I need for them: Given the matrix, return the amount of ships in it. Same as a), but separating them by state (amount of non-hit ships, hit and sunken ones). I will need a hand with those reports, and I would like to get some ideas. Remember it must be done using recursion, I want to understand this, and the only way to go is practice! Thanks a lot for your time and patience :).

    Read the article

  • Find all numbers that appear in each of a set of lists

    - by Ankur
    I have several ArrayLists of Integer objects, stored in a HashMap. I want to get a list (ArrayList) of all the numbers (Integer objects) that appear in each list. My thinking so far is: Iterate through each ArrayList and put all the values into a HashSet This will give us a "listing" of all the values in the lists, but only once Iterate through the HashSet 2.1 With each iteration perform ArrayList.contains() 2.2 If none of the ArrayLists return false for the operation add the number to a "master list" which contains all the final values. If you can come up with something faster or more efficient, funny thing is as I wrote this I came up with a reasonably good solution. But I'll still post it just in case it is useful for someone else. But of course if you have a better way please do let me know.

    Read the article

  • Comparing two speech sounds

    - by JessicaB
    I need to be able to determine if two sounds are very similar. The goal is to have a very limited vocabulary (10 or 15) of short one or two syllable words, then compare a captured sound to determine if it is one of those items with all the usual variability in environmental and capture conditions. The idea is that the user can issue a few simple commands by voice instead of keyboard or mouse. Does anyone know the best approach to this? I don't want to do full blown speech recognition, just something much more limited.

    Read the article

  • GWT Calendrical Calculations

    - by Kyle Hayes
    We have a GWT application that needs to display various holidays. Is there a library available to do these calendrical calculations? If not, we'll have to do our own that we can ingest a set of rules to. Cheers

    Read the article

  • question about quicksort

    - by davit-datuashvili
    i have write code of quicksort from programming pearls here is code public class Quick{ public static void quicksort(int x[], int l,int u) { if (l>=u) return ; int t=x[l]; int i=l; int j=u; do { i++; } while (i<=u && x[i]<t); do { j--; if (i>=j) break; } while ( x[j]>t); swap(x,i,j); swap(x, l,j); quicksort(x, l,j-1); quicksort(x, j+1,u); } public static void main(String[]args){ int x[]=new int[]{55,41,59,26,53,58,97,93}; quicksort(x,0,x.length-1); for (int i=0;i<x.length;i++){ System.out.println(x[i]); } } public static void swap(int x[], int i,int j){ int s=x[i]; x[i]=x[j]; x[j]=s; } } but it does not work here is output 59 41 55 26 53 97 58 93 any idea?

    Read the article

  • finding the maximum in series

    - by peril brain
    I need to know a code that will automatically:- search a specific word in excel notes it row or column number (depends on data arrangement) searches numerical type values in the respective row or column with that numeric value(suppose a[7][0]or a[0][7]) it compares all other values of respective row or column(ie. a[i][0] or a[0][i]) sets that value to the highest value only if IT HAS GOT NO FORMULA FOR DERIVATION i know most of coding but at a few places i got myself stuck... i'm writing a part of my program upto which i know: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading; using Microsoft.Office.Interop; using Excel = Microsoft.Office.Interop.Excel; Excel.Application oExcelApp; namespace a{ class b{ static void main(){ try { oExcelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); ; if(oExcelApp.ActiveWorkbook != null) {Excel.Workbook xlwkbook = (Excel.Workbook)oExcelApp.ActiveWorkbook; Excel.Worksheet ws = (Excel.Worksheet)xlwkbook.ActiveSheet; Excel.Range rn; rn = ws.Cells.Find("maximum", Type.Missing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlPart,Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing); }}} now ahead of this i only know tat i have to use cell.value2 ,cell.hasformula methods..... & no more idea can any one help me with this..

    Read the article

  • Solving a recurrence T(n) = 2T(n/2) + n^4

    - by user563454
    I am studying using the MIT Courseware and the CLRS book Introduction to Algorithms. Solving recurrence T(n) = 2T(n/2) + n4 (page 107) If I make a recurrence tree I get: level 0 n^4 level 1 2(n/2)^4 level 2 4(n/4)^4 level 3 8(n/8)^4 The tree has lg(n) levels. Therefore the recurrence is T(n) = Theta(lg(n)n^4)) But, If I use the Master method I get. Apply case 3: T(n) = Theta(n^4) If I apply the substitution method both seem to hold. Which one is ri?

    Read the article

  • Finding if a string is an iterative substring?

    - by EsotericMe
    I have a string S. How can I find if the string follows S = nT. Examples: Function should return true if 1) S = "abab" 2) S = "abcdabcd" 3) S = "abcabcabc" 4) S = "zzxzzxzzx" But if S="abcb" returns false. I though maybe we can repeatedly call KMP on substrings of S and then decide. eg: for "abab": call on KMP on "a". it returns 2(two instances). now 2*len("a")!=len(s) call on KMP on "ab". it returns 2. now 2*len("ab")==len(s) so return true Can you suggest any better algorithms?

    Read the article

  • A question about matrix manipulation

    - by appi
    Given a 1*N matrix or an array, how do I find the first 4 elements which have the same value and then store the index for those elements? PS: I'm just curious. What if we want to find the first 4 elements whose value differences are within a certain range, say below 2? For example, M=[10,15,14.5,9,15.1,8.5,15.5,9.5], the elements I'm looking for will be 15,14.5,15.1,15.5 and the indices will be 2,3,5,7.

    Read the article

  • more efficient version of this?

    - by john connor
    i have this thingy here : function numOfPackets(bufferSize, packetSize) { if (bufferSize <= 0 || packetSize > bufferSize) return 0; if (packetSize < 0) throw Error(); var out = 0; for(;;){ out++; bufferSize = bufferSize - packetSize; if( packetSize > bufferSize ) break; } return out; } which i run at often , can u give me more efficent variant of it?

    Read the article

  • Interview question : What is the fastest way to generate prime number recursively ?

    - by hilal
    Generation of prime number is simple but what is the fastest way to find it and generate( prime numbers) it recursively ? Here is my solution. However, it is not the best way. I think it is O(N*sqrt(N)). Please correct me, if I am wrong. public static boolean isPrime(int n) { if (n < 2) { return false; } else if (n % 2 == 0 & n != 2) { return false; } else { return isPrime(n, (int) Math.sqrt(n)); } } private static boolean isPrime(int n, int i) { if (i < 2) { return true; } else if (n % i == 0) { return false; } else { return isPrime(n, --i); } } public static void generatePrimes(int n){ if(n < 2) { return ; } else if(isPrime(n)) { System.out.println(n); } generatePrimes(--n); } public static void main(String[] args) { generatePrimes(200); }

    Read the article

  • How to find same-value rectangular areas of a given size in a matrix most efficiently?

    - by neo
    My problem is very simple but I haven't found an efficient implementation yet. Suppose there is a matrix A like this: 0 0 0 0 0 0 0 4 4 2 2 2 0 0 4 4 2 2 2 0 0 0 0 2 2 2 1 1 0 0 0 0 0 1 1 Now I want to find all starting positions of rectangular areas in this matrix which have a given size. An area is a subset of A where all numbers are the same. Let's say width=2 and height=3. There are 3 areas which have this size: 2 2 2 2 0 0 2 2 2 2 0 0 2 2 2 2 0 0 The result of the function call would be a list of starting positions (x,y starting with 0) of those areas. List((2,1),(3,1),(5,0)) The following is my current implementation. "Areas" are called "surfaces" here. case class Dimension2D(width: Int, height: Int) case class Position2D(x: Int, y: Int) def findFlatSurfaces(matrix: Array[Array[Int]], surfaceSize: Dimension2D): List[Position2D] = { val matrixWidth = matrix.length val matrixHeight = matrix(0).length var resultPositions: List[Position2D] = Nil for (y <- 0 to matrixHeight - surfaceSize.height) { var x = 0 while (x <= matrixWidth - surfaceSize.width) { val topLeft = matrix(x)(y) val topRight = matrix(x + surfaceSize.width - 1)(y) val bottomLeft = matrix(x)(y + surfaceSize.height - 1) val bottomRight = matrix(x + surfaceSize.width - 1)(y + surfaceSize.height - 1) // investigate further if corners are equal if (topLeft == bottomLeft && topLeft == topRight && topLeft == bottomRight) { breakable { for (sx <- x until x + surfaceSize.width; sy <- y until y + surfaceSize.height) { if (matrix(sx)(sy) != topLeft) { x = if (x == sx) sx + 1 else sx break } } // found one! resultPositions ::= Position2D(x, y) x += 1 } } else if (topRight != bottomRight) { // can skip x a bit as there won't be a valid match in current row in this area x += surfaceSize.width } else { x += 1 } } } return resultPositions } I already tried to include some optimizations in it but I am sure that there are far better solutions. Is there a matlab function existing for it which I could port? I'm also wondering whether this problem has its own name as I didn't exactly know what to google for. Thanks for thinking about it! I'm excited to see your proposals or solutions :)

    Read the article

  • How to find kth minimal element in the union of two sorted arrays?

    - by Michael
    This is a homework question. They say it takes O(logN + logM) where N and M are the arrays lengths. Let's name the arrays a and b. Obviously we can ignore all a[i] and b[i] where i k. First let's compare a[k/2] and b[k/2]. Let b[k/2] a[k/2]. Therefore we can discard also all b[i], where i k/2. Now we have all a[i], where i < k and all b[i], where i < k/2 to find the answer. What is the next step?

    Read the article

  • Creating an adjacency List for DFS

    - by user200081
    I'm having trouble creating a Depth First Search for my program. So far I have a class of edges and a class of regions. I want to store all the connected edges inside one node of my region. I can tell if something is connected by the getKey() function I have already implemented. If two edges have the same key, then they are connected. For the next region, I want to store another set of connected edges inside that region, etc etc. However, I am not fully understanding DFS and I'm having some trouble implementing it. I'm not sure when/where to call DFS again. Any help would be appreciated! class edge { private: int source, destination, length; int key; edge *next; public: getKey(){ return key; } } class region { edge *data; edge *next; region() { data = new edge(); next = NULL; } }; void runDFS(int i, edge **edge, int a) { region *head = new region(); aa[i]->visited == true;//mark the first vertex as true for(int v = 0; v < a; v++) { if(tem->edge[i].getKey() == tem->edge[v].getKey()) //if the edges of the vertex have the same root { if(head->data == NULL) { head->data = aa[i]; head->data->next == NULL; } //create an edge if(head->data) { head->data->next = aa[i]; head->data->next->next == NULL; }//if there is already a node connected to ti } if(aa[v]->visited == false) runDFS(v, edge, a); //call the DFS again } //for loop }

    Read the article

  • question about function derivatives

    - by davit-datuashvili
    hi i have question for example i have some function int sumefunction(//parameters here let say int x){ return something let say x*x+2*x+3 or does not matter } i am interesting how find derivative of this function ?if i have int f(int x){ return sin(x); } after derivative it must return cos(x) thanks

    Read the article

  • phrase split algorithm in PHP

    - by Eric Sim
    Not sure how to explain. Let's use an example. Say I want to split the sentence "Today is a great day." into today today is today is a today is a great today is a great day is is a is a great is a great day a a great a great day great great day day The idea is to get all the sequential combination in a sentence. I have been thinking what's the best way to do it in PHP. Any idea is welcome.

    Read the article

  • algorithms that destruct and copy_construct

    - by FredOverflow
    I am currently building my own toy vector for fun, and I was wondering if there is something like the following in the current or next standard or in Boost? template<class T> void destruct(T* begin, T* end) { while (begin != end) { begin -> ~T(); ++begin; } } template<class T> T* copy_construct(T* begin, T* end, T* dst) { while (begin != end) { new(dst) T(*begin); ++begin; ++dst; } return dst; }

    Read the article

  • question about Batcher odd-even sort

    - by davit-datuashvili
    hi i ave question about Batcher's odd-even sort i have following code public class Batcher{ public static void batchsort(int a[],int l,int r){ int n=r-l+1; for (int p=1;p<n;p+=p) for (int k=p;k>0;k/=2) for (int j=k%p;j+k<n;j+=(k+k)) for (int i=0;i<n-j-k;i++) if ((j+i)/(p+p)==(j+i+k)/(p+p)) exch(a,l+j+i,l+j+i+k); } public static void main(String[]args){ int a[]=new int[]{2,4,3,4,6,5,3}; batchsort(a,0,a.length-1); for (int i=0;i<a.length;i++){ System.out.println(a[i]); } } public static void exch(int a[],int i,int j){ int t=a[i]; a[i]=a[j]; a[j]=t; } } //result is 3 3 4 4 5 2 6 what i missed ? hat is wrong?

    Read the article

  • How does pattern matching work behind the scenes in F#?

    - by kryptic
    Hello Everyone, I am completely new to F# (and functional programming in general) but I see pattern matching used everywhere in sample code. I am wondering for example how pattern matching actually works? For example, I imagine it working the same as a for loop in other languages and checking for matches on each item in a collection. This is probably far from correct, how does it actually work behind the scenes?

    Read the article

< Previous Page | 90 91 92 93 94 95 96 97 98 99 100 101  | Next Page >