"a" and "b" are two arrays. They both have "n" elements. What does the following algorithm do?
350177
Sometimes adding some indents will help figure out what's going on.  In your algorithm, you have a lot of nested if and while statements, so space them out like this first to see how each is related to each other (I'm using periods because Yahoo won't show spaces):\n\ni <- 0\nwhile (i < n) do\n...j <- i+1\n...m <- a[i]\n...while (j < n) do\n......if (m > a[j]) then\n.........m <- a[j]\n......end if\n......j <- j + 1\n...end while\n...b[i] <- m\n...i <- i + 1\nend while\n\nYour i is a counter that starts with 0, and your j is a counter that starts with 1.  j will always be more than i.\n\nThe "while (i < n) do" line limits this algorithm to 3 loops, since n is 3.\n\nDirectly after this statement, j is established as a counter, and m is defined to be the i-th element of your matrix.  The next while statement then compares m (the i-th element in the matrix) to the element after this (using j to read the next element).\n\nIf m is larger, then the if statement makes m take on the smaller value.  If m is smaller, nothing happens and j is indexed to the next value.  Then the process repeats itself.  If we get to the end of the matrix and m isn't replaced anymore, it becomes the i-th value in matrix B.  After this, i is indexed to the next element in matrix A and the entire process is repeated once again, until all of matrix A has been checked.\n\nThe result then is that through m, matrix A is sorted least to greatest and is written into matrix B, which is answer (d).
271307
It has nothing to do with Java, except that you can\nimplement it in Java (just like you can with C or C++\nor Pascal or whatever).\n\nInsertion sort is distinct from bubble and selection sort.\nThe short description is that for each element, you \nfind the right position, shift everything up, and insert\nthe element.  It's very inefficient for large arrays, but\nit actually does pretty well for small arrays.  Because\nof this, it is sometimes used to finalize the array \nsegments which have been sorted using something like\nquicksort.\n\nSee the references for more information.
52716
I hope you can understand the pseudocode, it's pretty loose.\n\nConstruct two arrays P and Q.\nLet P be empty, and Q contain the n numbers you want to permute.\nTo start, call the function PrintPermute below passing in the arrays P and Q.\n\nPrintPermute( P, Q)\n{\n  if Q is empty, print the values in P in order and return\n  else\n\n  for each value q in Q,\n  {\n       Create the strings P' and Q' where P' = P + q and Q' = Q - q\n       Call PrintPermute(P', Q')\n }\nreturn\n}
482756
Well, they both take a lot of time! And, I must see the algorithm of (....;)! When both take a lot of time, We should check the one which takes the less time! If both takes the same time, we should choose the one which takes less space (Memory space I mean) But generally, Prefer the 2nd one! I think we should try to use a general code or function in the second choice! If there isn't a general rule, then, I prefer using the 1st one, cause it takes less memory and the lines of codes will be less I suppose...
604143
here is a program for 10 numbers in ascending order\n\n#include <iostream.h>\n#include <conio.h>\n\nvoid main()\n{\nclrscr();\nint array[10],t;\nfor(int x=0;x<10;x++)\n{\ncout << "Enter Integer No. " << x+1 << " : " << endl;\ncin>>array[x];\n}\nfor (x=0;x<10;x++)\n{\nfor(int y=0;y<9;y++)\n{\nif(array[y]>array[y+1])\n{\nt=array[y];\narray[y]=array[y+1];\narray[y+1]=t;\n}\n}\n}\ncout << "Array in ascending order is : ";\nfor (x=0;x<10;x++)\ncout << endl << array[x];\ngetch();\n}\n\nThis program takes in the ten integers array[x] to be stored in the single-dimensional array as a screen input from the user.\nIt then sorts out these ten integers into ascending order and prints them out using the 'cout' command.
2509
Here's a java solution that uses recursion.  The permute function takes two arguments: a done portion and a todo portion.   The basic idea is that each of the characters in the todo portion could be the next character.  So, at each step, n recursive calls are made, where n is the length of todo.  Each call chooses a different character as the next character to go into the done portion.  So, the first time the number of recursive calls will equal the number of characters in the initial string.  Each of these calls will make further recursive calls equal to the number of characters in the initial string minus one.  And so on.  Thus, the number of solutions will be n! = n*n-1*n-2*...*1, where n is the number of characters in the initial string.\n\nThe program below was tested with java's sun compiler 1.4.2.\npublic class perm\n{\n  public perm(String S)\n  {     \n    permute("", S);\n  }     \n  public void permute(String done, String todo) \n  {     \n    if ((todo.length()==0)||\n        (todo.equals("")))\n      System.out.println(done);\n    else        \n    {           \n      for (int i=0; i<todo.length(); i++)\n      {                 \n        String c = todo.substring(0,1);\n        todo = todo.substring(1);\n        permute(done+c, todo);  \n        todo = todo + c;        \n      }                 \n    }           \n  }     \n  public static void main(String args[])\n  {     \n    if ((args.length==0)||\n        (args[0].length()==0)||\n        (args[0].equals("")))\n      return;           \n    perm p = new perm(args[0]);\n  }     \n}
12389
It's all about the references.\n\ns1 = "java"- the constant string between "" is stored in one address in memory and s1 and s2 will referance that memory - so when comparing s1==s2 you're not comparing the strings but the pointers in memory.\ns3 = new String("java") obviously creates new object in memory and s3 points to a different address that's why it says not equal with s1\n\nyou need to use s1.CompareTo(s3) for comparing the string instead of address
359130
i) x is an element of B (or a member of B)\nii) A is a subset of B \niii) C is a subset of D\niv) The set A has exactly 2,4, and 6 as members.
691515
algorithms, data structures, computer organization
93226
algorithm is a basic and important part of programming. before writing any program(codes) we first design its algorithm i.e. genral steps to be taken to solve that program in normal english words called pseudocodes. so that one can easily understand what logic and aproach programmer has used to solve this problem.\n\nexample:\nalgorithm for multiplication of two numbers:\n1. declare three variables as a,b,c\n2. input first number into a\n3. input second number into b\n4. store c as a*b\n5. print c\n\nas this is not actual program but tells whats the logic behind this problem..\ni think you got answer
188148
try this:\n\nnumber of elements in the array is "n"\nnumbers are stored in array "Numbers"\n\nfor (i = 0; i < n - 2; i++)\n{\n   for (j = i + 1; j < n - 1; j++)\n   {\n      for (k = j + 1; k < n; k++)\n      {\n         cout << Array[i] << "," << Array[j] << "," << Array[k];\n      }\n   }\n}
819996
T1=m1*a, no matter are there m2 & m3 or not.\nT2=(m1+m2)*a, no matter whether m1 & m2 are connected with a string or are in one lump, the presence of m3 being unimportant too.
766645
Each row coresponds to coeficients of the binomial expansion.  The first row is the n=0 row with the entry 1, the second row n=1 with the entries 1,1 and so on.  The entries correspond to the coefficients of (a+b)^n.  \n\nAlso you can get relationships between the entries of pascal's triangle and the fibonaci numbers.  There are many other applications and patterns to be found.
612325
length = 9\nwidth = 9
909597
C/C++ solution\n\n#define MINIMUM2(a,b) ((a)< (b) ? (a) : (b))\n\nint x = MINIMUM2(3,5); // using it\n\nparentheses added in macro in case a or b is an expression and in case the macro itself is in another expression
267921
You can turn these into proper C++ statements:\n\nread a, b\n\nlet max = a\n\nif max < b\n  let max = b\nendif\n\nprint max\n\nThis program assumes that a <> b.
276232
Arrays are convenient ways to summarize numbers without writing out additional details.  For example, if I had two equations:\n\n3x + 2y = 5\n7x + 91y = 80\n\nthen an array would have just the numbers\n\n3 2 5\n7 91 80\n\nHow third graders will use this- I have no idea.