# Differences between algorithm and abstraction

I’m having my students work on Lesson 18, the practice PT and I expect that the hardest part for them will be circling and ‘rectangling’ (for lack of a better word) the requirements in the Create PT. Does anyone have any suggestions? I did read the thread from 3.10 about abstractions, but there seems to be a lot of overlap in the requirements from the College Board. I’m looking for suggestions on how others were able to help make the distinctions.

Specifically, I’m looking at these:

c. Capture and paste the program code segment that implements an algorithm (marked with an oval in 2e below) that is fundamental for your program to achieve its intended purpose. Your code segment must include an algorithm that integrates other algorithms and integrates mathematical and/or logical concepts. Describe how each algorithm within your selected algorithm functions independently, as well as in combination with others, to form a new algorithm that helps to achieve the intended purpose of the program.

d. Capture and paste the program code segment that contains an abstraction you developed (marked with a rectangle in 2e below). Your abstraction should integrate mathematical and logical concepts. Explain how your abstraction helped manage the complexity of your program.

Thanks!

They can actually be the same pieces of code. For abstraction they should describe a function in their code and how that function is an abstraction. The function can implement an algorithm. For describing the algorithm they need to describe what is being accomplished in their code and how. Here is a picture of the code and description that one of my students did last year. The description for abstraction can be expanded a bit more. But, I hope this helps in making the distinction.

2 Likes

@cmurakami There is also an awesome tool that @baker created to help make this process easier.
https://bakerfranke.github.io/codePrint/

My students have used it and it works well.

2 Likes

Hey, nice tool. Thanks for that!

1 Like

Thanks so much for this example Sangeeta. It makes so much sense that they could be one and the same thing. I think that’s what was tripping me up! I appreciate the help!

1 Like

I am assuming you have other functions like this for level 1 and 2. The function “ToenterLevel3” could be considered an algorithm. It is using logic (if - else statement) and some math (stats[4]++). It is also using other algorithms - “gamestats” and “tracklives”.

If you have other similar functions for level 1 and 2 (perhaps “ToenterLevel1” and “ToenterLevel2”) and are calling “gamestats” and “tracklives” in those functions, “gamestats” and “tracklives” can be treated as abstractions. You are calling them at multiple places. These abstractions are helping you handle the complexity of your code by reducing repetition of code in multiple places.

In conclusion, I would use the “ToenterLevel3” as an algorithm and one of the functions “gamestats” or “tracklives” as an abstraction.

1 Like

@228208

I would agree with @bhatnagars. The entire method ToenterLevel3 is an algorithm. Depending on the use of gamestats and trackLives, they could be considered abstractions. An another example might be - if the 4 lines in the else block that set array elements to 0 were put into a method called clearStats so it could be used anytime you needed, that would be an abstraction.

Andrea

@228208

If they had loops, then I would say the combo of ToenterLevel3 with either method would be the algorithm that calls another algorithm.

Based on the code provided, gamestats and trackLives are abstractions because they seem to reduce the complexity. It is actually not important what is in those methods. That is the beauty of abstraction. However, if the code in those methods is trivial ( 1 line) then I would not say it reduces complexity.

Andrea

1 Like

This is so great. Thank you!!

Abstraction is a function. I usually tell the students that if they start writing too much code, abstract it into smaller functions. I believe using these smaller functions within the function could be deemed an algorithm. With or without math… Just for thought!