CS50 Week 3: The Art of Algorithms

ยท

2 min read

Week 3 Algorithms

Have you ever wondered how Google can search millions of pages in just a few seconds? Or how your GPS can find the shortest route to your destination in real-time? It's all thanks to algorithms - a set of instructions that computers use to perform complex tasks.

Lecture

CS50's week 3 lecture was about algorithms as a way of solving problems in computer science with the help of a set of instructions. David Malan teaches about various algorithms such as searching and sorting algorithms with the help of pseudocode and c code.

When dealing with algorithms it is important to note it's running time, which can be expressed using big O notation. It helps to denote the worst case, or upper bound of the algorithm. Similarly to denote the and the best case, or lower bound, the ฮฉ symbol is used. And when both the upper bound and the lower bound is same, then the ฮธ symbol is used to denote the efficiency.

Searching algorithms are used to find specific data in large sets. There are different types of searching algorithms, each with their own strengths and weaknesses. This week we learned about two important searching algorithms: linear search and binary search.

Sorting algorithms are used to arrange data in a specific order. There are different types of sorting algorithms, each with their own strengths and weaknesses. The three important sorting algorithms: selection sort, bubble sort, and merge sort, are demonstrated by the professor.

David also introduced the concept of recursion, which is the process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself. This concept is also demonstrated in code to print the mario pyramid as in week 1, with the help of recursion in which a function calls itself. In lecture a C specific user defined data type "structure" is introduced, by using which we can define our own data types in C and name it whatever we want using the "typedef" keyword.

Conclusion

This was the 4th week in cs50 or Week 3, because we start counting from 0 in programming ๐Ÿ˜„๐Ÿ˜„. This week I learnt about various sorting and searching algorithms, their strengths and weaknesses, as well as their time complexity. I also learnt about recursion, user defined datatypes and their implementation. The lab and problem sets were challenging and helped to implement what I learnt from the lecture.

ย