Mastering DataStructure and Algorithms with C and C++ Flashcards

1
Q

what is a reference?

A

it’s just another name for the variable and it must be initialized when it’s declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are the two phases of recursion?

A

1 - calling time(ascending)

2 - returning time(Descending)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is the difference between recursion and looping?

A

recursion has descending while loops has ascending only

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are the types of recursion?

A
1 - Tail recursion
2 - Head recursion
3 - Tree recursion
4 - Indirect recursion
5 - Nested recursion
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the tail recursion?

A

the last call in the function is the recursion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is a head recursion?

A

the first call in the function is the recursive call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is the difference between linear recursion and tree recursion?

A

linear recursion calls itself only one time but tree recursion calls itself more than one time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is the O() for tree recursion

A

k^N for k is the number of recursion calls in the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is the indirect recursion?

A

when a function calls another function recursively and the second one calls the first one like a circular call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is the nested recursion?

A

the function parameter is another recursive function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is the formula that use to access an index of single array?

A

L + i * w

l -> first address of array
i -> index
w -> size of data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how are the 2D array stored in memory?

A

1 - row major mapping

2 - column major mapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to improve linear search?

A

it’s common if u search for one key that it will be searched for again so u can do:
1 - transposition:
each time u search for the same key u move it one step closer to the beginning of the array
2 - move to front or move to head
place the element in the first position of the element which will make it O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly