Skip to content

Commit f167a92

Browse files
author
codebasics
committed
2 parents 3174849 + 4d8a294 commit f167a92

File tree

21 files changed

+213
-32
lines changed

21 files changed

+213
-32
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
# Editor settings
132+
.vscode/settings.json

algorithms/1_BinarySearch/binary_search_exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
```
1212
This should return 5,6,7 as indices containing number 15 in the array
1313
14-
[Solution](https://github.com/codebasics/py/blob/master/Algorithms/1_BinarySearch/binary_search_exercise_solution.py)
14+
[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithms/1_BinarySearch/binary_search_exercise_solution.py)

algorithms/2_BubbleSort/bubble_sort_exercise.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Bubble Sort Exercise
22

3-
Modify [bubble_sort function](https://github.com/codebasics/py/blob/master/Algorithms/2_BubbleSort/bubble_sort.py) such that it can sort following list of transactions happening in an electronic store,
3+
Modify [bubble_sort function](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithms/2_BubbleSort/bubble_sort.py) such that it can sort following list of transactions happening in an electronic store,
44
```
55
elements = [
66
{ 'name': 'mona', 'transaction_amount': 1000, 'device': 'iphone-10'},
@@ -36,5 +36,5 @@ elements = [
3636
]
3737
```
3838

39-
[Solution](https://github.com/codebasics/py/blob/master/Algorithms/2_BubbleSort/bubble_sort_exercise_solution.py)
39+
[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithmsAlgorithms/2_BubbleSort/bubble_sort_exercise_solution.py)
4040

algorithms/3_QuickSort/quick_sort_exercise.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Implement quick sort using lumoto partition scheme. This partition scheme is explained in the video tutorial, you need to write python code to implement it.
33
Check the pseudo code here: https://en.wikipedia.org/wiki/Quicksort Check the section Lomuto partition scheme
44

5-
[Solution](https://github.com/codebasics/py/blob/master/Algorithms/3_QuickSort/quick_sort_exercise_soluiton_lomuto.py)
5+
[Solution](https://github.com/codebasics/data-structures-algorithms-python/blob/master/algorithms/3_QuickSort/quick_sort_exercise_soluiton_lomuto.py)
66

77

88

algorithms/8_DepthFirstSearch/dfs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# function for depth first search
2+
def dfs(data, start, visited=set()):
3+
4+
# if not visited print it
5+
if start not in visited:
6+
print(start, end=" ")
7+
8+
visited.add(start)
9+
10+
for i in data[start] - visited:
11+
12+
# if not visited gi in depth of it
13+
dfs(data, i, visited)
14+
return
15+
16+
17+
# sample data in dictionary form
18+
data = {
19+
'A': {'B'},
20+
'B': {'A', 'C', 'D'},
21+
'C': {'B', 'E'},
22+
'D': {'B', 'E'},
23+
'E': {'C', 'D', 'F'},
24+
'F': {'E'}
25+
}
26+
27+
28+
if __name__ == '__main__':
29+
30+
dfs(data, 'A')
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# function for depth first search
2+
def find_employees(data, start, employee, visited=set()):
3+
# if not visited print it
4+
if start not in visited:
5+
print(start, end=" ")
6+
if start == employee:
7+
print(":", end=" ")
8+
visited.add(start)
9+
10+
for i in data[start] - visited:
11+
# if not visited go in depth of it
12+
find_employees(data, i, visited)
13+
return
14+
15+
16+
# sample data in dictionary form
17+
data = {
18+
"karan": {"darshan", "nikhil"},
19+
"darshan": {"khantil", "tanuj"},
20+
"tanuj": {"nikhil"},
21+
"krinish": {"hetul"},
22+
"khantil": set(),
23+
"nikhil": set()
24+
}
25+
26+
27+
if __name__ == '__main__':
28+
29+
find_employees(data, "karan", "karan")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# DFS Exercise
2+
3+
![Overview : Employee hierarchy](https://github.com/beladiyadarshan/DFS/blob/main/emp.png?raw=true)
4+
5+
Given a graph containing managers and their employees as a dictionary of sets, print all employees reporting to a given manager.
6+
7+
```
8+
data = {
9+
"karan": {"darshan","nikhil"},
10+
"darshan": {"khantil", "tanuj"},
11+
"tanuj": {"nikhil"},
12+
"krinish": {"hetul"},
13+
"khantil" : set(),
14+
"nikhil" : set()
15+
}
16+
17+
18+
```
19+
20+
Example: Darshan and Nikhil are reporting to Karan. Khantil and Tanuj are reporting to Darshan.
21+
22+
```
23+
Q. Find all employees who are reporting to Karan.
24+
```
25+
26+
**Explanation:**
27+
28+
-So here, we want to find all the children nodes of Karan.
29+
30+
-We will perform DFS starting on Karan and then traverse all the children of Karan which are unvisited.
31+
32+
**Output:**
33+
34+
karan : nikhil darshan tanuj khantil
35+
36+
[Solution](https://github.com/beladiyadarshan/DFS/blob/main/dfs_exercise.py)

algorithms/8_DepthFirstSearch/emp.png

10.1 KB
Loading
17.3 KB
Loading
Loading

0 commit comments

Comments
 (0)