9/21 - Python Intro, Strings and Iterables
This week, we'll be expanding on our Python tutorial by delving into strings as well as basic data structures.
Python is an excellent language to quickly and efficiently parse through strings, which is a huge part in many programming
team competitions.
Python
Sorting and Searching
-
Read the intro here. Why might sorting be
important?
-
Check out this video comparing different
sorting algorithms, and their behavior in different situations. Don't worry about how they're
implemented, but do pay attention to the ones that are faster and slower.
-
If you have a sorted array, Binary search can help you quickly find the index of an element in that
array. This is extremely important for very large arrays where the difference between
O(n)
and O(log(n))
can be the difference between a second and an hour! Read
the Wikipedia page intro and the
"Procedure" subsection. This video will help
too
-
This website provides a cool way to interactively learn
about the different sorting algorithms and see a live example of the code on the side.
Try it out!
Here's a good intro problem.
This requires you to use built in string functions to get meta information on the provided strings.
Delving Deeper
Check out this problem. This
problem can be made trivial with the in
operator in Python.
- Research the
in
operator some more. How does it actually work under the hood?
-
Write a "naive" solution to this problem (using loops and not built-in operators/libraries)
and try running it on a larger case (a necklace with 100,000 beads). How fast is it?
-
Check out other methods for finding one string in another
,
in particular, Knuth-Morris-Pratt is fairly efficient.
Do
some
research
around this algorithm and code up your implementation to try out on the problem.