Programming techniques (excluding OOP)

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/14

flashcard set

Earn XP

Description and Tags

Made from P.M.T and Ada Comp. Sci. notes

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

15 Terms

1
New cards

A for loops in psuedo code inclusive (e.g. for val = 0 to 5… will the code within loop execute when val=5)?

Yes, for loops are inclusive

2
New cards

What columns would a trace table have tracing a recursive algorithm?

  • Function call

  • Any parameters the recursive function has

  • return

3
New cards

What is the DIV operation?

Integer division. For example 40 DIV 12 = 3 (26÷12= 3 remainder 4)

4
New cards

What is the MOD operation?

Modulo; the remainder of a division. For example, 40 MOD 12 = 4 (26÷12= 3 remainder 4)

5
New cards

What are the 3 programming constructs?

  • Sequence

  • Selection (aka branching)

  • Iteration

6
New cards

What is the sequence programming construct?

What is the sequence programming construct?

7
New cards

What is the selection programming construct?

A certain block of code is only run if a specific condition is met

8
New cards

What is the iteration programming construct?

Repeatedly executing a block of code a number of times or while a condition is met

9
New cards

Count-controlled iteration

  • Code is repeated a specific number of times

  • Definit iteration

  • Uses for loops

10
New cards

Condition-controlled iteration

  • Repeitions are based on if a condition is met or not.

  • Indefinite iteration

  • Uses while, do while & repeat until loops

11
New cards

Define recursion

A programming construct in which a subroutine calls itself during its execution

12
New cards

What are the key features of a recursive algorithm?

  • The function calls itself

  • There is a base case / condition that stops the recursive calls

  • Each recursive call will create a new copy of the values in the function and add all of the values of the copy the call is being made from to a stack 

  • There may be more than one base case

13
New cards

Advantages of recursion

  • Can represent certain problems with fewer lines of code, meaning that the function is:

    • Easier to read

    • Less prone to errors

  • Natural way to process certain data structures (such as trees) that are recursive by nature

14
New cards

Disadvantage of recursion

  • Harder to trace which makes debuging more difficult

  • Uses more memory because of the need to store multiple stack frames. If the call stack runs out of memory, there will be a stack overflow, and the program will crash.

  • Can be slower because of the need to manage stack operations.

15
New cards

Are parameter(s) passed by value or by reference in recursive subroutines, and why?

  • If the parameter is sent by value, it will be a copy of the parameter that is used so the parameter wont be overridden. This will produce the correct output.

  • If the parameter is passed by reference it would not produce the correct result as it would be overridden / because it is a pointer to the address of the variable.