Thread: Data Structures and Algorithms questions

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    4

    Talking Data Structures and Algorithms questions

    Hello everyone,these are my questions.I have to do by one by ,however I do not understand and I have been trying to do for 1 week but always I still do some mistakes.If you do not time or its too boring for you,please even at least one of them is okey for me.If you help me, I will be happy.Thank you all

    Data Structures and Algorithms questions-1-jpgData Structures and Algorithms questions-2-jpgData Structures and Algorithms questions-3-jpgData Structures and Algorithms questions-4-jpgData Structures and Algorithms questions-5-jpg

  2. #2

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    Task 1 is very easy if you can just say "the program doesn't compile so complexity is N/A" LOL


  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,731
    If you want to know why Hodor is right, just remember that in C, "I" is not equivalent to "i".

    Also, I don't understand why it gives the third array 200x200... The result of a matrix multiplication always is (mat1_rows times mat2_columns), or the opposite for column-major. In this case, 100x100.
    Devoted my life to programming...

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Forget about I, that inner loop is awesomely tight.

    gg

  6. #6
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    I know but hard to solve for me and its my assignment I have to do until tomorrow if you help me I'll be glad

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,197
    You need to post your own attempts, and then we'll help.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    Of course for example I have been trying to do
    Task 2
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main{
    int x=225;
    int p=215;
    int q=205;
    int r=230;
    int *p=NULL ;
    int *q=NULL ;
    int **q=NULL ;
    int *r=NULL ;
    int **r=NULL ;
    int ***r=NULL ;
    int x = 5;
    int *p = &x;
    *p = 6;
    int **q = &p;
    int ***r = &q;
    printf (%d\n, *p);
    printf (%d\n, *q);
    printf(%d\n, **q);
    printf(%d\n, **r);
    printf(%d\n, ***r);
    
    system("pause");
    
    return 0;
    }
    In order compiler to compile but didnt get to output to learn answer

    Also for task 5
    I did like this but its not what it says
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    #define size 20
    
    
    int main()
    {
    
    
    char largest_word[size];
    char smalest_word[size];
    char wrd[size];
    int ch;
    
    
    printf("Enter a word: ");
    scanf("%s", wrd);
    strcpy(largest_word, wrd);
    strcpy(smalest_word, wrd);
    
    
    while(strlen(wrd) != 4 )
    {
    printf("Enter a word: ");
    scanf("%s", wrd);
    if( strcmp(smalest_word, wrd) > 0 )
    strcpy(smalest_word, wrd);
    if( strcmp(largest_word, wrd) < 0 )
    strcpy(largest_word, wrd);
    }
    
    
    printf("The Smalest word: %s\n", smalest_word);
    printf("The Largest word: %s\n", largest_word);
    
    
    return 0;
    }

  9. #9
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    For task #2, this is something you should be able to do in your head or on paper. It's ok that you write a program to see, but this is the kind of question you will see on a written test.

    For task #5, why do you have while(strlen(wrd) != 4 ) ? (Note: I haven't reviewed the rest of the code because that needs to be answered first I think)

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,197
    I doubt you'll get task 2 to compile and run on any real machine. There aren't many based on the idea of 5-byte pointers and integers.
    It's meant to be an exercise in the abstract.
    Code:
    .
        +-----+
    205 |  q  |
        +-----+
    210 |     |
        +-----+
    215 |  p  |
        +-----+
    220 |     |
        +-----+
    225 | x=5 |
        +-----+
    230 |  r  |
        +-----+
    Start with a diagram like this, then you manually 'run' the code one line at a time to find out what each memory location contains.

    As for task 5, I'd say
    > while(strlen(wrd) != 4 )
    How does this match up to entering the word "STOPPP"?

    Other than that, your general approach seems to be on the right track.

    The example doesn't help either - it says "longest word: zebra".
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    Can I ask what sort of course you're studying? School or... ?

  12. #12
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,795
    Quote Originally Posted by Salem View Post
    Other than that, your general approach seems to be on the right track.
    Yes, on the right track. Array size is another concern but I thought I'd leave that for now.

  13. #13
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    ok ı did thanks for everybody

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Algorithms and Data Structures...
    By Junior89 in forum C++ Programming
    Replies: 2
    Last Post: 04-05-2007, 05:13 AM
  2. data structures and algorithms
    By ajrillik in forum C Programming
    Replies: 0
    Last Post: 08-11-2005, 01:50 PM
  3. I have some questions about data structures and algorithms
    By Tonyukuk in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2003, 01:31 PM
  4. data structures and algorithms
    By Tonyukuk in forum C Programming
    Replies: 2
    Last Post: 03-19-2003, 08:25 AM
  5. Data Structures and Algorithms
    By Nor in forum C++ Programming
    Replies: 0
    Last Post: 04-13-2002, 11:56 PM