Recent content by ducks

  1. D

    Sum of prime numbers taken from the command-line

    As far as the break line. You proved it false, so the break would kill the for loop. This would be a faster and optimal code to get it out of that for loop. Take numb = 1 billion, 2 would prove it not prime. Your break command got it out of that for loop within 1 iteration. However without it...
  2. D

    Comp Sci How can I efficiently find the closest leaf in a Java Binary Search Tree?

    A breadth first search would hit the nodes top down. You could check if its a leaf as you go top down. Stop it once detected. Never coded a breadth first to help much further than that.
  3. D

    Comp Sci Function 'for' and 'while' in C++

    Use your example of 0-10 adding up the digits to be 55. Do you have to rewrite your for loop to solve the same thing for say 0-15? 0-50? 0-100? Would you want to use this for loop for 0-10 as a function that accepts different values of X, where x=10 means sum up all the digits up to 10 and...
  4. D

    Comp Sci C++ Program Help (Newtons method)

    I suggest testing the first guess outside the while loop x0 = (y/4); x1 = (x0+(y/x0))/2; while (!( x1 - x0 <= 0.0001 && x1 - x0 >= -0.0001)) It will enter the loop if it wasn't divisible by 4. Now you need a new guess to use. Update your guess x0 = something. Then you can try your formula...
  5. D

    Comp Sci C++ Program Help (Newtons method)

    x1 = ((x0 + (y/x0))/2); x0 = x1; in normal terms: x1 = calculate a new value x0 = update me to that new calculated value Now x0 holds the same value as x1 When you print them out, you confirm this. Which means your while loop is seeing X1-X0 (BOTH BEING EQUAL) = 0 This breaks the while...
  6. D

    Proving AVL Tree Height using -2 to 2 Balance Factor

    Homework Statement An avl tree typically balances with a balance factor of -1, 1, 0. What if the tree allows -2,-1,,0,1, 2 as a balance factor. Prove or disprove that the height of the tree is logarithmic to the number of nodes O(logn) Homework Equations Normal balanced AVL tree everyone...
  7. D

    Thin disc above grounded plane

    I figured out the z axis part since it forms a right triangle. I can't wrap my head around how I would measure the potential at a point not on the z axis.
  8. D

    Thin disc above grounded plane

    Homework Statement A thin disk of radius R consists of a uniformly distributed total charge Q. The disk lies a distance D above a grounded perfectly conducting plane. The disk and the plane are parallel. Set the conducting plane in the x-y axis, and the z axis through the center of the disk...
Back
Top