Esdap Unit 2 Activity 2
Esdap Unit 2 Activity 2
PRESENTA:
Introduction ........................................................................................... 1
Sorting methods.................................................................................... 2
Search methods..................................................................................... 3
Linear Search ............................................................................................. 3
Conclusion ............................................................................................... 5
I
Table of Figure
FIGURE PAGE
Figure 1 Sorted ............................................................................................. 2
Figure 2 list.sort ............................................................................................ 2
Figure 3 Linear Search ................................................................................... 3
Figure 4 Binary search. .................................................................................. 4
II
Introduction
This document covers the sorting method and the methods of searching arrays.in
lists in python by knowing two methods of each.
1
Sorting methods
Python lists have a built-in list.sort()method that modifies the list in place. There
is also a built-in sorted()function that creates a new sorted list from an iterable.
A simple ascending sort is very easy: just call the sorted()function. It returns a
new sorted list.
Figure 1 Sorted
You can also use the list.sort method. It sorts the list in place (and returns Noneto
avoid confusion). This is generally less convenient than sorted(), but if you don't
need the original list, it's a bit more efficient.
Figure 2 list.sort
Another difference is that the list.sort method is only defined for lists, while the
sorted()function accepts any iterable.
2
Search methods
Linear Search
3
Binary Search
Binary search is a more efficient searching algorithm suitable for sorted lists. It
repeatedly divides the search interval in half until the target value is found.
4
Conclusion
In conclusion we saw an easy way to learn or understand what are sorting and
searching methods, as well as giving two methods of each and improve the
knowledge that has been obtained.