id
stringlengths
14
18
image_path
stringlengths
31
34
prompt
stringclasses
1 value
response
stringclasses
93 values
code
stringclasses
93 values
category
stringclasses
17 values
difficulty
stringclasses
3 values
algo_a47_00201
images_generated/code_00201.png
Read this Algorim code image and explain what it does:
Heap sort using max-heap. Code: Action heapify(T: arr, n: int, i: int) var largest: int left: int right: int temp: int begin largest <--- i left <--- 2 * i + 1 right <--- 2 * i + 2 if (left < n and T[left] > T[largest]) then largest <--- left endif if (right < n and...
Action heapify(T: arr, n: int, i: int) var largest: int left: int right: int temp: int begin largest <--- i left <--- 2 * i + 1 right <--- 2 * i + 2 if (left < n and T[left] > T[largest]) then largest <--- left endif if (right < n and T[right] > T[largest]) then ...
sorting
advanced
algo_a47_00202
images_generated/code_00202.png
Read this Algorim code image and explain what it does:
Singly linked list node creation and insertion operations. Code: // Node structure for Singly Linked List // node.data: int // node.next: pointer to next node Action create_node(val: int): node var new_node: node begin new_node.data <--- val new_node.next <--- null create_node <--- new_node end Act...
// Node structure for Singly Linked List // node.data: int // node.next: pointer to next node Action create_node(val: int): node var new_node: node begin new_node.data <--- val new_node.next <--- null create_node <--- new_node end Action insert_front(head: node, val: int): node var new_node: nod...
linked_list
intermediate
algo_a47_00203
images_generated/code_00203.png
Read this Algorim code image and explain what it does:
Delete first occurrence of val from linked list. Code: Action delete_node(head: node, val: int): node var current: node prev: node begin if (head = null) then delete_node <--- null else if (head.data = val) then delete_node <--- head.next else prev <--...
Action delete_node(head: node, val: int): node var current: node prev: node begin if (head = null) then delete_node <--- null else if (head.data = val) then delete_node <--- head.next else prev <--- head current <--- head.next wh...
linked_list
intermediate
algo_a47_00204
images_generated/code_00204.png
Read this Algorim code image and explain what it does:
Reverses a singly linked list in-place. Code: Action reverse_list(head: node): node var prev: node current: node next_node: node begin prev <--- null current <--- head while (current != null) do next_node <--- current.next current.next <--- prev prev <--- c...
Action reverse_list(head: node): node var prev: node current: node next_node: node begin prev <--- null current <--- head while (current != null) do next_node <--- current.next current.next <--- prev prev <--- current current <--- next_node ...
linked_list
intermediate
algo_a47_00205
images_generated/code_00205.png
Read this Algorim code image and explain what it does:
Returns the length of a singly linked list. Code: Action list_length(head: node): int var count: int current: node begin count <--- 0 current <--- head while (current != null) do count <--- count + 1 current <--- current.next done list_length <--- count end
Action list_length(head: node): int var count: int current: node begin count <--- 0 current <--- head while (current != null) do count <--- count + 1 current <--- current.next done list_length <--- count end
linked_list
beginner
algo_a47_00206
images_generated/code_00206.png
Read this Algorim code image and explain what it does:
Stack implementation using array with push, pop, peek, isEmpty. Code: // Stack using array // stack.data: arr // stack.top: int (index of top, -1 if empty) Action stack_init(): stack var s: stack begin s.top <--- -1 stack_init <--- s end Action stack_push(s: stack, val: int) begin s.top <---...
// Stack using array // stack.data: arr // stack.top: int (index of top, -1 if empty) Action stack_init(): stack var s: stack begin s.top <--- -1 stack_init <--- s end Action stack_push(s: stack, val: int) begin s.top <--- s.top + 1 s.data[s.top] <--- val end Action stack_pop(s: stack): ...
data_structures
intermediate
algo_a47_00207
images_generated/code_00207.png
Read this Algorim code image and explain what it does:
Checks if parentheses/brackets/braces are balanced using a stack. Code: Action is_balanced(expr: arr, n: int): bool var s: stack i: int ch: char top_ch: char begin s <--- stack_init() for (i <--- 0 to n-1) do ch <--- expr[i] if (ch = '(' or ch = '[' or ch = '{') then ...
Action is_balanced(expr: arr, n: int): bool var s: stack i: int ch: char top_ch: char begin s <--- stack_init() for (i <--- 0 to n-1) do ch <--- expr[i] if (ch = '(' or ch = '[' or ch = '{') then stack_push(s, ch) else if (ch = ')' or ch = ']' or c...
data_structures
intermediate
algo_a47_00208
images_generated/code_00208.png
Read this Algorim code image and explain what it does:
Circular queue implementation with enqueue, dequeue, isEmpty. Code: // Queue using circular array // q.data: arr // q.front: int // q.rear: int // q.size: int // q.capacity: int Action queue_init(cap: int): queue var q: queue begin q.front <--- 0 q.rear <--- -1 q.size <--- 0 q.capacity ...
// Queue using circular array // q.data: arr // q.front: int // q.rear: int // q.size: int // q.capacity: int Action queue_init(cap: int): queue var q: queue begin q.front <--- 0 q.rear <--- -1 q.size <--- 0 q.capacity <--- cap queue_init <--- q end Action enqueue(q: queue, val: int...
data_structures
intermediate
algo_a47_00209
images_generated/code_00209.png
Read this Algorim code image and explain what it does:
Inserts a key into a Binary Search Tree. Code: // Binary Search Tree // node.key: int // node.left: node // node.right: node Action bst_insert(root: node, key: int): node var new_node: node begin if (root = null) then new_node.key <--- key new_node.left <--- null new_node.right <---...
// Binary Search Tree // node.key: int // node.left: node // node.right: node Action bst_insert(root: node, key: int): node var new_node: node begin if (root = null) then new_node.key <--- key new_node.left <--- null new_node.right <--- null bst_insert <--- new_node e...
trees
intermediate
algo_a47_00210
images_generated/code_00210.png
Read this Algorim code image and explain what it does:
Searches for a key in a Binary Search Tree. Code: Action bst_search(root: node, key: int): bool begin if (root = null) then bst_search <--- false else if (root.key = key) then bst_search <--- true else if (key < root.key) then bst_search <--- bst_...
Action bst_search(root: node, key: int): bool begin if (root = null) then bst_search <--- false else if (root.key = key) then bst_search <--- true else if (key < root.key) then bst_search <--- bst_search(root.left, key) else ...
trees
intermediate
algo_a47_00211
images_generated/code_00211.png
Read this Algorim code image and explain what it does:
In-order traversal of binary tree (Left-Root-Right). Code: Action inorder(root: node) begin if (root != null) then inorder(root.left) print(root.key) inorder(root.right) endif end
Action inorder(root: node) begin if (root != null) then inorder(root.left) print(root.key) inorder(root.right) endif end
trees
beginner
algo_a47_00212
images_generated/code_00212.png
Read this Algorim code image and explain what it does:
Pre-order traversal (Root-Left-Right). Code: Action preorder(root: node) begin if (root != null) then print(root.key) preorder(root.left) preorder(root.right) endif end
Action preorder(root: node) begin if (root != null) then print(root.key) preorder(root.left) preorder(root.right) endif end
trees
beginner
algo_a47_00213
images_generated/code_00213.png
Read this Algorim code image and explain what it does:
Post-order traversal (Left-Right-Root). Code: Action postorder(root: node) begin if (root != null) then postorder(root.left) postorder(root.right) print(root.key) endif end
Action postorder(root: node) begin if (root != null) then postorder(root.left) postorder(root.right) print(root.key) endif end
trees
beginner
algo_a47_00214
images_generated/code_00214.png
Read this Algorim code image and explain what it does:
Computes the height (depth) of a binary tree. Code: Action tree_height(root: node): int var left_h: int right_h: int begin if (root = null) then tree_height <--- 0 else left_h <--- tree_height(root.left) right_h <--- tree_height(root.right) if (left_h > right_h) then ...
Action tree_height(root: node): int var left_h: int right_h: int begin if (root = null) then tree_height <--- 0 else left_h <--- tree_height(root.left) right_h <--- tree_height(root.right) if (left_h > right_h) then tree_height <--- left_h + 1 else ...
trees
intermediate
algo_a47_00215
images_generated/code_00215.png
Read this Algorim code image and explain what it does:
Counts total nodes in a binary tree. Code: Action count_nodes(root: node): int begin if (root = null) then count_nodes <--- 0 else count_nodes <--- 1 + count_nodes(root.left) + count_nodes(root.right) endif end
Action count_nodes(root: node): int begin if (root = null) then count_nodes <--- 0 else count_nodes <--- 1 + count_nodes(root.left) + count_nodes(root.right) endif end
trees
beginner
algo_a47_00216
images_generated/code_00216.png
Read this Algorim code image and explain what it does:
BFS level-order traversal of binary tree using a queue. Code: Action level_order(root: node) var q: queue current: node begin if (root = null) then // empty tree else q <--- queue_init(100) enqueue(q, root) while (not queue_is_empty(q)) do current <--- dequeu...
Action level_order(root: node) var q: queue current: node begin if (root = null) then // empty tree else q <--- queue_init(100) enqueue(q, root) while (not queue_is_empty(q)) do current <--- dequeue(q) print(current.key) if (current.lef...
trees
intermediate
algo_a47_00217
images_generated/code_00217.png
Read this Algorim code image and explain what it does:
DFS graph traversal using adjacency matrix and recursion. Code: // Graph represented as adjacency matrix // graph[i][j] = 1 if edge i-j exists Action dfs(graph: arr, n: int, v: int, visited: arr) var i: int begin visited[v] <--- true print(v) for (i <--- 0 to n-1) do if (graph[v][i] = 1 and vi...
// Graph represented as adjacency matrix // graph[i][j] = 1 if edge i-j exists Action dfs(graph: arr, n: int, v: int, visited: arr) var i: int begin visited[v] <--- true print(v) for (i <--- 0 to n-1) do if (graph[v][i] = 1 and visited[i] = false) then dfs(graph, n, i, visited) ...
graphs
advanced
algo_a47_00218
images_generated/code_00218.png
Read this Algorim code image and explain what it does:
BFS graph traversal using adjacency matrix and queue. Code: Action bfs(graph: arr, n: int, start: int) var visited: arr q: queue v: int i: int begin for (i <--- 0 to n-1) do visited[i] <--- false endfor q <--- queue_init(n) visited[start] <--- true enqueue(q, start...
Action bfs(graph: arr, n: int, start: int) var visited: arr q: queue v: int i: int begin for (i <--- 0 to n-1) do visited[i] <--- false endfor q <--- queue_init(n) visited[start] <--- true enqueue(q, start) while (not queue_is_empty(q)) do v <--- dequeue...
graphs
advanced
algo_a47_00219
images_generated/code_00219.png
Read this Algorim code image and explain what it does:
Computes string length by counting until null terminator. Code: Action str_len(s: arr): int var i: int begin i <--- 0 while (s[i] != '\0') do i <--- i + 1 done str_len <--- i end
Action str_len(s: arr): int var i: int begin i <--- 0 while (s[i] != '\0') do i <--- i + 1 done str_len <--- i end
strings
beginner
algo_a47_00220
images_generated/code_00220.png
Read this Algorim code image and explain what it does:
Checks if a string is a palindrome using two pointers. Code: Action is_palindrome(s: arr, n: int): bool var i: int j: int result: bool begin result <--- true i <--- 0 j <--- n - 1 while (i < j and result = true) do if (s[i] != s[j]) then result <--- false ...
Action is_palindrome(s: arr, n: int): bool var i: int j: int result: bool begin result <--- true i <--- 0 j <--- n - 1 while (i < j and result = true) do if (s[i] != s[j]) then result <--- false endif i <--- i + 1 j <--- j - 1 done ...
strings
beginner
algo_a47_00221
images_generated/code_00221.png
Read this Algorim code image and explain what it does:
Reverses a string in-place. Code: Action str_reverse(s: arr, n: int) var i: int j: int temp: char begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- s[i] s[i] <--- s[j] s[j] <--- temp i <--- i + 1 j <--- j - 1 done end
Action str_reverse(s: arr, n: int) var i: int j: int temp: char begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- s[i] s[i] <--- s[j] s[j] <--- temp i <--- i + 1 j <--- j - 1 done end
strings
beginner
algo_a47_00222
images_generated/code_00222.png
Read this Algorim code image and explain what it does:
Copies string src to dst. Code: Action str_copy(src: arr, dst: arr) var i: int begin i <--- 0 while (src[i] != '\0') do dst[i] <--- src[i] i <--- i + 1 done dst[i] <--- '\0' end
Action str_copy(src: arr, dst: arr) var i: int begin i <--- 0 while (src[i] != '\0') do dst[i] <--- src[i] i <--- i + 1 done dst[i] <--- '\0' end
strings
beginner
algo_a47_00223
images_generated/code_00223.png
Read this Algorim code image and explain what it does:
Counts occurrences of character c in string s. Code: Action count_char(s: arr, n: int, c: char): int var i: int count: int begin count <--- 0 for (i <--- 0 to n-1) do if (s[i] = c) then count <--- count + 1 endif endfor count_char <--- count end
Action count_char(s: arr, n: int, c: char): int var i: int count: int begin count <--- 0 for (i <--- 0 to n-1) do if (s[i] = c) then count <--- count + 1 endif endfor count_char <--- count end
strings
beginner
algo_a47_00224
images_generated/code_00224.png
Read this Algorim code image and explain what it does:
Finds the length of the Longest Common Subsequence using DP. Code: Action lcs_length(A: arr, B: arr, m: int, n: int): int var dp: array[m+1][n+1] i: int j: int begin for (i <--- 0 to m) do for (j <--- 0 to n) do if (i = 0 or j = 0) then dp[i][j] <--- 0 el...
Action lcs_length(A: arr, B: arr, m: int, n: int): int var dp: array[m+1][n+1] i: int j: int begin for (i <--- 0 to m) do for (j <--- 0 to n) do if (i = 0 or j = 0) then dp[i][j] <--- 0 else if (A[i-1] = B[j-1]) then dp[...
dynamic_programming
advanced
algo_a47_00225
images_generated/code_00225.png
Read this Algorim code image and explain what it does:
0/1 Knapsack problem using bottom-up DP. Code: Action knapsack(weights: arr, values: arr, n: int, W: int): int var dp: array[n+1][W+1] i: int w: int begin for (i <--- 0 to n) do for (w <--- 0 to W) do if (i = 0 or w = 0) then dp[i][w] <--- 0 else ...
Action knapsack(weights: arr, values: arr, n: int, W: int): int var dp: array[n+1][W+1] i: int w: int begin for (i <--- 0 to n) do for (w <--- 0 to W) do if (i = 0 or w = 0) then dp[i][w] <--- 0 else if (weights[i-1] <= w) then ...
dynamic_programming
advanced
algo_a47_00226
images_generated/code_00226.png
Read this Algorim code image and explain what it does:
Minimum number of coins to make an amount (DP). Code: Action coin_change(coins: arr, n: int, amount: int): int var dp: arr i: int j: int INF: int begin INF <--- amount + 1 for (i <--- 0 to amount) do dp[i] <--- INF endfor dp[0] <--- 0 for (i <--- 1 to amount) do for ...
Action coin_change(coins: arr, n: int, amount: int): int var dp: arr i: int j: int INF: int begin INF <--- amount + 1 for (i <--- 0 to amount) do dp[i] <--- INF endfor dp[0] <--- 0 for (i <--- 1 to amount) do for (j <--- 0 to n-1) do if (coins[j] <= i) the...
dynamic_programming
advanced
algo_a47_00227
images_generated/code_00227.png
Read this Algorim code image and explain what it does:
Sieve of Eratosthenes to find all primes up to n. Code: Action sieve_of_eratosthenes(n: int): arr var is_prime: arr i: int j: int begin for (i <--- 0 to n) do is_prime[i] <--- true endfor is_prime[0] <--- false is_prime[1] <--- false i <--- 2 while (i * i <= n) do if...
Action sieve_of_eratosthenes(n: int): arr var is_prime: arr i: int j: int begin for (i <--- 0 to n) do is_prime[i] <--- true endfor is_prime[0] <--- false is_prime[1] <--- false i <--- 2 while (i * i <= n) do if (is_prime[i] = true) then j <--- i * i ...
number_theory
intermediate
algo_a47_00228
images_generated/code_00228.png
Read this Algorim code image and explain what it does:
Converts binary string to decimal integer. Code: Action bin_to_dec(binary: arr, n: int): int var decimal: int power: int i: int begin decimal <--- 0 power <--- 1 for (i <--- n-1 to 0) do if (binary[i] = '1') then decimal <--- decimal + power endif power <--...
Action bin_to_dec(binary: arr, n: int): int var decimal: int power: int i: int begin decimal <--- 0 power <--- 1 for (i <--- n-1 to 0) do if (binary[i] = '1') then decimal <--- decimal + power endif power <--- power * 2 endfor bin_to_dec <--- decimal...
number_theory
beginner
algo_a47_00229
images_generated/code_00229.png
Read this Algorim code image and explain what it does:
Hash table with separate chaining collision resolution. Code: // Simple hash table with chaining // TABLE_SIZE = 100 // table: array of linked_list heads Action hash(key: int): int begin hash <--- key mod 100 end Action hash_insert(table: arr, key: int, value: int) var idx: int new_node: node begin i...
// Simple hash table with chaining // TABLE_SIZE = 100 // table: array of linked_list heads Action hash(key: int): int begin hash <--- key mod 100 end Action hash_insert(table: arr, key: int, value: int) var idx: int new_node: node begin idx <--- hash(key) new_node.key <--- key ne...
data_structures
advanced
algo_a47_00230
images_generated/code_00230.png
Read this Algorim code image and explain what it does:
Multiplies two n×n matrices A and B, stores result in C. Code: Action matrix_multiply(A: arr, B: arr, C: arr, n: int) var i: int j: int k: int sum: int begin for (i <--- 0 to n-1) do for (j <--- 0 to n-1) do sum <--- 0 for (k <--- 0 to n-1) do sum <--...
Action matrix_multiply(A: arr, B: arr, C: arr, n: int) var i: int j: int k: int sum: int begin for (i <--- 0 to n-1) do for (j <--- 0 to n-1) do sum <--- 0 for (k <--- 0 to n-1) do sum <--- sum + A[i][k] * B[k][j] endfor C[i][j]...
matrix
intermediate
algo_a47_00231
images_generated/code_00231.png
Read this Algorim code image and explain what it does:
Transposes a square matrix in-place. Code: Action transpose(A: arr, n: int) var i: int j: int temp: int begin for (i <--- 0 to n-1) do for (j <--- i+1 to n-1) do temp <--- A[i][j] A[i][j] <--- A[j][i] A[j][i] <--- temp endfor endfor end
Action transpose(A: arr, n: int) var i: int j: int temp: int begin for (i <--- 0 to n-1) do for (j <--- i+1 to n-1) do temp <--- A[i][j] A[i][j] <--- A[j][i] A[j][i] <--- temp endfor endfor end
matrix
beginner
algo_a47_00232
images_generated/code_00232.png
Read this Algorim code image and explain what it does:
Min-heap with insert and extract_min operations. Code: // Min-Heap operations // heap.data: arr // heap.size: int Action heap_parent(i: int): int begin heap_parent <--- (i - 1) div 2 end Action heap_left(i: int): int begin heap_left <--- 2 * i + 1 end Action heap_right(i: int): int begin heap_right <---...
// Min-Heap operations // heap.data: arr // heap.size: int Action heap_parent(i: int): int begin heap_parent <--- (i - 1) div 2 end Action heap_left(i: int): int begin heap_left <--- 2 * i + 1 end Action heap_right(i: int): int begin heap_right <--- 2 * i + 2 end Action min_heap_insert(heap: heap_struct...
data_structures
advanced
algo_a47_00233
images_generated/code_00233.png
Read this Algorim code image and explain what it does:
N-Queens problem using backtracking. Code: Action is_safe(board: arr, row: int, col: int, n: int): bool var i: int j: int safe: bool begin safe <--- true // Check column for (i <--- 0 to row-1) do if (board[i][col] = 1) then safe <--- false endif endfor // Ch...
Action is_safe(board: arr, row: int, col: int, n: int): bool var i: int j: int safe: bool begin safe <--- true // Check column for (i <--- 0 to row-1) do if (board[i][col] = 1) then safe <--- false endif endfor // Check upper-left diagonal i <--- row - 1 ...
backtracking
advanced
algo_a47_00234
images_generated/code_00234.png
Read this Algorim code image and explain what it does:
Command to generate a visual image of an algorithm or code. Code: /imagine A code visualization showing merge sort dividing array [8,3,1,5,2] into subarrays and merging them back in sorted order, dark background with neon syntax highlighting
/imagine A code visualization showing merge sort dividing array [8,3,1,5,2] into subarrays and merging them back in sorted order, dark background with neon syntax highlighting
commands
beginner
algo_a47_00235
images_generated/code_00235.png
Read this Algorim code image and explain what it does:
Command to compile Algorim code to executable bytecode. Code: /compile Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
/compile Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
commands
intermediate
algo_a47_00236
images_generated/code_00236.png
Read this Algorim code image and explain what it does:
Command to debug Algorim code with execution trace. Code: /debug Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) then bina...
/debug Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) then binary_search <--- mid else if (T[mid] < ta...
commands
intermediate
algo_a47_00237
images_generated/code_00237.png
Read this Algorim code image and explain what it does:
Exchange values of two integer variables using a temporary variable. Code: Action swap(a: int, b: int) var temp: int begin temp <--- a a <--- b b <--- temp end
Action swap(a: int, b: int) var temp: int begin temp <--- a a <--- b b <--- temp end
basic
beginner
algo_a47_00238
images_generated/code_00238.png
Read this Algorim code image and explain what it does:
Returns the absolute value of an integer. Code: Action absolute(n: int): int var result: int begin if (n < 0) then result <--- n * -1 else result <--- n endif absolute <--- result end
Action absolute(n: int): int var result: int begin if (n < 0) then result <--- n * -1 else result <--- n endif absolute <--- result end
math
beginner
algo_a47_00239
images_generated/code_00239.png
Read this Algorim code image and explain what it does:
Computes base raised to the power of exp using iteration. Code: Action power(base: int, exp: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to exp) do result <--- result * base endfor power <--- result end
Action power(base: int, exp: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to exp) do result <--- result * base endfor power <--- result end
math
beginner
algo_a47_00240
images_generated/code_00240.png
Read this Algorim code image and explain what it does:
Computes n! iteratively. Code: Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
math
beginner
algo_a47_00241
images_generated/code_00241.png
Read this Algorim code image and explain what it does:
Recursive factorial computation. Code: Action factorial_rec(n: int): int begin if (n <= 1) then factorial_rec <--- 1 else factorial_rec <--- n * factorial_rec(n - 1) endif end
Action factorial_rec(n: int): int begin if (n <= 1) then factorial_rec <--- 1 else factorial_rec <--- n * factorial_rec(n - 1) endif end
recursion
intermediate
algo_a47_00242
images_generated/code_00242.png
Read this Algorim code image and explain what it does:
Computes the n-th Fibonacci number iteratively. Code: Action fibonacci(n: int): int var a: int b: int temp: int i: int begin a <--- 0 b <--- 1 if (n = 0) then fibonacci <--- 0 else for (i <--- 2 to n) do temp <--- a + b a <--- b b ...
Action fibonacci(n: int): int var a: int b: int temp: int i: int begin a <--- 0 b <--- 1 if (n = 0) then fibonacci <--- 0 else for (i <--- 2 to n) do temp <--- a + b a <--- b b <--- temp endfor fibonacci <--- b ...
math
intermediate
algo_a47_00243
images_generated/code_00243.png
Read this Algorim code image and explain what it does:
Recursive Fibonacci using two recursive calls. Code: Action fib_rec(n: int): int begin if (n <= 1) then fib_rec <--- n else fib_rec <--- fib_rec(n-1) + fib_rec(n-2) endif end
Action fib_rec(n: int): int begin if (n <= 1) then fib_rec <--- n else fib_rec <--- fib_rec(n-1) + fib_rec(n-2) endif end
recursion
intermediate
algo_a47_00244
images_generated/code_00244.png
Read this Algorim code image and explain what it does:
Computes GCD using Euclidean algorithm. Code: Action gcd(a: int, b: int): int var temp: int begin while (b != 0) do temp <--- b b <--- a mod b a <--- temp done gcd <--- a end
Action gcd(a: int, b: int): int var temp: int begin while (b != 0) do temp <--- b b <--- a mod b a <--- temp done gcd <--- a end
math
intermediate
algo_a47_00245
images_generated/code_00245.png
Read this Algorim code image and explain what it does:
Computes LCM using GCD. Code: Action lcm(a: int, b: int): int begin lcm <--- (a * b) div gcd(a, b) end
Action lcm(a: int, b: int): int begin lcm <--- (a * b) div gcd(a, b) end
math
intermediate
algo_a47_00246
images_generated/code_00246.png
Read this Algorim code image and explain what it does:
Checks if a number is prime using trial division up to sqrt(n). Code: Action is_prime(n: int): bool var i: int prime: bool begin prime <--- true if (n < 2) then prime <--- false else i <--- 2 while (i * i <= n) do if (n mod i = 0) then prime <--- ...
Action is_prime(n: int): bool var i: int prime: bool begin prime <--- true if (n < 2) then prime <--- false else i <--- 2 while (i * i <= n) do if (n mod i = 0) then prime <--- false endif i <--- i + 1 done endif...
math
intermediate
algo_a47_00247
images_generated/code_00247.png
Read this Algorim code image and explain what it does:
Sums all elements of an integer array. Code: Action array_sum(T: arr, n: int): int var total: int i: int begin total <--- 0 for (i <--- 0 to n-1) do total <--- total + T[i] endfor array_sum <--- total end
Action array_sum(T: arr, n: int): int var total: int i: int begin total <--- 0 for (i <--- 0 to n-1) do total <--- total + T[i] endfor array_sum <--- total end
arrays
beginner
algo_a47_00248
images_generated/code_00248.png
Read this Algorim code image and explain what it does:
Finds the maximum element in an array. Code: Action array_max(T: arr, n: int): int var max_val: int i: int begin max_val <--- T[0] for (i <--- 1 to n-1) do if (T[i] > max_val) then max_val <--- T[i] endif endfor array_max <--- max_val end
Action array_max(T: arr, n: int): int var max_val: int i: int begin max_val <--- T[0] for (i <--- 1 to n-1) do if (T[i] > max_val) then max_val <--- T[i] endif endfor array_max <--- max_val end
arrays
beginner
algo_a47_00249
images_generated/code_00249.png
Read this Algorim code image and explain what it does:
Finds the minimum element in an array. Code: Action array_min(T: arr, n: int): int var min_val: int i: int begin min_val <--- T[0] for (i <--- 1 to n-1) do if (T[i] < min_val) then min_val <--- T[i] endif endfor array_min <--- min_val end
Action array_min(T: arr, n: int): int var min_val: int i: int begin min_val <--- T[0] for (i <--- 1 to n-1) do if (T[i] < min_val) then min_val <--- T[i] endif endfor array_min <--- min_val end
arrays
beginner
algo_a47_00250
images_generated/code_00250.png
Read this Algorim code image and explain what it does:
Searches for target in array, returns index or -1. Code: Action linear_search(T: arr, n: int, target: int): int var i: int pos: int begin pos <--- -1 for (i <--- 0 to n-1) do if (T[i] = target) then pos <--- i endif endfor linear_search <--- pos end
Action linear_search(T: arr, n: int, target: int): int var i: int pos: int begin pos <--- -1 for (i <--- 0 to n-1) do if (T[i] = target) then pos <--- i endif endfor linear_search <--- pos end
searching
beginner
algo_a47_00251
images_generated/code_00251.png
Read this Algorim code image and explain what it does:
Binary search on sorted array. Returns index or -1. Code: Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 binary_search <--- -1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) th...
Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 binary_search <--- -1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) then binary_search <--- mid low <--- ...
searching
intermediate
algo_a47_00252
images_generated/code_00252.png
Read this Algorim code image and explain what it does:
Reverses an array in-place using two pointers. Code: Action reverse_array(T: arr, n: int) var i: int j: int temp: int begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- T[i] T[i] <--- T[j] T[j] <--- temp i <--- i + 1 j <--- j - 1 done end
Action reverse_array(T: arr, n: int) var i: int j: int temp: int begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- T[i] T[i] <--- T[j] T[j] <--- temp i <--- i + 1 j <--- j - 1 done end
arrays
beginner
algo_a47_00253
images_generated/code_00253.png
Read this Algorim code image and explain what it does:
Counts occurrences of val in array T. Code: Action count_occurrences(T: arr, n: int, val: int): int var count: int i: int begin count <--- 0 for (i <--- 0 to n-1) do if (T[i] = val) then count <--- count + 1 endif endfor count_occurrences <--- count end
Action count_occurrences(T: arr, n: int, val: int): int var count: int i: int begin count <--- 0 for (i <--- 0 to n-1) do if (T[i] = val) then count <--- count + 1 endif endfor count_occurrences <--- count end
arrays
beginner
algo_a47_00254
images_generated/code_00254.png
Read this Algorim code image and explain what it does:
Copies elements from src to dst array. Code: Action copy_array(src: arr, dst: arr, n: int) var i: int begin for (i <--- 0 to n-1) do dst[i] <--- src[i] endfor end
Action copy_array(src: arr, dst: arr, n: int) var i: int begin for (i <--- 0 to n-1) do dst[i] <--- src[i] endfor end
arrays
beginner
algo_a47_00255
images_generated/code_00255.png
Read this Algorim code image and explain what it does:
Bubble sort with early exit optimization. Code: Action bubble_sort(T: arr, n: int) var i: int j: int temp: int swapped: bool begin for (i <--- 0 to n-2) do swapped <--- false for (j <--- 0 to n-i-2) do if (T[j] > T[j+1]) then temp <--- T[j] ...
Action bubble_sort(T: arr, n: int) var i: int j: int temp: int swapped: bool begin for (i <--- 0 to n-2) do swapped <--- false for (j <--- 0 to n-i-2) do if (T[j] > T[j+1]) then temp <--- T[j] T[j] <--- T[j+1] T[j+1] ...
sorting
beginner
algo_a47_00256
images_generated/code_00256.png
Read this Algorim code image and explain what it does:
Selection sort: finds minimum and places it at front. Code: Action selection_sort(T: arr, n: int) var i: int j: int min_idx: int temp: int begin for (i <--- 0 to n-2) do min_idx <--- i for (j <--- i+1 to n-1) do if (T[j] < T[min_idx]) then min_idx <--- j ...
Action selection_sort(T: arr, n: int) var i: int j: int min_idx: int temp: int begin for (i <--- 0 to n-2) do min_idx <--- i for (j <--- i+1 to n-1) do if (T[j] < T[min_idx]) then min_idx <--- j endif endfor if (min_idx != i) th...
sorting
beginner
algo_a47_00257
images_generated/code_00257.png
Read this Algorim code image and explain what it does:
Insertion sort: builds sorted array one element at a time. Code: Action insertion_sort(T: arr, n: int) var i: int j: int key: int begin for (i <--- 1 to n-1) do key <--- T[i] j <--- i - 1 while (j >= 0 and T[j] > key) do T[j+1] <--- T[j] j <--- j -...
Action insertion_sort(T: arr, n: int) var i: int j: int key: int begin for (i <--- 1 to n-1) do key <--- T[i] j <--- i - 1 while (j >= 0 and T[j] > key) do T[j+1] <--- T[j] j <--- j - 1 done T[j+1] <--- key endfor end
sorting
intermediate
algo_a47_00258
images_generated/code_00258.png
Read this Algorim code image and explain what it does:
Merge sort: divide-and-conquer stable sorting algorithm. Code: Action merge(T: arr, left: int, mid: int, right: int) var n1: int n2: int L: arr R: arr i: int j: int k: int begin n1 <--- mid - left + 1 n2 <--- right - mid for (i <--- 0 to n1-1) do L[i] <--- T[left + i] ...
Action merge(T: arr, left: int, mid: int, right: int) var n1: int n2: int L: arr R: arr i: int j: int k: int begin n1 <--- mid - left + 1 n2 <--- right - mid for (i <--- 0 to n1-1) do L[i] <--- T[left + i] endfor for (j <--- 0 to n2-1) do R[j] <--- T[mid +...
sorting
advanced
algo_a47_00259
images_generated/code_00259.png
Read this Algorim code image and explain what it does:
Quick sort with last element as pivot using Lomuto partition. Code: Action partition(T: arr, low: int, high: int): int var pivot: int i: int j: int temp: int begin pivot <--- T[high] i <--- low - 1 for (j <--- low to high-1) do if (T[j] <= pivot) then i <--- i +...
Action partition(T: arr, low: int, high: int): int var pivot: int i: int j: int temp: int begin pivot <--- T[high] i <--- low - 1 for (j <--- low to high-1) do if (T[j] <= pivot) then i <--- i + 1 temp <--- T[i] T[i] <--- T[j] ...
sorting
advanced
algo_a47_00260
images_generated/code_00260.png
Read this Algorim code image and explain what it does:
Heap sort using max-heap. Code: Action heapify(T: arr, n: int, i: int) var largest: int left: int right: int temp: int begin largest <--- i left <--- 2 * i + 1 right <--- 2 * i + 2 if (left < n and T[left] > T[largest]) then largest <--- left endif if (right < n and...
Action heapify(T: arr, n: int, i: int) var largest: int left: int right: int temp: int begin largest <--- i left <--- 2 * i + 1 right <--- 2 * i + 2 if (left < n and T[left] > T[largest]) then largest <--- left endif if (right < n and T[right] > T[largest]) then ...
sorting
advanced
algo_a47_00261
images_generated/code_00261.png
Read this Algorim code image and explain what it does:
Singly linked list node creation and insertion operations. Code: // Node structure for Singly Linked List // node.data: int // node.next: pointer to next node Action create_node(val: int): node var new_node: node begin new_node.data <--- val new_node.next <--- null create_node <--- new_node end Act...
// Node structure for Singly Linked List // node.data: int // node.next: pointer to next node Action create_node(val: int): node var new_node: node begin new_node.data <--- val new_node.next <--- null create_node <--- new_node end Action insert_front(head: node, val: int): node var new_node: nod...
linked_list
intermediate
algo_a47_00262
images_generated/code_00262.png
Read this Algorim code image and explain what it does:
Delete first occurrence of val from linked list. Code: Action delete_node(head: node, val: int): node var current: node prev: node begin if (head = null) then delete_node <--- null else if (head.data = val) then delete_node <--- head.next else prev <--...
Action delete_node(head: node, val: int): node var current: node prev: node begin if (head = null) then delete_node <--- null else if (head.data = val) then delete_node <--- head.next else prev <--- head current <--- head.next wh...
linked_list
intermediate
algo_a47_00263
images_generated/code_00263.png
Read this Algorim code image and explain what it does:
Reverses a singly linked list in-place. Code: Action reverse_list(head: node): node var prev: node current: node next_node: node begin prev <--- null current <--- head while (current != null) do next_node <--- current.next current.next <--- prev prev <--- c...
Action reverse_list(head: node): node var prev: node current: node next_node: node begin prev <--- null current <--- head while (current != null) do next_node <--- current.next current.next <--- prev prev <--- current current <--- next_node ...
linked_list
intermediate
algo_a47_00264
images_generated/code_00264.png
Read this Algorim code image and explain what it does:
Returns the length of a singly linked list. Code: Action list_length(head: node): int var count: int current: node begin count <--- 0 current <--- head while (current != null) do count <--- count + 1 current <--- current.next done list_length <--- count end
Action list_length(head: node): int var count: int current: node begin count <--- 0 current <--- head while (current != null) do count <--- count + 1 current <--- current.next done list_length <--- count end
linked_list
beginner
algo_a47_00265
images_generated/code_00265.png
Read this Algorim code image and explain what it does:
Stack implementation using array with push, pop, peek, isEmpty. Code: // Stack using array // stack.data: arr // stack.top: int (index of top, -1 if empty) Action stack_init(): stack var s: stack begin s.top <--- -1 stack_init <--- s end Action stack_push(s: stack, val: int) begin s.top <---...
// Stack using array // stack.data: arr // stack.top: int (index of top, -1 if empty) Action stack_init(): stack var s: stack begin s.top <--- -1 stack_init <--- s end Action stack_push(s: stack, val: int) begin s.top <--- s.top + 1 s.data[s.top] <--- val end Action stack_pop(s: stack): ...
data_structures
intermediate
algo_a47_00266
images_generated/code_00266.png
Read this Algorim code image and explain what it does:
Checks if parentheses/brackets/braces are balanced using a stack. Code: Action is_balanced(expr: arr, n: int): bool var s: stack i: int ch: char top_ch: char begin s <--- stack_init() for (i <--- 0 to n-1) do ch <--- expr[i] if (ch = '(' or ch = '[' or ch = '{') then ...
Action is_balanced(expr: arr, n: int): bool var s: stack i: int ch: char top_ch: char begin s <--- stack_init() for (i <--- 0 to n-1) do ch <--- expr[i] if (ch = '(' or ch = '[' or ch = '{') then stack_push(s, ch) else if (ch = ')' or ch = ']' or c...
data_structures
intermediate
algo_a47_00267
images_generated/code_00267.png
Read this Algorim code image and explain what it does:
Circular queue implementation with enqueue, dequeue, isEmpty. Code: // Queue using circular array // q.data: arr // q.front: int // q.rear: int // q.size: int // q.capacity: int Action queue_init(cap: int): queue var q: queue begin q.front <--- 0 q.rear <--- -1 q.size <--- 0 q.capacity ...
// Queue using circular array // q.data: arr // q.front: int // q.rear: int // q.size: int // q.capacity: int Action queue_init(cap: int): queue var q: queue begin q.front <--- 0 q.rear <--- -1 q.size <--- 0 q.capacity <--- cap queue_init <--- q end Action enqueue(q: queue, val: int...
data_structures
intermediate
algo_a47_00268
images_generated/code_00268.png
Read this Algorim code image and explain what it does:
Inserts a key into a Binary Search Tree. Code: // Binary Search Tree // node.key: int // node.left: node // node.right: node Action bst_insert(root: node, key: int): node var new_node: node begin if (root = null) then new_node.key <--- key new_node.left <--- null new_node.right <---...
// Binary Search Tree // node.key: int // node.left: node // node.right: node Action bst_insert(root: node, key: int): node var new_node: node begin if (root = null) then new_node.key <--- key new_node.left <--- null new_node.right <--- null bst_insert <--- new_node e...
trees
intermediate
algo_a47_00269
images_generated/code_00269.png
Read this Algorim code image and explain what it does:
Searches for a key in a Binary Search Tree. Code: Action bst_search(root: node, key: int): bool begin if (root = null) then bst_search <--- false else if (root.key = key) then bst_search <--- true else if (key < root.key) then bst_search <--- bst_...
Action bst_search(root: node, key: int): bool begin if (root = null) then bst_search <--- false else if (root.key = key) then bst_search <--- true else if (key < root.key) then bst_search <--- bst_search(root.left, key) else ...
trees
intermediate
algo_a47_00270
images_generated/code_00270.png
Read this Algorim code image and explain what it does:
In-order traversal of binary tree (Left-Root-Right). Code: Action inorder(root: node) begin if (root != null) then inorder(root.left) print(root.key) inorder(root.right) endif end
Action inorder(root: node) begin if (root != null) then inorder(root.left) print(root.key) inorder(root.right) endif end
trees
beginner
algo_a47_00271
images_generated/code_00271.png
Read this Algorim code image and explain what it does:
Pre-order traversal (Root-Left-Right). Code: Action preorder(root: node) begin if (root != null) then print(root.key) preorder(root.left) preorder(root.right) endif end
Action preorder(root: node) begin if (root != null) then print(root.key) preorder(root.left) preorder(root.right) endif end
trees
beginner
algo_a47_00272
images_generated/code_00272.png
Read this Algorim code image and explain what it does:
Post-order traversal (Left-Right-Root). Code: Action postorder(root: node) begin if (root != null) then postorder(root.left) postorder(root.right) print(root.key) endif end
Action postorder(root: node) begin if (root != null) then postorder(root.left) postorder(root.right) print(root.key) endif end
trees
beginner
algo_a47_00273
images_generated/code_00273.png
Read this Algorim code image and explain what it does:
Computes the height (depth) of a binary tree. Code: Action tree_height(root: node): int var left_h: int right_h: int begin if (root = null) then tree_height <--- 0 else left_h <--- tree_height(root.left) right_h <--- tree_height(root.right) if (left_h > right_h) then ...
Action tree_height(root: node): int var left_h: int right_h: int begin if (root = null) then tree_height <--- 0 else left_h <--- tree_height(root.left) right_h <--- tree_height(root.right) if (left_h > right_h) then tree_height <--- left_h + 1 else ...
trees
intermediate
algo_a47_00274
images_generated/code_00274.png
Read this Algorim code image and explain what it does:
Counts total nodes in a binary tree. Code: Action count_nodes(root: node): int begin if (root = null) then count_nodes <--- 0 else count_nodes <--- 1 + count_nodes(root.left) + count_nodes(root.right) endif end
Action count_nodes(root: node): int begin if (root = null) then count_nodes <--- 0 else count_nodes <--- 1 + count_nodes(root.left) + count_nodes(root.right) endif end
trees
beginner
algo_a47_00275
images_generated/code_00275.png
Read this Algorim code image and explain what it does:
BFS level-order traversal of binary tree using a queue. Code: Action level_order(root: node) var q: queue current: node begin if (root = null) then // empty tree else q <--- queue_init(100) enqueue(q, root) while (not queue_is_empty(q)) do current <--- dequeu...
Action level_order(root: node) var q: queue current: node begin if (root = null) then // empty tree else q <--- queue_init(100) enqueue(q, root) while (not queue_is_empty(q)) do current <--- dequeue(q) print(current.key) if (current.lef...
trees
intermediate
algo_a47_00276
images_generated/code_00276.png
Read this Algorim code image and explain what it does:
DFS graph traversal using adjacency matrix and recursion. Code: // Graph represented as adjacency matrix // graph[i][j] = 1 if edge i-j exists Action dfs(graph: arr, n: int, v: int, visited: arr) var i: int begin visited[v] <--- true print(v) for (i <--- 0 to n-1) do if (graph[v][i] = 1 and vi...
// Graph represented as adjacency matrix // graph[i][j] = 1 if edge i-j exists Action dfs(graph: arr, n: int, v: int, visited: arr) var i: int begin visited[v] <--- true print(v) for (i <--- 0 to n-1) do if (graph[v][i] = 1 and visited[i] = false) then dfs(graph, n, i, visited) ...
graphs
advanced
algo_a47_00277
images_generated/code_00277.png
Read this Algorim code image and explain what it does:
BFS graph traversal using adjacency matrix and queue. Code: Action bfs(graph: arr, n: int, start: int) var visited: arr q: queue v: int i: int begin for (i <--- 0 to n-1) do visited[i] <--- false endfor q <--- queue_init(n) visited[start] <--- true enqueue(q, start...
Action bfs(graph: arr, n: int, start: int) var visited: arr q: queue v: int i: int begin for (i <--- 0 to n-1) do visited[i] <--- false endfor q <--- queue_init(n) visited[start] <--- true enqueue(q, start) while (not queue_is_empty(q)) do v <--- dequeue...
graphs
advanced
algo_a47_00278
images_generated/code_00278.png
Read this Algorim code image and explain what it does:
Computes string length by counting until null terminator. Code: Action str_len(s: arr): int var i: int begin i <--- 0 while (s[i] != '\0') do i <--- i + 1 done str_len <--- i end
Action str_len(s: arr): int var i: int begin i <--- 0 while (s[i] != '\0') do i <--- i + 1 done str_len <--- i end
strings
beginner
algo_a47_00279
images_generated/code_00279.png
Read this Algorim code image and explain what it does:
Checks if a string is a palindrome using two pointers. Code: Action is_palindrome(s: arr, n: int): bool var i: int j: int result: bool begin result <--- true i <--- 0 j <--- n - 1 while (i < j and result = true) do if (s[i] != s[j]) then result <--- false ...
Action is_palindrome(s: arr, n: int): bool var i: int j: int result: bool begin result <--- true i <--- 0 j <--- n - 1 while (i < j and result = true) do if (s[i] != s[j]) then result <--- false endif i <--- i + 1 j <--- j - 1 done ...
strings
beginner
algo_a47_00280
images_generated/code_00280.png
Read this Algorim code image and explain what it does:
Reverses a string in-place. Code: Action str_reverse(s: arr, n: int) var i: int j: int temp: char begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- s[i] s[i] <--- s[j] s[j] <--- temp i <--- i + 1 j <--- j - 1 done end
Action str_reverse(s: arr, n: int) var i: int j: int temp: char begin i <--- 0 j <--- n - 1 while (i < j) do temp <--- s[i] s[i] <--- s[j] s[j] <--- temp i <--- i + 1 j <--- j - 1 done end
strings
beginner
algo_a47_00281
images_generated/code_00281.png
Read this Algorim code image and explain what it does:
Copies string src to dst. Code: Action str_copy(src: arr, dst: arr) var i: int begin i <--- 0 while (src[i] != '\0') do dst[i] <--- src[i] i <--- i + 1 done dst[i] <--- '\0' end
Action str_copy(src: arr, dst: arr) var i: int begin i <--- 0 while (src[i] != '\0') do dst[i] <--- src[i] i <--- i + 1 done dst[i] <--- '\0' end
strings
beginner
algo_a47_00282
images_generated/code_00282.png
Read this Algorim code image and explain what it does:
Counts occurrences of character c in string s. Code: Action count_char(s: arr, n: int, c: char): int var i: int count: int begin count <--- 0 for (i <--- 0 to n-1) do if (s[i] = c) then count <--- count + 1 endif endfor count_char <--- count end
Action count_char(s: arr, n: int, c: char): int var i: int count: int begin count <--- 0 for (i <--- 0 to n-1) do if (s[i] = c) then count <--- count + 1 endif endfor count_char <--- count end
strings
beginner
algo_a47_00283
images_generated/code_00283.png
Read this Algorim code image and explain what it does:
Finds the length of the Longest Common Subsequence using DP. Code: Action lcs_length(A: arr, B: arr, m: int, n: int): int var dp: array[m+1][n+1] i: int j: int begin for (i <--- 0 to m) do for (j <--- 0 to n) do if (i = 0 or j = 0) then dp[i][j] <--- 0 el...
Action lcs_length(A: arr, B: arr, m: int, n: int): int var dp: array[m+1][n+1] i: int j: int begin for (i <--- 0 to m) do for (j <--- 0 to n) do if (i = 0 or j = 0) then dp[i][j] <--- 0 else if (A[i-1] = B[j-1]) then dp[...
dynamic_programming
advanced
algo_a47_00284
images_generated/code_00284.png
Read this Algorim code image and explain what it does:
0/1 Knapsack problem using bottom-up DP. Code: Action knapsack(weights: arr, values: arr, n: int, W: int): int var dp: array[n+1][W+1] i: int w: int begin for (i <--- 0 to n) do for (w <--- 0 to W) do if (i = 0 or w = 0) then dp[i][w] <--- 0 else ...
Action knapsack(weights: arr, values: arr, n: int, W: int): int var dp: array[n+1][W+1] i: int w: int begin for (i <--- 0 to n) do for (w <--- 0 to W) do if (i = 0 or w = 0) then dp[i][w] <--- 0 else if (weights[i-1] <= w) then ...
dynamic_programming
advanced
algo_a47_00285
images_generated/code_00285.png
Read this Algorim code image and explain what it does:
Minimum number of coins to make an amount (DP). Code: Action coin_change(coins: arr, n: int, amount: int): int var dp: arr i: int j: int INF: int begin INF <--- amount + 1 for (i <--- 0 to amount) do dp[i] <--- INF endfor dp[0] <--- 0 for (i <--- 1 to amount) do for ...
Action coin_change(coins: arr, n: int, amount: int): int var dp: arr i: int j: int INF: int begin INF <--- amount + 1 for (i <--- 0 to amount) do dp[i] <--- INF endfor dp[0] <--- 0 for (i <--- 1 to amount) do for (j <--- 0 to n-1) do if (coins[j] <= i) the...
dynamic_programming
advanced
algo_a47_00286
images_generated/code_00286.png
Read this Algorim code image and explain what it does:
Sieve of Eratosthenes to find all primes up to n. Code: Action sieve_of_eratosthenes(n: int): arr var is_prime: arr i: int j: int begin for (i <--- 0 to n) do is_prime[i] <--- true endfor is_prime[0] <--- false is_prime[1] <--- false i <--- 2 while (i * i <= n) do if...
Action sieve_of_eratosthenes(n: int): arr var is_prime: arr i: int j: int begin for (i <--- 0 to n) do is_prime[i] <--- true endfor is_prime[0] <--- false is_prime[1] <--- false i <--- 2 while (i * i <= n) do if (is_prime[i] = true) then j <--- i * i ...
number_theory
intermediate
algo_a47_00287
images_generated/code_00287.png
Read this Algorim code image and explain what it does:
Converts binary string to decimal integer. Code: Action bin_to_dec(binary: arr, n: int): int var decimal: int power: int i: int begin decimal <--- 0 power <--- 1 for (i <--- n-1 to 0) do if (binary[i] = '1') then decimal <--- decimal + power endif power <--...
Action bin_to_dec(binary: arr, n: int): int var decimal: int power: int i: int begin decimal <--- 0 power <--- 1 for (i <--- n-1 to 0) do if (binary[i] = '1') then decimal <--- decimal + power endif power <--- power * 2 endfor bin_to_dec <--- decimal...
number_theory
beginner
algo_a47_00288
images_generated/code_00288.png
Read this Algorim code image and explain what it does:
Hash table with separate chaining collision resolution. Code: // Simple hash table with chaining // TABLE_SIZE = 100 // table: array of linked_list heads Action hash(key: int): int begin hash <--- key mod 100 end Action hash_insert(table: arr, key: int, value: int) var idx: int new_node: node begin i...
// Simple hash table with chaining // TABLE_SIZE = 100 // table: array of linked_list heads Action hash(key: int): int begin hash <--- key mod 100 end Action hash_insert(table: arr, key: int, value: int) var idx: int new_node: node begin idx <--- hash(key) new_node.key <--- key ne...
data_structures
advanced
algo_a47_00289
images_generated/code_00289.png
Read this Algorim code image and explain what it does:
Multiplies two n×n matrices A and B, stores result in C. Code: Action matrix_multiply(A: arr, B: arr, C: arr, n: int) var i: int j: int k: int sum: int begin for (i <--- 0 to n-1) do for (j <--- 0 to n-1) do sum <--- 0 for (k <--- 0 to n-1) do sum <--...
Action matrix_multiply(A: arr, B: arr, C: arr, n: int) var i: int j: int k: int sum: int begin for (i <--- 0 to n-1) do for (j <--- 0 to n-1) do sum <--- 0 for (k <--- 0 to n-1) do sum <--- sum + A[i][k] * B[k][j] endfor C[i][j]...
matrix
intermediate
algo_a47_00290
images_generated/code_00290.png
Read this Algorim code image and explain what it does:
Transposes a square matrix in-place. Code: Action transpose(A: arr, n: int) var i: int j: int temp: int begin for (i <--- 0 to n-1) do for (j <--- i+1 to n-1) do temp <--- A[i][j] A[i][j] <--- A[j][i] A[j][i] <--- temp endfor endfor end
Action transpose(A: arr, n: int) var i: int j: int temp: int begin for (i <--- 0 to n-1) do for (j <--- i+1 to n-1) do temp <--- A[i][j] A[i][j] <--- A[j][i] A[j][i] <--- temp endfor endfor end
matrix
beginner
algo_a47_00291
images_generated/code_00291.png
Read this Algorim code image and explain what it does:
Min-heap with insert and extract_min operations. Code: // Min-Heap operations // heap.data: arr // heap.size: int Action heap_parent(i: int): int begin heap_parent <--- (i - 1) div 2 end Action heap_left(i: int): int begin heap_left <--- 2 * i + 1 end Action heap_right(i: int): int begin heap_right <---...
// Min-Heap operations // heap.data: arr // heap.size: int Action heap_parent(i: int): int begin heap_parent <--- (i - 1) div 2 end Action heap_left(i: int): int begin heap_left <--- 2 * i + 1 end Action heap_right(i: int): int begin heap_right <--- 2 * i + 2 end Action min_heap_insert(heap: heap_struct...
data_structures
advanced
algo_a47_00292
images_generated/code_00292.png
Read this Algorim code image and explain what it does:
N-Queens problem using backtracking. Code: Action is_safe(board: arr, row: int, col: int, n: int): bool var i: int j: int safe: bool begin safe <--- true // Check column for (i <--- 0 to row-1) do if (board[i][col] = 1) then safe <--- false endif endfor // Ch...
Action is_safe(board: arr, row: int, col: int, n: int): bool var i: int j: int safe: bool begin safe <--- true // Check column for (i <--- 0 to row-1) do if (board[i][col] = 1) then safe <--- false endif endfor // Check upper-left diagonal i <--- row - 1 ...
backtracking
advanced
algo_a47_00293
images_generated/code_00293.png
Read this Algorim code image and explain what it does:
Command to generate a visual image of an algorithm or code. Code: /imagine A code visualization showing merge sort dividing array [8,3,1,5,2] into subarrays and merging them back in sorted order, dark background with neon syntax highlighting
/imagine A code visualization showing merge sort dividing array [8,3,1,5,2] into subarrays and merging them back in sorted order, dark background with neon syntax highlighting
commands
beginner
algo_a47_00294
images_generated/code_00294.png
Read this Algorim code image and explain what it does:
Command to compile Algorim code to executable bytecode. Code: /compile Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
/compile Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
commands
intermediate
algo_a47_00295
images_generated/code_00295.png
Read this Algorim code image and explain what it does:
Command to debug Algorim code with execution trace. Code: /debug Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) then bina...
/debug Action binary_search(T: arr, n: int, target: int): int var low: int high: int mid: int begin low <--- 0 high <--- n - 1 while (low <= high) do mid <--- (low + high) div 2 if (T[mid] = target) then binary_search <--- mid else if (T[mid] < ta...
commands
intermediate
algo_a47_00296
images_generated/code_00296.png
Read this Algorim code image and explain what it does:
Exchange values of two integer variables using a temporary variable. Code: Action swap(a: int, b: int) var temp: int begin temp <--- a a <--- b b <--- temp end
Action swap(a: int, b: int) var temp: int begin temp <--- a a <--- b b <--- temp end
basic
beginner
algo_a47_00297
images_generated/code_00297.png
Read this Algorim code image and explain what it does:
Returns the absolute value of an integer. Code: Action absolute(n: int): int var result: int begin if (n < 0) then result <--- n * -1 else result <--- n endif absolute <--- result end
Action absolute(n: int): int var result: int begin if (n < 0) then result <--- n * -1 else result <--- n endif absolute <--- result end
math
beginner
algo_a47_00298
images_generated/code_00298.png
Read this Algorim code image and explain what it does:
Computes base raised to the power of exp using iteration. Code: Action power(base: int, exp: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to exp) do result <--- result * base endfor power <--- result end
Action power(base: int, exp: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to exp) do result <--- result * base endfor power <--- result end
math
beginner
algo_a47_00299
images_generated/code_00299.png
Read this Algorim code image and explain what it does:
Computes n! iteratively. Code: Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
Action factorial(n: int): int var result: int i: int begin result <--- 1 for (i <--- 1 to n) do result <--- result * i endfor factorial <--- result end
math
beginner
algo_a47_00300
images_generated/code_00300.png
Read this Algorim code image and explain what it does:
Recursive factorial computation. Code: Action factorial_rec(n: int): int begin if (n <= 1) then factorial_rec <--- 1 else factorial_rec <--- n * factorial_rec(n - 1) endif end
Action factorial_rec(n: int): int begin if (n <= 1) then factorial_rec <--- 1 else factorial_rec <--- n * factorial_rec(n - 1) endif end
recursion
intermediate