- ob1010 => 10
- ob0011 => 3
- ob1010 => 0x10
- ob0011 => 0x3
class KeyValuePair { | |
constructor(key, value) { | |
this.key = key; | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class HashTable { // get O(1), set O(1), deleteKey O(1) |
/* Identify the time complexity of each of these functions with a 1 sentence justification for your answer. Assume arr is an array of length n. | |
arr.push() | |
Time complexity: O(1) Space complexity: O(1) Justification: .push() mutates the input array inplace there by not using the array's length property to identify a valid length and placing the new element at that position, it also does'nt create an new array | |
push on MDN | |
arr.pop() | |
Time complexity: O(1) Space complexity: O(1) Justification: .pop() works just like push() |
animals = [ | |
'alligator', 'bear', 'cat', 'dog', 'elephant', | |
'fish', 'goose', 'hamster', 'iguana', 'jaguar', 'kangaroo' | |
]; | |
// Count how many animals are in the list | |
// Time complexity: O(?) // O(n) | |
// Space complexity: O(?) // o(1) | |
function countAnimals(animals) { | |
let count = 0; |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>HTML Tags Cheat Sheet</title> | |
</head> | |
<body> | |
<h1 id="top-of-page">My HTML Cheat Sheet</h1> |
// Require the 'readline' module to handle user input. | |
readline = require('node:readline'); | |
/** | |
* Create an interface for reading user input from the console. | |
* @type {readline.Interface} | |
*/ | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout // Use process.stdout for output |