Repository for the Fall 2021 course web page
View the Project on GitHub IUDataStructuresCourse/course-web-page-Fall-2021
In the beginning was the Tao. The Tao gave birth to Space and Time. Therefore Space and Time are the Yin and Yang of programming.
Programmers that do not comprehend the Tao are always running out of time and space for their programs. Programmers that comprehend the Tao have enough time and space to accomplish their goals.
How could it be otherwise? – The Tao of Programming
https://iudatastructurescourse.github.io/course-web-page-Fall-2021/
Learn to use and Integrated Development Environment such as IntelliJ (Text Editor + Debugger)
Autograder for submitting assignments
Optional: learn github for managing group work
Find the section of the Tecumseh Trail Marathon with the greatest net change in altitude. Show TecumsehMarathon.pdf.
change: -25, -100, +100, -25,-75,-125,+100,+100,-25, +75, -50, -100
0 1 2 3 4 5 6 7 8 9 10 11
We want the contiguous subsequence with the largest sum. This is also known as the Maximum Subarray Problem.
Brute force: try every pair of locations
The time it takes, given an input array of size n, is
n choose 2 = n * (n-1) / 2
which is roughly n².
Divide-and-conquer: Cut the array in half, then consider three cases:
Cases 1&2 are the same problem but smaller -> recursion Case 3 needs work:
Analysis of the time complexity:
The crossing-subarray is linear, that is, c * m where m is the size of the subarray.
Recursion tree:
c*n = c*n
/ \
c*n/2 c*n/2 = c*n
/ \ / \
c*n/4 c*n/4 c*n/4 c*n/4 = c*n
...
What’s the height?
At the bottom, at a leaf, we have n/(2^h) = 1. We want to solve for h, so we isolate the 2^h term on one side.
n = 2^h
Then we take the log of both sides. (Recall that log (2^x) = x for any x.)
log n = h
Total work is c * n * lg n, so the time for this divide-and conquer algorithm for maximum-subarray is is roughly
n lg n