-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91c6f69
commit cfff8e4
Showing
9 changed files
with
277 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v22.11.0 |
50 changes: 50 additions & 0 deletions
50
content/Networking/Labs/Lab - Implement Inter-VLAN Routing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
## Topology | ||
|
||
![[Pasted image 20241123094119.png]] | ||
|
||
## Addressing Table | ||
|
||
| Device | Interface | IPv4 Address | IPv6 Address | IPv6 Link-Local | | ||
| ------ | --------- | ------------- | ------------------------- | --------------- | | ||
| R1 | G0/0/1 | 10.1.13.1/24 | 2001:db8:acad:10d1::1/64 | fe80::1:1 | | ||
| R1 | S0/1/1 | 10.1.3.1/24 | 2001:db8:acad:1013::1/64 | fe80::1:2 | | ||
| D1 | G1/0/11 | 10.1.13.13/24 | 2001:db8:acad:10d1::d1/64 | fe80::d1:1 | | ||
| D1 | VLAN50 | 10.2.50.1/24 | 2001:db8:acad:1050::d1/64 | fe80::d1:2 | | ||
| D1 | VLAN60 | 10.2.60.1/24 | 2001:db8:acad:1060::d1/64 | fe80::d1:3 | | ||
| R3 | S0/1/1 | 10.1.3.3/24 | 2001:db8:acad:1013::3/64 | fe80::3:1 | | ||
| R3 | G0/0/1.75 | 10.3.75.1/24 | 2001:db8:acad:3075::1/64 | fe80::3:2 | | ||
| R3 | G0/0/1.85 | 10.3.85.1/24 | 2001:db8:acad:3085::1/64 | fe80::3:3 | | ||
| D2 | VLAN75 | 10.3.75.14/24 | 2001:db8:acad:3075::d2/64 | fe80::d2:1 | | ||
| PC1 | NIC | 10.2.50.50/24 | 2001:db8:acad:1050::50/64 | EUI-64 | | ||
| PC2 | NIC | 10.2.60.50/24 | 2001:db8:acad:1060::50/64 | EUI-64 | | ||
| PC3 | NIC | 10.3.75.50/24 | 2001:db8:acad:3075::50/64 | EUI-64 | | ||
| PC4 | NIC | 10.3.85.50/24 | 2001:db8:acad:3085::50/64 | EUI-64 | | ||
|
||
## Objectives | ||
Part 1: Build the Network and Configure Basic Device Settings | ||
|
||
Part 2: Configure and Verify Inter-VLAN Routing on a Layer 3 Switch | ||
|
||
Part 3: Configure and Verify Router-based Inter-VLAN Routing | ||
|
||
Part 4: Examine CAM and CEF Details | ||
|
||
# Background / Scenario | ||
|
||
The methods used to move packets and frames from one interface to the next has changed over the years. In this lab you will configure Inter-VLAN Routing in its various forms and then examine the different tables used in making forwarding decisions. | ||
|
||
**Note**: This lab is an exercise in configuring and verifying various methods of Inter-VLAN routing and does not reflect networking best practices. | ||
|
||
**Note**: The routers and switches used with CCNP hands-on labs are Cisco 4221 and Cisco 3650, both with Cisco IOS XE Release 16.9.4 (universalk9 image). Other routers and Cisco IOS versions can be used. Depending on the model and Cisco IOS version, the commands available and the output produced might vary from what is shown in the labs. | ||
|
||
**Note**: Ensure that the routers and switches have been erased and have no startup configurations. If you are unsure contact your instructor. | ||
|
||
# Instructions | ||
|
||
## Part 1: Build the Network and Configure Basic Device Settings | ||
|
||
In Part 1, you will set up the network topology and configure basic settings. | ||
|
||
### Step 1: Cable the network as shown in the topology. | ||
|
||
Attach the devices as shown in the topology diagram, and cable as necessary. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. | ||
|
||
You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. | ||
|
||
You can return the answer in any order. | ||
|
||
**Example 1:** | ||
|
||
**Input:** nums = [2,7,11,15], target = 9 | ||
**Output:** [0,1] | ||
**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]. | ||
|
||
**Example 2:** | ||
|
||
**Input:** nums = [3,2,4], target = 6 | ||
**Output:** [1,2] | ||
|
||
**Example 3:** | ||
|
||
**Input:** nums = [3,3], target = 6 | ||
**Output:** [0,1] | ||
|
||
**Constraints:** | ||
|
||
- `2 <= nums.length <= 104` | ||
- `-109 <= nums[i] <= 109` | ||
- `-109 <= target <= 109` | ||
- **Only one valid answer exists.** | ||
|
||
**Follow-up:** Can you come up with an algorithm that is less than $O(n^2)$ time complexity? | ||
|
||
## Solution | ||
### **Concept** | ||
The task is to find two indices $i$ and $j$ in the array `nums` such that: | ||
$\text{nums}[i] + \text{nums}[j] = \text{target}$ | ||
|
||
We have the following constraints: | ||
1. Each input will have exactly one solution. | ||
2. Indices $i$ and $j$ must be distinct. | ||
3. The solution must be efficient, ideally better than $O(n^2)$. | ||
|
||
--- | ||
|
||
### **Naive Approach** | ||
1. Use two nested loops to check every pair of numbers in the array. | ||
2. For each pair, check if their sum equals the target. | ||
3. Return the indices if a match is found. | ||
|
||
**Time Complexity:** $O(n^2)$ (inefficient for large arrays). | ||
|
||
--- | ||
|
||
### **Optimized Approach: Using a Hash Map** | ||
The optimized solution uses a **hash map (dictionary)** to store the difference between the target and each element as we iterate through the array. | ||
#### **Steps:** | ||
1. Create an empty hash map to store values we've seen so far as key-value pairs. | ||
2. Traverse the array. For each number, calculate its complement: | ||
$\text{complement} = \text{target} - \text{nums}[i]$ | ||
3. Check if the complement exists in the hash map: | ||
- If it does, return the current index and the index of the complement. | ||
- If it doesn’t, add the current number and its index to the hash map. | ||
4. Continue until the solution is found (guaranteed as per constraints). | ||
|
||
**Time Complexity:** $O(n)$, since we traverse the array once. | ||
**Space Complexity:** $O(n)$, for the hash map. | ||
|
||
--- | ||
|
||
### **Implementation** | ||
Here are some implementations of the optimized solution: | ||
|
||
```python | ||
def twoSum(nums, target): | ||
# Dictionary to store the value and its index | ||
num_map = {} | ||
|
||
# Iterate through the array | ||
for i, num in enumerate(nums): | ||
complement = target - num | ||
|
||
# Check if complement exists in the dictionary | ||
if complement in num_map: | ||
return [num_map[complement], i] | ||
|
||
# Add current number and its index to the dictionary | ||
num_map[num] = i | ||
``` | ||
|
||
```java | ||
import java.util.HashMap; | ||
|
||
public class TwoSum { | ||
public int[] twoSum(int[] nums, int target) { | ||
HashMap<Integer, Integer> numMap = new HashMap<>(); | ||
for (int i = 0; i < nums.length; i++) { | ||
int complement = target - nums[i]; | ||
if (numMap.containsKey(complement)) { | ||
return new int[] {numMap.get(complement), i}; | ||
} | ||
numMap.put(nums[i], i); | ||
} | ||
return new int[0]; // No solution, but the problem guarantees a solution exists | ||
} | ||
} | ||
|
||
``` | ||
|
||
```c++ | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
std::vector<int> twoSum(std::vector<int>& nums, int target) { | ||
std::unordered_map<int, int> num_map; | ||
for (int i = 0; i < nums.size(); i++) { | ||
int complement = target - nums[i]; | ||
if (num_map.find(complement) != num_map.end()) { | ||
return {num_map[complement], i}; | ||
} | ||
num_map[nums[i]] = i; | ||
} | ||
return {}; | ||
} | ||
|
||
``` | ||
```C# | ||
using System; | ||
using System.Collections.Generic; | ||
public class Solution { | ||
public int[] TwoSum(int[] nums, int target) { | ||
Dictionary<int, int> numMap = new Dictionary<int, int>(); | ||
for (int i = 0; i < nums.Length; i++) { | ||
int complement = target - nums[i]; | ||
if (numMap.ContainsKey(complement)) { | ||
return new int[] {numMap[complement], i}; | ||
} | ||
numMap[nums[i]] = i; | ||
} | ||
return new int[0]; | ||
} | ||
} | ||
``` | ||
|
||
```Javascript | ||
function twoSum(nums, target) { | ||
const numMap = new Map(); | ||
for (let i = 0; i < nums.length; i++) { | ||
const complement = target - nums[i]; | ||
if (numMap.has(complement)) { | ||
return [numMap.get(complement), i]; | ||
} | ||
numMap.set(nums[i], i); | ||
} | ||
} | ||
|
||
``` | ||
|
||
```typescript | ||
function twoSum(nums: number[], target: number): number[] { | ||
const numMap: Map<number, number> = new Map(); | ||
|
||
for (let i = 0; i < nums.length; i++) { | ||
const complement = target - nums[i]; | ||
|
||
// Check if the complement exists in the map | ||
if (numMap.has(complement)) { | ||
return [numMap.get(complement)!, i]; | ||
} | ||
|
||
// Add the current number and its index to the map | ||
numMap.set(nums[i], i); | ||
} | ||
|
||
// Problem guarantees a solution, so no need for a fallback return | ||
throw new Error("No solution found"); | ||
} | ||
|
||
``` | ||
--- | ||
|
||
### **Example Walkthrough** | ||
|
||
#### Example 1 | ||
**Input:** `nums = [2, 7, 11, 15]`, `target = 9` | ||
|
||
1. Start with `num_map = {}`. | ||
2. Iterate: | ||
- $i = 0$, $\text{num} = 2$, $\text{complement} = 9 - 2 = 7$: | ||
- `7` is not in `num_map`. | ||
- Add `2` to the map: `num_map = {2: 0}`. | ||
- $i = 1$, $\text{num} = 7$, $\text{complement} = 9 - 7 = 2$: | ||
- `2` is in `num_map` with index `0`. | ||
- Return `[0, 1]`. | ||
|
||
**Output:** `[0, 1]` | ||
|
||
--- | ||
|
||
#### Example 2 | ||
**Input:** `nums = [3, 2, 4]`, `target = 6` | ||
|
||
1. Start with `num_map = {}`. | ||
2. Iterate: | ||
- $i = 0$, $\text{num} = 3$, $\text{complement} = 6 - 3 = 3$: | ||
- `3` is not in `num_map`. | ||
- Add `3` to the map: `num_map = {3: 0}`. | ||
- $i = 1$, $\text{num} = 2$, $\text{complement} = 6 - 2 = 4$: | ||
- `4` is not in `num_map`. | ||
- Add `2` to the map: `num_map = {3: 0, 2: 1}`. | ||
- $i = 2$, $\text{num} = 4$, $\text{complement} = 6 - 4 = 2$: | ||
- `2` is in `num_map` with index `1`. | ||
- Return `[1, 2]`. | ||
|
||
**Output:** `[1, 2]` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Leetcode Problems | ||
|
||
[[1. Two Sum|1. Two Sum]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
- [[Programming/Leetcode/index|index]] | ||
- [[Programming/Leetcode/index|Leetcode]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
- [ ] Finish [[Lab - Implement Inter-VLAN Routing]] | ||
- [ ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters