Mastering DataStructure and Algorithms with C and C++ Flashcards
what is a reference?
it’s just another name for the variable and it must be initialized when it’s declared
what are the two phases of recursion?
1 - calling time(ascending)
2 - returning time(Descending)
what is the difference between recursion and looping?
recursion has descending while loops has ascending only
what are the types of recursion?
1 - Tail recursion 2 - Head recursion 3 - Tree recursion 4 - Indirect recursion 5 - Nested recursion
what is the tail recursion?
the last call in the function is the recursion
what is a head recursion?
the first call in the function is the recursive call
what is the difference between linear recursion and tree recursion?
linear recursion calls itself only one time but tree recursion calls itself more than one time
what is the O() for tree recursion
k^N for k is the number of recursion calls in the function
what is the indirect recursion?
when a function calls another function recursively and the second one calls the first one like a circular call
what is the nested recursion?
the function parameter is another recursive function
what is the formula that use to access an index of single array?
L + i * w
l -> first address of array
i -> index
w -> size of data type
how are the 2D array stored in memory?
1 - row major mapping
2 - column major mapping
how to improve linear search?
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)