This is repo to store solutions, my learning about data structure and algorithms from multiple sources.
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
Stack is data structure first in last out , This data structure was used in storing memory Implement : 1.We can use a list to implement stack : Use append to store to a list Use pop to get value from a list Using Queue is data structure first in first out. This data structure mainly was used in scheduling tasks Implement : We can use 2 ways to implement
- Using list :
- When we want to insert a new , use insert(0,item) => but it's a bad way because it's O(n) algorithm when we insert or delete at the begining, every item have to move and reindex
- Use pop to get value from a list
Because of this, please use
collections.deque
, In short this data structure will make insert or delete at beginning nearly O(1) Read this link for get more useful informationhttps://docs.python.org/2/library/collections.html#collections.deque
Step:
- Insert data : using
appendleft
- Remove data : using
pop
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
Stack is the data structure (FIFO), This data structure was used mainly for storing memory When function was called they will push to stack, and they this fuction finised it will be removed from this stack
Stack and Heap was stored in RAM
- Linear Recursion / De qui tuyen tinh
A linear recursive function is a function that only makes a single call to itself each time the function runs 2. Binary Recursive / De qui nhi phan
Some recursive functions don't just have one call to themself, they have two (or more). Functions with two recursive calls are referred to as binary recursive functions.
- Check follow the row
- Check follow the column
- Check follow the border The first row a[0][j], the last row a[n-1][j] , a[i][0] & a[i][-1] if 0 <i < n-1 (n is the number of rows )
- Check follow principal diagonal We will loop for per row : and get matrix[i][i] (i is the index of current row)
- Check follow secondary diagonal We will loop for per row : and get matrix[i][n-i-1] (i is the index of current row, n is the the number of rows)
####What ####Why/When ####How
####What ####Why/When ####How
####What ####Why/When ####How
Use breath First Search to find the shortest path, implement on graph data They will answer 2 questions :
- If have any path from node
A
to nodeB
- What is the shortest path from node
A
to nodeB
.
It's data structure which include nodes and edge,(they are a set of connection)
node a
have arrows to node b
and node c
=> node b
and node c
are node a
neighbours
- Direct graph is only one way relationship , it's meaning some nodes have arrows toward them, but they don't have arrow for another nodes