-
Notifications
You must be signed in to change notification settings - Fork 3
Week 6: Intro to Algorithms
Reid Russom edited this page Jul 2, 2024
·
6 revisions
| Week | Topic | Learning Objectives | Key Resources |
|---|---|---|---|
| 6 | Intro to Algorithms | Students will be able to define an algorithm, identify properties of a good algorithm, and understand methods of solving algorithms. | Week 6 Slides |
- Intro to algorithms
- Solving problems using algorithms
- Use of algorithms
- Web development
- Mathematics
- Operations Research
- Artificial intelligence
- Data science
- Pseudocode
- Intro to IDEs (CTD recommends VS Code)
Some potential trouble spots for students:
- Understanding the relevance
- Finding the patience for the most elegant/efficient solution to a problem rather than a brute force approach.
- Connecting theory to practice
The assignment questions have not necessarily been covered in depth in the lessons so far, students are encouraged to use additional resources and research to help.
Question 1:
function pairsMaker(array) {
// remove duplicate numbers
let uniqueElements = new Set(array);
let tempArray = [...uniqueElements];
// Now, create the pairs
let pairs = [];
for (let i = 0; i < tempArray.length; i++) {
for (let j = 0; j < tempArray.length; j++) {
pairs.push([tempArray[i], tempArray[j]]);
}
}
return pairs;
}
let numbersArray = [1, 2, 1, 1, 3, 5, 2];
console.log(
`Q1 pairsMaker: input: [${numbersArray}], output:`,
pairsMaker(numbersArray),
);
Question 2:
function twoSum(arr, target) {
let complements = new Set();
for (let i = 0; i < arr.length; i++) {
let complement = target - arr[i];
if (complements.has(complement)) {
return true;
}
complements.add(arr[i]);
}
return false;
}
let numbers = [2, 4, 6, 8, 10];
let target = 12;
console.log("Q2: ", target + ": ", twoSum(numbers, target));
Question 3:
function pairProduct(arr, product) {
let complements = new Set();
for (let i = 0; i < arr.length; i++) {
if (product % arr[i] === 0) {
let complement = product / arr[i];
if (complements.has(complement)) {
return true;
}
complements.add(arr[i]);
}
}
return false;
}
let numbers3 = [2, 4, 6, 8, 10];
let targetProduct = 20;
console.log("Q3: ", targetProduct + ": ", pairProduct(numbers3, targetProduct));
Question 4:
function strangeSums(arr) {
let count = 0;
let complements = new Set();
for (let i = 0; i < arr.length; i++) {
let complement = -arr[i];
if (complements.has(complement)) {
count++;
}
complements.add(arr[i]);
}
return count;
}
let numbers4 = [2, -2, 3, -3, 4, -4, 5, -5];
console.log("Q4: ", strangeSums(numbers4));
The Intro Guidebook is created by Code the Dream staff and volunteers for Code the Dream volunteers. This is your tool – please feel free to suggest edits or improvements.
Overview of the wiki.
Onboarding guide for new volunteers.
Links to pages for specific assignments, including rubrics, overviews of student content, and mentor-created resources.