version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
complete
Data_Structure
Data_Structure_26708_C
def gcd_mod(a: int, b: int) -> int: """Compute the GCD of a and b using Euclid's algorithm with modulus operation. >>> gcd_mod(24, 36) == 12 >>> gcd_mod(48, 18) == 6 >>> gcd_mod(101, 10) == 1 >>> gcd_mod(0, 5) == 5 >>> gcd_mod(17, 0) == 17 """ pass def gcd_bitwise(a: int, b: int) -> int...
def gcd_mod(a, b): """ Compute the GCD of a and b using Euclid's algorithm with modulus operation. """ while b != 0: a, b = b, a % b return a def gcd_bitwise(a, b): """ Compute the GCD of a and b using the binary GCD algorithm. """ if a == 0: return b if b == 0: ...
from solution import gcd_mod, gcd_bitwise, lcm, gcd_lcm def test_gcd_mod(): assert gcd_mod(24, 36) == 12 assert gcd_mod(48, 18) == 6 assert gcd_mod(101, 10) == 1 assert gcd_mod(0, 5) == 5 assert gcd_mod(17, 0) == 17 def test_gcd_bitwise(): assert gcd_bitwise(24, 36) == 12 assert gcd_bitwis...
[ { "docstring": "Compute the GCD of a and b using Euclid's algorithm with modulus operation.", "function_declaration": "def gcd_mod(a, b):", "function_name": "gcd_mod", "parameter_list": "(a, b)" }, { "docstring": "Compute the GCD of a and b using the binary GCD algorithm.", "function_dec...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_mod(a: int, b: int) -> int:\n \"\"\"\n Calculate GCD using Euclid's modulus algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n r...
trial_gpt4o_1
{ "original_instruction": "### Question: Advanced GCD and LCM Implementations\n\nYou are to implement a function that computes the greatest common divisor (GCD) and the least common multiple (LCM) of two integers with the following improvements over given reference methods:\n1. Implement Euclid's algorithm for GCD us...
0.753895
Data_Structure_26708
C
[ "gcd_mod", "gcd_bitwise", "lcm", "gcd_lcm" ]
4
[ [ "gcd_lcm", "gcd_mod" ], [ "lcm", "gcd_mod" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bad70acdf5b807186a8e787ad320d7fa08d80ea4
7bad2f87255a981f1a52745c72daf6f9c4fba3fc
v1.0
complete
Data_Structure
Data_Structure_26967_C
import random from sympy import gcd, mod_inverse, isprime def efficient_gen_prime(k, seed=None): """ Generates a prime number with k bits using a probabilistic approach. Args: k (int): Number of bits. seed (int): Optional seed for deterministic randomness. Returns: int: A prime nu...
import random from sympy import gcd, mod_inverse, isprime def efficient_gen_prime(k, seed=None): """ Generates a prime number with k bits using a probabilistic approach. Args: k (int): Number of bits. seed (int): Optional seed for deterministic randomness. Returns: int: A prime nu...
from solution import efficient_gen_prime, generate_key, validate_keys def test_efficient_gen_prime(): # Check for 16-bit prime generation with a fixed seed prime = efficient_gen_prime(16, seed=42) assert prime.bit_length() == 16 assert isprime(prime) def test_generate_key(): n, e, d = generate...
[ { "docstring": "Generates a prime number with k bits using a probabilistic approach.\n\nArgs:\nk (int): Number of bits.\nseed (int): Optional seed for deterministic randomness.\n\nReturns:\nint: A prime number with k bits.", "function_declaration": "def efficient_gen_prime(k, seed=None):", "function_nam...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(n, k=30):\n \"\"\"\n Miller-Rabin primality test to check if n is a probable prime.\n \"\"\"\n if n in (2, 3):\n ...
trial_gpt4o_9
{ "original_instruction": "### RSA Encryption Algorithm Implementation and Analysis\n\n#### Context\nThe RSA algorithm is crucial for secure communication in modern applications, from web browsing to secure email and digital signatures. As a cryptographer in training, you need to solidify your understanding of RSA by...
0.588595
Data_Structure_26967
C
[ "efficient_gen_prime", "generate_key", "validate_keys" ]
3
[ [ "generate_key", "efficient_gen_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
708e5a6de46b2040fba8fa847ace5609d8af2419
9b2bf82d4b4bc9bd7312ee1f84765960888840d2
v1.0
complete
Data_Structure
Data_Structure_26918_C
from typing import List def find_optimal_location(grid: List[List[int]]) -> int: """ Find the optimal location to place a distribution center in a city grid. The grid contains `1` for buildings, `0` for empty lands, and `2` for obstacles. The objective is to minimize the sum of the shortest distances from...
from typing import List, Tuple from collections import deque def bfs(grid: List[List[int]], m: int, n: int, start_x: int, start_y: int) -> List[List[int]]: distances = [[-1] * n for _ in range(m)] queue = deque([(start_x, start_y, 0)]) while queue: x, y, dist = queue.popleft() for dx, dy in...
from solution import find_optimal_location def test_case_1(): grid = [ [1, 0, 2, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0] ] assert find_optimal_location(grid) == 7 def test_case_2(): grid = [ [1, 0], [0, 0] ] assert find_optimal_location(grid) == 1 def t...
[ { "docstring": null, "function_declaration": "def bfs(grid, m, n, start_x, start_y):", "function_name": "bfs", "parameter_list": "(grid, m, n, start_x, start_y)" }, { "docstring": null, "function_declaration": "def find_optimal_location(grid):", "function_name": "find_optimal_locatio...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom collections import deque\n\ndef find_optimal_location(grid: List[List[int]]) -> int:\n def bfs(start_row, start_col, dist, re...
trial_gpt4o_8
{ "original_instruction": "### Question: Optimal Facility Placement on a Grid\n\nYou are tasked with building a new distribution center in a city represented by an `m x n` grid. The city's map is provided as a 2D grid where:\n- `1` represents a building.\n- `0` represents an empty land that can be chosen for the new ...
0.59104
Data_Structure_26918
C
[ "bfs", "find_optimal_location" ]
2
[ [ "find_optimal_location", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6dfda29e5255b7d0622061133265d13783448710
6502d34e6fd4e4177b34dda712923ab705e3604f
v1.0
complete
Data_Structure
Data_Structure_26984_C
from typing import List def generate_primes(n: int, k: int) -> List[int]: """ Generate the first `k` prime numbers greater than or equal to a given integer `n`. >>> generate_primes(10, 5) [11, 13, 17, 19, 23] >>> generate_primes(50, 3) [53, 59, 61] >>> generate_primes(1, 5) [2, 3, 5, 7, 11]...
from typing import List import math def is_prime(num: int) -> bool: if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i +=...
from solution import generate_primes def test_generate_primes_example1(): assert generate_primes(10, 5) == [11, 13, 17, 19, 23] def test_generate_primes_example2(): assert generate_primes(50, 3) == [53, 59, 61] def test_generate_primes_edge_case_small_n(): assert generate_primes(1, 5) == [2, 3, 5, 7, 11]...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def generate_primes(n, k):", "function_name": "generate_primes", "parameter_list": "(n, k)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nimport math\n\ndef is_prime(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n return True\n if...
trial_gpt4o_0
{ "original_instruction": "As a software engineer at a security company, you need to implement an authentication feature that relies on prime numbers for encryption keys. Your task is to write a function to generate the first `k` prime numbers greater than or equal to a given integer n.\n\n**Task**:\nWrite a function...
0.70149
Data_Structure_26984
C
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f09d2b8e40dbccb77c9c92bbce14d4bd0d293ed
b555b1bb5fe22ada0222af3aa661fadb82a4acf8
v1.0
complete
Data_Structure
Data_Structure_26950_C
from typing import Tuple, Dict def nearest_neighbor(x: Tuple[float, ...], tSet: Dict[Tuple[float, ...], str]) -> str: """ Find the label of the nearest neighbor to the vector `x` from the training set `tSet`. Parameters: - x: A tuple of floats representing the feature vector of the point to be classif...
from math import sqrt from typing import Tuple, Dict def distance(vec1: Tuple[float, ...], vec2: Tuple[float, ...]) -> float: """ Calculate the Euclidean distance between two vectors. """ return sqrt(sum((v1 - v2) ** 2 for v1, v2 in zip(vec1, vec2))) def nearest_neighbor(x: Tuple[float, ...], tSet: Di...
from solution import nearest_neighbor def test_basic_case(): tSet = { (1.0, 2.0): 'A', (2.0, 3.0): 'B', (3.0, 4.0): 'C' } x = (2.5, 3.5) assert nearest_neighbor(x, tSet) == 'B' def test_exact_match(): tSet = { (1.0, 2.0): 'A', (2.5, 3.5): 'B', (3.0, ...
[ { "docstring": "Calculate the Euclidean distance between two vectors.", "function_declaration": "def distance(vec1, vec2):", "function_name": "distance", "parameter_list": "(vec1, vec2)" }, { "docstring": "Find the label of the nearest neighbor to the vector `x` from the training set `tSet`....
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import Tuple, Dict\n\ndef distance(a: Tuple[float, ...], b: Tuple[float, ...]) -> float:\n \"\"\"\n Returns the Euclidean distance between t...
trial_gpt4o_1
{ "original_instruction": "### Question: Nearest Neighbor Classifier with Euclidean Distance\n\nYou need to implement the nearest neighbor algorithm to classify data points. You are provided with a function called `distance` that calculates the Euclidean distance between two vectors, and a partially implemented funct...
0.641134
Data_Structure_26950
C
[ "distance", "nearest_neighbor" ]
2
[ [ "nearest_neighbor", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd2d2703b3a5d7406919b78d328f57f5eb099ee3
eaaae09f40ad9585366bad68c786680a9ce0d204
v1.0
complete
Data_Structure
Data_Structure_26874_C
def bitonic_sort(arr, reverse=False): """ Sorts an array using bitonic sort algorithm. Parameters: arr (List[int]): The array to sort. reverse (bool): Whether to sort in descending order. Default is False. Returns: List[int]: Sorted array. Raises: ValueError: if the size of...
def bitonic_sort(arr, reverse=False): """ Sorts an array using the bitonic sort algorithm. Parameters: arr (List[int]): The array to sort. reverse (bool): Whether to sort in descending order. Default is False. Returns: List[int]: Sorted array. Raises: ValueError: if th...
from solution import bitonic_sort, batch_bitonic_sort import pytest def test_bitonic_sort_ascending(): arr = [3, 7, 4, 8, 6, 2, 1, 5] expected = [1, 2, 3, 4, 5, 6, 7, 8] assert bitonic_sort(arr) == expected def test_bitonic_sort_descending(): arr = [3, 7, 4, 8, 6, 2, 1, 5] expected = [8, 7, 6, 5, ...
[ { "docstring": "Sorts an array using the bitonic sort algorithm.\n\nParameters:\narr (List[int]): The array to sort.\nreverse (bool): Whether to sort in descending order. Default is False.\n\nReturns:\nList[int]: Sorted array.\n\nRaises:\nValueError: if the size of the input array is not a power of two", "f...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_power_of_two(n):\n return (n & (n - 1) == 0) and n != 0\n\ndef bitonic_sort(arr, reverse=False):\n \"\"\"\n Sorts an array using bitonic sort ...
trial_gpt4o_1
{ "original_instruction": "### Context\nYou have been tasked with implementing the Bitonic Sort algorithm, which will be used in a high-performance computing environment. The Bitonic Sort must be capable of sorting arrays both in ascending and descending order, and the input size must be a power of two.\n\n### Task\n...
0.69454
Data_Structure_26874
C
[ "bitonic_sort", "batch_bitonic_sort" ]
2
[ [ "batch_bitonic_sort", "bitonic_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad5b88830147b18482a2ee81b44977ccbe636726
ac6c753d512e8ae3db1f6fce28bf9bfedb10e94a
v1.0
complete
Data_Structure
Data_Structure_27043_C
def int_to_base(number, base): """ Converts an integer to its string representation in a specified base. """ def base_to_int(number_str, base): """ Converts a string representation of a number in a specified base to an integer. """ def convert_base(number_str, from_base, to_base): """ ...
def int_to_base(number, base): """ Converts an integer to its string representation in a specified base. """ if number == 0: return "0" digits = [] while number: digits.append(int(number % base)) number //= base return ''.join(chr(digit + ord('0')) if digit < 10 else ...
from solution import int_to_base, base_to_int, convert_base def test_int_to_base(): assert int_to_base(5, 2) == "101" assert int_to_base(255, 16) == "FF" assert int_to_base(10, 10) == "10" assert int_to_base(0, 10) == "0" assert int_to_base(35, 36) == "Z" def test_base_to_int(): assert base_to...
[ { "docstring": "Converts an integer to its string representation in a specified base.", "function_declaration": "def int_to_base(number, base):", "function_name": "int_to_base", "parameter_list": "(number, base)" }, { "docstring": "Converts a string representation of a number in a specified ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_base(num, base):\n \"\"\"\n Converts an integer to a base-represented string.\n \"\"\"\n if num == 0:\n return \"0\"\n digits...
trial_gpt4o_7
{ "original_instruction": "#### Problem Statement\nYou are provided with two utility functions: `int_to_base` and `base_to_int` to convert numbers between integer form and base-represented strings. Your task is to implement a new function called `convert_base` that leverages these utilities to convert a number repres...
0.854508
Data_Structure_27043
C
[ "int_to_base", "base_to_int", "convert_base" ]
3
[ [ "convert_base", "base_to_int" ], [ "convert_base", "int_to_base" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aa03e6f46a87b477803fa1a5a6dad3359337513b
8a19ca25fca7eed503e2c3293af20b28ad535018
v1.0
complete
Data_Structure
Data_Structure_27182_C
def search_insert(arr: List[int], value: int) -> int: """ Helper function that uses binary search to find the index where the value should be inserted. """ low, high = 0, len(arr) while low < high: mid = (low + high) // 2 if arr[mid] < value: low = mid + 1 else: ...
from typing import List def search_insert(arr: List[int], value: int) -> int: """ Helper function that uses binary search to find the index where the value should be inserted. """ low, high = 0, len(arr) while low < high: mid = (low + high) // 2 if arr[mid] < value: low ...
from solution import enhanced_insertion_sort def test_empty_array(): assert enhanced_insertion_sort([]) == [] def test_single_element_array(): assert enhanced_insertion_sort([1]) == [1] def test_sorted_array(): assert enhanced_insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_ar...
[ { "docstring": "Helper function that uses binary search to find the index where the value should be inserted.", "function_declaration": "def search_insert(arr, value):", "function_name": "search_insert", "parameter_list": "(arr, value)" }, { "docstring": "Sorts an array using an enhanced ins...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(arr: List[int], value: int) -> int:\n \"\"\"\n This function finds the index at which the value should be i...
trial_gpt4o_2
{ "original_instruction": "### Coding Problem: Enhanced Insertion Sort\n\n**Context**:\nYou are tasked with implementing an enhanced version of insertion sort that leverages a binary search approach to find the appropriate insertion index. This will ensure that the sorting process performs better, particularly for la...
0.663837
Data_Structure_27182
C
[ "search_insert", "enhanced_insertion_sort" ]
2
[ [ "enhanced_insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a0ec6bb50127051a8173b3258be79c84975df8e6
93394c1e9322684807cb32badb6b41c8d458274e
v1.0
complete
Data_Structure
Data_Structure_27192_C
import random from typing import List def is_sorted(arr: List[int]) -> bool: """ Recursively checks if the array is sorted in ascending order. >>> is_sorted([1, 2, 3, 4, 5]) True >>> is_sorted([5, 4, 3, 2, 1]) False """ pass def bogo_sort(arr: List[int]) -> List[int]: """ Sorts...
import random def is_sorted(arr): """ Recursively checks if the array is sorted in ascending order. """ if len(arr) <= 1: return True return arr[0] <= arr[1] and is_sorted(arr[1:]) def bogo_sort(arr): """ Sorts the array using the highly inefficient Bogo Sort algorithm. Repeate...
from solution import bogo_sort, is_sorted import pytest def test_is_sorted_single_element(): assert is_sorted([1]) == True assert is_sorted([2]) == True def test_is_sorted_multiple_elements(): assert is_sorted([1, 2, 3, 4, 5]) == True assert is_sorted([1, 3, 2, 4, 5]) == False assert is_sorted([5,...
[ { "docstring": "Recursively checks if the array is sorted in ascending order.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sorts the array using the highly inefficient Bogo Sort algorithm.\nRepeatedly shuffles the...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_sorted(arr):\n \"\"\"\n Check if the list is sorted in ascending order.\n Returns True if sorted, False otherwise.\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "### Question\nYou are tasked with implementing a sorting function using the Bogo Sort algorithm. This algorithm repeatedly shuffles the array until it is sorted, checking after every shuffle to see if the array is in the correct order. \n\nWrite a function `bogo_sort` which takes a list of ...
0.678199
Data_Structure_27192
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2e0c26ed4eb15da7f815d57e9d79d6f4e2aab279
dbce71425ad229449e5cbba7616cd8cd1c9ee5aa
v1.0
complete
Data_Structure
Data_Structure_27302_C
import random from typing import List def custom_bogo_sort(arr: List[int]) -> List[int]: """ Sort the list using Bogo Sort algorithm. >>> custom_bogo_sort([3, 1, 2]) [1, 2, 3] >>> custom_bogo_sort([]) [] >>> custom_bogo_sort([1, 1, 1]) [1, 1, 1] """
import random from typing import List def is_sorted(arr: List[int]) -> bool: """ Helper function to check if the list is sorted in ascending order. """ return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) def custom_bogo_sort(arr: List[int]) -> List[int]: """ Sort the list using Bogo ...
from solution import custom_bogo_sort def test_sorted_list(): assert custom_bogo_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_list(): assert custom_bogo_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_empty_list(): assert custom_bogo_sort([]) == [] def test_single_element_list(): ...
[ { "docstring": "Helper function to check if the list is sorted in ascending order.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sort the list using Bogo Sort algorithm", "function_declaration": "def custom_bog...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef is_sorted(arr: List[int]) -> bool:\n \"\"\"\n Returns True if the array is sorted in ascending order, othe...
trial_gpt4o_2
{ "original_instruction": "### Question\n\n#### Context\nBogo Sort is an intentionally inefficient sorting algorithm based on the generate-and-test paradigm. Given an array of integers, Bogo Sort repeatedly checks if the array is sorted and randomly shuffles it if it is not. Although highly impractical, this algorith...
0.577899
Data_Structure_27302
C
[ "is_sorted", "custom_bogo_sort" ]
2
[ [ "custom_bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
06d0a0296d011ba75550dd1c467152f9e9ad6e78
53c3a606ee2fee93185155325f654663964f56a1
v1.0
complete
Data_Structure
Data_Structure_27178_C
def extended_gcd(a: int, b: int) -> (int, int, int): """ Implement the Extended GCD Algorithm. Returns a tuple (s, t, g) such that a * s + b * t = g where g is the greatest common divisor of a and b. >>> extended_gcd(30, 20) (1, -1, 10) >>> extended_gcd(101, 10) (1, -10, 1) """ pass de...
def extended_gcd(a, b): """ Returns a tuple (s, t, g) such that a * s + b * t = g where g is the greatest common divisor of a and b. """ if b == 0: return 1, 0, a else: s, t, g = extended_gcd(b, a % b) return t, s - (a // b) * t, g def modular_inverse(a, m): """ Retu...
from solution import extended_gcd, modular_inverse def test_extended_gcd(): # Basic tests assert extended_gcd(30, 20) == (1, -1, 10) assert extended_gcd(35, 15) == (1, -2, 5) assert extended_gcd(101, 10) == (1, -10, 1) # Edge cases assert extended_gcd(1, 1) == (0, 1, 1) assert extended_gcd...
[ { "docstring": "Returns a tuple (s, t, g) such that a * s + b * t = g where g is the greatest common divisor of a and b.", "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns an integer x such that (a * x) ...
[ 0, 0, 1, 1, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def extended_gcd(a, b):\n \"\"\"\n Extended Euclidean Algorithm that computes the gcd of a and b\n while also finding coefficients s and t such that ...
trial_gpt4o_8
{ "original_instruction": "You are to implement two functions as described in the following tasks:\n\n1. **Implement the Extended GCD Algorithm**: Write a function `extended_gcd(a: int, b: int) -> (int, int, int)` that returns a tuple `(s, t, g)` such that `a * s + b * t = g` where `g` is the greatest common divisor ...
0.662145
Data_Structure_27178
C
[ "extended_gcd", "modular_inverse" ]
2
[ [ "modular_inverse", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d2b40dd1c386d007a7a2f8ff0e473a2ef813e3ef
b8fb997e1d75be2e6134fada73a88d9c88900fb1
v1.0
complete
Data_Structure
Data_Structure_26380_C
def enhanced_stoogesort(arr, l, h, t): """ Enhanced Stooge Sort algorithm with a threshold parameter to switch to Insertion Sort for small segments. Inputs: - arr: List[int] : Array to be sorted - l: int : Starting index of the segment to be sorted - h: int : Ending index of the segment to be s...
def insertion_sort(arr, l, h): """ Helper function to perform Insertion Sort on the subarray from indices l to h """ for i in range(l + 1, h + 1): key = arr[i] j = i - 1 while j >= l and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key de...
from solution import enhanced_stoogesort def test_small_threshold(): arr = [5, 2, 9, 1, 5, 6] enhanced_stoogesort(arr, 0, len(arr) - 1, 3) assert arr == [1, 2, 5, 5, 6, 9] def test_large_threshold(): arr = [3, 0, 2, 5, -1, 4, 1] enhanced_stoogesort(arr, 0, len(arr) - 1, 6) assert arr == [-1, 0...
[ { "docstring": "Helper function to perform Insertion Sort on the subarray from indices l to h", "function_declaration": "def insertion_sort(arr, l, h):", "function_name": "insertion_sort", "parameter_list": "(arr, l, h)" }, { "docstring": "Enhanced Stooge Sort algorithm with a threshold para...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insertion_sort(arr, l, h):\n \"\"\"\n Helper function to perform Insertion Sort on the subarray from indices l to h\n \"\"\"\n for i in range(...
trial_gpt4o_0
{ "original_instruction": "### Stooge Sort Enhancement Task\n\nYou are tasked with enhancing the Stooge Sort algorithm. Given the highly inefficient nature of Stooge Sort, you need to modify the original algorithm to improve its performance where possible.\n\n### Objective\nCreate a modified version of Stooge Sort th...
0.615848
Data_Structure_26380
C
[ "insertion_sort", "enhanced_stoogesort" ]
2
[ [ "enhanced_stoogesort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6644ff60916c753a07c845507c73f616fc10a4c3
4ad9dbd9417bca2a0c08986a341dbed235325695
v1.0
complete
Data_Structure
Data_Structure_26625_C
from typing import Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: """Extended Euclidean Algorithm to find the gcd of a and b.""" pass def modular_inverse(e: int, phi: int) -> int: """Find the modular inverse of e modulo phi using the extended Euclidean algorithm.""" pass def generate...
import random from typing import Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: if a == 0: return b, 0, 1 gcd, x1, y1 = extended_gcd(b % a, a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y def modular_inverse(e: int, phi: int) -> int: gcd, x, y = extended_gcd(e, phi) ...
from solution import generate_rsa_keys def test_rsa_key_generation(): public_key, private_key = generate_rsa_keys(61, 53) n, e = public_key n_, d = private_key assert n == n_ assert (e * d) % ((61 - 1) * (53 - 1)) == 1 def test_rsa_key_generation_different_primes(): public_key, private_ke...
[ { "docstring": null, "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def modular_inverse(e, phi):", "function_name": "modular_inverse", "parameter_list": "(e, phi)" }...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import Tuple\n\ndef extended_gcd(a: int, b: int) -> Tuple[int, int, int]:\n if a == 0:\n return b, 0, 1\n gcd, x1, y1 ...
trial_gpt4o_1
{ "original_instruction": "Implement an RSA Key Generation Function\n\n#### Context:\nYou are tasked with designing a simplified RSA public and private key generation script. RSA relies on the Extended Euclidean Algorithm for modular inverse calculations.\n\n#### Objective:\nWrite a Python function `generate_rsa_keys...
0.588919
Data_Structure_26625
C
[ "extended_gcd", "modular_inverse", "generate_rsa_keys" ]
3
[ [ "generate_rsa_keys", "extended_gcd" ], [ "generate_rsa_keys", "modular_inverse" ], [ "modular_inverse", "extended_gcd" ] ]
3
[]
false
[]
false
pytest
true
[]
true
760eb21018d5bc217573e6978d064c4bf7b1695e
e1233d1a6779421ca753d3ddae0f7d520214702d
v1.0
complete
Data_Structure
Data_Structure_26835_C
def int_to_base(num, base): """ Convert an integer to a string representation in a given base """ if num == 0: return "0" digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" sign = "" if num < 0: sign = "-" num = -num result = "" while num > 0: rema...
def int_to_base(num, base): """ Convert an integer to a string representation in a given base """ if num == 0: return "0" digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" sign = "" if num < 0: sign = "-" num = -num result = "" while num > 0: remainder = num %...
def test_convert_and_revert_positive(): assert convert_and_revert(15, 16) == 15 def test_convert_and_revert_negative(): assert convert_and_revert(-8, 2) == -8 def test_convert_and_revert_zero(): assert convert_and_revert(0, 10) == 0 def test_convert_and_revert_large_positive(): assert convert_and_rev...
[ { "docstring": "Convert an integer to a string representation in a given base ", "function_declaration": "def int_to_base(num, base):", "function_name": "int_to_base", "parameter_list": "(num, base)" }, { "docstring": "Convert a string representation of a number in a given base back to an in...
[ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def int_to_base(num, base):\n \"\"\"\n Converts an integer num to its base-n string representation.\n \"\"\"\n if num == 0:\n return \"0\"\...
trial_gpt4o_7
{ "original_instruction": "### Question\n\nYou are provided with two functions for converting integers between different bases:\n\n1. `int_to_base(num, base)`: Converts an integer `num` to a string representation of that number in the provided `base`.\n2. `base_to_int(str_to_convert, base)`: Converts a string represe...
0.784895
Data_Structure_26835
C
[ "int_to_base", "base_to_int", "convert_and_revert" ]
3
[ [ "convert_and_revert", "base_to_int" ], [ "convert_and_revert", "int_to_base" ] ]
2
[]
false
[]
false
pytest
false
[]
true
4ee111d592abffb75e180fa32ced7323c00ac080
6d5032fa2074ce9d58eaed8e6ba94aa2d69fa03d
v1.0
complete
Data_Structure
Data_Structure_27348_C
def modular_inverse(a: int, m: int) -> [bool, int]: """ Verify if two integers are co-prime, and if so, find their modular inverse. Args: a: An integer. m: An integer. Returns: [bool, int]: A list where the first element is a boolean indicating if `a` and `m` are coprime, and ...
def gcd(a, b): while b: a, b = b, a % b return a def modular_inverse(a, m): """ Returns whether a and m are coprime and the modular inverse of a under modulo m. If they are not coprime, returns -1 as the modular inverse. """ if gcd(a, m) != 1: return [False, -1] # U...
from solution import modular_inverse def test_modular_inverse_coprime(): result = modular_inverse(3, 11) assert result == [True, 4], f"Expected [True, 4] but got {result}" def test_modular_inverse_not_coprime(): result = modular_inverse(10, 20) assert result == [False, -1], f"Expected [False, -1] ...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns whether a and m are coprime and the modular inverse of a under modulo m.\nIf they are not coprime, returns -1 as the modular inverse.", "function_d...
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Helper function to compute the greatest common divisor (GCD) of a and b using the Euclidean algorithm.\n \"\"\"\n while ...
trial_gpt4o_9
{ "original_instruction": "You are tasked with implementing a function to verify two conditions for a given pair of integers:\n1. Whether these two integers are co-prime (i.e., their greatest common divisor is 1).\n2. If they are co-prime, find their modular inverse.\n\n### Function Specification\nImplement the funct...
0.601995
Data_Structure_27348
C
[ "gcd", "modular_inverse" ]
2
[ [ "modular_inverse", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a151f5ae825f95d22edd6257f7bac0006812d795
e90e7ac0c481ca828f7e26c21d1b1cfe84330f43
v1.0
complete
Data_Structure
Data_Structure_26703_C
import random def alice_private_key(p): """ Returns a random private key for Alice. """ def alice_public_key(a_pr_k, a, p): """ Computes and returns Alice's public key. """ def bob_private_key(p): """ Returns a random private key for Bob. """ def bob_public_key(b_pr_k, a, p): ...
import random def alice_private_key(p): """ Returns a random private key for Alice. """ return random.randint(1, p-1) def alice_public_key(a_pr_k, a, p): """ Computes and returns Alice's public key. """ return pow(a, a_pr_k, p) def bob_private_key(p): """ Returns a random priv...
from solution import ( alice_private_key, alice_public_key, bob_private_key, bob_public_key, alice_shared_key, bob_shared_key, diffie_hellman_key_exchange ) def test_diffie_hellman_key_exchange(): p = 23 # A small prime for simplicity a = 5 # A primitive root of 23 a_pr_k = alice_private_key(p)...
[ { "docstring": "Returns a random private key for Alice.", "function_declaration": "def alice_private_key(p):", "function_name": "alice_private_key", "parameter_list": "(p)" }, { "docstring": "Computes and returns Alice's public key.", "function_declaration": "def alice_public_key(a_pr_k,...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return...
trial_gpt4o_2
{ "original_instruction": "### Shared Secret Agreement Using Diffie-Hellman Key Exchange\n\nAlice and Bob want to securely share a secret key using the Diffie-Hellman key exchange method. The Diffie-Hellman algorithm involves the following steps:\n\n1. Choose a large prime number `p` and a primitive root `a` of `p`.\...
0.45133
Data_Structure_26703
C
[ "alice_private_key", "alice_public_key", "bob_private_key", "bob_public_key", "alice_shared_key", "bob_shared_key", "diffie_hellman_key_exchange" ]
7
[ [ "diffie_hellman_key_exchange", "alice_private_key" ], [ "diffie_hellman_key_exchange", "alice_public_key" ], [ "diffie_hellman_key_exchange", "alice_shared_key" ], [ "diffie_hellman_key_exchange", "bob_private_key" ], [ "diffie_hellman_key_exchange", "bob_pu...
6
[]
false
[]
false
pytest
true
[]
true
84393c769bc3ccab1e729f518e976a1b08f3ea2f
91ba2a5d3340a3dba92da605f513347e6a96e573
v1.0
complete
Data_Structure
Data_Structure_27001_C
def matrix_operations(matA: list, matB: list, matC: list, p: int) -> list: """ Computes the matrix ((matA * matB) * (matC^p)) Parameters: matA (list of list of int): First matrix to multiply. matB (list of list of int): Second matrix to multiply. matC (list of list of int): Matrix to raise ...
def matrix_multiply(mat1, mat2): """ Multiplies two matrices mat1 and mat2. """ n = len(mat1) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] += mat1[i][k] * mat2[k][j] return result def...
from solution import matrix_operations def test_matrix_operations_basic(): matA = [ [1, 2], [3, 4] ] matB = [ [5, 6], [7, 8] ] matC = [ [2, 0], [0, 2] ] p = 2 expected_result = [ [76, 88], [172, 200] ] assert matrix...
[ { "docstring": "Multiplies two matrices mat1 and mat2.", "function_declaration": "def matrix_multiply(mat1, mat2):", "function_name": "matrix_multiply", "parameter_list": "(mat1, mat2)" }, { "docstring": "Raises matrix mat to the power of `power`.\nUses exponentiation by squaring for efficie...
[ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(mat1, mat2):\n n = len(mat1)\n result = [[0] * n for _ in range(n)]\n for i in range(n):\n for j in range(n):\n ...
trial_gpt4o_8
{ "original_instruction": "### Question\n\nYou are given three matrices: `matA`, `matB`, and `matC`, each of size `n x n`. \nYou are required to implement a function `matrix_operations` that takes these matrices along with an integer `p` as inputs and returns the product of the following operations:\n\n1. Matrix mult...
0.54832
Data_Structure_27001
C
[ "matrix_multiply", "matrix_exponentiate", "matrix_operations" ]
3
[ [ "matrix_exponentiate", "matrix_multiply" ], [ "matrix_operations", "matrix_exponentiate" ], [ "matrix_operations", "matrix_multiply" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5ac25ce6fd8f79906ca0a3e5a3c98e5e058bc794
aa522def94b58bd38a5af15f14d59a76834f2328
v1.0
complete
Data_Structure
Data_Structure_27353_C
import random def is_sorted(arr: list) -> bool: """ Checks if a given array is sorted in non-decreasing order. >>> is_sorted([1, 2, 3]) True >>> is_sorted([1, 3, 2]) False """ ... def bogo_sort(arr: list) -> int: """ Performs Bogo Sort on the array and returns the number of iterations....
import random def is_sorted(arr): """ Checks if a given array is sorted in non-decreasing order. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr): """ Performs Bogo Sort on the array and returns the number of iteratio...
from solution import is_sorted, bogo_sort, find_maximum_bogo_sort_iterations def test_is_sorted(): assert is_sorted([1, 2, 3]) assert not is_sorted([1, 3, 2]) assert is_sorted([5]) assert is_sorted([]) def test_bogo_sort_sorted_array(): arr = [1, 2, 3] assert bogo_sort(arr) == 0 # Because it ...
[ { "docstring": "Checks if a given array is sorted in non-decreasing order.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Performs Bogo Sort on the array and returns the number of iterations.\nBogo Sort shuffles the...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_sorted(arr):\n \"\"\"\n Helper function to check if the array is sorted.\n \"\"\"\n return all(arr[i] <= arr[i+1] for i in...
trial_gpt4o_1
{ "original_instruction": "### Question Statement\nYou are given a sorting algorithm called Bogo Sort which sorts an array by repeatedly shuffling it until it is sorted. The algorithm is highly inefficient but serves as a theoretical model for understanding randomness in sorting.\n\n#### Task\nWrite a function `find_...
0.661527
Data_Structure_27353
C
[ "is_sorted", "bogo_sort", "find_maximum_bogo_sort_iterations" ]
3
[ [ "bogo_sort", "is_sorted" ], [ "find_maximum_bogo_sort_iterations", "bogo_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
277963c553394a3834b2991127b72b1a74d341e8
244bf2990e98e021758a1fee5d38238d89a03c62
v1.0
complete
Data_Structure
Data_Structure_27570_C
def fib_matrix_exp(n: int) -> int: """ Computes the nth Fibonacci number using the Matrix Exponentiation method, which can compute Fibonacci numbers in O(log n) time complexity. >>> fib_matrix_exp(0) 0 >>> fib_matrix_exp(1) 1 >>> fib_matrix_exp(10) 55 >>> fib_matrix_exp(100) 35422484817...
def matrix_mult(A, B): # Multiplies two 2x2 matrices A and B return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]]] def matrix_pow(matrix, n): # Exponentiates matrix using binary exp...
from solution import fib_matrix_exp def test_fib_matrix_exp_0(): assert fib_matrix_exp(0) == 0 def test_fib_matrix_exp_1(): assert fib_matrix_exp(1) == 1 def test_fib_matrix_exp_2(): assert fib_matrix_exp(2) == 1 def test_fib_matrix_exp_3(): assert fib_matrix_exp(3) == 2 def test_fib_matrix_exp_10(...
[ { "docstring": null, "function_declaration": "def matrix_mult(A, B):", "function_name": "matrix_mult", "parameter_list": "(A, B)" }, { "docstring": null, "function_declaration": "def matrix_pow(matrix, n):", "function_name": "matrix_pow", "parameter_list": "(matrix, n)" }, { ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_mult(A, B):\n # Multiplies two 2x2 matrices A and B\n return [[A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]],...
trial_gpt4o_0
{ "original_instruction": "### Fibonacci Sequence Algorithm Implementation\n\n#### Objective\nYou are provided with code snippets that compute the nth Fibonacci number using different algorithmic approaches: Recursive, Dynamic Programming, and Iterative. Your task is to write a Python function that computes the nth F...
0.777243
Data_Structure_27570
C
[ "matrix_mult", "matrix_pow", "fib_matrix_exp" ]
3
[ [ "fib_matrix_exp", "matrix_pow" ], [ "matrix_pow", "matrix_mult" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bec4a043c66726953c0e01d46031cd1ccc4eca68
46cf7ace60182e6fa30f07c8ed05596aff2cf13e
v1.0
complete
Data_Structure
Data_Structure_27314_C
def find_all_cliques(edges: dict) -> list: """ Implement a function `find_all_cliques(edges)` that takes an undirected graph represented as an adjacency list and returns all maximal cliques in it. Args: edges (dict): Keys are vertex identifiers (strings or integers), and values are sets of adjacen...
from itertools import combinations def is_clique(edges, vertices): for v1, v2 in combinations(vertices, 2): if v2 not in edges[v1]: return False return True def find_all_cliques(edges: dict) -> list: vertices = list(edges.keys()) n = len(vertices) max_cliques = [] # Check ...
from solution import find_all_cliques def test_simple_case(): edges = { '1': {'2', '5'}, '2': {'1', '3'}, '3': {'2', '4'}, '4': {'3', '5'}, '5': {'1', '4'} } result = find_all_cliques(edges) expected = [['1', '2'], ['2', '3'], ['3', '4'], ['4', '5'], ['1', '5']] ...
[ { "docstring": null, "function_declaration": "def is_clique(edges, vertices):", "function_name": "is_clique", "parameter_list": "(edges, vertices)" }, { "docstring": null, "function_declaration": "def find_all_cliques(edges):", "function_name": "find_all_cliques", "parameter_list...
[ 0, 0, 0, 0, 1, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_all_cliques(edges):\n \"\"\"\n Find all maximal cliques in an undirected graph represented as an adjacency list.\n \"\"\"\n # Helper func...
trial_gpt4o_7
{ "original_instruction": "**Context**:\nYou have been hired by a social networking company to analyze clusters of users who are all friends with each other. This analysis will help in determining closely-knit groups within the network, which can be useful for suggestions, targeted ads, and group activities.\n\n**Tas...
0.434461
Data_Structure_27314
C
[ "is_clique", "find_all_cliques" ]
2
[ [ "find_all_cliques", "is_clique" ] ]
1
[]
false
[]
false
pytest
true
[]
true
129919a81e476c342629aa27c0e6bbf0704fc939
4a80c4c14deaaed1cd2154ab78343cb5597245f1
v1.0
complete
Data_Structure
Data_Structure_27489_C
from typing import List def compute_prefix_function(pattern: str) -> List[int]: """ Computes the prefix function for the Knuth-Morris-Pratt algorithm. """ def detect_pattern_occurrences(text: str, pattern: str) -> List[int]: """ Uses the KMP algorithm to find and return the starting indices of all...
from typing import List def compute_prefix_function(pattern: str) -> List[int]: """ Computes the prefix function for the Knuth-Morris-Pratt algorithm. """ m = len(pattern) pi = [0] * m k = 0 for q in range(1, m): while k > 0 and pattern[k] != pattern[q]: k = pi[k - ...
from solution import detect_pattern_occurrences def test_detect_pattern_occurrences_basic(): assert detect_pattern_occurrences('hello there hero!', 'he') == [0, 7, 12] def test_empty_text(): assert detect_pattern_occurrences('', 'he') == [] def test_empty_pattern(): assert detect_pattern_occurrences('hel...
[ { "docstring": "Computes the prefix function for the Knuth-Morris-Pratt algorithm.", "function_declaration": "def compute_prefix_function(pattern):", "function_name": "compute_prefix_function", "parameter_list": "(pattern)" }, { "docstring": "Uses the KMP algorithm to find and return the sta...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef build_lps(pattern: str) -> List[int]:\n \"\"\"\n Builds the longest prefix suffix (LPS) array used in KMP algorithm.\n ...
trial_gpt4o_2
{ "original_instruction": "### Advanced String Matching\n\nAs a software developer, you are tasked with creating a function that leverages an advanced string matching algorithm to search for a pattern in a large body of text. The requirement is to implement the Knuth-Morris-Pratt (KMP) string matching algorithm.\n\n#...
0.61739
Data_Structure_27489
C
[ "compute_prefix_function", "detect_pattern_occurrences" ]
2
[ [ "detect_pattern_occurrences", "compute_prefix_function" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c56427a64d9b17d6106264ac50160760796b6755
581079deae60e0ffb9b90fe4cafd5eb68842a7cb
v1.0
complete
Data_Structure
Data_Structure_27133_C
def optimized_insertion_sort(arr: list) -> list: """ Sorts an array of integers using an optimized insertion sort, which leverages binary search for efficient insertion point discovery. >>> optimized_insertion_sort([8, 3, 5, 4, 2, 7]) [2, 3, 4, 5, 7, 8] >>> optimized_insertion_sort([1, 2, 3, 4, 5...
def binary_search(arr, val, start, end): """ Perform binary search to find the index at which val should be inserted in the subarray arr[start:end]. Return the appropriate index. """ while start < end: mid = (start + end) // 2 if arr[mid] < val: start = mid + 1 el...
from solution import optimized_insertion_sort def test_optimized_insertion_sort_unsorted_array(): assert optimized_insertion_sort([8, 3, 5, 4, 2, 7]) == [2, 3, 4, 5, 7, 8] def test_optimized_insertion_sort_sorted_array(): assert optimized_insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_optimized_...
[ { "docstring": "Perform binary search to find the index at which val should be inserted\nin the subarray arr[start:end]. Return the appropriate index.", "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_insertion_sort(arr):\n \"\"\"\n Enhanced insertion sort algorithm with binary search to find \n the correct insertion position.\n \"...
trial_gpt4o_1
{ "original_instruction": "Optimized Very Large Array Sort\n\n**Scenario**:\nYou have been appointed as a software engineer at a logistics company. Your task is to write a function that sorts arrays of shipment weights. Some arrays might be very large or almost sorted. To accommodate this, you will enhance an existin...
0.627387
Data_Structure_27133
C
[ "binary_search", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f4a31f893d6d9e77ddd36f8db1a86a7a535f70c1
0a2489e82837b195e72e594e3daa54c3ced2a98b
v1.0
complete
Data_Structure
Data_Structure_27525_C
def prime_check(n): """Return True if n is a prime number Else return False. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: retur...
def prime_check(n): """Return True if n is a prime number Else return False. """ if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: retur...
from solution import find_prime_neighbors def test_find_prime_neighbors(): assert find_prime_neighbors(10) == (7, 11) assert find_prime_neighbors(6) == (5, 7) assert find_prime_neighbors(2) == (-1, 3) assert find_prime_neighbors(1) == (-1, 2) assert find_prime_neighbors(3) == (2, 5) assert find...
[ { "docstring": "Return True if n is a prime number\nElse return False.", "function_declaration": "def prime_check(n):", "function_name": "prime_check", "parameter_list": "(n)" }, { "docstring": "Finds the closest prime numbers smaller and larger than a given positive integer n.", "functi...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_check(n):\n \"\"\"Return True if n is a prime number\n Else return False.\n \"\"\"\n if n <= 1:\n return False\n if n == 2 or ...
trial_gpt4o_0
{ "original_instruction": "### Prime Numbers and their Neighbors\n\nYou are tasked to implement a function `find_prime_neighbors(n)`, which finds the closest prime numbers that are smaller and larger than a given positive integer `n`.\n\n#### Detailed Description & Requirements:\n1. **Input**: An integer `n` (1 ≤ n ≤...
0.715605
Data_Structure_27525
C
[ "prime_check", "find_prime_neighbors" ]
2
[ [ "find_prime_neighbors", "prime_check" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0fdeb863bf4cf9521fa05a8b4e12ba2a1d7fcfd1
8d94d9c4c4abb6aca3d59b7efe3d8a4640b73e0c
v1.0
complete
Data_Structure
Data_Structure_27759_C
def is_strongly_connected(vertex_count: int, edges: List[Tuple[int, int]]) -> bool: """ Checks if the entire graph is one strongly connected component. >>> is_strongly_connected(4, [(0, 1), (1, 2), (2, 0), (1, 3), (3, 1)]) True >>> is_strongly_connected(4, [(0, 1), (1, 2), (2, 0), (1, 3)]) Fals...
from typing import List, Tuple def dfs(graph: List[List[int]], start: int, visited: List[bool]): stack = [start] while stack: node = stack.pop() for neighbor in graph[node]: if not visited[neighbor]: visited[neighbor] = True stack.append(neighbor) de...
from solution import is_strongly_connected def test_strongly_connected(): # Fully connected simple graph assert is_strongly_connected(3, [(0, 1), (1, 2), (2, 0)]) == True def test_not_strongly_connected(): # Not strongly connected graph with one disconnected node assert is_strongly_connected(4, [(0, 1...
[ { "docstring": null, "function_declaration": "def dfs(graph, start, visited):", "function_name": "dfs", "parameter_list": "(graph, start, visited)" }, { "docstring": null, "function_declaration": "def is_strongly_connected(vertex_count, edges):", "function_name": "is_strongly_connect...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\nfrom collections import defaultdict, deque\n\ndef is_strongly_connected(vertex_count: int, edges: List[Tuple[int, int]]) -> bo...
trial_gpt4o_2
{ "original_instruction": "### Question:\n\n**Strongly Connected Graph Detection**\n\nIn graph theory, a *strongly connected component* (SCC) of a directed graph is a maximal strongly connected subgraph. A directed graph is said to be strongly connected if there is a path in each direction between each pair of vertic...
0.431109
Data_Structure_27759
C
[ "dfs", "is_strongly_connected" ]
2
[ [ "is_strongly_connected", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
69a361f82e2d8ebc9d17e58ae681ab4160fa52c8
0474ab3335ad9a5badd311c1eec4a317a7d7d356
v1.0
complete
Data_Structure
Data_Structure_27311_C
def dfs_traverse(graph, start): """ Returns a set of nodes reachable from the start node using DFS. >>> graph = { >>> 'A': ['B', 'C'], >>> 'B': ['A', 'D', 'E'], >>> 'C': ['A', 'F'], >>> 'D': ['B'], >>> 'E': ['B', 'F'], >>> 'F': ['C', 'E'] >>> } >>> dfs_tra...
def dfs_traverse(graph, start): """ Returns a set of nodes reachable from the start node using DFS. """ visited = set() def dfs(node): if node not in visited: visited.add(node) for neighbor in graph.get(node, []): dfs(neighbor) dfs(start) ...
from solution import dfs_traverse, bfs_traverse, is_connected def test_dfs_traverse(): graph = { 'A': ['B', 'C'], 'B': ['A', 'D', 'E'], 'C': ['A', 'F'], 'D': ['B'], 'E': ['B', 'F'], 'F': ['C', 'E'] } assert dfs_traverse(graph, 'A') == {'A', 'B', 'C', 'D', 'E'...
[ { "docstring": "Returns a set of nodes reachable from the start node using DFS.", "function_declaration": "def dfs_traverse(graph, start):", "function_name": "dfs_traverse", "parameter_list": "(graph, start)" }, { "docstring": "Returns a set of nodes reachable from the start node using BFS."...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs_traverse(graph, start):\n \"\"\"\n Returns a set of nodes reachable from the start node using DFS.\n \"\"\"\n visited = set()\n stack =...
trial_gpt4o_1
{ "original_instruction": "### Question\n\n#### Context:\nYou are tasked with analyzing the connectivity of a social network, represented as a graph where nodes are users and edges are friendships between users. You need to determine which users are reachable from a particular user, and also check if it's possible to...
0.530395
Data_Structure_27311
C
[ "dfs_traverse", "bfs_traverse", "is_connected" ]
3
[ [ "is_connected", "bfs_traverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b7c9c15abb7aea05c193c9eb9ba51ee2c99062ea
79aa7601f223ad6cfdcd1b2a1f670c86a95713eb
v1.0
complete
Data_Structure
Data_Structure_27590_C
def diffie_hellman_key_exchange(a, p, option=None): """ Implement the Diffie-Hellman Key Exchange algorithm. - a: supposed primitive root - p: large prime number - option: for debugging purposes. If set, extra output is printed. Returns: Boolean indicating success or failure of key exchange. ...
def is_prime(num): if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i ** 2 <= num: if num % i == 0 or num % (i + 2) == 0: return False i += 6 return True def find_primitive_root(p): ...
import pytest from solution import is_prime, find_primitive_root, diffie_hellman_key_exchange def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(13) == True assert is_prime(25) == False def test_find...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_primitive_root(p):", "function_name": "find_primitive_root", "parameter_list": "(p)" }, { "d...
[ 0, 0, 0, 1, 1, 0, 0, 0, 0 ]
2
hard
0.222
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_results_combined.jsonl", "solution_code": "import random\n\ndef prime_check(num):\n if num < 2:\n return False\n for i in range(2, int(num**0.5) + 1):\n if ...
trial_gpt4o_5
{ "original_instruction": "### Diffie-Hellman Key Exchange Implementation\n\n#### Objective\nImplement the `diffie_hellman_key_exchange` function using Diffie-Hellman algorithm principles. Your task also includes creating a prime-checking function and finding a primitive root related to the given prime.\n\n#### Detai...
0.566969
Data_Structure_27590
C
[ "is_prime", "find_primitive_root", "diffie_hellman_key_exchange" ]
3
[ [ "diffie_hellman_key_exchange", "find_primitive_root" ], [ "diffie_hellman_key_exchange", "is_prime" ], [ "find_primitive_root", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8c97858158065450f8f8063ceb631b9e647b35ae
1db933d814173a3573751fc917c72579e911cbb5
v1.0
complete
Data_Structure
Data_Structure_27228_C
from typing import List def optimized_shell_sort(arr: List[int]) -> List[int]: """ Sort a list of integers in ascending order using Shell Sort with the Sedgewick gap sequence. Parameters: arr (List[int]): A list of integers to be sorted. Returns: List[int]: The sorted list of integer...
from typing import List def optimized_shell_sort(arr: List[int]) -> List[int]: n = len(arr) gaps = _sedgewick_sequence(n) for gap in gaps: for i in range(gap, n): temp = arr[i] j = i while j >= gap and arr[j - gap] > temp: arr[j] = arr[j - ga...
from solution import optimized_shell_sort def test_optimized_shell_sort_standard_case(): assert optimized_shell_sort([12, 34, 54, 2, 3]) == [2, 3, 12, 34, 54] def test_optimized_shell_sort_with_repeated_elements(): assert optimized_shell_sort([6, 2, 5, 9, 0, 2]) == [0, 2, 2, 5, 6, 9] assert optimized_shel...
[ { "docstring": null, "function_declaration": "def optimized_shell_sort(arr):", "function_name": "optimized_shell_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def _sedgewick_sequence(n):", "function_name": "_sedgewick_sequence", "parameter_list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_shell_sort(arr):\n \"\"\"\n Function to sort the array using optimized Shell Sort with Sedgewick gap sequence.\n \"\"\"\n # Sedgewic...
trial_gpt4o_2
{ "original_instruction": "### Question: Shell Sort Implementation and Optimization\n\nYou are tasked with writing a function that implements Shell Sort with an optimized gap sequence. The goal is to sort an array of integers effectively and handle edge cases properly.\n\n**Prompt**:\nImplement the function `optimize...
0.65736
Data_Structure_27228
C
[ "optimized_shell_sort", "_sedgewick_sequence" ]
2
[ [ "optimized_shell_sort", "_sedgewick_sequence" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d159a67a8b2f034fd6ba68ea84dd42e63cc3be66
e26afd572de37889fcb5cdd78135d0622130f895
v1.0
complete
Data_Structure
Data_Structure_28003_C
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Merge Sort implementation that sorts an array in non-decreasing order. >>> merge_sort([34, 7, 23, 32, 5, 62]) [5, 7, 23, 32, 34, 62] >>> merge_sort([2, 3, 5, 5, 7, 7, 19]) [2, 3, 5, 5, 7, 7, 19] >>> merge_sort([1]) [1]...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Merge Sort implementation that sorts an array in non-decreasing order. """ # Base case: a list of zero or one elements is already sorted if len(arr) <= 1: return arr # Recursive case: split the list into two subli...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_multiple_elements(): assert merge_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62] assert merge_sort([2, 3, 5, 5, 7, 7...
[ { "docstring": "Merge Sort implementation that sorts an array in non-decreasing order.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n \n # Find the middle point\n mid...
trial_gpt4o_2
{ "original_instruction": "### Merge Sort Implementation\n\nGiven an array of integers, implement the Merge Sort algorithm to sort the array in non-decreasing order.\n\n#### Function Signature\n```python\ndef merge_sort(arr: List[int]) -> List[int]:\n```\n\n#### Input\n\n- `arr`: A list of integers (1 <= len(arr) <= ...
0.63298
Data_Structure_28003
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2fdfdecc114daebf8323300ac623d4c942568f82
dbb9c5a8acc4166def54958611e58888b5d22497
v1.0
complete
Data_Structure
Data_Structure_27534_C
import math def generalized_cosine_similarity(vectors: list[list[float]]) -> list[list[float]]: """ Calculate the pairwise cosine similarity for multiple vectors. Each vector must have the same length; otherwise, raise a ValueError. :param vectors: List of n vectors, each consisting of m elements :ret...
import math def dot_product(v1, v2): return sum(x * y for x, y in zip(v1, v2)) def magnitude(v): return math.sqrt(sum(x ** 2 for x in v)) def cosine_similarity(v1, v2): return dot_product(v1, v2) / (magnitude(v1) * magnitude(v2)) def generalized_cosine_similarity(vectors): if not vectors or not vect...
from solution import generalized_cosine_similarity def test_generalized_cosine_similarity_with_simple_vectors(): vectors = [ [1, 1, 1], [1, 2, -1] ] expected = [ [1.0, 0.47140452079103173], [0.47140452079103173, 1.0] ] result = generalized_cosine_similarity(vectors...
[ { "docstring": null, "function_declaration": "def dot_product(v1, v2):", "function_name": "dot_product", "parameter_list": "(v1, v2)" }, { "docstring": null, "function_declaration": "def magnitude(v):", "function_name": "magnitude", "parameter_list": "(v)" }, { "docstring...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\nfrom typing import List\n\ndef generalized_cosine_similarity(vectors: List[List[float]]) -> List[List[float]]:\n n = len(vectors)\n m = len...
trial_gpt4o_1
{ "original_instruction": "### Coding Challenge\n\n**Context**: In many applications, such as search engines, recommendation systems, and data clustering, measuring the similarity between vectors is crucial. Cosine similarity is an effective method to ascertain the degree of similarity between two vectors.\n\n**Probl...
0.572129
Data_Structure_27534
C
[ "dot_product", "magnitude", "cosine_similarity", "generalized_cosine_similarity" ]
4
[ [ "cosine_similarity", "dot_product" ], [ "cosine_similarity", "magnitude" ], [ "generalized_cosine_similarity", "cosine_similarity" ] ]
3
[]
false
[]
false
pytest
true
[]
true
01b262d0bc89dc683ddbbac91df012b0431c7e8c
b87f91050ce7292752f4a94ce2ccb4a2ffbfcfda
v1.0
complete
Data_Structure
Data_Structure_27663_C
def improved_random_sort(arr): """ Sorts an array using an improved randomized sorting algorithm. >>> improved_random_sort([]) == [] True >>> improved_random_sort([1]) == [1] True >>> improved_random_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] True >>> improved_random_sort([5, 4, 3, 2, ...
import random def partition(arr, low, high): pivot = arr[high] i = low - 1 for j in range(low, high): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i + 1], arr[high] = arr[high], arr[i + 1] return i + 1 def randomized_partition(arr, low, high): ...
from solution import improved_random_sort def test_empty_list(): assert improved_random_sort([]) == [] def test_single_element(): assert improved_random_sort([1]) == [1] def test_sorted_list(): assert improved_random_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_list(): assert imp...
[ { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def randomized_partition(arr, low, high):", "function_name": "randomized_partition", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef partition(arr: List[int], low: int, high: int) -> int:\n pivot = arr[high]\n i = low - 1\n for j in ran...
trial_gpt4o_2
{ "original_instruction": "Implement an Optimized Random Sorting Algorithm\n\n#### Context\nBogo Sort is a humorous yet impractical sorting algorithm that works by randomly shuffling an array until it is sorted. You are tasked with creating a more practical version of a similarly random-based sorting algorithm, calle...
0.651723
Data_Structure_27663
C
[ "partition", "randomized_partition", "randomized_quick_sort", "improved_random_sort" ]
4
[ [ "improved_random_sort", "randomized_quick_sort" ], [ "randomized_partition", "partition" ], [ "randomized_quick_sort", "randomized_partition" ] ]
3
[]
false
[]
false
pytest
true
[]
true
623864f3020713f0be71e005c45797942c59bee0
2269cb50221baad847f7d8e5d959b91f794690da
v1.0
complete
Data_Structure
Data_Structure_27789_C
def add_bitwise(a, b): """ Function to add two integers using only bitwise operations. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def multiply_bitwise(a: int, b: int) -> int: """ Multiplies two positive integers using bitwise operations and add...
def add_bitwise(a, b): """ Function to add two integers using only bitwise operations. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def multiply_bitwise(a: int, b: int) -> int: """ Multiplies two positive integers using bitwise operations and add...
from solution import multiply_bitwise def test_multiply_bitwise_positive_numbers(): assert multiply_bitwise(3, 5) == 15 assert multiply_bitwise(6, 7) == 42 assert multiply_bitwise(10, 10) == 100 assert multiply_bitwise(2, 8) == 16 assert multiply_bitwise(1234, 5678) == 7006652 def test_multiply_bi...
[ { "docstring": "Function to add two integers using only bitwise operations.", "function_declaration": "def add_bitwise(a, b):", "function_name": "add_bitwise", "parameter_list": "(a, b)" }, { "docstring": "Multiplies two positive integers using bitwise operations and addition.", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add(a, b):\n \"\"\"\n Returns the sum of a and b using bitwise operations.\n \"\"\"\n while b != 0:\n carry = a & b\n a = a ^ b\...
trial_gpt4o_2
{ "original_instruction": "### Question\nYou are required to implement a function that multiplies two positive integers using only bitwise operations and addition (which we've covered already) and returns the product. This exercise will assess your understanding of bitwise manipulation and fundamental arithmetic oper...
0.661927
Data_Structure_27789
C
[ "add_bitwise", "multiply_bitwise" ]
2
[ [ "multiply_bitwise", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
784b6dde1a11a979867f202b1c892a3fca6544a5
2b1dde87bfdabc294546630f6279049dd66da0af
v1.0
complete
Data_Structure
Data_Structure_27682_C
def normalize_string(s): """Normalize the string by removing non-alphanumeric characters and converting to lowercase.""" pass def check_palindrome_two_pointer(s): """ Check if string is palindrome using the two-pointer method. """ pass def check_palindrome_reverse(s): """ Check if string is palind...
import re from collections import deque def normalize_string(s): return re.sub(r'[^a-zA-Z0-9]', '', s).lower() def check_palindrome_two_pointer(s): normalized = normalize_string(s) left, right = 0, len(normalized) - 1 while left < right: if normalized[left] != normalized[right]: re...
from solution import check_palindrome def test_two_pointer_method(): assert check_palindrome("A man, a plan, a canal: Panama", "two_pointer") == True assert check_palindrome("race a car", "two_pointer") == False assert check_palindrome("", "two_pointer") == True assert check_palindrome(" ", "two_pointe...
[ { "docstring": null, "function_declaration": "def normalize_string(s):", "function_name": "normalize_string", "parameter_list": "(s)" }, { "docstring": null, "function_declaration": "def check_palindrome_two_pointer(s):", "function_name": "check_palindrome_two_pointer", "paramete...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import collections\n\ndef normalize_string(s: str) -> str:\n \"\"\"\n Removes non-alphanumeric characters from a string and converts to lowercase.\n ...
trial_gpt4o_1
{ "original_instruction": "### Question: Advanced Palindrome Checker\n\nImplement a Python function that checks if a given string is a palindrome, considering only alphanumeric characters and ignoring case. Additionally, the function should address the following requirements:\n\n1. Handle mixed case and punctuation b...
0.788413
Data_Structure_27682
C
[ "normalize_string", "check_palindrome_two_pointer", "check_palindrome_reverse", "check_palindrome_stack", "check_palindrome_deque", "check_palindrome" ]
6
[ [ "check_palindrome", "check_palindrome_deque" ], [ "check_palindrome", "check_palindrome_reverse" ], [ "check_palindrome", "check_palindrome_stack" ], [ "check_palindrome", "check_palindrome_two_pointer" ], [ "check_palindrome_deque", "normalize_string" ], ...
8
[]
false
[]
false
pytest
true
[]
true
79d3e27ce157e204b0a15838966eac6d40c8f18e
33bfc4e6950641f0dc0db711d97c28bc2bd5c527
v1.0
complete
Data_Structure
Data_Structure_27364_C
def bron_kerbosch(R, P, X, edges, cliques): """ Bron-Kerbosch recursive algorithm to find all maximal cliques. """ # Implement the Bron-Kerbosch algorithm here def filter_cliques(edges, threshold): """ Given an undirected graph represented by 'edges' and an integer 'threshold', find all max...
def bron_kerbosch(R, P, X, edges, cliques): """ Bron-Kerbosch recursive algorithm to find all maximal cliques. """ if not P and not X: cliques.append(R) return for v in list(P): bron_kerbosch(R | {v}, P & edges[v], X & edges[v], edges, cliques) P.remove(v) X.a...
from solution import filter_cliques def test_filter_cliques(): edges = { "1": {"2", "3"}, "2": {"1", "3", "4"}, "3": {"1", "2", "4"}, "4": {"2", "3"} } threshold = 2 expected = [["1", "2", "3"], ["2", "3", "4"]] result = filter_cliques(edges, threshold) assert le...
[ { "docstring": "Bron-Kerbosch recursive algorithm to find all maximal cliques.", "function_declaration": "def bron_kerbosch(R, P, X, edges, cliques):", "function_name": "bron_kerbosch", "parameter_list": "(R, P, X, edges, cliques)" }, { "docstring": "Given an undirected graph represented by ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bron_kerbosch(r, p, x, graph, cliques):\n if not p and not x:\n cliques.append(r)\n return\n for v in list(p):\n bron_kerbosch(...
trial_gpt4o_7
{ "original_instruction": "**Problem**: Maximum Clique Identification with Filtering\n\nYou are given an undirected graph represented as an adjacency list. Your task is to identify all maximal cliques in the graph using the Bron-Kerbosch algorithm and further filter these cliques to only return those cliques whose si...
0.471092
Data_Structure_27364
C
[ "bron_kerbosch", "filter_cliques" ]
2
[ [ "filter_cliques", "bron_kerbosch" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3c043d3fae568b3a3b38b9f835b5c2d408396a0e
55203b34a9e41c9c7d71100562b3076ad8144037
v1.0
complete
Data_Structure
Data_Structure_27778_C
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts the given array in ascending order using the Merge Sort algorithm. """ pass def merge(left: List[int], right: List[int]) -> List[int]: pass # Tests def test_empty_array(): assert merge_sort([]) == [] def test_sing...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr # Split the array into two halves mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) # Merge the two halves return merge(left_half, right_hal...
from solution import merge_sort def test_empty_array(): assert merge_sort([]) == [] def test_single_element_array(): assert merge_sort([1]) == [1] assert merge_sort([-1]) == [-1] def test_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert merge_sort([-5, -4, -3, -2, -1])...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts the given array in ascending order using the Merge Sort algorit...
trial_gpt4o_2
{ "original_instruction": "You are provided an array of integers. Your task is to implement the Merge Sort algorithm to sort the array in ascending order. Your implementation must adhere to the following requirements and constraints:\n\n#### Input\n* An array `arr` with `n` integers, where `0 <= n <= 10^5` and `-10^9...
0.647176
Data_Structure_27778
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
066ea987bcefa9f67ca7d2f029bc310f2d3d37a5
7ea9e63fb50b94d622ed68101023859f4bdf79a0
v1.0
complete
Data_Structure
Data_Structure_28087_C
def invert_matrix(matrix): """ Compute the inverse of a given n x n matrix. If the matrix is not invertible, return an appropriate error message. >>> invert_matrix([ ... [4, 7], ... [2, 6] ... ]) [[0.6, -0.7], [-0.2, 0.4]] >>> invert_matrix(123) [[-1]] >>> invert_matrix(...
def get_matrix_minor(matrix, row, col): return [r[:col] + r[col+1:] for r in (matrix[:row] + matrix[row+1:])] def get_matrix_determinant(matrix): if len(matrix) == 2: return matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0] determinant = 0 for c in range(len(matrix)): determinant +...
from solution import invert_matrix def test_valid_2x2_matrix(): matrix = [ [4, 7], [2, 6] ] expected = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) assert result == expected def test_not_a_matrix(): result = invert_matrix(123) assert resu...
[ { "docstring": null, "function_declaration": "def get_matrix_minor(matrix, row, col):", "function_name": "get_matrix_minor", "parameter_list": "(matrix, row, col)" }, { "docstring": null, "function_declaration": "def get_matrix_determinant(matrix):", "function_name": "get_matrix_dete...
[ 0, 0, 0, 0, 1, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def invert_matrix(matrix):\n def determinant(m):\n # Base cases for 2x2 matrix\n if len(m) == 2:\n return m[0][0] * m[1][1] - m[0]...
trial_gpt4o_7
{ "original_instruction": "**Matrix Inversion Challenge**\n\nYou are tasked with implementing an algorithm to compute the inverse of a given n x n matrix. This problem will assess your understanding of matrix operations, recursive determinant calculation, and optimization of matrix traversals.\n\n### Problem Statemen...
0.607694
Data_Structure_28087
C
[ "get_matrix_minor", "get_matrix_determinant", "get_matrix_inverse", "invert_matrix" ]
4
[ [ "get_matrix_determinant", "get_matrix_minor" ], [ "get_matrix_inverse", "get_matrix_determinant" ], [ "get_matrix_inverse", "get_matrix_minor" ], [ "invert_matrix", "get_matrix_inverse" ] ]
4
[]
false
[]
false
pytest
true
[]
true
d6fbb8b623df1f5b2e3acec7043d42e52286e5b8
a724ecf5fe0453d57d762c531266b44cc0c92a31
v1.0
complete
Data_Structure
Data_Structure_27899_C
def gcd_and_lcm(a: int, b: int) -> (int, int): """ Computes the Greatest Common Divisor and Least Common Multiple of integers a and b. Arguments: a -- First non-negative integer b -- Second non-negative integer Returns: (gcd, lcm) -- Tuple containing the GCD and LCM of a and b. >>> gc...
def gcd(a, b): """ Returns the Greatest Common Divisor (GCD) of integers a and b using the Euclidean Algorithm. """ while b: a, b = b, a % b return a def gcd_and_lcm(a: int, b: int) -> (int, int): """ Computes the Greatest Common Divisor and Least Common Multiple of integers a and b...
from solution import gcd_and_lcm def test_gcd_and_lcm_both_non_zero(): assert gcd_and_lcm(15, 25) == (5, 75) assert gcd_and_lcm(18, 24) == (6, 72) assert gcd_and_lcm(21, 14) == (7, 42) def test_gcd_and_lcm_one_zero(): assert gcd_and_lcm(0, 10) == (10, 0) assert gcd_and_lcm(20, 0) == (20, 0) ...
[ { "docstring": "Returns the Greatest Common Divisor (GCD) of integers a and b using the Euclidean Algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Computes the Greatest Common Divisor and Least Common Multiple of int...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_and_lcm(a: int, b: int) -> (int, int):\n \"\"\"\n Computes the Greatest Common Divisor and Least Common Multiple of integers a and b.\n\n Arg...
trial_gpt4o_2
{ "original_instruction": "You are tasked with developing a function that takes two non-negative integers and returns both their Greatest Common Divisor (GCD) and Least Common Multiple (LCM). The solution will test your understanding of the Euclidean algorithm, binary operations, and handling of edge cases in integer...
0.848484
Data_Structure_27899
C
[ "gcd", "gcd_and_lcm" ]
2
[ [ "gcd_and_lcm", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f12a8be8403c493fbcdca41e63539e67c45871d2
edd47bb9bb49a4c6d0f4566d52cb9faf4e2e4aca
v1.0
complete
Data_Structure
Data_Structure_27950_C
def get_primes(n: int) -> list: """ Return a list of all prime numbers less than n """ pass def count_primes(n: int) -> int: """ Returns the count of prime numbers less than n >>> count_primes(10) 4 >>> count_primes(2) 0 >>> count_primes(50) 15 """ pass def sum_primes(n: i...
def get_primes(n): """ Return a list of all prime numbers less than n """ if n <= 2: return [] sieve = [True] * n sieve[0] = sieve[1] = False for start in range(2, int(n**0.5) + 1): if sieve[start]: for i in range(start*start, n, start): sieve[i]...
from solution import count_primes, sum_primes def test_count_primes(): assert count_primes(10) == 4 # primes: [2, 3, 5, 7] assert count_primes(20) == 8 # primes: [2, 3, 5, 7, 11, 13, 17, 19] assert count_primes(2) == 0 # primes: [] assert count_primes(50) == 15 # primes: [2, 3, 5, 7, 11, 13, 17, 19...
[ { "docstring": "Return a list of all prime numbers less than n", "function_declaration": "def get_primes(n):", "function_name": "get_primes", "parameter_list": "(n)" }, { "docstring": "Returns the count of prime numbers less than n", "function_declaration": "def count_primes(n):", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def get_primes(n):\n \"\"\"\n Returns a list of prime numbers less than n using the Sieve of Eratosthenes algorithm.\n \"\"\"\n is_prime = [True] ...
trial_gpt4o_2
{ "original_instruction": "You are provided with a function for generating prime numbers less than a given integer \\( n \\) using a modified version of the Sieve of Eratosthenes algorithm. Your task is to extend this functionality in the following ways:\n\n1. **Prime Count**: Write a function `count_primes(n)` which...
0.759548
Data_Structure_27950
C
[ "get_primes", "count_primes", "sum_primes" ]
3
[ [ "count_primes", "get_primes" ], [ "sum_primes", "get_primes" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f534029b3f202b52d0a4a501cbcf6ea9a48ac6aa
64422b3342e80c1195071543124ac318d69fbe25
v1.0
complete
Data_Structure
Data_Structure_28070_C
def efficient_lcm(a: int, b: int) -> int: """ Compute the Least Common Multiple (LCM) of two non-negative integers using the Greatest Common Divisor (GCD) algorithm with bitwise operations for efficiency. >>> efficient_lcm(12, 18) 36 >>> efficient_lcm(0, 5) 0 >>> efficient_lcm(21, 6) 42...
def gcd(a: int, b: int) -> int: while b != 0: a, b = b, a % b return a def efficient_lcm(a: int, b: int) -> int: if a == 0 or b == 0: return 0 return (a * b) // gcd(a, b)
from solution import efficient_lcm, gcd def test_gcd(): assert gcd(12, 18) == 6 assert gcd(7, 5) == 1 assert gcd(0, 5) == 5 assert gcd(10, 0) == 10 assert gcd(48, 18) == 6 assert gcd(20, 5) == 5 def test_efficient_lcm(): assert efficient_lcm(12, 18) == 36 assert efficient_lcm(0, 5) == ...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def efficient_lcm(a, b):", "function_name": "efficient_lcm", "parameter_list": "(a, b)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def efficient_lcm(a: int, b: int) -> int:\n def gcd(x, y):\n while y:\n x, y = y, x % y\n return x\n\n if a == 0 or b == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "You are tasked with implementing a function that computes the **Least Common Multiple (LCM)** of two non-negative integers using the **Greatest Common Divisor (GCD)** algorithm, but with bitwise operations for efficiency. \n\nWrite a function `efficient_lcm(a, b)` that takes two non-negativ...
0.683172
Data_Structure_28070
C
[ "gcd", "efficient_lcm" ]
2
[ [ "efficient_lcm", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2a52ccfcafb86b790fc128bfb1144b697294dea1
1fa3c88199684820d15b8750e6a2b17805df05c1
v1.0
complete
Data_Structure
Data_Structure_27878_C
from typing import List def quick_sort(arr: List[int]) -> List[int]: """ Helper function to perform Quick Sort on the input array. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in...
from typing import List def quick_sort(arr: List[int]) -> List[int]: """Helper function to perform Quick Sort.""" if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] ...
from solution import bucket_sort def test_bucket_sort_general_case(): assert bucket_sort([4, 1, 7, 3, 5, 2, 6, 8]) == [1, 2, 3, 4, 5, 6, 7, 8] def test_bucket_sort_empty(): assert bucket_sort([]) == [] def test_bucket_sort_single_element(): assert bucket_sort([42]) == [42] def test_bucket_sort_all_same_...
[ { "docstring": "Helper function to perform Quick Sort.", "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" }, { "docstring": "Function to perform Bucket Sort with Quick Sort inside each bucket.", "function_declaration": "def bucket_s...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef quick_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left =...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers and the task is to implement a function that sorts the given array using the Bucket Sort algorithm. However, within each bucket, use the Quick Sort algorithm instead of Insertion Sort to improve the performance.\n\n### Function Signature\n```python\ndef bu...
0.639684
Data_Structure_27878
C
[ "quick_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "quick_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5479c98dae5ebe1fc559a620a6c35a6c07bb7df
5ed92452103aaeba70316e31daa5d29a14d1bcfd
v1.0
complete
Data_Structure
Data_Structure_27429_C
from typing import List def multiply(mat1: List[List[int]], mat2: List[List[int]]) -> List[List[int]]: """ Multiplies two matrices mat1 and mat2. """ # Implementation here def identity(size: int) -> List[List[int]]: """ Returns an identity matrix of the given size. """ # Implementatio...
def multiply(mat1, mat2): """ Multiplies two matrices mat1 and mat2. """ n = len(mat1) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] += mat1[i][k] * mat2[k][j] return result def identi...
from solution import multiply, identity, matrix_exponentiation, pow_matrix_sum def test_multiply(): assert multiply([[1, 2], [3, 4]], [[1, 0], [0, 1]]) == [[1, 2], [3, 4]] assert multiply([[1]], [[1]]) == [[1]] assert multiply([[0, 1], [1, 0]], [[1, 2], [3, 4]]) == [[3, 4], [1, 2]] def test_identity(): ...
[ { "docstring": "Multiplies two matrices mat1 and mat2.", "function_declaration": "def multiply(mat1, mat2):", "function_name": "multiply", "parameter_list": "(mat1, mat2)" }, { "docstring": "Returns an identity matrix of given size.", "function_declaration": "def identity(size):", "f...
[ 0, 0, 1, 1, 0, 0, 0, 1, 0 ]
3
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiply(mat1, mat2):\n \"\"\"\n Multiplies two matrices mat1 and mat2.\n \"\"\"\n n = len(mat1)\n result = [[0] * n for _ in range(n)]\n ...
trial_gpt4o_8
{ "original_instruction": "### Matrix Exponentiation and Multiplication\n\nYou have been provided functions for matrix multiplication, identity matrix creation, and matrix exponentiation.\n\nYou are tasked to implement a function `pow_matrix_sum(mat: list, exponents: list) -> list` that calculates the sum of a matrix...
0.511966
Data_Structure_27429
C
[ "multiply", "identity", "matrix_exponentiation", "pow_matrix_sum" ]
4
[ [ "matrix_exponentiation", "identity" ], [ "matrix_exponentiation", "multiply" ], [ "pow_matrix_sum", "matrix_exponentiation" ] ]
3
[]
false
[]
false
pytest
true
[]
true
edd335baba61c60fd6a0e301b37366a3b53566e0
5c612ed826a1bdb9408ac48859bd7441545a601b
v1.0
complete
Data_Structure
Data_Structure_28215_C
from typing import List def radix_sort(arr: List[int], simulation=False) -> List[int]: """ Implement the Radix Sort algorithm to sort a given list of non-negative integers representing the transaction IDs. If the simulation flag is set to True, the function prints each iteration's state of the list for de...
from typing import List def counting_sort_for_radix(arr, exp, simulation=False): n = len(arr) output = [0] * n count = [0] * 10 for i in range(n): index = arr[i] // exp count[index % 10] += 1 for i in range(1, 10): count[i] += count[i - 1] for i in range(n...
from solution import radix_sort def test_radix_sort_basics(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] assert radix_sort([5, 2, 2, 8, 3]) == [2, 2, 3, 5, 8] assert radix_sort([]) == [] assert radix_sort([123456789]) == [123456789] def test_radix_sort_ed...
[ { "docstring": null, "function_declaration": "def counting_sort_for_radix(arr, exp, simulation=False):", "function_name": "counting_sort_for_radix", "parameter_list": "(arr, exp, simulation=False)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort_for_radix(arr, exp, simulation=False):\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n \n f...
trial_gpt4o_0
{ "original_instruction": "### Radix Sort Implementation and Analysis\n\n#### Scenario\nYou are tasked with writing an efficient sorting algorithm for a large finance application. The input consists of millions of records, each identified by a unique transaction ID, which is a non-negative integer.\n\n#### Task\nImpl...
0.643051
Data_Structure_28215
C
[ "counting_sort_for_radix", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort_for_radix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87bfc933c82e4516382d199a131a47270c19f346
92c212765bbcf6ff1aa0fecf4a651cd23b6c7793
v1.0
complete
Data_Structure
Data_Structure_28222_C
from typing import List def max_heap_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using Max-Heap Sort. >>> max_heap_sort([10, 5, 3, 15, 8]) [3, 5, 8, 10, 15] >>> max_heap_sort([7, 14, 2, 18, 4, 11]) [2, 4, 7, 11, 14, 18] """ pass def min_heap_sort(arr:...
def max_heapify(arr, n, i): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: largest = right if largest != i: arr[i], arr[largest] = arr[largest], arr[i] ...
def test_heap_sorts(): # Test array arr1 = [10, 5, 3, 15, 8] arr2 = [7, 14, 2, 18, 4, 11] arr3 = [-3, -5, -10, -2, -4] arr4 = [3, 1, 2, 3, 1, 2] arr5 = [1] # Expected results sorted1 = [3, 5, 8, 10, 15] sorted2 = [2, 4, 7, 11, 14, 18] sorted3 = [-10, -5, -4, -3, -2] sort...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i):", "function_name": "max_heapify", "parameter_list": "(arr, n, i)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr):", "function_name": "max_heap_sort", "parameter_list": "(arr)" }, ...
[ 0, 0, 0, 1, 0, 1, 1, 0, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_heapify(arr, n, i):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if left < n and arr[left] > arr[largest]:\n largest = ...
trial_gpt4o_9
{ "original_instruction": "### Scenario\nYou are working on an e-commerce platform where you need to process a list of product prices for sorting in ascending order. You have learned about Heap Sort and are tasked to implement both Max-Heap Sort and Min-Heap Sort for this purpose.\n\n### Problem Statement\n\nYour tas...
0.683226
Data_Structure_28222
C
[ "max_heapify", "max_heap_sort", "min_heapify", "min_heap_sort" ]
4
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c3882c0f7ab0f5cbb91aec6c8ef1ec837f0c9ff9
3509245a21f99c261e98ee01493f3a272f96a368
v1.0
complete
Data_Structure
Data_Structure_27931_C
from typing import List, Optional def prime_check(num: int) -> bool: """ Checks if a given number is prime. >>> prime_check(7) == True >>> prime_check(18) == False >>> prime_check(1) == False >>> prime_check(2) == True """ pass def find_order(a: int, n: int) -> int: """ Finds t...
from typing import List, Optional import math def prime_check(num: int) -> bool: """ Checks if a given number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num %...
import pytest from solution import prime_check, find_order, euler_totient, find_primitive_root, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(7) == True assert prime_check(18) == False assert prime_check(1) == False assert prime_check(2) == True def test_find_order(): asse...
[ { "docstring": "Checks if a given number is prime.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Finds the order of element 'a' modulo 'n'.", "function_declaration": "def find_order(a, n):", "function_n...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef prime_check(num: int) -> bool:\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if nu...
trial_gpt4o_6
{ "original_instruction": "### Diffie-Hellman and Primality Utility Implementation\n\nIn this exercise, you will enhance the provided Diffie-Hellman Key Exchange implementation along with accompanying mathematical utilities. The purpose is to assess your understanding of both cryptographic protocols and fundamental m...
0.663431
Data_Structure_27931
C
[ "prime_check", "find_order", "euler_totient", "find_primitive_root", "diffie_hellman_key_exchange" ]
5
[ [ "diffie_hellman_key_exchange", "find_primitive_root" ], [ "diffie_hellman_key_exchange", "prime_check" ], [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "prime_check" ] ]
4
[]
false
[]
false
pytest
true
[]
true
05939ad912475944aa8110fdb340d3addc1113a8
3b71e08bdca37921d0075965cf36907263b96d50
v1.0
complete
Data_Structure
Data_Structure_27885_C
def hybrid_heap_sort(arr): """Sort an array using a variation of Heap Sort. Specifically, dynamically choose between max-heap sort or min-heap sort based on the initial ordering of the array. If more than half of the array elements are already sorted in ascending order, use min-heap sort, otherwise use ma...
def hybrid_heap_sort(arr): if len(arr) <= 1: return arr # Determine if more than half the array is sorted in ascending order sorted_count = sum(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) if sorted_count >= len(arr) // 2: return min_heap_sort(arr) else: return max_hea...
import pytest from solution import hybrid_heap_sort def test_hybrid_heap_sort_empty(): assert hybrid_heap_sort([]) == [] def test_hybrid_heap_sort_single_element(): assert hybrid_heap_sort([1]) == [1] def test_hybrid_heap_sort_sorted_asc(): assert hybrid_heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def...
[ { "docstring": null, "function_declaration": "def hybrid_heap_sort(arr):", "function_name": "hybrid_heap_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr):", "function_name": "max_heap_sort", "parameter_list": "(arr)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def hybrid_heap_sort(arr):\n \"\"\"\n Sorts an array using a hybrid heap sort algorithm.\n Chooses min-heap sort if more than half of the elements ar...
trial_gpt4o_2
{ "original_instruction": "Design and implement a function to sort an array using a variation of Heap Sort. Specifically, you are required to write a function `hybrid_heap_sort` that dynamically chooses between max-heap sort or min-heap sort based on the initial ordering of the array. If more than half of the array e...
0.578167
Data_Structure_27885
C
[ "hybrid_heap_sort", "max_heap_sort", "min_heap_sort" ]
3
[ [ "hybrid_heap_sort", "max_heap_sort" ], [ "hybrid_heap_sort", "min_heap_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f519749ff8d8da8e227b75acd7d03b08a9709832
3c09904daf52b27ebeb37dd5df4f8553470e75cd
v1.0
complete
Data_Structure
Data_Structure_28056_C
from typing import List def search_insert(arr: List[int], value: int, hi: int) -> int: lo = 0 while lo < hi: mid = (lo + hi) // 2 if arr[mid] < value: lo = mid + 1 else: hi = mid return lo def insertion_sort(arr: List[int]) -> None: """ Sorts the giv...
from typing import List def search_insert(arr: List[int], value: int, hi: int) -> int: lo = 0 while lo < hi: mid = (lo + hi) // 2 if arr[mid] < value: lo = mid + 1 else: hi = mid return lo def insertion_sort(arr: List[int]) -> None: for i in range(1, len...
from solution import insertion_sort def test_insertion_sort_sorted_list(): arr = [1, 2, 3, 4, 5] insertion_sort(arr) assert arr == [1, 2, 3, 4, 5] def test_insertion_sort_reverse_sorted_list(): arr = [5, 4, 3, 2, 1] insertion_sort(arr) assert arr == [1, 2, 3, 4, 5] def test_insertion_sort_ran...
[ { "docstring": null, "function_declaration": "def search_insert(arr, value, hi):", "function_name": "search_insert", "parameter_list": "(arr, value, hi)" }, { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(arr: List[int], left: int, right: int, key: int) -> int:\n while left < right:\n mid = (left + right) /...
trial_gpt4o_2
{ "original_instruction": "### Question: Efficient Insertion Sort Implementation\n\nYou are tasked with implementing the insertion sort algorithm for a list of integers, but with a twist: instead of using a linear search to find the position where a new element should be inserted, you will use binary search as outlin...
0.668086
Data_Structure_28056
C
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b3b337a2ff35daa886967592673876080bbd2ff8
f369393ecfa37e5bbd5b00939651a44ad927b450
v1.0
complete
Data_Structure
Data_Structure_28206_C
def network_max_flow(algorithm: str, capacity: List[List[int]], source: int, sink: int) -> int: """ Selects the appropriate algorithm based on the properties of the input graph and computes the maximum flow from the source to the sink. Args: algorithm (str): The algorithm to use ("ford_fulker...
from collections import deque def ford_fulkerson(capacity, source, sink): n = len(capacity) flow = 0 parent = [-1] * n def bfs(s, t): visited = [False] * n queue = deque([s]) visited[s] = True while queue: u = queue.popleft() for v in range(n): ...
import pytest from solution import network_max_flow def test_network_max_flow_ford_fulkerson(): capacity = [ [0, 16, 13, 0, 0, 0], [16, 0, 10, 12, 0, 0], [13, 4, 0, 0, 14, 0], [0, 12, 9, 0, 0, 20], [0, 0, 14, 7, 0, 4], [0, 0, 0, 20, 4, 0] ] assert network_max...
[ { "docstring": null, "function_declaration": "def ford_fulkerson(capacity, source, sink):", "function_name": "ford_fulkerson", "parameter_list": "(capacity, source, sink)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "e...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\n# Ford-Fulkerson Algorithm using Depth First Search (DFS)\ndef ford_fulkerson(capacity, source, sink):\n n = len(capacity)...
trial_gpt4o_2
{ "original_instruction": "**Network Maximum Flow**\n\nNetwork flow problems are commonly encountered in various fields and require precise calculation of the maximum possible flow from a source to a sink in a given network. You are provided with the code implementations of three maximum flow algorithms: Ford-Fulkers...
0.547311
Data_Structure_28206
C
[ "ford_fulkerson", "edmonds_karp", "dinic", "network_max_flow" ]
4
[ [ "network_max_flow", "dinic" ], [ "network_max_flow", "edmonds_karp" ], [ "network_max_flow", "ford_fulkerson" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0b645446a242311b9da3f8ba3bb1e883e78e0d2e
24a3a8c07f18a946685505b05601757fcbb79746
v1.0
complete
Data_Structure
Data_Structure_27689_C
import math from typing import List, Optional def optimized_prime_check(num: int) -> bool: """ Efficiently checks if a number is prime. :param num: An integer to check for primality (1 <= num <= 10^12). :return: True if `num` is a prime number, False otherwise. >>> optimized_prime_check(2...
import math from typing import List, Optional def optimized_prime_check(num: int) -> bool: """ Efficiently checks if a number is prime. :param num: An integer to check for primality (1 <= num <= 10^12). :return: True if `num` is a prime number, False otherwise. """ if num <= 1: ret...
from solution import optimized_prime_check, optimized_find_primitive_root, enhanced_diffie_hellman_key_exchange def test_optimized_prime_check(): assert optimized_prime_check(2) is True assert optimized_prime_check(3) is True assert optimized_prime_check(4) is False assert optimized_prime_check(5) is T...
[ { "docstring": "Efficiently checks if a number is prime.\n\n:param num: An integer to check for primality (1 <= num <= 10^12).\n:return: True if `num` is a prime number, False otherwise.", "function_declaration": "def optimized_prime_check(num):", "function_name": "optimized_prime_check", "parameter...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef optimized_prime_check(num: int) -> bool:\n \"\"\"Returns True if num is a prime number, False otherwise.\"\"\"\n if num <= 1:\n ...
trial_gpt4o_8
{ "original_instruction": "Implementing and Enhancing Diffie-Hellman Key Exchange\n\nThe goal of this question is to verify your understanding of the Diffie-Hellman key exchange process and associated number-theoretic functions. You will implement an enhanced Diffie-Hellman key exchange algorithm incorporating optimi...
0.594257
Data_Structure_27689
C
[ "optimized_prime_check", "optimized_find_primitive_root", "enhanced_diffie_hellman_key_exchange" ]
3
[ [ "enhanced_diffie_hellman_key_exchange", "optimized_find_primitive_root" ], [ "enhanced_diffie_hellman_key_exchange", "optimized_prime_check" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b6a10d5a24cbdb7c8281577ac28d1d8452b2e73d
eb5099474176e1c4212b72d6b9d0a1527f006e34
v1.0
complete
Data_Structure
Data_Structure_27303_C
def enhanced_knuth_morris_pratt(text: str, pattern: str) -> (List[int], int, List[int]): """ Given the KMP algorithm for string matching, this function enhances its functionality by finding all positions where the pattern occurs in the text, the total number of occurrences of the pattern, and the size of th...
from typing import List, Tuple def compute_pi_table(pattern: str) -> List[int]: # pi[i] is the length of the longest proper prefix which is also a suffix for substring pattern[0:i+1] pi = [0] * len(pattern) k = 0 for i in range(1, len(pattern)): while k > 0 and pattern[k] != pattern[i]: ...
from solution import enhanced_knuth_morris_pratt def test_enhanced_knuth_morris_pratt_example_case(): text = 'hello there hero!' pattern = 'he' assert enhanced_knuth_morris_pratt(text, pattern) == ([0, 7, 12], 3, [0, 0]) def test_enhanced_knuth_morris_pratt_no_match(): text = 'abcdef' pattern = 'g...
[ { "docstring": null, "function_declaration": "def compute_pi_table(pattern):", "function_name": "compute_pi_table", "parameter_list": "(pattern)" }, { "docstring": null, "function_declaration": "def enhanced_knuth_morris_pratt(text, pattern):", "function_name": "enhanced_knuth_morris...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef build_pi_table(pattern: str) -> List[int]:\n \"\"\"\n Constructs the prefix table (pi table) for the given pattern...
trial_gpt4o_1
{ "original_instruction": "### KMP String Matching Implementation and Enhancement\n\nGiven the KMP algorithm for string matching, your task is to enhance its functionality by implementing a function that, in addition to finding all positions where the pattern occurs in the text, also returns the total number of occur...
0.574191
Data_Structure_27303
C
[ "compute_pi_table", "enhanced_knuth_morris_pratt" ]
2
[ [ "enhanced_knuth_morris_pratt", "compute_pi_table" ] ]
1
[]
false
[]
false
pytest
true
[]
true
984c24d45da83175110df172bd0d628db4e06d67
9aa9efa385a93549dbf98779819c88e4d4315c7c
v1.0
complete
Data_Structure
Data_Structure_28004_C
from typing import List def binary_tree_inorder(preorder: List[int], postorder: List[int]) -> List[int]: """ Given two arrays representing the preorder and postorder traversal of a full binary tree, construct the binary tree and return its inorder traversal as a list. >>> binary_tree_inorder([1, 2, 4, ...
from typing import List class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def build_tree(preorder, postorder): """ Helper function to build the binary tree. """ if not preorder or not postorder: retu...
import pytest from solution import binary_tree_inorder def test_example_1(): preorder = [1, 2, 4, 8, 9, 5, 3, 6, 7] postorder = [8, 9, 4, 5, 2, 6, 7, 3, 1] expected = [8, 4, 9, 2, 5, 1, 6, 3, 7] assert binary_tree_inorder(preorder, postorder) == expected def test_example_2(): preorder = [1, 2, 3] ...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\nclass TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n s...
trial_gpt4o_0
{ "original_instruction": "### Binary Tree Construction and Inorder Traversal\n\nGiven two arrays representing the preorder and postorder traversal of a full binary tree, write a function to construct the binary tree and return its inorder traversal as a list.\n\nA full binary tree has the property that every node ha...
0.505994
Data_Structure_28004
C
[ "build_tree", "inorder_traversal", "binary_tree_inorder" ]
3
[ [ "binary_tree_inorder", "build_tree" ], [ "binary_tree_inorder", "inorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
8572a3fee73f93cc08f0aeec7f530b3e9626e0e3
ab669602500acf330534c9ef78b482294ff7f284
v1.0
complete
Data_Structure
Data_Structure_28337_C
from typing import List def exchange_sort(arr: List[int]) -> List[int]: """ Exchanges elements to sort the array. Args: arr (List[int]): A list of integers to be sorted. Returns: List[int]: A list of sorted integers. >>> exchange_sort([64, 34, 25, 12, 22, 11, 90]) [11, 12, 22, 25, 34...
def exchange_sort(arr): """ Exchanges elements to sort the array. """ n = len(arr) for i in range(n - 1): for j in range(i + 1, n): if arr[i] > arr[j]: arr[i], arr[j] = arr[j], arr[i] return arr def merge_sort(arr): """ Implements merge sort algorithm...
from solution import exchange_sort, merge_sort, hybrid_sort def test_exchange_sort_empty_array(): assert exchange_sort([]) == [] def test_exchange_sort_single_element(): assert exchange_sort([5]) == [5] def test_exchange_sort_sorted_array(): assert exchange_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def t...
[ { "docstring": "Exchanges elements to sort the array.", "function_declaration": "def exchange_sort(arr):", "function_name": "exchange_sort", "parameter_list": "(arr)" }, { "docstring": "Implements merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def exchange_sort(arr):\n n = len(arr)\n for i in range(n-1):\n for j in range(i+1, n):\n if arr[i] > arr[j]:\n arr[i],...
trial_gpt4o_1
{ "original_instruction": "#### Context\nYou are tasked with implementing and enhancing an existing algorithm, the Exchange Sort. However, given its inefficiency for large datasets, your goal is to adapt or combine it with another efficient sorting algorithm.\n\n#### Requirements\nWrite two functions:\n1. **exchange_...
0.619088
Data_Structure_28337
C
[ "exchange_sort", "merge_sort", "hybrid_sort" ]
3
[ [ "hybrid_sort", "exchange_sort" ], [ "hybrid_sort", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
73a0f76e8dc4418ec8a203f56132784ce66eb6e8
337c891aa2cfeb6183caf4d8c06a1fdb1a5fec25
v1.0
complete
Data_Structure
Data_Structure_28392_C
def construct_tree(pre: list, post: list) -> list: """ Given arrays representing the preorder and postorder traversal of a full binary tree, constructs the binary tree from the given traversals and returns a list representing the inorder traversal of the constructed tree. >>> construct_tree([1, 2...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def construct_tree_helper(pre, post, pre_start, pre_end, post_start, post_end, post_map): if pre_start > pre_end or post_start > post_end: return None root = TreeNode(pre[pre_start]) i...
from solution import construct_tree def test_construct_tree_simple(): pre = [1, 2, 3] post = [2, 3, 1] assert construct_tree(pre, post) == [2, 1, 3] def test_construct_tree_full_binary(): pre = [1, 2, 4, 5, 3, 6, 7] post = [4, 5, 2, 6, 7, 3, 1] assert construct_tree(pre, post) == [4, 2, 5, 1, ...
[]
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n \"\"\"Definition for a binary tree node.\"\"\"\n def __init__(self, x):\n self.val = x\n self.left = None\n self....
trial_gpt4o_7
{ "original_instruction": "**Question**:\n\n### Context\nIn certain applications like data serialization and graphics, it is common to reconstruct data structures from their traversal outputs. One such problem is reconstructing a full binary tree from its preorder and postorder traversal outputs.\n\n### Task\nGiven a...
0.514478
Data_Structure_28392
C
[ "construct_tree_helper", "inorder_traversal", "construct_tree" ]
3
[ [ "construct_tree", "construct_tree_helper" ], [ "construct_tree", "inorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
254340d023e10538d063a1c46498f26876fdb1b7
92e16848af0c9aa4d9d00d83b3bd81fa08b930de
v1.0
complete
Data_Structure
Data_Structure_28036_C
from typing import List def search_insert(array: List[int], value: int, start: int, end: int) -> int: """ Uses binary search to find the index where value should be inserted to keep the array sorted between start and end. """ while start < end: mid = (start + end) // 2 if array[mid] < v...
from typing import List def search_insert(array: List[int], value: int, start: int, end: int) -> int: """ Uses binary search to find the index where value should be inserted to keep the array sorted between start and end. """ while start < end: mid = (start + end) // 2 if array[mid] < v...
from solution import insertion_sort def test_insertion_sort_example1(): assert insertion_sort([4, 3, 2, 10, 12, 1, 5, 6]) == [1, 2, 3, 4, 5, 6, 10, 12] def test_insertion_sort_empty(): assert insertion_sort([]) == [] def test_insertion_sort_all_identical(): assert insertion_sort([1, 1, 1, 1, 1]) == [1, 1...
[ { "docstring": "Uses binary search to find the index where value should be inserted to keep the array sorted between start and end.", "function_declaration": "def search_insert(array, value, start, end):", "function_name": "search_insert", "parameter_list": "(array, value, start, end)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(array: List[int], value: int) -> int:\n \"\"\"\n Searches for the insert index for 'value' using binary sea...
trial_gpt4o_2
{ "original_instruction": "You are given an unsorted list of integers and your task is to implement the insertion sort algorithm to sort the list in ascending order. However, instead of performing a linear search to find the correct position for an element, you are to use the provided `search_insert` function that us...
0.638152
Data_Structure_28036
C
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0357dbeb63444391264d157513710d0630aec075
8973b1f4bf2695e661debe755bd6d7b046c1be8a
v1.0
complete
Data_Structure
Data_Structure_28516_C
import random import time def is_sorted(arr): """ Helper function to check if array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr, simulation=False): """ This function sorts an array using Bogo Sort algor...
import random import time def is_sorted(arr): """ Helper function to check if array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr, simulation=False): """ This function sorts an array using Bogo Sort algor...
from solution import bogo_sort, compare_sorts def test_bogo_sort_already_sorted(): assert bogo_sort([1, 2, 3], simulation=False) == [1, 2, 3] def test_bogo_sort_reverse_order(): assert bogo_sort([3, 2, 1], simulation=False) == [1, 2, 3] def test_bogo_sort_random_order(): arr = [2, 3, 1] sorted_arr = ...
[ { "docstring": "Helper function to check if array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "This function sorts an array using Bogo Sort algorithm with an option for simulation.\n\n:param arr: List[i...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nimport time\n\ndef is_sorted(arr):\n \"\"\"\n Check if the array is sorted.\n \"\"\"\n for i in range(len(arr) - 1):\n if ar...
trial_gpt4o_1
{ "original_instruction": "### Coding Challenge: Bogo Sort Simulation and Alternatives\n\n#### Context\nYou are tasked with implementing an inefficient, theoretical algorithm called Bogo Sort. This is mainly for educational purposes to understand why certain algorithms are impractical. In the real world, we would nev...
0.609285
Data_Structure_28516
C
[ "is_sorted", "bogo_sort", "compare_sorts" ]
3
[ [ "bogo_sort", "is_sorted" ], [ "compare_sorts", "bogo_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8583008d9e8d65751b13e959ee76609d68a398e7
0d9f4b1c9a4b9341d4333da0dc6785c12bc61eca
v1.0
complete
Data_Structure
Data_Structure_27643_C
def gcd(a: int, b: int) -> int: """Compute the Greatest Common Divisor (GCD) of two integers using Euclid's algorithm. Both input values `a` and `b` should be positive integers. If either value is zero, raise a `ValueError`. Args: a (int): The first integer. b (int): The second integer. R...
def gcd(a, b): """Compute the Greatest Common Divisor (GCD) of two integers using Euclid's algorithm.""" if a <= 0 or b <= 0: raise ValueError("Both a and b should be positive integers.") while b: a, b = b, a % b return a def trailing_zero(x): """Count the number of trailing zeros i...
import pytest from solution import gcd, lcm, trailing_zero, gcd_bit def test_gcd(): assert gcd(48, 18) == 6 assert gcd(5, 3) == 1 assert gcd(1, 1) == 1 with pytest.raises(ValueError): gcd(0, 10) with pytest.raises(ValueError): gcd(10, 0) with pytest.raises(ValueError): ...
[ { "docstring": "Compute the Greatest Common Divisor (GCD) of two integers using Euclid's algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Count the number of trailing zeros in the binary representation of x.", "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a: int, b: int) -> int:\n if a <= 0 or b <= 0:\n raise ValueError(\"Both numbers must be positive integers.\")\n \n while b:\n ...
trial_gpt4o_1
{ "original_instruction": "### Assignment: Optimized GCD and LCM Calculation\n\nYou are tasked with implementing and optimizing a set of utility functions for computing the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) for two integers. In addition to the traditional approach, you need to ensure that ...
0.77649
Data_Structure_27643
C
[ "gcd", "trailing_zero", "gcd_bit", "lcm" ]
4
[ [ "gcd_bit", "trailing_zero" ], [ "lcm", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d5dca264222e38014ee1332d2b26ab7cc4c6e646
90d9d6cdac4047eb20af56cc19d483bdf0e66884
v1.0
complete
Data_Structure
Data_Structure_28316_C
def prime_check(num): """ Check if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False i...
import random def prime_check(num): """ Check if a number is a prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return ...
from solution import secure_key_exchange, prime_check, find_primitive_root def test_secure_key_exchange_valid(): result = secure_key_exchange(2, 11) assert isinstance(result, tuple) assert len(result) == 2 assert result[0] == result[1] def test_secure_key_exchange_invalid_p(): result = secure_key_...
[ { "docstring": "Check if a number is a prime.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Calculates Euler's totient function of n.", "function_declaration": "def euler_totient(n):", "function_name": ...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef prime_check(num):\n \"\"\"\n Check if a number is a prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_0
{ "original_instruction": "### Question\nAlice and Bob want to securely share a secret key using the Diffie-Hellman key exchange algorithm. You are provided with the following functions to help you build the system:\n1. `prime_check(num)`: Checks if a number is a prime.\n2. `find_primitive_root(n)`: Finds all primiti...
0.587623
Data_Structure_28316
C
[ "prime_check", "euler_totient", "find_primitive_root", "secure_key_exchange" ]
4
[ [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "prime_check" ], [ "secure_key_exchange", "find_primitive_root" ], [ "secure_key_exchange", "prime_check" ] ]
4
[]
false
[]
false
pytest
true
[]
true
6f19af691a832157b076a0d5913ac59aab025da3
46ee551cfee72d25ceebf17389b5e3a8754baeca
v1.0
complete
Data_Structure
Data_Structure_28635_C
from typing import List def optimized_radix_sort(arr: List[int]) -> List[int]: """ Sorts a list of non-negative integers using the radix sort algorithm. >>> optimized_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) [2, 24, 45, 66, 75, 90, 170, 802] >>> optimized_radix_sort([3, 3, 2, 1, 0]) [...
from typing import List def optimized_radix_sort(arr: List[int]) -> List[int]: """ Sorts a list of non-negative integers using the radix sort algorithm. """ if not arr: # Early exit for empty array return arr # Find the maximum number to know number of digits max_val = max(arr) ...
from solution import optimized_radix_sort def test_empty_array(): assert optimized_radix_sort([]) == [] def test_single_element(): assert optimized_radix_sort([5]) == [5] def test_multiple_elements(): assert optimized_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] ...
[ { "docstring": "Sorts a list of non-negative integers using the radix sort algorithm.", "function_declaration": "def optimized_radix_sort(arr):", "function_name": "optimized_radix_sort", "parameter_list": "(arr)" }, { "docstring": "A function to do counting sort of arr[] according to the dig...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef optimized_radix_sort(arr: List[int]) -> List[int]:\n if not arr:\n return []\n\n # Get the maximum number to deter...
trial_gpt4o_2
{ "original_instruction": "### Context:\nYou are assigned to optimize the processing of large datasets of non-negative integers. To this end, you have decided to implement the Radix Sort, a non-comparative sorting algorithm known for its efficiency with certain datasets.\n\n### Question:\nImplement a function `optimi...
0.651008
Data_Structure_28635
C
[ "optimized_radix_sort", "counting_sort" ]
2
[ [ "optimized_radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f150205de9d0f330c181549ba5a2fe66f1b38043
a4321a3776d02c8f44e67bf5fecec660d7655ee6
v1.0
complete
Data_Structure
Data_Structure_28186_C
from typing import List def compute_maximum_flow(adjacency_matrix: List[List[int]]) -> int: """Determine the maximum possible flow from the source (node 0) to the sink (the last node) in a given graph using the Ford-Fulkerson method with the Breadth-First Search (BFS) approach. Args: adjacency_matrix (...
from collections import deque from typing import List def bfs(rGraph, s, t, parent): visited = [False] * len(rGraph) queue = deque([s]) visited[s] = True while queue: u = queue.popleft() for ind, val in enumerate(rGraph[u]): if visited[ind] == False and val > 0: ...
import pytest from solution import compute_maximum_flow def test_example_case(): graph = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0] ] assert compute_maximum_flow(graph) == 23 ...
[ { "docstring": null, "function_declaration": "def bfs(rGraph, s, t, parent):", "function_name": "bfs", "parameter_list": "(rGraph, s, t, parent)" }, { "docstring": null, "function_declaration": "def compute_maximum_flow(adjacency_matrix):", "function_name": "compute_maximum_flow", ...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom collections import deque\n\ndef bfs(rGraph, s, t, parent):\n visited = [False] * len(rGraph)\n queue = deque()\n \n ...
trial_gpt4o_8
{ "original_instruction": "### Coding Assessment: Maximum Flow in a Network\n\n#### Scenario:\nYou are given a directed graph representing a simplified model of a city's traffic network, where intersections are represented as nodes and roads as edges with specific capacity limits (the maximum number of vehicles that ...
0.600416
Data_Structure_28186
C
[ "bfs", "compute_maximum_flow" ]
2
[ [ "compute_maximum_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a5c13ef07b2f99d586ea69a0ec7045240acb971
633809381f610501f60aa7d37d3446b27f3c9130
v1.0
complete
Data_Structure
Data_Structure_28067_C
from typing import List def insertion_sort(arr: List[float]) -> List[float]: """ A helper function to perform insertion sort on a list. """ # Implementation here def bucket_sort(arr: List[float]) -> List[float]: """ Perform bucket sort on a list of floating-point numbers in the range [0, 1). ...
from typing import List def insertion_sort(arr: List[float]) -> List[float]: """ A helper function to perform insertion sort on a list. """ for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 ...
from solution import bucket_sort def test_bucket_sort_example(): assert bucket_sort([0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68]) == [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, 0.78, 0.94] def test_bucket_sort_empty(): assert bucket_sort([]) == [] def test_bucket_sort_single_element(): ...
[ { "docstring": "A helper function to perform insertion sort on a list.", "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": "Perform bucket sort on a list of floating-point numbers in the range [0, 1).", "fun...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(bucket):\n \"\"\"\n Sorts a bucket using insertion sort.\n \"\"\"\n for i in range(1, len(bucket)):\...
trial_gpt4o_2
{ "original_instruction": "### Bucket Sort Implementation Challenge\n\n#### Objective:\nImplement the Bucket Sort algorithm to effectively sort a given list of floating-point numbers.\n\n#### Problem Statement:\nYou are given a list of floating-point numbers \\(arr\\) where each element is uniformly distributed in th...
0.631873
Data_Structure_28067
C
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f6bc60c3683e9757454bf75fd4fb74facf7b418
bd7e1e031c01c4ac819358b732affd69fee85a1a
v1.0
complete
Data_Structure
Data_Structure_28523_C
class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def insert_into_bst(root: TreeNode, val: int) -> TreeNode: """ Inserts a value into the BST and returns the root of the tree. If the tree is empty, it creates a new root. """ pas...
class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def insert_into_bst(root: TreeNode, val: int) -> TreeNode: """ Inserts a value into the BST and returns the root of the tree. If the tree is empty, it creates a new root. """ if ...
from solution import TreeNode, insert_into_bst, in_order_traversal, construct_bst_from_list def test_insert_into_bst(): root = insert_into_bst(None, 10) assert root.val == 10 root = insert_into_bst(root, 5) root = insert_into_bst(root, 15) root = insert_into_bst(root, 3) root = insert_into_bst(...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = None\n\ndef insert_into_bst(root: Tree...
trial_gpt4o_2
{ "original_instruction": "You are tasked with implementing a function for a binary search tree (BST). The function will insert a list of values into a BST and then perform an in-order traversal to produce a sorted list of the values.\n\n### Requirements\n1. Implement a function `insert_into_bst(root, val)` to insert...
0.486103
Data_Structure_28523
C
[ "insert_into_bst", "in_order_traversal", "construct_bst_from_list" ]
3
[ [ "construct_bst_from_list", "in_order_traversal" ], [ "construct_bst_from_list", "insert_into_bst" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e7996979f3c8176cba3ef6bc99b8e65c9fe8aae8
8e7da81c8ca691cbf4b803580ea14c08ff1a628f
v1.0
complete
Data_Structure
Data_Structure_28689_C
import random def generate_markov_path(chain, initial_state, steps): """ Generates a path through a Markov chain. :param chain: dictionary where keys are states and values are dictionaries of transition probabilities. :param initial_state: string representing the starting state. :param steps: ...
import random def generate_markov_path(chain, initial_state, steps): """ Generates a path through a Markov chain. :param chain: dictionary where keys are states and values are dictionaries of transition probabilities. :param initial_state: string representing the starting state. :param steps: ...
import pytest from solution import generate_markov_path def test_generate_markov_path_basic(): chain = { 'A': {'A': 0.6, 'E': 0.4}, 'E': {'A': 0.7, 'E': 0.3} } path = generate_markov_path(chain, 'A', 5) assert len(path) == 6 assert path[0] == 'A' def test_generate_markov_path_to_se...
[ { "docstring": "Generates a path through a Markov chain.\n\n:param chain: dictionary where keys are states and values are dictionaries of transition probabilities.\n:param initial_state: string representing the starting state.\n:param steps: integer specifying the number of transitions.\n:return: list of states...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef generate_markov_path(chain, initial_state, steps):\n \"\"\"\n Generates a path through a Markov chain.\n \n :param chain: dic...
trial_gpt4o_0
{ "original_instruction": "### Question: Markov Chain Path Generator\n\nYou are given a Markov chain represented as a dictionary, where keys are states and values are dictionaries that map possible next states to their transition probabilities. Your task is to implement a function that generates a finite path through...
0.604474
Data_Structure_28689
C
[ "generate_markov_path", "_choose_next_state" ]
2
[ [ "generate_markov_path", "_choose_next_state" ] ]
1
[]
false
[]
false
pytest
true
[]
true
96a347729dd77438f5c2559fa5c5bc75878d2b9a
8a9b866bdd394521a8134125920f24d1acc3e819
v1.0
complete
Data_Structure
Data_Structure_29029_C
from typing import Tuple, Optional def generate_key(k: int, seed: Optional[int] = None) -> Tuple[int, int, int]: """ Generates an RSA key pair with a specified bit length k. Optionally accepts a seed for reproducibility. >>> n, e, d = generate_key(16, seed=42) >>> isinstance(n, int) and isinstance(e, ...
import random from typing import Tuple, Optional import sympy def generate_prime(bits: int) -> int: return sympy.randprime(2**(bits-1), 2**bits) def gcd(a, b): while b: a, b = b, a % b return a def extended_gcd(a, b): if a == 0: return b, 0, 1 gcd, x1, y1 = extended_gcd(b % a, a) ...
from solution import generate_key, encrypt, decrypt def test_generate_key(): n, e, d = generate_key(16, seed=42) assert isinstance(n, int) and isinstance(e, int) and isinstance(d, int) assert gcd(e, (n - 1 - (e - 1) % (n - 1))) == 1 def test_encrypt_decrypt(): n, e, d = generate_key(16) data = 20 ...
[ { "docstring": null, "function_declaration": "def generate_prime(bits):", "function_name": "generate_prime", "parameter_list": "(bits)" }, { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": n...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import Tuple, Optional\n\ndef generate_prime_candidate(length: int) -> int:\n # Generate random odd integer\n p = random.getr...
trial_gpt4o_1
{ "original_instruction": "### RSA Encryption Coding Challenge\n\n#### Scenario\nYou are tasked with implementing an RSA encryption system for secure communications. The company requires you to develop functions that can generate RSA keys, encrypt data using the public key, and decrypt data using the private key.\n\n...
0.735002
Data_Structure_29029
C
[ "generate_prime", "gcd", "extended_gcd", "mod_inverse", "generate_key", "encrypt", "decrypt" ]
7
[ [ "generate_key", "gcd" ], [ "generate_key", "generate_prime" ], [ "generate_key", "mod_inverse" ], [ "mod_inverse", "extended_gcd" ] ]
4
[]
false
[]
false
pytest
true
[ "sympy" ]
false
8fb290ac3b21991bb334fc5047bd5d50b12f3958
49c3a59be4e20a4e775c44356caf52d8b8debc14
v1.0
complete
Data_Structure
Data_Structure_29063_C
from typing import List, Tuple def is_graph_strongly_connected(vertex_count: int, edges: List[Tuple[int, int]]) -> bool: """ Determine whether a given directed graph is strongly connected using depth-first search (DFS) and graph reversal methods. Args: vertex_count (int): An integer representing ...
from typing import List, Tuple def dfs(graph, start, visited): stack = [start] while stack: node = stack.pop() if not visited[node]: visited[node] = True for neighbor in graph[node]: if not visited[neighbor]: stack.append(neighbor) de...
from solution import is_graph_strongly_connected def test_example_cases(): assert is_graph_strongly_connected(5, [(0, 1), (1, 2), (2, 0), (1, 3), (3, 4), (4, 1)]) == True assert is_graph_strongly_connected(5, [(0, 1), (1, 2), (2, 0), (1, 3), (3, 4)]) == False def test_single_node_graph(): assert is_graph_...
[ { "docstring": null, "function_declaration": "def dfs(graph, start, visited):", "function_name": "dfs", "parameter_list": "(graph, start, visited)" }, { "docstring": null, "function_declaration": "def is_graph_strongly_connected(vertex_count, edges):", "function_name": "is_graph_stro...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef dfs(graph, start, visited):\n stack = [start]\n while stack:\n node = stack.pop()\n if not visited[n...
trial_gpt4o_0
{ "original_instruction": "Verifying Strongly Connected Components\n\n**Scenario**: You are working on a network analysis tool that inspects directed networks represented as graphs. One of the core functionalities is to verify whether the network graph is strongly connected. This means checking if there is a path fro...
0.528345
Data_Structure_29063
C
[ "dfs", "is_graph_strongly_connected" ]
2
[ [ "is_graph_strongly_connected", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a55d01c22a77fd9b58e86653c402645c8e7558bb
f04d997b0cd7b087361a6577cae4bad1ec8b6aa1
v1.0
complete
Data_Structure
Data_Structure_28559_C
from typing import List def bucket_sort(arr: List[float]) -> List[float]: """ Sort an array of floating-point numbers within the range [0, 1) using the Bucket Sort algorithm. >>> bucket_sort([0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68]) [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, ...
from typing import List def bucket_sort(arr: List[float]) -> List[float]: n = len(arr) if n == 0: return arr # Create buckets buckets = [[] for _ in range(n)] # Distribute input array values into buckets for num in arr: index = int(num * n) buckets[index].appen...
from solution import bucket_sort def test_bucket_sort_with_example(): arr = [0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68] expected = [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, 0.78, 0.94] assert bucket_sort(arr) == expected def test_bucket_sort_empty_array(): arr = [] expected...
[ { "docstring": null, "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(arr: List[float]) -> List[float]:\n \"\"\"\n Sorts a list using the insertion sort algorithm.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "### Coding Assessment Task\n\n**Scenario**:\nYou are a software engineer working on a system where you need to sort a large set of floating-point numbers that are mostly well distributed. To ensure efficient sorting, you decide to implement the Bucket Sort algorithm.\n\n**Task**:\nImplement...
0.604485
Data_Structure_28559
C
[ "bucket_sort", "insertion_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
712f65699fffe287558916698e0422fcec981f89
9d9ce065eddbb17d5b386e646d518e0f2b293509
v1.0
complete
Data_Structure
Data_Structure_28203_C
def optimized_insertion_sort(arr: list) -> list: """ Sort a list of integers in ascending order using the optimized Insertion Sort algorithm. This implementation uses binary search to reduce the number of comparisons required to find the correct position for insertion. Args: arr (List[int...
def binary_search(arr, val, start, end): if start == end: if arr[start] > val: return start else: return start + 1 if start > end: return start mid = (start + end) // 2 if arr[mid] < val: return binary_search(arr, val, mid + 1, end) elif arr[m...
from solution import optimized_insertion_sort def test_optimized_insertion_sort(): # Test with a general case assert optimized_insertion_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9] # Test with an empty list assert optimized_insertion_sort([]) == [] # Test with a single element list ass...
[ { "docstring": null, "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" }, { "docstring": null, "function_declaration": "def optimized_insertion_sort(arr):", "function_name": "optimized_inse...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(arr, val, start, end):\n \"\"\"\n Helper function to perform a binary search for inserting an element.\n \"\"\"\n if start == en...
trial_gpt4o_2
{ "original_instruction": "### Problem Description\n\nImplement a function `optimized_insertion_sort` that sorts an array using the Insertion Sort algorithm. In this implementation, you should optimize the sorting process by using binary search to find the position where the current element should be inserted. This o...
0.663397
Data_Structure_28203
C
[ "binary_search", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ecdb35da70ae695be1d7bb69cceadb98e8aece9e
b3acd5357b300b76e89e14e6ea901dc9955a2834
v1.0
complete
Data_Structure
Data_Structure_28505_C
def custom_factorial(n: int, approach: str, mod: int = None) -> int: """Calculate the factorial of a given number `n` using the specified approach, and optionally return the result modulo `mod`. Parameters: n (int): A non-negative integer representing the number whose factorial needs to be calculat...
def custom_factorial(n: int, approach: str, mod: int = None) -> int: if not isinstance(n, int) or n < 0: raise ValueError("n must be a non-negative integer.") if mod is not None and (not isinstance(mod, int) or mod <= 0): raise ValueError("mod must be a positive integer.") if appro...
from solution import custom_factorial def test_custom_factorial_iterative(): assert custom_factorial(5, "iterative") == 120 def test_custom_factorial_recursive(): assert custom_factorial(5, "recursive") == 120 def test_custom_factorial_iterative_with_mod(): assert custom_factorial(5, "iterative", 3) == 0...
[ { "docstring": null, "function_declaration": "def custom_factorial(n, approach, mod=None):", "function_name": "custom_factorial", "parameter_list": "(n, approach, mod=None)" }, { "docstring": null, "function_declaration": "def _factorial_iterative(n, mod=None):", "function_name": "_f...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def custom_factorial(n: int, approach: str, mod: int = None) -> int:\n # Auxiliary function for iterative calculation\n def iterative_factorial(n, mod):...
trial_gpt4o_2
{ "original_instruction": "### Factorial Calculation with Extended Functionality\n\n#### Scenario\nA researcher working with large numbers in combinatorial problems frequently needs to compute factorials. However, due to the size of the numbers, the results often need to be taken modulo a specific value to avoid over...
0.689569
Data_Structure_28505
C
[ "custom_factorial", "_factorial_iterative", "_factorial_recursive" ]
3
[ [ "custom_factorial", "_factorial_iterative" ], [ "custom_factorial", "_factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
88d026f822ef5a0347a977b83355cf364decd046
67a61162dc3d4a9aa5cab0f3675d19b51f84f364
v1.0
complete
Data_Structure
Data_Structure_29183_C
def gcd(a, b): """ Compute the GCD using Euclid's Algorithm. >>> gcd(48, 18) 6 >>> gcd(56, 98) 14 """ pass def gcd_bit(a, b): """ Compute the GCD using the Bitwise GCD Algorithm. >>> gcd_bit(48, 18) 6 >>> gcd_bit(56, 98) 14 """ pass def validate_gcd_meth...
def gcd(a, b): """ Compute the GCD using Euclid's Algorithm. """ while b: a, b = b, a % b return abs(a) def gcd_bit(a, b): """ Compute the GCD using the Bitwise GCD Algorithm. """ a, b = abs(a), abs(b) if a == 0: return b if b == 0: return a ...
from solution import gcd, gcd_bit, validate_gcd_methods def test_gcd(): assert gcd(48, 18) == 6 assert gcd(56, 98) == 14 assert gcd(72, 120) == 24 assert gcd(81, 153) == 9 assert gcd(101, 103) == 1 def test_gcd_bit(): assert gcd_bit(48, 18) == 6 assert gcd_bit(56, 98) == 14 assert gcd_...
[ { "docstring": "Compute the GCD using Euclid's Algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Compute the GCD using the Bitwise GCD Algorithm.", "function_declaration": "def gcd_bit(a, b):", "function_name"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Returns the Greatest Common Divisor (GCD) of a and b using Euclid's Algorithm.\n \"\"\"\n while b:\n a, b = b, a ...
trial_gpt4o_1
{ "original_instruction": "#### Context\nGiven the critical role of the Greatest Common Divisor (GCD) in many mathematical and real-world applications, understanding its calculation and optimization is essential. In this task, you will implement a function that computes the GCD using both traditional and optimized bi...
0.711012
Data_Structure_29183
C
[ "gcd", "gcd_bit", "validate_gcd_methods" ]
3
[ [ "validate_gcd_methods", "gcd" ], [ "validate_gcd_methods", "gcd_bit" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b9ec57b29339fe78eb5b1921f8e089f506e1c1bd
c8e8d63366831960b6b6f8aeb0188c59841e9c75
v1.0
complete
Data_Structure
Data_Structure_28404_C
from typing import List def improved_gcd(a: int, b: int) -> int: """ Compute the greatest common divisor using Euclid's algorithm. >>> improved_gcd(25, 15) 5 >>> improved_gcd(48, 18) 6 >>> improved_gcd(-1, 15) Traceback (most recent call last): ... ValueError: Both inputs must be po...
def improved_gcd(a: int, b: int) -> int: """ Compute the greatest common divisor using Euclid's algorithm. """ if a <= 0 or b <= 0: raise ValueError('Both inputs must be positive integers.') while b: a, b = b, a % b return a def efficient_lcm(a: int, b: int) -> int: """ Compute the ...
from solution import improved_gcd, efficient_lcm, trailing_zero_count, gcd_with_bitwise def test_improved_gcd(): assert improved_gcd(25, 15) == 5 assert improved_gcd(48, 18) == 6 try: improved_gcd(-1, 15) except ValueError as e: assert str(e) == 'Both inputs must be positive integers.' ...
[ { "docstring": "Compute the greatest common divisor using Euclid's algorithm. ", "function_declaration": "def improved_gcd(a, b):", "function_name": "improved_gcd", "parameter_list": "(a, b)" }, { "docstring": "Compute the least common multiple using the GCD function. ", "function_declar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def improved_gcd(a: int, b: int) -> int:\n \"\"\" Compute the greatest common divisor using Euclid's algorithm. \"\"\"\n if a <= 0 or b <= 0:\n r...
trial_gpt4o_0
{ "original_instruction": "#### Scenario\nYou are tasked with building a library that efficiently handles calculations for mathematical properties and relationships involving integers. The core functions include computing the greatest common divisor (GCD) using both iterative and bitwise methods, least common multipl...
0.711413
Data_Structure_28404
C
[ "improved_gcd", "efficient_lcm", "trailing_zero_count", "gcd_with_bitwise", "__builtin_ctz" ]
5
[ [ "efficient_lcm", "improved_gcd" ], [ "gcd_with_bitwise", "__builtin_ctz" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f0d96355cf763b6ce1e2d4794cecd48ab743fa37
c9a7f7135905f4914429cf11eaba6434ea87779f
v1.0
complete
Data_Structure
Data_Structure_29304_C
from typing import List, Tuple def find_first_and_last_occurrence(arr: List[int], key: int) -> Tuple[int, int]: """ Given a sorted array `arr` and an integer `key`, find both the first and last occurrence indices of the key. If the key is not found, return (-1, -1). >>> find_first_and_last_occurr...
def ternary_search(arr, key, left, right): while right >= left: mid1 = left + (right - left) // 3 mid2 = right - (right - left) // 3 if arr[mid1] == key: return mid1 if arr[mid2] == key: return mid2 if key < arr[mid1]: rig...
from solution import find_first_and_last_occurrence def test_find_first_and_last_occurrence(): assert find_first_and_last_occurrence([1, 2, 2, 2, 3, 4, 5], 2) == (1, 3) assert find_first_and_last_occurrence([1, 1, 1, 1, 1], 1) == (0, 4) assert find_first_and_last_occurrence([1, 2, 3, 4, 5], 6) == (-1, -1) ...
[ { "docstring": null, "function_declaration": "def ternary_search(arr, key, left, right):", "function_name": "ternary_search", "parameter_list": "(arr, key, left, right)" }, { "docstring": null, "function_declaration": "def find_first_occurrence(arr, key, index):", "function_name": "f...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def ternary_search(arr, key, left, right):\n while right >= left:\n mid1 = left + (right - left) // 3\n mid2 = right - (right - left) // 3\n ...
trial_gpt4o_0
{ "original_instruction": "**Given Task**:\nYou are required to implement the ternary search algorithm and then extend it to find the boundary indices of a given key in a sorted array. Specifically, find the first and the last occurrence indices of the key.\n\n**Scenario**:\nYou are given a sorted array of integers a...
0.620804
Data_Structure_29304
C
[ "ternary_search", "find_first_occurrence", "find_last_occurrence", "find_first_and_last_occurrence" ]
4
[ [ "find_first_and_last_occurrence", "find_first_occurrence" ], [ "find_first_and_last_occurrence", "find_last_occurrence" ], [ "find_first_and_last_occurrence", "ternary_search" ] ]
3
[]
false
[]
false
pytest
true
[]
true
285e7d4d23c1aea37a0944acbd524647102f2949
52e809660c7beb992b402cb583c366fdebfad591
v1.0
complete
Data_Structure
Data_Structure_28706_C
from typing import List def sort_even_indices_desc(arr: List[int]) -> List[int]: """ Sort the elements at even indices in an array in descending order using Merge Sort, while leaving the elements at odd indices unchanged. >>> sort_even_indices_desc([10, 3, 2, 7, 6, 5, 4, 1]) [10, 3, 6, 7, 4, 5, 2, 1] >...
from typing import List def merge_sort_desc(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort_desc(arr[:mid]) right = merge_sort_desc(arr[mid:]) return merge_desc(left, right) def merge_desc(left: List[int], right: List[int]) -> List[int]: ...
def test_sort_even_indices_desc_all_even(): assert sort_even_indices_desc([10, 3, 2, 7, 6, 5, 4, 1]) == [10, 3, 6, 7, 4, 5, 2, 1] def test_sort_even_indices_desc_empty(): assert sort_even_indices_desc([]) == [] def test_sort_even_indices_desc_single_element(): assert sort_even_indices_desc([5]) == [5] de...
[ { "docstring": null, "function_declaration": "def merge_sort_desc(arr):", "function_name": "merge_sort_desc", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_desc(left, right):", "function_name": "merge_desc", "parameter_list": "(left, right)"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort_desc(arr: List[int]) -> List[int]:\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]...
trial_gpt4o_2
{ "original_instruction": "### Sort Even Indexed Elements in Descending Order Using Merge Sort\n\n**Problem Statement**:\n\nYour task is to implement a function that sorts the elements at even indices in an array in descending order, while leaving the elements at odd indices unchanged. Use the Merge Sort algorithm fo...
0.820446
Data_Structure_28706
C
[ "merge_sort_desc", "merge_desc", "sort_even_indices_desc" ]
3
[ [ "merge_sort_desc", "merge_desc" ], [ "sort_even_indices_desc", "merge_sort_desc" ] ]
2
[]
false
[]
false
pytest
false
[]
true
d8baa60dda50e27242b6fe1a1592440e96566134
b3b1539473c13dd39dc27ac1bf52e2691e870880
v1.0
complete
Data_Structure
Data_Structure_28514_C
def bucket_sort_floats(arr): ''' Bucket Sort for floating point numbers between 0 and 1 ''' num_buckets = len(arr) buckets = [[] for _ in range(num_buckets)] for value in arr: index = int(value * num_buckets) buckets[index].append(value) sorted_list = [] for i in range(num_bucket...
def bucket_sort_floats(arr): ''' Bucket Sort for floating point numbers between 0 and 1 ''' num_buckets = len(arr) if num_buckets <= 1: return arr buckets = [[] for _ in range(num_buckets)] for value in arr: index = int(value * num_buckets) buckets[index].append(value) so...
from solution import bucket_sort_floats def test_bucket_sort_floats_basic(): assert bucket_sort_floats([0.34, 0.23, 0.55, 0.14, 0.95]) == [0.14, 0.23, 0.34, 0.55, 0.95] def test_bucket_sort_floats_duplicates(): assert bucket_sort_floats([0.5, 0.5, 0.5, 0.5]) == [0.5, 0.5, 0.5, 0.5] def test_bucket_sort_float...
[ { "docstring": "Bucket Sort for floating point numbers between 0 and 1 ", "function_declaration": "def bucket_sort_floats(arr):", "function_name": "bucket_sort_floats", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def next_sort(arr):", "function_name": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def bucket_sort_floats(arr):\n ''' Bucket Sort for floating point numbers between 0 and 1 '''\n if not arr:\n return []\n \n num_buckets = ...
trial_gpt4o_1
{ "original_instruction": "### Bucket Sort Implementation\n\n#### Scenario\nImagine you have been given an array of floating-point numbers between 0 and 1, and you need to sort these numbers. The values are assumed to be uniformly distributed.\n\n### Task\nImplement a function `bucket_sort_floats` that performs the b...
0.656191
Data_Structure_28514
C
[ "bucket_sort_floats", "next_sort" ]
2
[ [ "bucket_sort_floats", "next_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4dfcb1d2d2ae2492de66aa7208b2c0632176586d
70d9de46bc364a11b9415ce125b2b7388145d36a
v1.0
complete
Data_Structure
Data_Structure_28974_C
import random def is_prime(num: int) -> bool: """ Returns True if the provided number is prime, otherwise False. Optimize to handle numbers larger than 10^5. """ def optimized_modinv(a: int, m: int) -> int: """ Returns the modular inverse of `a` mod `m` using the Extended Euclidean Algor...
import random def is_prime(num: int) -> bool: """ Returns True if num is a prime number, otherwise False. Uses the Miller-Rabin primality test. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False def miller_ra...
from solution import is_prime, optimized_modinv, encrypt_string, decrypt_string, generate_key def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(29) == True assert is_prime(97) == True assert is_prime(100001) == False def test...
[ { "docstring": "Returns True if num is a prime number, otherwise False.\nUses the Miller-Rabin primality test.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the modular inverse of a modulus m using the Extend...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n return True\n ...
trial_gpt4o_3
{ "original_instruction": "### Encryption Examination\n\nWe want to simulate a simple secure messaging system using RSA asymmetric encryption. Given RSA's complexity and implementation constraints, your task is to:\n\n1. Implement an efficient primality test for generating large primes.\n2. Optimize the modular inver...
0.598821
Data_Structure_28974
C
[ "is_prime", "optimized_modinv", "encrypt_string", "decrypt_string", "generate_key" ]
5
[ [ "generate_key", "is_prime" ], [ "generate_key", "optimized_modinv" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9d2d2132c76cabb848c69bc3a415014763b5d599
b1623c5520355ca75cb8837d6459b7671bfd8f59
v1.0
complete
Data_Structure
Data_Structure_29168_C
from typing import List def solve_chinese_remainder_optimized(nums: List[int], rems: List[int]) -> int: """ Solve the system of simultaneous linear congruences using the Chinese Remainder Theorem. Args: nums (List[int]): A list of positive integers, where all integers are pairwise coprime. rems (List[...
from typing import List from functools import reduce from math import gcd def modular_inverse(a, m): m0, x0, x1 = m, 0, 1 while a > 1: q = a // m m, a = a % m, m x0, x1 = x1 - q * x0, x0 return x1 + m0 if x1 < 0 else x1 def solve_chinese_remainder_optimized(nums: List[int], rems: L...
from solution import solve_chinese_remainder_optimized def test_basic_functionality(): nums = [3, 5, 7] rems = [2, 3, 2] assert solve_chinese_remainder_optimized(nums, rems) == 23 def test_single_congruence(): nums = [7] rems = [5] assert solve_chinese_remainder_optimized(nums, rems) == 5 def...
[ { "docstring": null, "function_declaration": "def modular_inverse(a, m):", "function_name": "modular_inverse", "parameter_list": "(a, m)" }, { "docstring": null, "function_declaration": "def solve_chinese_remainder_optimized(nums, rems):", "function_name": "solve_chinese_remainder_op...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom functools import reduce\nimport math\n\ndef solve_chinese_remainder_optimized(nums: List[int], rems: List[int]) -> int:\n if ...
trial_gpt4o_8
{ "original_instruction": "#### Scenario\nYou are part of a team working on a project to implement cryptographic protocols in a secure communication system. To ensure the correct functioning of your protocol, you need to solve systems of simultaneous linear congruences efficiently.\n\n### Problem Statement\nWrite a f...
0.565672
Data_Structure_29168
C
[ "modular_inverse", "solve_chinese_remainder_optimized" ]
2
[ [ "solve_chinese_remainder_optimized", "modular_inverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5559cc1a9f8946ca5ce867f95a3f24a539350c89
8c975f5ebacea217307de3a6b231f773a8dae8be
v1.0
complete
Data_Structure
Data_Structure_29535_C
from typing import List def find_primitive_roots(n: int) -> List[int]: """Given a positive integer n, return a list of primitive roots of n. >>> find_primitive_roots(7) [3, 5] >>> find_primitive_roots(12) [] """
from math import gcd from sympy import isprime, primefactors from functools import reduce def euler_totient(n): """Calculate Euler's Totient function φ(n).""" if n == 1: return 1 factors = set(primefactors(n)) phi = n for p in factors: phi *= (1 - 1/p) return int(phi) def is_pr...
from solution import find_primitive_roots def test_find_primitive_roots(): assert find_primitive_roots(7) == [3, 5] assert find_primitive_roots(12) == [] assert find_primitive_roots(5) == [2, 3] assert find_primitive_roots(11) == [2, 6, 7, 8] assert find_primitive_roots(15) == [] assert find_pr...
[ { "docstring": "Calculate Euler's Totient function φ(n).", "function_declaration": "def euler_totient(n):", "function_name": "euler_totient", "parameter_list": "(n)" }, { "docstring": "Check if g is a primitive root of n by verifying its order.", "function_declaration": "def is_primitive...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom sympy import isprime, primefactors\nfrom functools import reduce\n\ndef euler_totient(n):\n \"\"\"Calculate Euler's Totient func...
trial_gpt4o_0
{ "original_instruction": "Finding Special Numbers\n\nYou are given a positive integer \\( n \\). Write a program to find all primitive roots of \\( n \\). Note that not all integers have primitive roots.\n\n### Input\n* A single integer \\( n \\) (1 \\( \\leq n \\leq 10^6 \\)).\n\n### Output\n* A list of integers wh...
0.519588
Data_Structure_29535
C
[ "euler_totient", "is_primitive_root", "find_primitive_roots" ]
3
[ [ "find_primitive_roots", "euler_totient" ], [ "find_primitive_roots", "is_primitive_root" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
d4992ddab5d837c75f16fb8c1ea57f2dbbff838c
b09651f07a5343d81493034afe499f83e34755d0
v1.0
complete
Data_Structure
Data_Structure_29225_C
import random def prime_check(num): """Check if a number is prime.""" # Implementation here def find_primitive_root(n): """Find primitive roots modulo n.""" # Implementation here def alice_private_key(p): """Generate Alice's private key.""" # Implementation here def bob_private_key(p): "...
import random def prime_check(num): """Check if a number is prime.""" if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
import pytest from solution import prime_check, find_primitive_root, alice_private_key, bob_private_key, alice_public_key, bob_public_key, alice_shared_key, bob_shared_key, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(2) == True assert prime_check(4) == False assert prime_check(23...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Find primitive roots modulo n.", "function_declaration": "def find_primitive_root(n):", "function_name": "find_p...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef prime_check(num):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n elif num <= 3:\n ...
trial_gpt4o_6
{ "original_instruction": "### Diffie-Hellman Key Exchange Validation\n\nIn the context of secure communication, the Diffie-Hellman key exchange is used to allow two parties to securely share a symmetric key over an insecure channel. Based on the following code snippets and your understanding:\n\n1. `def prime_check(...
0.551805
Data_Structure_29225
C
[ "prime_check", "find_primitive_root", "alice_private_key", "bob_private_key", "alice_public_key", "bob_public_key", "alice_shared_key", "bob_shared_key", "diffie_hellman_key_exchange" ]
9
[ [ "diffie_hellman_key_exchange", "alice_private_key" ], [ "diffie_hellman_key_exchange", "alice_public_key" ], [ "diffie_hellman_key_exchange", "alice_shared_key" ], [ "diffie_hellman_key_exchange", "bob_private_key" ], [ "diffie_hellman_key_exchange", "bob_pu...
9
[]
false
[]
false
pytest
true
[]
true
0b06a84d32ecddef61bcc9befaaad32ac7cc9af7
d2c6f57deb7fdbcbc9c4732436b10338737017eb
v1.0
complete
Data_Structure
Data_Structure_29414_C
def generate_key(k: int, seed: int=None) -> (int, int, int): """ Generates RSA keys of approximate k bits in length. If seed is provided, the generation should be consistent. """ pass def encrypt(data: int, e: int, n: int) -> int: """ Encrypts integer data using public key (e, n). """ pass ...
import random from sympy import mod_inverse def generate_key(k, seed=None): if seed is not None: random.seed(seed) def get_prime(bit_length): while True: candidate = random.getrandbits(bit_length) if is_prime(candidate): return candidate p = get_pri...
from solution import generate_key, encrypt, decrypt, is_prime def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(1) assert not is_prime(0) assert not is_prime(-7) def test_generate_key(): n, e, d = generate_key(16, s...
[ { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "parameter_list": "(k, seed=None)" }, { "docstring": null, "function_declaration": "def encrypt(data, e, n):", "function_name": "encrypt", "parameter_list": "(data, e,...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime\nfrom sympy.core.numbers import mod_inverse\n\ndef generate_key(k, seed=None):\n if seed is not None:\n ran...
trial_gpt4o_2
{ "original_instruction": "### Scenario\nYou are implementing a secure communications software. As part of this software, you must include an RSA encryption system to ensure that messages can be securely transmitted. Your task is to implement the RSA key generation and encryption/decryption functions along with addit...
0.674624
Data_Structure_29414
C
[ "generate_key", "encrypt", "decrypt", "is_prime" ]
4
[ [ "generate_key", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
a2ce8ca9f8c7a859a3cd188e558f5dc7c6899d94
e7a7931e839bd5057b51399db5ebe98682b9e779
v1.0
complete
Data_Structure
Data_Structure_29109_C
def hybrid_heap_sort(arr: [int]) -> [int]: """ Perform a hybrid heap sort using both max-heap and min-heap. The first half of sorting is done using max-heap (building heap), and the second half using min-heap (extracting elements in sorted order). Args: arr (list of int): The list of integers t...
import heapq def hybrid_heap_sort(arr): """ Perform a hybrid heap sort using both max-heap and min-heap. The first half of sorting is done using max-heap (building heap), and the second half using min-heap (extracting elements in sorted order). """ n = len(arr) if n <= 1: retur...
from solution import hybrid_heap_sort def test_hybrid_heap_sort_empty(): assert hybrid_heap_sort([]) == [] def test_hybrid_heap_sort_single_element(): assert hybrid_heap_sort([1]) == [1] def test_hybrid_heap_sort_sorted_array(): assert hybrid_heap_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_hybrid...
[ { "docstring": "Perform a hybrid heap sort using both max-heap and min-heap.\nThe first half of sorting is done using max-heap (building heap),\nand the second half using min-heap (extracting elements in sorted order).", "function_declaration": "def hybrid_heap_sort(arr):", "function_name": "hybrid_heap...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i, min_heap=False):\n \"\"\"\n Helper function to maintain the heap property.\n It works as a min-heap or max-heap based on the m...
trial_gpt4o_2
{ "original_instruction": "**Context:** Suppose you have been hired by a tech company to optimize their data processing system. One of their requirements is to enhance the performance of the sorting sub-routine in their system. The current system uses a heap sort algorithm and you are required to improve it by implem...
0.663411
Data_Structure_29109
C
[ "hybrid_heap_sort", "heapify" ]
2
[ [ "hybrid_heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
342f38f8c0f622051486c6d9ce4a4d6a6e01d8d4
40a5647292b7be1bb96e8fe83e3e06d22e2b7fac
v1.0
complete
Data_Structure
Data_Structure_29460_C
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): """ Insert 'key' into the BST with 'root' being the root of the BST. If the value already exists, do not insert it. >>> root = None >>> root = insert(root, 5) ...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): if root is None: return TreeNode(key) if key < root.val: root.left = insert(root.left, key) elif key > root.val: root.right = insert(roo...
from solution import TreeNode, insert, search, delete def test_insert_and_search_empty_tree(): root = None root = insert(root, 5) assert search(root, 5) == True def test_insert_multiple_values(): root = None root = insert(root, 5) root = insert(root, 3) root = insert(root, 7) assert se...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef in...
trial_gpt4o_1
{ "original_instruction": "You are tasked with building and managing a Binary Search Tree (BST). Specifically, you will implement a function that allows for inserting new values into the BST, another function to search for a value, and a final function to delete a value.\n\n### Function Requirements\n\n1. **Function ...
0.591705
Data_Structure_29460
C
[ "insert", "search", "delete", "minValueNode" ]
4
[ [ "delete", "minValueNode" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
b3ee0f50022054d729be6cf16ba25e831a0b8c5a
2aa70c0d61529d6b2d6815bf2fbd69dcd715e161
v1.0
complete
Data_Structure
Data_Structure_29522_C
from cmath import exp, pi def ifft(x): """ Compute the inverse Fast Fourier Transform (IFFT) of a given list of complex numbers using the Cooley-Tukey algorithm. Args: x (List[complex]): A list of complex numbers with length N, where N is a power of 2. Returns: List[complex]: The inverse FFT ...
from cmath import exp, pi def ifft(x): """ Recursive implementation of the Cooley-Tukey IFFT algorithm. """ N = len(x) if N == 1: return x # Conjugate the input x_conj = [xi.conjugate() for xi in x] # Apply FFT to the conjugated input y = fft(x_conj) # Conjugate the r...
from solution import ifft from cmath import isclose def test_ifft_basic(): input_data = [8.0+8.0j, 0.0+2.0j, 2.0-2.0j, -2.0+0.0j] expected_output = [2.0+2.0j, 1.0+3.0j, 3.0+1.0j, 2.0+2.0j] output_data = ifft(input_data) assert all(isclose(output_data[i], expected_output[i], rel_tol=1e-9) for i in range...
[ { "docstring": "Recursive implementation of the Cooley-Tukey IFFT algorithm.", "function_declaration": "def ifft(x):", "function_name": "ifft", "parameter_list": "(x)" }, { "docstring": "Recursive implementation of the Cooley-Tukey FFT algorithm. ", "function_declaration": "def fft(x):",...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from cmath import exp, pi\n\ndef ifft(x):\n \"\"\"\n Recursive implementation of the Cooley-Tukey IFFT algorithm.\n \"\"\"\n N = len(x)\n if N ...
trial_gpt4o_1
{ "original_instruction": "### Question\nYou are tasked with writing a function that computes the inverse Fast Fourier Transform (IFFT) of a given list of complex numbers using the Cooley-Tukey algorithm. The Inverse FFT is used to convert a signal from its frequency domain representation back to the time domain.\n\n...
0.590803
Data_Structure_29522
C
[ "ifft", "fft" ]
2
[ [ "ifft", "fft" ] ]
1
[]
false
[]
false
pytest
true
[]
true
458fc6e55123a163cc15fda82fb70124586060ef
0f61e5f7421246937a28b68e43b2879aaf645ab0
v1.0
complete
Data_Structure
Data_Structure_29395_C
from typing import List import random def bogo_sort(arr: List[int]) -> List[int]: """ Sort an array using the highly inefficient Bogo Sort algorithm. The function keeps shuffling the list until it is sorted in non-decreasing order, demonstrating the inefficiency of Bogo Sort. >>> bogo_so...
import random def is_sorted(arr): """ Helper function to check if the array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr): """ Sorts an array using the highly inefficient Bogo Sort algorithm. """ ...
from solution import bogo_sort import pytest def test_bogo_sort_already_sorted(): assert bogo_sort([1, 2, 3]) == [1, 2, 3] def test_bogo_sort_reverse_sorted(): assert bogo_sort([3, 2, 1]) == [1, 2, 3] def test_bogo_sort_random_order(): assert bogo_sort([4, 1, 3, 2]) == [1, 2, 3, 4] def test_bogo_sort_si...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sorts an array using the highly inefficient Bogo Sort algorithm.", "function_declaration": "def bog...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef is_sorted(arr: List[int]) -> bool:\n \"\"\"\n Helper function to check if the list is sorted.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers that needs to be sorted. However, instead of using an efficient sorting algorithm, you are tasked to implement the Bogo Sort algorithm to demonstrate an extreme case of algorithm inefficiency.\n\n#### Function Signature\n\n```python\ndef bogo_sort(arr: Lis...
0.544882
Data_Structure_29395
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c54d00ed6a1ccaba862d74f1fb09ef835f35c790
daf807a25e03bc4b182d87fd9e57a7d61b013dc3
v1.0
complete
Data_Structure
Data_Structure_29677_C
def find_primitive_root(n): """ Returns a list of all primitive roots of n. Parameters: - n (int): Positive integer for which to find the primitive roots. Returns: - List[int]: List of primitive roots of n. Examples: >>> find_primitive_root(1) [0] >>> find_primitiv...
def gcd(a, b): while b: a, b = b, a % b return a def euler_totient(n): if n == 1: return 1 result = n p = 2 while p * p <= n: if n % p == 0: while n % p == 0: n //= p result -= result // p p += 1 if n > 1: resul...
from solution import find_primitive_root def test_find_primitive_root_1(): assert find_primitive_root(1) == [0] def test_find_primitive_root_10(): assert find_primitive_root(10) == [3, 7] def test_find_primitive_root_13(): assert find_primitive_root(13) == [2, 6, 7, 11] def test_find_primitive_root_23()...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def euler_totient(n):", "function_name": "euler_totient", "parameter_list": "(n)" }, { "docstring": null, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_primitive_root(n):\n \"\"\"\n Returns a list of all primitive roots of n.\n \n Parameters:\n - n (int): Positive integer for which to ...
trial_gpt4o_2
{ "original_instruction": "### Programming Assessment: Finding Primitive Roots Efficiently\n\n#### Context\nAn encrypted communication system relies on primitive roots to generate secure keys. As part of the system upgrade, you are required to write an efficient function to identify all primitive roots for given inte...
0.544666
Data_Structure_29677
C
[ "gcd", "euler_totient", "all_prime_factors", "is_primitive_root", "find_primitive_root" ]
5
[ [ "find_primitive_root", "all_prime_factors" ], [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "gcd" ], [ "find_primitive_root", "is_primitive_root" ] ]
4
[]
false
[]
false
pytest
true
[]
true
57cf27cfd57d1784c7f2bf3338987ce05b60f3db
3c5c4db7a6ef9566ca6d6cb931921a83c527e0fd
v1.0
complete
Data_Structure
Data_Structure_29355_C
def custom_heap_sort(arr): """ Sort an array using a custom heap sort mechanism. This involves building a max heap for the first half of the array and a min heap for the second half, then merging them into a sorted array. Parameters: arr (list[int]): The input array of integers to sort. ...
def heapify(arr, n, i, reverse=False): """ To heapify a subtree rooted with node i which is an index in arr. n is size of heap. If reverse is True, it creates a min heap else max heap. """ largest_smallest = i left = 2 * i + 1 right = 2 * i + 2 if reverse: if left < n and a...
from solution import custom_heap_sort def test_example_case(): input_array = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] assert custom_heap_sort(input_array) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] def test_single_element(): input_array = [1] assert custom_heap_sort(input_array) == [1] def test_empty_array(): ...
[ { "docstring": "To heapify a subtree rooted with node i which is an index in arr.\nn is size of heap. If reverse is True, it creates a min heap else max heap.", "function_declaration": "def heapify(arr, n, i, reverse=False):", "function_name": "heapify", "parameter_list": "(arr, n, i, reverse=False)...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def custom_heap_sort(arr):\n \"\"\"\n Sort an array using a custom heap sort mechanism.\n \n Parameters:\n arr (list[int]): The input array...
trial_gpt4o_1
{ "original_instruction": "### Scenario\nYou are provided with an array of integers that need to be sorted using a custom sorting method based on heap properties. You have learned Max Heap Sort and Min Heap Sort algorithms, and now it's your task to implement an advanced sorting mechanism combining principles from bo...
0.653165
Data_Structure_29355
C
[ "heapify", "build_heap", "custom_heap_sort" ]
3
[ [ "build_heap", "heapify" ], [ "custom_heap_sort", "build_heap" ], [ "custom_heap_sort", "heapify" ] ]
3
[]
false
[]
false
pytest
true
[]
true
080ed83784ef5cc1e831d843230dd7425d270bf4
655dea6bc6299bdccccd0b4a48e3a1d99fde4e49
v1.0
complete
Data_Structure
Data_Structure_29617_C
def is_prime(n: int) -> bool: """ Check if a number is prime. >>> is_prime(2) True >>> is_prime(3) True >>> is_prime(4) False >>> is_prime(17) True >>> is_prime(18) False """ def next_prime_after(m: int) -> int: """ Find the smallest prime number greater than m. ...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def next_prime_after(m: int) -> int: num =...
from solution import next_prime_after, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(17) == True assert is_prime(18) == False def test_next_prime_after(): assert next_prime_after(10) == 11 assert next_prime_a...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def next_prime_after(m):", "function_name": "next_prime_after", "parameter_list": "(m)" } ]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_0
{ "original_instruction": "Next Prime Number Generator\n\n#### Context\nGiven the fundamental concept of checking for a prime number, let's extend this concept to generate the next prime number after a given integer `m`.\n\n#### Task\nWrite a function `next_prime_after(m)` that takes an integer `m` and returns the sm...
0.785817
Data_Structure_29617
C
[ "is_prime", "next_prime_after" ]
2
[ [ "next_prime_after", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
87bc1a6f17c0669e0f49ba7f510ca2260f57dc2e
64022bdaa8f4db726f4a515cc235798f44a9084c
v1.0
complete
Data_Structure
Data_Structure_29685_C
def find_pattern_occurrences(text: str, pattern: str) -> List[int]: """ Finds all starting indices where a pattern string matches within a given text string using the Knuth-Morris-Pratt algorithm. >>> find_pattern_occurrences("abracadabra", "abra") == [0, 7] >>> find_pattern_occurrences("aaaaa", "aa")...
from typing import List def compute_prefix_function(pattern: str) -> List[int]: """ Computes the prefix function (partial match table) for the KMP algorithm. """ m = len(pattern) pi = [0] * m j = 0 for i in range(1, m): while j > 0 and pattern[i] != pattern[j]: j = ...
from solution import find_pattern_occurrences def test_find_pattern_occurrences_example_case_1(): assert find_pattern_occurrences("abracadabra", "abra") == [0, 7] def test_find_pattern_occurrences_example_case_2(): assert find_pattern_occurrences("aaaaa", "aa") == [0, 1, 2, 3] def test_find_pattern_occurrenc...
[ { "docstring": "Computes the prefix function (partial match table) for the KMP algorithm.", "function_declaration": "def compute_prefix_function(pattern):", "function_name": "compute_prefix_function", "parameter_list": "(pattern)" }, { "docstring": "Finds all occurrences of the pattern in th...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef compute_lps(pattern: str) -> List[int]:\n \"\"\"\n Computes the longest proper prefix which is also a suffix array for th...
trial_gpt4o_1
{ "original_instruction": "### Question\nYou need to implement a function that uses the Knuth-Morris-Pratt algorithm to find all starting indices where a pattern string matches within a given text string. Implement the function `find_pattern_occurrences(text: str, pattern: str) -> List[int]`.\n\n#### Function Signatu...
0.656081
Data_Structure_29685
C
[ "compute_prefix_function", "find_pattern_occurrences" ]
2
[ [ "find_pattern_occurrences", "compute_prefix_function" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff8d916f633dd32e9ed7c91fa9ba12cd1fd30f40
ad70208f0d3821067bcdadbfe40af54d8e88b4d9
v1.0
complete
Data_Structure
Data_Structure_29613_C
class Node: def __init__(self, value): self.value = value self.next = None def remove_dups_from_unsorted_list(head: Node, use_set: bool = True) -> Node: """ Removes duplicates from an unsorted linked list. Args: head (Node): A pointer to the head of the singly linked list. use_...
class Node: def __init__(self, value): self.value = value self.next = None def remove_dups(head): if not head: return head node_set = set() current = head node_set.add(current.value) while current.next: if current.next.value in node_set: current....
import pytest from solution import Node, remove_dups_from_unsorted_list def construct_linked_list(values): if not values: return None head = Node(values[0]) current = head for value in values[1:]: current.next = Node(value) current = current.next return head def convert_lin...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, value):\n self.value = value\n self.next = None\n\ndef remove_dups(head):\n if not head:\n return ...
trial_gpt4o_0
{ "original_instruction": "You are provided with the implementation of a singly linked list and two functions, `remove_dups` and `remove_dups_without_set`, for removing duplicate elements from the list. Your task is to build upon this functionality to solve the following problem:\n\n### Task:\nImplement a function `r...
0.573546
Data_Structure_29613
C
[ "remove_dups", "remove_dups_without_set", "remove_dups_from_unsorted_list" ]
3
[ [ "remove_dups_from_unsorted_list", "remove_dups" ], [ "remove_dups_from_unsorted_list", "remove_dups_without_set" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
747ca2fd6caf2d0fbb4b3f2a6e862e6fb41baff3
3a4e3c1d639e35ff7ca08798db52a4930440415c
v1.0
complete
Data_Structure
Data_Structure_29059_C
def optimized_strStr(haystack: str, needle: str) -> int: """ Finds the first occurrence of the needle in the haystack string using an optimized approach for performance. Parameters: haystack (str): The main string where search is performed, length N. needle (str): The substring to find in...
def computeLPSArray(needle): """ Helper function to compute the Longest Prefix Suffix (LPS) array for KMP algorithm. """ m = len(needle) lps = [0] * m length = 0 # length of the previous longest prefix suffix i = 1 while i < m: if needle[i] == needle[length]: length...
from solution import optimized_strStr def test_optimized_strStr(): assert optimized_strStr("hello", "ll") == 2 assert optimized_strStr("aaaaa", "bba") == -1 assert optimized_strStr("", "") == 0 assert optimized_strStr("mississippi", "pi") == 9 assert optimized_strStr("mississippi", "issi") == 1 ...
[ { "docstring": "Helper function to compute the Longest Prefix Suffix (LPS) array for KMP algorithm.", "function_declaration": "def computeLPSArray(needle):", "function_name": "computeLPSArray", "parameter_list": "(needle)" }, { "docstring": "Finds the first occurrence of the needle in haysta...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_strStr(haystack, needle):\n \"\"\"\n Returns the index of the first occurrence of the needle in the haystack, or -1 if the needle is not p...
trial_gpt4o_1
{ "original_instruction": "You are given two non-negative integers `N` and `M` representing the respective lengths of the `haystack` and `needle` strings. You need to write a function `optimized_strStr(haystack, needle)` that returns the index of the first occurrence of the needle in the haystack, or -1 if the needle...
0.628044
Data_Structure_29059
C
[ "computeLPSArray", "optimized_strStr" ]
2
[ [ "optimized_strStr", "computeLPSArray" ] ]
1
[]
false
[]
false
pytest
true
[]
true
036532d2056f1cf28c0403a2c43539467007c362
4d83a81c6e1186eaed526d2e6dd13c7413d5d67f
v1.0
complete
Data_Structure
Data_Structure_29774_C
def one_sparse(array: List[Tuple[int, str]]) -> int: """ Determines if the stream is 1-sparse and returns the unique number left uncanceled, otherwise returns None. >>> one_sparse([(4, '+'), (2, '+'), (2, '-'), (4, '+'), (3, '+'), (3, '-')]) 4 >>> one_sparse([(2, '+'), (2, '+'), (2, '+'), (2, '+'), (2, ...
def one_sparse(array): """ Determines if the stream is 1-sparse. If it is, returns the unique number left uncanceled. """ value_sum = 0 sum_signs = 0 bitsum = [0] * 32 for val, sign in array: if sign == '+': value_sum += val sum_signs += 1 else: ...
import pytest from solution import one_sparse, _check_every_number_in_bitsum, _get_bit_sum def test_one_sparse_case1(): assert one_sparse([(4, '+'), (2, '+'), (2, '-'), (4, '+'), (3, '+'), (3, '-')]) == 4 def test_one_sparse_case2(): assert one_sparse([(2, '+'), (2, '+'), (2, '+'), (2, '+'), (2, '+'), (2, '+'...
[ { "docstring": "Determines if the stream is 1-sparse. If it is, returns the unique number left uncanceled.", "function_declaration": "def one_sparse(array):", "function_name": "one_sparse", "parameter_list": "(array)" }, { "docstring": "Validate the internal bit sum array", "function_dec...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def one_sparse(array):\n \"\"\"\n Determines if the stream is 1-sparse and returns the unique number.\n If the stream is not 1-sparse, returns None.\...
trial_gpt4o_1
{ "original_instruction": "### 1-Sparse Stream Recovery Algorithm Implementation\n\nYou are given a stream of tuples, where each tuple contains a number and a sign denoting an addition or a subtraction. Your task is to implement an algorithm to determine if the stream is 1-sparse, which means that, considering the si...
0.629972
Data_Structure_29774
C
[ "one_sparse", "_check_every_number_in_bitsum", "_get_bit_sum" ]
3
[ [ "one_sparse", "_check_every_number_in_bitsum" ], [ "one_sparse", "_get_bit_sum" ] ]
2
[]
false
[]
false
pytest
true
[]
true
af29ba9227e2f0a6687a0461af661af08583863a
73cc49a2d09e43c8ce5488bdde762d12a8e77ea3
v1.0
complete
Data_Structure
Data_Structure_29753_C
def roman_to_int(s: str) -> int: """ Converts a Roman numeral to an integer and validates the input. Args: s (str): A string representing a Roman numeral. Returns: int: The integer value of the Roman numeral if valid, otherwise -1. Examples: >>> roman_to_int("III") 3 ...
def roman_to_int(s: str) -> int: """ Converts a Roman numeral to an integer and validates the input. Args: s (str): A string representing a Roman numeral. Returns: int: The integer value of the Roman numeral if valid, otherwise -1. """ # Define Roman numeral values roman_nu...
from solution import roman_to_int, int_to_roman def test_roman_to_int(): """ Test conversion of Roman numeral to integer. """ assert roman_to_int("III") == 3 assert roman_to_int("IV") == 4 assert roman_to_int("IX") == 9 assert roman_to_int("LVIII") == 58 assert roman_to_int("MCMXCIV") =...
[ { "docstring": "Converts a Roman numeral to an integer and validates the input.\n\nArgs:\ns (str): A string representing a Roman numeral.\n\nReturns:\nint: The integer value of the Roman numeral if valid, otherwise -1.", "function_declaration": "def roman_to_int(s):", "function_name": "roman_to_int", ...
[ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def roman_to_int(s: str) -> int:\n roman_to_int_map = {\n 'I': 1, 'V': 5, 'X': 10, 'L': 50,\n 'C': 100, 'D': 500, 'M': 1000\n }\n \n ...
trial_gpt4o_4
{ "original_instruction": "### Question: Roman Numeral Validator and Converter\n\nIn certain historical and computer science contexts, you might need to convert Roman numerals to integers. Given a string representing a Roman numeral, your task is to create a function that not only converts the Roman numeral to an int...
0.80944
Data_Structure_29753
C
[ "roman_to_int", "int_to_roman" ]
2
[ [ "roman_to_int", "int_to_roman" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fce33b459bbb3a4d8981ebbf0c51451fdd95c859
b066f584945cb87ef9290661ecf8a5657dcdc52e
v1.0
complete
Data_Structure
Data_Structure_29009_C
def search_insert(sorted_list, value): """ Helper function to find the position to insert the value. """ left, right = 0, len(sorted_list) while left < right: mid = (left + right) // 2 if sorted_list[mid] < value: left = mid + 1 else: right = mid ...
def search_insert(sorted_list, value): """ Helper function to find the position to insert the value. """ left, right = 0, len(sorted_list) while left < right: mid = (left + right) // 2 if sorted_list[mid] < value: left = mid + 1 else: right = mid ...
from solution import insert_into_sorted_list def test_insert_middle(): sorted_list = [1, 3, 5, 6] value = 5 assert insert_into_sorted_list(sorted_list, value) == [1, 3, 5, 5, 6] def test_insert_beginning(): sorted_list = [1, 3, 5, 6] value = 0 assert insert_into_sorted_list(sorted_list, value)...
[ { "docstring": "Helper function to find the position to insert the value.", "function_declaration": "def search_insert(sorted_list, value):", "function_name": "search_insert", "parameter_list": "(sorted_list, value)" }, { "docstring": "Inserts value into sorted_list maintaining the sorted or...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from bisect import bisect_left\n\ndef insert_into_sorted_list(sorted_list, value):\n \"\"\"\n Inserts value into sorted_list maintaining the sorted orde...
trial_gpt4o_2
{ "original_instruction": "#### Context\nYou are developing a performance-optimized system for managing a sorted list of transaction records in a financial application. One crucial aspect is efficiently inserting new transactions in the correct order to maintain the sorted structure of the list. Your task is to imple...
0.669092
Data_Structure_29009
C
[ "search_insert", "insert_into_sorted_list" ]
2
[ [ "insert_into_sorted_list", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b47adce426905274ddfe93011ba43fa7b2b8e293
c01915facc20317e6c2798c68c52c3843a7d44b9
v1.0
complete
Data_Structure
Data_Structure_29319_C
def matrix_multiply(mat1, mat2): """ Multiplies two square matrices mat1 and mat2. """ n = len(mat1) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] += mat1[i][k] * mat2[k][j] return result def id...
def matrix_multiply(mat1, mat2): """ Multiplies two square matrices mat1 and mat2. """ n = len(mat1) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] += mat1[i][k] * mat2[k][j] return result def id...
def test_matrix_exponentiation(): mat1 = [ [1, 2], [3, 4] ] n1 = 2 output1 = matrix_exponentiation(mat1, n1) expected1 = [ [7, 10], [15, 22] ] assert output1 == expected1 mat2 = [ [1, 0, 0], [0, 1, 0], [0, 0, 1] ] n2 = 5 ...
[ { "docstring": "Multiplies two square matrices mat1 and mat2.", "function_declaration": "def matrix_multiply(mat1, mat2):", "function_name": "matrix_multiply", "parameter_list": "(mat1, mat2)" }, { "docstring": "Generates an identity matrix of given size.", "function_declaration": "def i...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(mat1, mat2):\n \"\"\"\n Multiplies two matrices mat1 and mat2.\n \"\"\"\n n = len(mat1)\n m = len(mat2[0])\n p = len(mat...
trial_gpt4o_2
{ "original_instruction": "**Context**: You are analyzing ecological models and require an efficient method to model exponential growth using matrix exponentiation. You've been provided with a basic framework for matrix multiplication and identity matrix generation. \n\nHowever, an essential component is missing — a ...
0.564075
Data_Structure_29319
C
[ "matrix_multiply", "identity_matrix", "matrix_exponentiation" ]
3
[ [ "matrix_exponentiation", "identity_matrix" ], [ "matrix_exponentiation", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
false
[]
true
7d6d1d1d0a9192097fb33fbeb243d009a88807a8
3749a2b7a83127df7d8f3a1ddbcae66dde0e811f
v1.0
complete
Data_Structure
Data_Structure_29892_C
from typing import List def batch_interpolation_search(array: List[int], search_keys: List[int]) -> List[int]: """ Perform a batch interpolation search for multiple keys in the array. Parameters: array (List[int]): A sorted list of unique integers. search_keys (List[int]): A list of integers t...
from typing import List def interpolation_search(array: List[int], key: int) -> int: """ Perform an interpolation search for a given key in the array. Parameters: array (List[int]): A sorted list of unique integers. key (int): The integer value to search in the array. Returns: int...
from solution import batch_interpolation_search def test_batch_interpolation_search_single_element(): array = [10] search_keys = [10, 5] assert batch_interpolation_search(array, search_keys) == [0, -1] def test_batch_interpolation_search_multiple_elements(): array = [-25, -12, -1, 10, 12, 15, 20, 41, ...
[ { "docstring": "Perform an interpolation search for a given key in the array.\n\nParameters:\narray (List[int]): A sorted list of unique integers.\nkey (int): The integer value to search in the array.\n\nReturns:\nint: The index of the key in the array if found, otherwise -1.", "function_declaration": "def ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef interpolation_search(array: List[int], key: int) -> int:\n \"\"\"\n Perform an interpolation search for a given key in th...
trial_gpt4o_0
{ "original_instruction": "#### Interpolation Search Extension\n\nYou are given a sorted array `array` of integers and a list `search_keys` containing multiple search keys. Implement a function `batch_interpolation_search` that searches for each key in `search_keys` within the `array` using the Interpolation Search a...
0.524922
Data_Structure_29892
C
[ "interpolation_search", "batch_interpolation_search" ]
2
[ [ "batch_interpolation_search", "interpolation_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
33e906002ea1eb6a64e19151c2552c9fbe557dc5
ed54d387b3e5120d05828faf7c218ba09fe835ea
v1.0
complete
Data_Structure
Data_Structure_29639_C
def gcd_bit(a: int, b: int) -> int: """ Compute the Greatest Common Divisor (GCD) of two given integers using the bitwise GCD algorithm. >>> gcd_bit(12, 18) 6 >>> gcd_bit(0, 0) 0 """ pass def lcm(a: int, b: int) -> int: """ Compute the Least Common Multiple (LCM) of two given integers u...
def gcd_bit(a: int, b: int) -> int: if a == 0: return b if b == 0: return a shift = 0 # Reduce a and b by finding the common factors of 2 while ((a | b) & 1) == 0: a >>= 1 b >>= 1 shift += 1 while (a & 1) == 0: a >>= 1 while b !...
from solution import gcd_bit, lcm def test_gcd_bit_positive_numbers(): assert gcd_bit(48, 18) == 6 def test_gcd_bit_with_one_zero(): assert gcd_bit(48, 0) == 48 assert gcd_bit(0, 18) == 18 def test_gcd_bit_with_both_zeros(): assert gcd_bit(0, 0) == 0 def test_gcd_bit_prime_numbers(): assert gcd_...
[ { "docstring": null, "function_declaration": "def gcd_bit(a, b):", "function_name": "gcd_bit", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_bit(a: int, b: int) -> int:\n \"\"\"\n Compute the GCD of two integers using the bitwise GCD algorithm.\n \"\"\"\n if a == 0:\n ret...
trial_gpt4o_2
{ "original_instruction": "#### Background\nYou are building a calculator that supports a variety of arithmetic operations. As part of this project, you need to implement some fundamental algorithms related to number theory. Specifically, you will need to calculate the Greatest Common Divisor (GCD) and Least Common M...
0.731247
Data_Structure_29639
C
[ "gcd_bit", "lcm" ]
2
[ [ "lcm", "gcd_bit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43e789d2416c8366f7fee0fe69c4e9d1e6a35f1d
bc5075d34f1c079a411bf52147a88440e150d153
v1.0
complete
Data_Structure
Data_Structure_29827_C
import random from typing import Optional, Tuple def is_prime(n: int, k: int = 40) -> bool: """ Use Miller-Rabin primality test to check if a number is prime """ pass def generate_large_prime(bits: int) -> int: """ Generate a large prime number of given bits using Miller-Rabin Test """ pass def gcd(a...
import random from typing import Optional, Tuple def is_prime(n: int, k: int = 40) -> bool: """ Use Miller-Rabin primality test to check if a number is prime """ if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False # Write n as d*2^r + 1 with d odd (by...
from solution import generate_key, is_prime def test_generate_key(): n, e, d = generate_key(16, seed=42) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert n > 0 assert e > 0 assert d > 0 def test_key_correctness(): # Testing for a small key size n...
[ { "docstring": "Use Miller-Rabin primality test to check if a number is prime ", "function_declaration": "def is_prime(n, k=40):", "function_name": "is_prime", "parameter_list": "(n, k=40)" }, { "docstring": "Generate a large prime number of given bits using Miller-Rabin Test ", "functio...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import Tuple, Optional\n\ndef is_prime(n, k=5):\n \"\"\" Test if a number is prime using the Miller-Rabin test \"\"\"\n if n ...
trial_gpt4o_1
{ "original_instruction": "### RSA Key Generation Algorithm Implementation\n\nYou are given the task of implementing a function that generates a pair of RSA keys (public and private keys). You are required to modify the existing code to improve the performance of the key generation process, specifically focusing on p...
0.59233
Data_Structure_29827
C
[ "is_prime", "generate_large_prime", "gcd", "egcd", "modinv", "generate_key" ]
6
[ [ "generate_key", "gcd" ], [ "generate_key", "generate_large_prime" ], [ "generate_key", "modinv" ], [ "generate_large_prime", "is_prime" ], [ "modinv", "egcd" ] ]
5
[]
false
[]
false
pytest
true
[]
true
9c9ea686309598db18b601835771c23c42727277
f864885b19ecdded3f06d56fea0403a5352fe72c
v1.0
complete
Data_Structure
Data_Structure_29086_C
def bfs_capacity(graph, source, sink, parent): """ Returns True if there is an augmenting path from source to sink in residual graph. Also fills parent[] to store the path. """ pass def max_flow(graph: List[List[int]]) -> int: """ Computes the maximum flow from source (0) to sink (n-1) in a dir...
from collections import deque def bfs_capacity(graph, source, sink, parent): """ Returns True if there is an augmenting path from source to sink in residual graph. Also fills parent[] to store the path. """ visited = [False] * len(graph) queue = deque([source]) visited[source] = True ...
from solution import max_flow def test_graph_with_direct_path(): graph = [[0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0]] assert max_flow(graph) == 23 def test_graph_w...
[ { "docstring": "Returns True if there is an augmenting path from source to sink in residual graph.\nAlso fills parent[] to store the path.", "function_declaration": "def bfs_capacity(graph, source, sink, parent):", "function_name": "bfs_capacity", "parameter_list": "(graph, source, sink, parent)" ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nfrom typing import List\n\ndef bfs_find_path(graph: List[List[int]], source: int, sink: int, parent: List[int]) -> bool:\n v...
trial_gpt4o_2
{ "original_instruction": "Maximum Flow Problem\n\n#### Context:\nYou are given a directed graph represented as an `n x n` adjacency matrix, where each element `graph[i][j]` represents the capacity of a directed edge from node `i` to node `j`. Your task is to compute the maximum possible flow from the source node (no...
0.547034
Data_Structure_29086
C
[ "bfs_capacity", "max_flow" ]
2
[ [ "max_flow", "bfs_capacity" ] ]
1
[]
false
[]
false
pytest
true
[]
true
12c90f3dffac86c2cc2dc588ef64d04b985a4883
55a1c97bddc8aa9d931828d9c83bf5d06f90289b
v1.0
complete
Data_Structure
Data_Structure_29866_C
from typing import List def find_order(a: int, n: int) -> int: """ Calculate the order of integer `a` modulo `n`, where the order `k` is the smallest positive integer such that `a^k ≡ 1 (mod n)`. >>> find_order(2, 5) 4 >>> find_order(3, 7) 6 """ pass def euler_totient(n: int) -> in...
from typing import List def find_order(a: int, n: int) -> int: """ Calculates the order of `a` modulo `n`, the smallest k such that a^k ≡ 1 (mod n). """ if (a % n == 0): return -1 order = 1 value = a % n while value != 1: value = (value * a) % n order += 1 ...
from solution import find_order, euler_totient, find_primitive_root def test_find_order(): assert find_order(2, 5) == 4 assert find_order(2, 6) == -1 assert find_order(3, 7) == 6 assert find_order(7, 10) == 4 def test_euler_totient(): assert euler_totient(9) == 6 assert euler_totient(10) == 4 ...
[ { "docstring": "Calculates the order of `a` modulo `n`, the smallest k such that a^k ≡ 1 (mod n).", "function_declaration": "def find_order(a, n):", "function_name": "find_order", "parameter_list": "(a, n)" }, { "docstring": "Calculates Euler's totient function φ(n), the count of integers up...
[ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from math import gcd\nfrom typing import List\n\ndef find_order(a: int, n: int) -> int:\n \"\"\"\n Returns the order of integer a modulo n, or -1 if no ...
trial_gpt4o_3
{ "original_instruction": "Optimized Primitive Root Finder\n\nYou are tasked to write an optimized version of the primitive root finder algorithms provided. Specifically, implement the following functions:\n\n#### Function Signature:\n```python\ndef find_order(a: int, n: int) -> int:\n pass\n\ndef euler_totient(n:...
0.624507
Data_Structure_29866
C
[ "find_order", "euler_totient", "find_primitive_root", "gcd" ]
4
[ [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ], [ "find_primitive_root", "gcd" ] ]
3
[]
false
[]
false
pytest
true
[]
true
d75f8ec8eaff85143ef9fac5df2037ba2fa45357
c09611a0f061727285634d0050acdc04af88f03c
v1.0
complete
Data_Structure
Data_Structure_29600_C
def compute_gcd(a: int, b: int) -> int: """ Computes the greatest common divisor (GCD) of two non-zero integers using Euclid's Algorithm. >>> compute_gcd(48, 18) 6 >>> compute_gcd(-48, 18) 6 """ def compute_lcm(a: int, b: int) -> int: """ Computes the lowest common multiple (LC...
def compute_gcd(a: int, b: int) -> int: """ Computes the greatest common divisor (GCD) of two non-zero integers using Euclid's Algorithm. """ a = abs(a) b = abs(b) while b: a, b = b, a % b return a def compute_lcm(a: int, b: int) -> int: """ Computes the lowest common multip...
from solution import compute_gcd, compute_lcm def test_compute_gcd(): assert compute_gcd(48, 18) == 6 assert compute_gcd(-48, 18) == 6 assert compute_gcd(48, -18) == 6 assert compute_gcd(-48, -18) == 6 assert compute_gcd(17, 13) == 1 assert compute_gcd(0, 5) == 5 # edge case assert compute...
[ { "docstring": "Computes the greatest common divisor (GCD) of two non-zero integers using Euclid's Algorithm.", "function_declaration": "def compute_gcd(a, b):", "function_name": "compute_gcd", "parameter_list": "(a, b)" }, { "docstring": "Computes the lowest common multiple (LCM) of two non...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_gcd(a: int, b: int) -> int:\n \"\"\"\n Compute the greatest common divisor (GCD) of two non-zero integers using Euclid's Algorithm.\n \"\...
trial_gpt4o_2
{ "original_instruction": "Greatest Common Divisor and Least Common Multiple\n\n#### Part 1: Computation of GCD using Euclid's Algorithm\nWrite a function `compute_gcd` that computes the greatest common divisor (GCD) of two non-zero integers using Euclid's Algorithm.\n\n#### Function Signature:\n```python\ndef comput...
0.801011
Data_Structure_29600
C
[ "compute_gcd", "compute_lcm" ]
2
[ [ "compute_lcm", "compute_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
633dbcfa5519d3b5cc58ef679d6cc7a6bb62ff23
1117c3cfef43834a9b869e1933977b8030691091
v1.0
complete
Data_Structure
Data_Structure_29891_C
def extended_factorial(n: int, mod: int = None, strategy: str = 'iterative') -> int: """ Compute the factorial of a non-negative integer n optionally modulo mod using the specified strategy. Parameters: n (int): A non-negative integer whose factorial is to be computed. mod (int, optional): A positi...
def extended_factorial(n, mod=None, strategy='iterative'): """ Compute the factorial of a non-negative integer n optionally modulo mod using the specified strategy. Parameters: n (int): A non-negative integer whose factorial is to be computed. mod (int, optional): A positive integer for modulo oper...
from solution import extended_factorial def test_extended_factorial_no_mod_iterative(): assert extended_factorial(5) == 120 assert extended_factorial(0) == 1 assert extended_factorial(1) == 1 def test_extended_factorial_with_mod_iterative(): assert extended_factorial(5, 3) == 0 assert extended_fac...
[ { "docstring": "Compute the factorial of a non-negative integer n optionally modulo mod using the specified strategy.\n\nParameters:\nn (int): A non-negative integer whose factorial is to be computed.\nmod (int, optional): A positive integer for modulo operation. Defaults to None.\nstrategy (str, optional): A s...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def extended_factorial(n: int, mod: int = None, strategy: str = 'iterative') -> int:\n \"\"\"\n Compute the factorial of a non-negative integer n option...
trial_gpt4o_2
{ "original_instruction": "### Coding Task: Extended Factorial Calculation\n\n#### Context and Description\nYou are helping a research team to perform combinatorial calculations, and they require a function to compute the factorial of a number with the possibility of returning the result modulo a given value. You are...
0.71518
Data_Structure_29891
C
[ "extended_factorial", "factorial_iterative", "factorial_recursive" ]
3
[ [ "extended_factorial", "factorial_iterative" ], [ "extended_factorial", "factorial_recursive" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9e04e88d28c473a268d07f209ab0ab505f91900b
99968eff41e02f850b9a3a219c74eab53c599291
v1.0
complete
Data_Structure
Data_Structure_30058_C
import math def optimized_nearest_neighbor(x, tSet): """ Find the value associated with the nearest neighbor to vector x in tSet. >>> optimized_nearest_neighbor((2, 3), {(1, 2): "A", (4, 5): "B", (1, 3): "C"}) "C" >>> optimized_nearest_neighbor((1, 2), {(1, 2): "Match", (3, 4): "No Match"}) "Match"...
import math def euclidean_distance(a, b): """ Calculate the Euclidean distance between two vectors a and b. """ return math.sqrt(sum((a_i - b_i) ** 2 for a_i, b_i in zip(a, b))) def optimized_nearest_neighbor(x, tSet): """ Find the value associated with the nearest neighbor to vector x in tSet...
from solution import optimized_nearest_neighbor def test_nearest_neighbor_single_element(): x = (2, 3) tSet = {(1, 2): "A"} assert optimized_nearest_neighbor(x, tSet) == "A" def test_nearest_neighbor_multiple_elements(): x = (2, 3) tSet = {(1, 2): "A", (4, 5): "B", (1, 3): "C"} assert optimize...
[ { "docstring": "Calculate the Euclidean distance between two vectors a and b.", "function_declaration": "def euclidean_distance(a, b):", "function_name": "euclidean_distance", "parameter_list": "(a, b)" }, { "docstring": "Find the value associated with the nearest neighbor to vector x in tSe...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef euclidean_distance(x, y):\n \"\"\"\n Calculate the Euclidean distance between two vectors x and y.\n \"\"\"\n return math.sqrt(...
trial_gpt4o_6
{ "original_instruction": "### Nearest Neighbor Search Algorithm\n\n#### Background\nYou are tasked with implementing a crucial component of a recommendation system that quickly identifies the most similar historical data point to a newly incoming data point. This function is a simplified version of the nearest neigh...
0.619752
Data_Structure_30058
C
[ "euclidean_distance", "optimized_nearest_neighbor" ]
2
[ [ "optimized_nearest_neighbor", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7d79aa0eb55476bb214af18c3a42e73b3769e2f8
160fa557c6d35777218179c355006ac1050683ff
v1.0
complete
Data_Structure
Data_Structure_30028_C
from typing import List import random def optimized_quick_sort(arr: List[int], threshold: int) -> List[int]: """ Optimized Quick Sort with Randomized Pivot and Insertion Sort for small sub-arrays. Args: arr: A list of integers to sort. threshold: An integer threshold below which to use insertio...
from typing import List import random def insertion_sort(arr: List[int], left: int, right: int) -> None: for i in range(left + 1, right + 1): key = arr[i] j = i - 1 while j >= left and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def partition(a...
from solution import optimized_quick_sort def test_empty_array(): assert optimized_quick_sort([], 5) == [] def test_single_element(): assert optimized_quick_sort([10], 5) == [10] def test_pre_sorted_array(): assert optimized_quick_sort([1, 2, 3, 4, 5], 5) == [1, 2, 3, 4, 5] def test_reverse_sort...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "paramet...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef insertion_sort(arr, low, high):\n for i in range(low + 1, high + 1):\n key = arr[i]\n j = i - 1\n while j >= low ...
trial_gpt4o_2
{ "original_instruction": "**Question: Optimized Quick Sort with Randomized Pivot**\n\nYou are tasked with implementing an optimized version of the Quick Sort algorithm. This optimized version must address the performance bottleneck of selecting a bad pivot by using a randomized pivot. Additionally, to minimize the r...
0.660257
Data_Structure_30028
C
[ "insertion_sort", "partition", "quick_sort", "optimized_quick_sort" ]
4
[ [ "optimized_quick_sort", "quick_sort" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "partition" ] ]
3
[]
false
[]
false
pytest
true
[]
true
45784a2751514e341d5d8ce8be9c48b3127a415d
cc36aff4ea2e6d205c9bab0ba89e43582b75f231
v1.0
complete
Data_Structure
Data_Structure_30167_C
from typing import List def find_primes_in_range(start: int, end: int) -> List[int]: """ Find all prime numbers in the given range [start, end]. >>> find_primes_in_range(10, 30) [11, 13, 17, 19, 23, 29] >>> find_primes_in_range(1, 10) [2, 3, 5, 7] """
from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: retur...
from solution import find_primes_in_range def test_find_primes_in_range_basic_cases(): assert find_primes_in_range(10, 30) == [11, 13, 17, 19, 23, 29] assert find_primes_in_range(1, 10) == [2, 3, 5, 7] def test_find_primes_in_range_single_element(): assert find_primes_in_range(7, 7) == [7] assert find...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all prime numbers in the given range [start, end].", "function_declaration": "def find_primes_in_range(start, end):", ...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_1
{ "original_instruction": "### Prime Number Range Finder\n\n#### Background\nIn various applications, such as cryptography and numerical analysis, determining the prime numbers within a given range is essential. You've identified that having an efficient algorithm that can verify the primality of a number is a crucia...
0.610239
Data_Structure_30167
C
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
585f5e56d4456d5120e11cbd1729964dcbffa9a1
9ef53d31681a6d0774e6f7854c4016aa1b91c6d1
v1.0
complete
Data_Structure
Data_Structure_29967_C
from typing import Optional, List class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def insert(root: Optional[TreeNode], val: int) -> TreeNode: """ Insert a value into the BST. >>> root = insert(None, 5) >>> root = insert(root, 3) ...
from typing import Optional, List class TreeNode: def __init__(self, val=0): self.val = val self.left = None self.right = None def insert(root: Optional[TreeNode], val: int) -> TreeNode: if root is None: return TreeNode(val) if val < root.val: root.left = insert(roo...
from solution import TreeNode, insert, delete, lookup, inorder_traversal def test_insert(): root = None root = insert(root, 5) root = insert(root, 3) root = insert(root, 7) assert inorder_traversal(root) == [3, 5, 7] def test_delete_leaf_node(): root = None root = insert(root, 5) root ...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import Optional, List\n\nclass TreeNode:\n def __init__(self, val=0):\n self.val = val\n self.left = None\n self.right = N...
trial_gpt4o_1
{ "original_instruction": "You are tasked with developing a function to manage a collection of unique integer values using a Binary Search Tree (BST). Implement the core operations of a BST: insertion, deletion, and lookup. Additionally, provide a method to return the values of the BST sorted in ascending order (i.e....
0.540309
Data_Structure_29967
C
[ "insert", "min_value_node", "delete", "lookup", "inorder_traversal" ]
5
[ [ "delete", "min_value_node" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2ddec6784c52989b36d7f1fc4812dd8c083defc0
67161d39b67e88c693c3b57e9f265cc663b71bae