Search:

Type: Posts; User: peripatein

Page 1 of 5 1 2 3 4

Search: Search took 0.01 seconds.

  1. Replies
    0
    Views
    2,080

    Running time analysis and Master Theorem.

    Given the following code:


    Alg(A,n,p,r)
    {
    if (r ≤ p+n^1/3)
    Proc1(A,p,r)
    else {
    t := |_(r-p+1) /3_|
    Alg(A,n,p,p+t-1)
  2. Thread: Bubble Sort

    by peripatein
    Replies
    3
    Views
    1,531

    Suppose I wished to make an assertion concerning...

    Suppose I wished to make an assertion concerning array A at the end of the i-th iteration, in other words describe A. Would it still not be correct to say that A[i+1..n] would be sorted?
    How may I...
  3. Replies
    0
    Views
    1,150

    Insertion Sort

    Hi,
    I have the following pseudo-code for Insertion Sort:


    InsertionSort(Input: integer n, array A)
    {
    for j = 2 to n {
    newnum <- A[j]
    i <- j-1
    while (i > 0 and newnum <...
  4. Thread: Bubble Sort

    by peripatein
    Replies
    3
    Views
    1,531

    Bubble Sort

    Hi,
    I have the following pseudo-code for Bubble Sort, the correctness of which I'd like to prove via induction.


    BubbleSort(input: Array A[1…n], integer n)
    {
    for i = n-1 to 1
    {
    for j =...
  5. Replies
    11
    Views
    998

    Unfortunately, there ARE duplicates in the array...

    Unfortunately, there ARE duplicates in the array (the assignment indicates so). I wrote the following, which seems to work (I have tried it on several arrays), yet am not sure it's infallible:

    ...
  6. Replies
    11
    Views
    998

    I was actually trying to surmount the duplicate...

    I was actually trying to surmount the duplicate values problem by locating the first occurence of A[i]>=a thus:


    BinarySearch(n,A,A[i]>=a)

    That couldn't work, could it? :-)
    Suppose I didn't...
  7. Replies
    11
    Views
    998

    I am not quite sure I am following. Let me see...

    I am not quite sure I am following. Let me see whether I correctly understood what you wrote. Were you implying something like this:

    Range(Input: integer n, sorted array A, integer a, integer b){...
  8. Replies
    11
    Views
    998

    Well, in case array contains duplicate values,...

    Well, in case array contains duplicate values, couldn't I simply do this?:


    Range(Input: integer n, sorted array A, integer a, integer b){
    max <- n
    min <- 1
    i <- ...
  9. Replies
    11
    Views
    998

    Running time question.

    Hi,
    I have an array A of n integers, sorted from min to max, and two numbers a<=b, which are known to be in A. I would like to write a pseudo-code for a procedure whose running time is c1+c2log(n)...
  10. Replies
    24
    Views
    6,272

    De-allocation of a matrix.

    Hi,
    In my text book the de-allocation of a dynamically allocated matrix is carried out thus:


    void freeMatrix(char** mat) {
    free(mat[0]);
    free(mat);
    }

    Why is it mandatory to...
  11. Thread: Rand().

    by peripatein
    Replies
    3
    Views
    1,411

    Can it be interpreted thus - if number is not...

    Can it be interpreted thus - if number is not divisible by 3 a=0, else a=1?
  12. Thread: Rand().

    by peripatein
    Replies
    3
    Views
    1,411

    Rand().

    Hi,
    Could anyone please explain to me the following:


    int a = !(rand () % 3);

    Is there a condition here? What actually forms the condition? Is it the '!'? Why does it return 0 with...
  13. But I was no longer referring to #7. I was...

    But I was no longer referring to #7. I was referring to #1 and to ways which might render it not necessarily clearer, but more sophisticated. Perhaps coming up with a better algorithm altogether. Can...
  14. But other than that, can you come up with a more...

    But other than that, can you come up with a more elegant/sophisticated code to yield the same output?
    Preferably shorter!
  15. I could have used more variables, agreed. But how...

    I could have used more variables, agreed. But how may I improve the function I opened this thread with?
  16. It is given that in this section the tree could...

    It is given that in this section the tree could not be empty.
    I first coded it thus, but figured my above code suited better. What do you think?


    int findMaxDepth(Node * tree){
    if (!tree)...
  17. Replies
    4
    Views
    1,319

    I have. The recursion itself, the way it is...

    I have. The recursion itself, the way it is processed, is giving me a hard time!
    For instance, how would the program get to 12 after 9? 9->left is passed, it is NULL, then what happens? I have...
  18. depth 0. I have tried your code and it gave 7...

    depth 0. I have tried your code and it gave 7 where it supposed to have given 6 (and whereas my code gave 6).
  19. Replies
    4
    Views
    1,319

    Inorder of BT.

    Hi,
    I am having a hard time following the steps of the following recursion:


    void inorder(Node * node) {
    if (node==NULL)
    return;
    inorder(node->left);
    printf("%d ",node->data);...
  20. But that returns maxdepth + 1, and not the actual...

    But that returns maxdepth + 1, and not the actual maxdepth.
  21. Replies
    12
    Views
    2,363

    No problem :-)

    No problem :-)
  22. Replies
    12
    Views
    2,363

    It's not an array of structs. It's a dynamically...

    It's not an array of structs. It's a dynamically allocated array of integers.
  23. Replies
    12
    Views
    2,363

    I have an array of ints where each entry is...

    I have an array of ints where each entry is expected to be a counter, i.e. must be initialized to zero this way or the other before the actual count begins. That would justify calloc(), wouldn't it?...
  24. Replies
    12
    Views
    2,363

    Great, thank you.

    Great, thank you.
  25. Replies
    12
    Views
    2,363

    calloc() vs. malloc()

    Hi,
    Suppose I wished to initialize a dynamically allocated array of integers to zero. Would I do better to use calloc() or malloc + iterate over all entries setting each to zero? Which one is...
Results 1 to 25 of 122
Page 1 of 5 1 2 3 4