|
| 1 | +========= |
| 2 | +Searching |
| 3 | +========= |
| 4 | + |
| 5 | +Learning searching algorithms easily! |
| 6 | + |
| 7 | +----------------- |
| 8 | +Quick Start Guide |
| 9 | +----------------- |
| 10 | + |
| 11 | +.. code-block:: python |
| 12 | +
|
| 13 | + # import the required searching algorithm |
| 14 | + from pygorithm.searching import binary_search |
| 15 | +
|
| 16 | + myList = [12, 4, 2, 14, 3, 7, 5] |
| 17 | +
|
| 18 | + # pre-requisite for binary search is that the list should be sorted |
| 19 | + myList.sort() |
| 20 | +
|
| 21 | + # to search en element in the above list |
| 22 | + index = binary_search.search(myList, 7) |
| 23 | + print(index) |
| 24 | +
|
| 25 | +-------- |
| 26 | +Features |
| 27 | +-------- |
| 28 | + |
| 29 | +* Searching algorithms available: |
| 30 | + - Linear Search (linear_search) |
| 31 | + - Binary Search (binary_search) |
| 32 | + - Breadth First Search (breadth_first_search) |
| 33 | + - Depth First Search (depth_first_search) |
| 34 | + |
| 35 | +* For Searching: |
| 36 | + Remember search() function takes two parameters as a sorted list and the target element to be searched. |
| 37 | + |
| 38 | +.. code-block:: python |
| 39 | +
|
| 40 | + # import the required searching algorithm |
| 41 | + from pygorithm.searching import binary_search |
| 42 | +
|
| 43 | + myList = [12, 4, 2, 14, 3, 7, 5] |
| 44 | +
|
| 45 | + # pre-requisite for binary search is that the list should be sorted |
| 46 | + myList.sort() |
| 47 | +
|
| 48 | + # to search en element in the above list |
| 49 | + index = binary_search.search(myList, 7) |
| 50 | + print(index) |
| 51 | +
|
| 52 | +* Get time complexities of all the searching algorithms |
| 53 | + |
| 54 | +.. code-block:: python |
| 55 | +
|
| 56 | + from pygorithm.searching import binary_search |
| 57 | +
|
| 58 | + # for printing time complexities of binary_search |
| 59 | + print(binary_search.time_complexities()) |
| 60 | +
|
| 61 | +* Get the code used for any of the algorithm |
| 62 | + |
| 63 | +.. code-block:: python |
| 64 | +
|
| 65 | + from pygorithm.searching import binary_search |
| 66 | +
|
| 67 | + # for printing the source code of bubble_sort |
| 68 | + print(binary_search.get_code()) |
0 commit comments