# Thread: Data Structures and Algorithms questions

1. ## 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

2. What kind of mistakes?

gg

3. Task 1 is very easy if you can just say "the program doesn't compile so complexity is N/A" LOL

4. 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.

5. Forget about I, that inner loop is awesomely tight.

gg

6. 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. You need to post your own attempts, and then we'll help.

8. Of course for example I have been trying to do
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

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. 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. 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".

11. Can I ask what sort of course you're studying? School or... ?

12. Originally Posted by Salem
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. ok ı did thanks for everybody