Dataset Viewer
Auto-converted to Parquet Duplicate
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_00001
images_generated/code_00001.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_00002
images_generated/code_00002.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_00003
images_generated/code_00003.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_00004
images_generated/code_00004.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_00005
images_generated/code_00005.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_00006
images_generated/code_00006.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_00007
images_generated/code_00007.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_00008
images_generated/code_00008.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_00009
images_generated/code_00009.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_00010
images_generated/code_00010.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_00011
images_generated/code_00011.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_00012
images_generated/code_00012.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_00013
images_generated/code_00013.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_00014
images_generated/code_00014.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_00015
images_generated/code_00015.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_00016
images_generated/code_00016.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_00017
images_generated/code_00017.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_00018
images_generated/code_00018.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_00019
images_generated/code_00019.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_00020
images_generated/code_00020.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_00021
images_generated/code_00021.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_00022
images_generated/code_00022.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_00023
images_generated/code_00023.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_00024
images_generated/code_00024.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_00025
images_generated/code_00025.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_00026
images_generated/code_00026.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_00027
images_generated/code_00027.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_00028
images_generated/code_00028.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_00029
images_generated/code_00029.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_00030
images_generated/code_00030.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_00031
images_generated/code_00031.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_00032
images_generated/code_00032.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_00033
images_generated/code_00033.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_00034
images_generated/code_00034.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_00035
images_generated/code_00035.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_00036
images_generated/code_00036.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_00037
images_generated/code_00037.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_00038
images_generated/code_00038.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_00039
images_generated/code_00039.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_00040
images_generated/code_00040.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_00041
images_generated/code_00041.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_00042
images_generated/code_00042.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_00043
images_generated/code_00043.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_00044
images_generated/code_00044.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_00045
images_generated/code_00045.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_00046
images_generated/code_00046.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_00047
images_generated/code_00047.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_00048
images_generated/code_00048.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_00049
images_generated/code_00049.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_00050
images_generated/code_00050.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_00051
images_generated/code_00051.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_00052
images_generated/code_00052.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_00053
images_generated/code_00053.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_00054
images_generated/code_00054.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_00055
images_generated/code_00055.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_00056
images_generated/code_00056.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_00057
images_generated/code_00057.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_00058
images_generated/code_00058.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_00059
images_generated/code_00059.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_00060
images_generated/code_00060.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_00061
images_generated/code_00061.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_00062
images_generated/code_00062.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_00063
images_generated/code_00063.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_00064
images_generated/code_00064.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_00065
images_generated/code_00065.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_00066
images_generated/code_00066.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_00067
images_generated/code_00067.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_00068
images_generated/code_00068.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_00069
images_generated/code_00069.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_00070
images_generated/code_00070.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_00071
images_generated/code_00071.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_00072
images_generated/code_00072.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_00073
images_generated/code_00073.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_00074
images_generated/code_00074.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_00075
images_generated/code_00075.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_00076
images_generated/code_00076.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_00077
images_generated/code_00077.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_00078
images_generated/code_00078.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_00079
images_generated/code_00079.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_00080
images_generated/code_00080.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_00081
images_generated/code_00081.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_00082
images_generated/code_00082.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_00083
images_generated/code_00083.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_00084
images_generated/code_00084.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_00085
images_generated/code_00085.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_00086
images_generated/code_00086.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_00087
images_generated/code_00087.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_00088
images_generated/code_00088.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_00089
images_generated/code_00089.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_00090
images_generated/code_00090.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_00091
images_generated/code_00091.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_00092
images_generated/code_00092.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_00093
images_generated/code_00093.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_00094
images_generated/code_00094.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_00095
images_generated/code_00095.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_00096
images_generated/code_00096.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_00097
images_generated/code_00097.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_00098
images_generated/code_00098.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_00099
images_generated/code_00099.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_00100
images_generated/code_00100.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
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
230