L1- PEDAC + Selection&Transformation + Arr Element Flashcards
What do the letters of PEDAC stand for?
P - [Understand the] Problem
E - Examples / Test cases
D - Data Structure
A - Algorithm
C - Code
What is involved with PROBLEMS in PEDAC? (6 things)
Understand the problem
1.
- read the problem description
- examine all given examples for info
- identify INPUTS/OUTPUTS
- identify RULES/REQUIREMENTS. Restate descriptions in a way that make sense to you to help identify explicitly what is required.
- mental model problem. Sort of like a very simple algorithm. Just describe what you broadly need to do.
- ask clarifying questions (all these assumptions about edge cases, what data types it should handle, just ask!)
What is involved with EXAMPLES in PEDAC (4 things)
- understand how the input translates to output
- identify VALID CASES
- identify EDGE CASES
- create the test cases and confirm outputs
What is involved with DATA STRUCTURES in PEDAC? (3 things)
- what sort of actions do you have to do (sort, collect, filter, etc.)
- what kind of data are you primarily dealing with for inputs/outputs? (strings, arrays, numbers, objects, etc.)
- focus on methods for these types
What is involved with ALGORITHM in PEDAC? (2 things)
- step by step process that takes you from input to output, your code will depend on your algorithm
- handles edges cases and valid example inputs
What is the pseudocode format for multiple functions
// Algorithm:
// substrings function
// =================
// - create an empty array called result
that will contain all required substrings
// - create a startingIndex
variable (value 0
) for the starting index of a substring
// - start a loop that uses startingIndex
to iterate over string
from 0
to the length of the string minus 2
// - create a numChars
variable (value 2
) for the length of a substring
// - start an inner loop that uses numChars
to iterate over string
from 2
to string.length - startingIndex
// - extract a substring of length numChars
from string
starting at startingIndex
// - append the extracted substring to the result
array
// - increment the numChars
variable by 1
// - end the inner loop
// - increment the startingIndex
variable by 1
// - end the outer loop
// - return the result
array
// isPalindrome function
// =====================
// - Inside the isPalindrome
function, check whether the string
// value is equal to its reversed value.
// palindromeSubstrings function
// ============================
// - declare a result
variable and initialize it to an empty array
// - create an array named substrArray
that will contain all of the
// substrings of the input string that are at least 2 characters long.
// - loop through the words in the substrArray
array.
// - if the word is a palindrome, append it to the result
array
// - return the result
array
The pseudo code keywords (8)
Keyword Meaning
START start of the program
SET set a variable that we can use for later
GET retrieve input from user
PRINT display output to user
READ retrieve a value from a variable
IF/ELSE IF/ELSE show conditional branches in logic
WHILE show looping logic
END end of the program
What is filtering, selection, and transformation?
Selection- Selection is picking some elements out of a collection depending on one or more criteria. For example, you might want to pick out all the odd numbers from an array.
Transformation- refers to manipulating every element in the collection. For example, increment all elements of an array by 1. Though we didn’t change all of the elements, we can reasonably say that we performed a transformation on the array, it’s just that the transformation left some elements unchanged.
Transforming happens ONLY when a mutation occurs
T or F
F
Both mutation and returning and be referred to transformation.
Does this:
let array = [1]
array[‘4’] = 2
effect the length of the array? Or is it just a key named ‘4’
Yes it does.
An array’s elements are basically numbered keys with additional functionality. So giving it a string key is the same as going array[4] = 2
What is a sparse array?
an array with empty items