Chunk 3.1: Computational Complexity
- Watch the lecture from 0:00 - 26:14. We will cover this material in class as well, so you can skip this portion unless you miss class or need reinforcement of the concepts. In-class slides can be found here.
Questions
- Answer these questions (submit on Classroom):
- Describe Big O notation. What quality of an algorithm does it describe?
- Define an algorithm in English for linear search.
- Define an algorithm in English for binary search.
- Describe Big Ω notation. What quality of an algorithm does it describe?
Problem: Largest
- Implement a program in C in a file named
largest.c
which accepts any number of random integers as arguments and prints the highest number in the list. The inputs should be separated by spaces (this is what makes them separate arguments) and the program should return ausage
error if there are no arguments. You don’t have to handle any other errors and can assume that all arguments are positive or negative integers.- Execute
wget https://cs-acs.com/assets/source_code/largest.c
to download this problem’s distribution code.
- Execute
$ ./largest
Usage: ./largest [int 1] [int 2] ...
$ ./largest 1
1
$ ./largest -5 10 30 1 5 9 8
30
Check & Submit
Check style with style50:
style50 largest.c
Check functionality with check50:
check50 cs-acs/problems/main/largest
Submit with submit50:
submit50 cs-acs/problems/main/largest