Jun 26, 2024
enqueue
, dequeue
push
, pop
malloc
for dynamic memory allocationmalloc
returns nulltypedef struct node {
int number;
struct node *next;
} node;
bool search(node *tree, int number) {
if (tree == NULL) return false;
if (number < tree->number) return search(tree->left, number);
if (number > tree->number) return search(tree->right, number);
return true;
}
Concept: Map keys to values using a hash function
Example: Phone contacts application
unsigned int hash(const char *word) {
// Implementation example
return toupper(word[0]) - 'A';
}
Collision Handling: Linked Lists
Advantages: Near constant time, O(1), searching with good hash function
Disadvantages: Potential for collisions, worst-case O(n)
typedef struct node {
struct node *children[26];
char *number;
} node;