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_23282_C
def gcd_lcm_trailing_zeros(a: int, b: int) -> (int, int, int): """ Computes the GCD using bitwise operations, LCM, and the number of trailing zeros in the LCM. Parameters: a (int): First non-negative integer. b (int): Second non-negative integer. Returns: (int, int, int): Tuple con...
def gcd_lcm_trailing_zeros(a: int, b: int) -> (int, int, int): """ Computes the GCD using bitwise operations, LCM, and the number of trailing zeros in the LCM. Parameters: a (int): First non-negative integer. b (int): Second non-negative integer. Returns: (int, int, int): Tuple con...
def test_gcd_lcm_trailing_zeros(): assert gcd_lcm_trailing_zeros(12, 18) == (6, 36, 2) assert gcd_lcm_trailing_zeros(0, 5) == (5, 5, 0) assert gcd_lcm_trailing_zeros(10, 15) == (5, 30, 1) assert gcd_lcm_trailing_zeros(0, 0) == (0, 0, 0) assert gcd_lcm_trailing_zeros(7, 0) == (7, 7, 0) assert gcd...
[ { "docstring": "Computes the GCD using bitwise operations, LCM, and the number of trailing zeros in the LCM.\n\nParameters:\na (int): First non-negative integer.\nb (int): Second non-negative integer.\n\nReturns:\n(int, int, int): Tuple containing the GCD, LCM, and the number of trailing zeros in LCM.", "fu...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_lcm_trailing_zeros(a: int, b: int) -> (int, int, int):\n def gcd(x, y):\n if x == 0:\n return y\n if y == 0:\n ...
trial_gpt4o_4
{ "original_instruction": "You need to implement a function that combines the concepts of GCD using Euclid's algorithm and counting the number of trailing zeros using bitwise operations. Given two non-negative integers, your task is to:\n\n1. Compute their greatest common divisor (GCD) using bitwise operations.\n2. C...
0.660425
Data_Structure_23282
C
[ "gcd_lcm_trailing_zeros", "trailing_zeros" ]
2
[ [ "gcd_lcm_trailing_zeros", "trailing_zeros" ] ]
1
[]
false
[]
false
pytest
false
[]
true
07c0e7e5231016d8d6d723d159570d534dc8ed0d
bb847088e2f66d896dc05d83af1cabb7b21bf029
v1.0
complete
Data_Structure
Data_Structure_23356_C
from typing import List def trail_zero(x: int) -> int: count = 0 while x and not x & 1: count += 1 x >>= 1 return count def gcd_bit(a: int, b: int) -> int: """Calculate the greatest common divisor of two numbers using bitwise operations.""" tza = trail_zero(a) tzb = trail_zero(...
from typing import List def trailing_zero(x): count = 0 while x and not x & 1: count += 1 x >>= 1 return count def gcd_bit(a, b): if a == 0: return b if b == 0: return a tza = trailing_zero(a) tzb = trailing_zero(b) a >>= tza b >>= tzb while b: ...
from solution import multi_lcm def test_single_element(): assert multi_lcm([5]) == 5 assert multi_lcm([0]) == 0 def test_two_elements(): assert multi_lcm([4, 6]) == 12 assert multi_lcm([7, 3]) == 21 def test_multiple_elements(): assert multi_lcm([4, 6, 8]) == 24 assert multi_lcm([5, 10, 20]) ...
[ { "docstring": null, "function_declaration": "def trailing_zero(x):", "function_name": "trailing_zero", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def gcd_bit(a, b):", "function_name": "gcd_bit", "parameter_list": "(a, b)" }, { "docstring": n...
[ 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 typing import List\n\ndef trailing_zero(x: int) -> int:\n count = 0\n while x and not x & 1:\n count += 1\n x >>= 1\n return count...
trial_gpt4o_2
{ "original_instruction": "### Context\nYou are tasked with creating a library for handling various arithmetic operations needed in a number theory module. One of the crucial operations is to compute the Least Common Multiple (LCM) of multiple integers. Given that the LCM of two numbers can be derived from their Grea...
0.774929
Data_Structure_23356
C
[ "trailing_zero", "gcd_bit", "multi_lcm" ]
3
[ [ "gcd_bit", "trailing_zero" ], [ "multi_lcm", "gcd_bit" ] ]
2
[]
false
[]
false
pytest
true
[]
true
76e760220f98280ab28d5eda055d1a81cab45536
52730e07eda740f2cda09621c6aa4f44110eb4e8
v1.0
complete
Data_Structure
Data_Structure_23130_C
from typing import List def max_heap_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Sorts an array in ascending order using Max Heap Sort algorithm. If simulation is set to True, prints the current state of the heap at each step. >>> max_heap_sort([4, 10, 3, 5, 1], simulation=True) ...
def max_heapify(arr, n, i, simulation=False): 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[lar...
from solution import max_heap_sort, min_heap_sort def test_max_heap_sort_empty(): assert max_heap_sort([]) == [] def test_max_heap_sort_single_element(): assert max_heap_sort([1]) == [1] def test_max_heap_sort_multiple_elements(): arr = [4, 10, 3, 5, 1] assert max_heap_sort(arr) == [1, 3, 4, 5, 10] ...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation=False):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation=False)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr, simulation=False):", "function_name"...
[ 0, 1 ]
1
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, simulation):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n \n if left < n and arr[left] > arr[largest]:\n ...
trial_gpt4o_2
{ "original_instruction": "Given an array of integers, implement both Max Heap Sort and Min Heap Sort to sort the array in ascending order. You need to showcase your understanding by implementing the sorting algorithms and analyzing their performance.\n\nImplement two functions:\n1. `max_heap_sort(arr: List[int], sim...
0.647379
Data_Structure_23130
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
true
[]
true
ba3dd6606f30f5d2f88f561505eb1182f25c4c17
c6784473e403faf0336b724709099742f48724a6
v1.0
complete
Data_Structure
Data_Structure_22583_C
def optimized_quick_sort(arr, k): """ Sorts the array using the optimized quick sort algorithm with median-of-three pivot and insertion sort fall-back. Parameters: arr (list): list of integers to be sorted. k (int): threshold below which insertion sort is used instead of quick sort. Returns: ...
def median_of_three(arr, low, mid, high): if (arr[low] - arr[mid]) * (arr[high] - arr[low]) >= 0: return low elif (arr[mid] - arr[low]) * (arr[high] - arr[mid]) >= 0: return mid else: return high def insertion_sort(arr, low, high): for i in range(low + 1, high + 1): key ...
from solution import optimized_quick_sort def test_optimized_quick_sort_small_array(): assert optimized_quick_sort([3, 1, 2], 2) == [1, 2, 3] def test_optimized_quick_sort_with_k_larger_than_array(): assert optimized_quick_sort([10, 5, 7, 9], 5) == [5, 7, 9, 10] def test_optimized_quick_sort_with_duplicates(...
[ { "docstring": null, "function_declaration": "def median_of_three(arr, low, mid, high):", "function_name": "median_of_three", "parameter_list": "(arr, low, mid, high)" }, { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_s...
[ 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 median_of_three(arr, low, mid, high):\n if (arr[low] - arr[mid]) * (arr[high] - arr[low]) >= 0:\n return low\n elif (arr[mid] - arr[low]) * (...
trial_gpt4o_0
{ "original_instruction": "### Quick Sort Implementation with Median-of-Three Optimization\n\n#### Background\nQuick Sort is a popularly used sorting algorithm. However, its performance largely depends on the choice of pivot. The median-of-three method is an optimization technique that selects the pivot as the median...
0.609266
Data_Structure_22583
C
[ "median_of_three", "insertion_sort", "partition", "quick_sort", "optimized_quick_sort" ]
5
[ [ "optimized_quick_sort", "quick_sort" ], [ "partition", "median_of_three" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "partition" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2f79eae6b42fb895c991eeea1b67ad9797fabfb4
b72349513b5f8d9b0716481668b39cd838443167
v1.0
complete
Data_Structure
Data_Structure_23746_C
def multiply_bitwise_operator(a: int, b: int) -> int: """ Multiplies two positive integers using bitwise operations. Args: a: A positive integer. b: A positive integer. Returns: The product of the two integers. Example: >>> multiply_bitwise_operator(2, 3) 6 >>> multip...
def multiply_bitwise_operator(a: int, b: int) -> int: """ Multiplies two positive integers using bitwise operations. """ result = 0 while b > 0: if b & 1: # Check if the least significant bit is 1 result = add_bitwise(result, a) a = a << 1 # Left shift a by 1 (equivalen...
from solution import multiply_bitwise_operator def test_multiply_bitwise_operator_1(): assert multiply_bitwise_operator(2, 3) == 6 def test_multiply_bitwise_operator_2(): assert multiply_bitwise_operator(7, 8) == 56 def test_multiply_bitwise_operator_3(): assert multiply_bitwise_operator(0, 5) == 0 a...
[ { "docstring": "Multiplies two positive integers using bitwise operations.", "function_declaration": "def multiply_bitwise_operator(a, b):", "function_name": "multiply_bitwise_operator", "parameter_list": "(a, b)" }, { "docstring": "Adds two integers using bitwise operations.", "function...
[ 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 multiply_bitwise_operator(a: int, b: int) -> int:\n \"\"\"\n Multiplies two positive integers using bitwise operations.\n \"\"\"\n result = 0\...
trial_gpt4o_0
{ "original_instruction": "### Problem Description\n\nYou are provided with an algorithm that adds two positive integers using bitwise operations. To further reinforce your understanding of bitwise operations, implement a function that multiplies two positive integers without using the '*' operator.\n\n### Function S...
0.720802
Data_Structure_23746
C
[ "multiply_bitwise_operator", "add_bitwise" ]
2
[ [ "multiply_bitwise_operator", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
55be19d3eadadbf2ba60187292fcc727e6bf1b0b
3bcf52c4e23c5bbd571e17c99cece8b44e06d822
v1.0
complete
Data_Structure
Data_Structure_23395_C
def elias_gamma_encode(x: int) -> str: """Encodes an integer x using Elias Gamma coding""" pass def elias_gamma_decode(encoded: str) -> int: """Decodes a binary string encoded using Elias Gamma coding back to the integer""" pass def elias_delta_encode(x: int) -> str: """Encodes an integer x using ...
def elias_gamma_encode(x: int) -> str: """Encodes an integer x using Elias Gamma coding.""" if x <= 0: raise ValueError("Elias Gamma encoding is only defined for positive integers.") binary_representation = bin(x)[2:] # Get the binary representation of x without '0b' prefix n = len(binary_...
from solution import elias_gamma_encode, elias_gamma_decode, elias_delta_encode, elias_delta_decode def test_elias_gamma_encoding_decoding(): for x in range(1, 100): encoded = elias_gamma_encode(x) decoded = elias_gamma_decode(encoded) assert decoded == x, f"Failed for x={x}, encoded={encod...
[ { "docstring": "Encodes an integer x using Elias Gamma coding.", "function_declaration": "def elias_gamma_encode(x):", "function_name": "elias_gamma_encode", "parameter_list": "(x)" }, { "docstring": "Decodes a binary string encoded using Elias Gamma coding back to the integer.", "functi...
[ 0, 0, 0, 0, 0, 1, 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 elias_gamma_encode(x: int) -> str:\n \"\"\"\n Encodes an integer x using Elias Gamma coding.\n \"\"\"\n if x <= 0:\n raise ValueError(\...
trial_gpt4o_5
{ "original_instruction": "### Problem: Advanced Elias Coding Algorithm\n\nGiven the definitions and understanding of Elias Gamma and Elias Delta codings, your task is to implement a more advanced version of these codings that includes both encoding and decoding of positive integers. This added feature should be able...
0.509766
Data_Structure_23395
C
[ "elias_gamma_encode", "elias_gamma_decode", "elias_delta_encode", "elias_delta_decode" ]
4
[ [ "elias_delta_decode", "elias_gamma_decode" ], [ "elias_delta_encode", "elias_gamma_encode" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aee8b7d9a5a8b166786d1b464d97882ed4fc8a18
afb7785fba96f5d874358efef556e5b6128a71f4
v1.0
complete
Data_Structure
Data_Structure_23698_C
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the optimized merge sort algorithm. >>> merge_sort([6, 5, 12, 10, 9, 1]) [1, 5, 6, 9, 10, 12] >>> merge_sort([5, 4, 3, 2, 1]) [1, 2, 3, 4, 5] >>> merge_sor...
from typing import List 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 merge(arr: List[int], lef...
from solution import merge_sort def test_empty_array(): assert merge_sort([]) == [] def test_single_element_array(): assert merge_sort([1]) == [1] def test_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert merge_sort([5, 4, 3, 2, 1]) == [1,...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def merge(arr, left, mid, right):", "function_name": "merge", "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": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n # Use Insertion Sort for small sub-arrays\n def insertion_sort(sub_arr: List[i...
trial_gpt4o_1
{ "original_instruction": "### Question: Implement and Optimize Merge Sort for Large Data\n\nYou are given an array of integers, `arr`, which needs to be sorted in ascending order using the merge sort algorithm. While merge sort is efficient, it tends to use significant extra space. Your task is to:\n1. Implement the...
0.62645
Data_Structure_23698
C
[ "insertion_sort", "merge", "merge_sort_util", "merge_sort" ]
4
[ [ "merge_sort", "merge_sort_util" ], [ "merge_sort_util", "insertion_sort" ], [ "merge_sort_util", "merge" ] ]
3
[]
false
[]
false
pytest
true
[]
true
24ff58c8676b0a9873ef5e988c6c0208f2d303a5
d69f884ef4b5cfb83cfff03dfe3662ee90fcd8a2
v1.0
complete
Data_Structure
Data_Structure_23110_C
from typing import List def enhanced_bucket_sort(arr: List[int]) -> List[int]: """ Sorts an array of non-negative integers using the bucket sort mechanism. Args: arr: List of non-negative integers. Returns: Sorted list of integers in ascending order. Examples: >>> enhanced_bucket_sor...
from typing import List def insertion_sort(bucket: List[int]) -> List[int]: """ Helper function to perform insertion sort on a bucket. """ for i in range(1, len(bucket)): key = bucket[i] j = i - 1 while j >= 0 and key < bucket[j]: bucket[j + 1] = bucket[j] ...
from solution import enhanced_bucket_sort def test_enhanced_bucket_sort_empty(): assert enhanced_bucket_sort([]) == [] def test_enhanced_bucket_sort_single_element(): assert enhanced_bucket_sort([5]) == [5] def test_enhanced_bucket_sort_all_elements_same(): assert enhanced_bucket_sort([2, 2, 2, 2]) == [2...
[ { "docstring": "Helper function to perform insertion sort on a bucket.", "function_declaration": "def insertion_sort(bucket):", "function_name": "insertion_sort", "parameter_list": "(bucket)" }, { "docstring": null, "function_declaration": "def enhanced_bucket_sort(arr):", "function_...
[ 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 enhanced_bucket_sort(arr: List[int]) -> List[int]:\n if not arr:\n return [] # Edge case: empty input list\n \n ...
trial_gpt4o_2
{ "original_instruction": "You are given an array of non-negative integers. Your task is to implement a function `enhanced_bucket_sort(arr: List[int]) -> List[int]` that sorts the input array using the bucket sort mechanism provided in the below description.\n\n#### Function Signature\nThe function should have the fo...
0.631723
Data_Structure_23110
C
[ "insertion_sort", "enhanced_bucket_sort" ]
2
[ [ "enhanced_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
92605d8a014da7fd338019efecc6f71ef2dd4018
d50253f7c0221966219175102c005c4d3d189924
v1.0
complete
Data_Structure
Data_Structure_23128_C
import random from sympy import isprime, mod_inverse def generate_prime_candidate(length): """ Generate an odd integer randomly. """ p = random.getrandbits(length) p |= (1 << length - 1) | 1 return p def generate_prime_number(length): """ Generate a prime number of the specified bit length. """ ...
import random from sympy import isprime, mod_inverse def generate_prime_candidate(length): """ Generate an odd integer randomly. """ p = random.getrandbits(length) # Apply a mask to set MSB and LSB to 1 p |= (1 << length - 1) | 1 return p def generate_prime_number(length): """ Gene...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(16) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert e == 65537 def test_encryption_decryption(): n, e, d = generate_key(16) data = 42 encrypted = e...
[ { "docstring": "Generate an odd integer randomly.", "function_declaration": "def generate_prime_candidate(length):", "function_name": "generate_prime_candidate", "parameter_list": "(length)" }, { "docstring": "Generate a prime number of the specified bit length.", "function_declaration":...
[ 0, 0, 0, 1, 0, 1, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import randprime\n\ndef generate_key(k):\n \"\"\"\n Generates an RSA public/private key pair.\n \n Parameters:\n ...
trial_gpt4o_9
{ "original_instruction": "### RSA Key Generation and Encryption/Decryption\n\n**Objective**: Implement RSA key generation, encryption, and decryption algorithms to understand asymmetric cryptographic systems.\n\n### Problem Statement:\nYou are asked to implement the RSA key generation algorithm and then write functi...
0.685996
Data_Structure_23128
C
[ "generate_prime_candidate", "generate_prime_number", "generate_key", "encrypt", "decrypt" ]
5
[ [ "generate_key", "generate_prime_number" ], [ "generate_prime_number", "generate_prime_candidate" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
d404e685a12f263960ab3f8bec28dff5b6e0c8c7
c4a9f9eb5f6e02a7a5672efa13ea17350fe9b959
v1.0
complete
Data_Structure
Data_Structure_23584_C
from typing import List, Tuple import heapq def k_closest(points: List[Tuple[int, int]], k: int, origin: Tuple[int, int] = (0, 0)) -> List[Tuple[int, int]]: """ Find the k closest points to the given origin. >>> k_closest([(1, 2), (3, 4), (-1, -2), (2, 2)], 2, (0, 0)) [(1, 2), (2, 2)] >>> k_closest([(1...
import heapq from typing import List, Tuple def squared_distance(point: Tuple[int, int], origin: Tuple[int, int]) -> int: """ Calculate the squared Euclidean distance between a point and the origin. """ return (point[0] - origin[0])**2 + (point[1] - origin[1])**2 def k_closest(points: List[Tuple[int, ...
from solution import k_closest def test_k_closest_with_positive_points(): points = [(1, 2), (3, 4), (-1, -2), (2, 2)] k = 2 origin = (0, 0) result = k_closest(points, k, origin) assert set(result) == set([(1, 2), (2, 2)]) or set(result) == set([(1, 2), (-1, -2)]) or set(result) == set([(2, 2), (-1,...
[ { "docstring": "Calculate the squared Euclidean distance between a point and the origin.", "function_declaration": "def squared_distance(point, origin):", "function_name": "squared_distance", "parameter_list": "(point, origin)" }, { "docstring": "Find the k closest points to the origin.", ...
[ 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 heapq\nfrom math import sqrt\n\ndef k_closest(points, k, origin=(0, 0)):\n \"\"\"\n Returns the k closest points to the origin.\n \n :param...
trial_gpt4o_8
{ "original_instruction": "#### Context\nYou have been hired to work on a spatial analysis tool. One of the primary functions of this tool is to identify the k points that are closest to a given origin. Your task is to write a function that efficiently finds these k closest points.\n\n#### Task\nImplement a function ...
0.679877
Data_Structure_23584
C
[ "squared_distance", "k_closest" ]
2
[ [ "k_closest", "squared_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d4bd0268f92248c6f60276c44fd94dd2cdedada3
93a928fb3284f70d9aa3e1953bcc74fbfaa61190
v1.0
complete
Data_Structure
Data_Structure_23476_C
from typing import List def get_determinant(matrix: List[List[float]]) -> float: """Compute the determinant of a square matrix.""" pass def get_minor(matrix: List[List[float]], row: int, col: int) -> List[List[float]]: """Get the minor of a matrix excluding the specified row and column.""" pass def g...
from typing import List def get_determinant(matrix: List[List[float]]) -> float: """Compute the determinant of a square matrix.""" n = len(matrix) if n == 1: return matrix[0][0] if n == 2: return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0] determinant = ...
from solution import invert_matrix def test_invert_2x2_matrix(): matrix = [ [4, 7], [2, 6] ] expected = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) for r, e in zip(result, expected): assert all(abs(x - y) < 1e-9 for x, y in zip(r, e)) def...
[ { "docstring": "Compute the determinant of a square matrix.", "function_declaration": "def get_determinant(matrix):", "function_name": "get_determinant", "parameter_list": "(matrix)" }, { "docstring": "Get the minor of a matrix excluding the specified row and column.", "function_declarat...
[ 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\n\nclass MatrixError(Exception):\n \"\"\"Exception raised for errors in the input matrix.\"\"\"\n def __init__(self, message):\n...
trial_gpt4o_8
{ "original_instruction": "### Invert a Matrix\n\n**Objective**: Implement a function to find the inverse of an \\( n \\times n \\) matrix, given the matrix is invertible (i.e., it has a non-zero determinant).\n\n**Function Signature**:\n```python\ndef invert_matrix(matrix: List[List[float]]) -> List[List[float]]:\n`...
0.555371
Data_Structure_23476
C
[ "get_determinant", "get_minor", "get_matrix_of_minors", "transpose", "get_cofactor_matrix", "invert_matrix" ]
6
[ [ "get_cofactor_matrix", "get_matrix_of_minors" ], [ "get_determinant", "get_minor" ], [ "get_matrix_of_minors", "get_determinant" ], [ "get_matrix_of_minors", "get_minor" ], [ "invert_matrix", "get_cofactor_matrix" ], [ "invert_matrix", "get_deter...
7
[]
false
[]
false
pytest
true
[]
true
df765e1909ff02c5cd9496cdc48cfa84bb519316
2ef5481dad78c920c5a0628e4905d75dd2641e87
v1.0
complete
Data_Structure
Data_Structure_23513_C
def perform_radix_sort(arr): """ Implement radix sort to arrange arr in ascending order. Args: arr (List[int]): List of non-negative integers to sort. Returns: List[int]: Sorted list in ascending order. """ # Your code here return arr # Unit tests def test_perform_rad...
def counting_sort_for_radix(arr, exp): """ A helper function to perform counting sort on arr based on the digit represented by exp. Args: arr (List[int]): List of non-negative integers to sort. exp (int): The digit position to sort by. Returns: List[int]: Partially sorted list. ...
from solution import perform_radix_sort def test_perform_radix_sort_basic(): assert perform_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_perform_radix_sort_single_element(): assert perform_radix_sort([5]) == [5] def test_perform_radix_sort_same_elements(): a...
[ { "docstring": "A helper function to perform counting sort on arr based on the digit represented by exp.\n\nArgs:\narr (List[int]): List of non-negative integers to sort.\nexp (int): The digit position to sort by.\n\nReturns:\nList[int]: Partially sorted list.", "function_declaration": "def counting_sort_fo...
[ 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 perform_radix_sort(arr):\n \"\"\"\n Implement radix sort to arrange arr in ascending order.\n \n Args:\n arr (List[int]): List of non-negat...
trial_gpt4o_2
{ "original_instruction": "### Radix Sorting Implementation and Analysis\n\n#### Scenario\nYou are tasked with implementing the radix sort algorithm to sort a list of non-negative integers in increasing order. Your implementation should handle typical edge cases and provide a detailed examination of the algorithm's p...
0.642112
Data_Structure_23513
C
[ "counting_sort_for_radix", "perform_radix_sort" ]
2
[ [ "perform_radix_sort", "counting_sort_for_radix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ecc79f92d22e84a0bb0814d1f0255861ef8ac4c7
2f17f7450089bb9b66701622c952f8b02f13ffad
v1.0
complete
Data_Structure
Data_Structure_22600_C
from typing import List def insertion_sort(arr: List[float]) -> List[float]: """ Perform insertion sort on a list of floating point numbers. >>> insertion_sort([0.789, 0.123, 0.456, 0.333]) == [0.123, 0.333, 0.456, 0.789] """ pass def bucket_sort(arr: List[float]) -> List[float]: """ Sort a list o...
from typing import List def insertion_sort(arr: List[float]) -> List[float]: 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 arr[j + 1] = key return arr def bucket_sort(arr: List[float]) -> Li...
from solution import bucket_sort def test_bucket_sort(): assert bucket_sort([0.789, 0.123, 0.456, 0.333]) == [0.123, 0.333, 0.456, 0.789] assert bucket_sort([0.5, 0.7, 0.1]) == [0.1, 0.5, 0.7] assert bucket_sort([0.25, 0.85, 0.45, 0.65]) == [0.25, 0.45, 0.65, 0.85] assert bucket_sort([]) == [] asse...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_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(bucket: List[float]) -> List[float]:\n for i in range(1, len(bucket)):\n key = bucket[i]\n j = ...
trial_gpt4o_2
{ "original_instruction": "## Problem Statement\nYou are given an array of floating point numbers in the range [0, 1). Implement the `bucket_sort` function to sort this array. Each element is to be placed into bins, then bins are sorted individually using insertion sort, and finally, bins are concatenated to form the...
0.630755
Data_Structure_22600
C
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73e00d8a93ebe62e6909c81ff66769a08ee0b5cd
a363e7e5938eb81d1d26a1b44414a03e6b222f18
v1.0
complete
Data_Structure
Data_Structure_23615_C
def secure_key_exchange(p: int, a: int) -> bool: """ Secure Key Exchange: Check if the shared keys calculated by both parties (Alice and Bob) are the same using a modified Diffie-Hellman method. Args: p (int): A large prime number. a (int): A number which must be a primitive root of p. Returns...
def is_prime(n): """ Helper function to 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: return False i += 6 ...
from solution import secure_key_exchange def test_valid_exchange(): assert secure_key_exchange(23, 5) == True # 5 is a primitive root of 23 def test_invalid_non_prime_p(): assert secure_key_exchange(15, 2) == False # 15 is not prime def test_invalid_non_primitive_root(): assert secure_key_exchange(23, ...
[ { "docstring": "Helper function to check if a number is prime. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Helper function to check if `a` is a primitive root of `p`. ", "function_declaration": "def is_primitive_r...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check primality of a number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n...
trial_gpt4o_1
{ "original_instruction": "### Question: Secure Key Exchange\n\nYou are tasked with implementing a secure key exchange system similar to Diffie-Hellman where two parties (Alice and Bob) can exchange keys over an insecure channel.\n\n**Function Signature**: `secure_key_exchange(p: int, a: int) -> bool`\n\n### Input\n-...
0.56685
Data_Structure_23615
C
[ "is_prime", "is_primitive_root", "secure_key_exchange" ]
3
[ [ "is_primitive_root", "is_prime" ], [ "secure_key_exchange", "is_prime" ], [ "secure_key_exchange", "is_primitive_root" ] ]
3
[]
false
[]
false
pytest
true
[]
true
568402043e5e792cfb4d61ced3998cc93e36033d
d923e77928e02dd8843f716543e0810a90bf9f19
v1.0
complete
Data_Structure
Data_Structure_23387_C
def fast_fibonacci(n: int) -> int: """ Computes the nth Fibonacci number using matrix exponentiation. >>> fast_fibonacci(0) 0 >>> fast_fibonacci(1) 1 >>> fast_fibonacci(10) 55 >>> fast_fibonacci(50) 12586269025 """ def matrix_multiply(A, B): """ Multiplies two 2x2 matrices A and B. """ def...
def matrix_multiply(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_exponentiation(matrix, power):...
from solution import fast_fibonacci def test_fast_fibonacci_base_cases(): assert fast_fibonacci(0) == 0 assert fast_fibonacci(1) == 1 def test_fast_fibonacci_small_numbers(): assert fast_fibonacci(2) == 1 assert fast_fibonacci(3) == 2 assert fast_fibonacci(4) == 3 assert fast_fibonacci(5) == 5...
[ { "docstring": "Multiplies two 2x2 matrices A and B.", "function_declaration": "def matrix_multiply(A, B):", "function_name": "matrix_multiply", "parameter_list": "(A, B)" }, { "docstring": "Raises the 2x2 matrix to the given power using exponentiation by squaring.", "function_declaratio...
[ 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 multiply_matrices(A, B):\n \"\"\"Multiplies two 2x2 matrices A and B.\"\"\"\n return [\n [\n A[0][0] * B[0][0] + A[0][1] * B[1][0]...
trial_gpt4o_1
{ "original_instruction": "### Matrix Exponentiation - Fast Fibonacci Computation\n\n**Objective**:\nImplement a function that uses matrix exponentiation to compute large Fibonacci numbers efficiently.\n\n**Description**:\nThe Fibonacci sequence is defined as:\n- F(0) = 0\n- F(1) = 1\n- F(n) = F(n-1) + F(n-2) for n >...
0.720585
Data_Structure_23387
C
[ "matrix_multiply", "matrix_exponentiation", "fast_fibonacci" ]
3
[ [ "fast_fibonacci", "matrix_exponentiation" ], [ "matrix_exponentiation", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c0b6114bd0f4cb80b424f8c901cebc7e1917829a
f6d8df2c642ddec24151927b7c8e67c21521ba48
v1.0
complete
Data_Structure
Data_Structure_22676_C
from typing import List, Dict def does_path_exist_dfs(graph: Dict[int, List[int]], start: int, end: int) -> bool: """ Determine if a path exists from start to end using Depth-First Search (DFS). >>> graph = { >>> 0: [1, 2], >>> 1: [3, 4], >>> 2: [5], >>> 3: [], >>> 4: []...
from collections import deque from typing import List, Dict def does_path_exist_dfs(graph: Dict[int, List[int]], start: int, end: int) -> bool: """ Determine if a path exists from start to end using Depth-First Search (DFS). """ stack = [start] visited = set() while stack: node = s...
from solution import does_path_exist_dfs, does_path_exist_bfs, compare_performance def test_does_path_exist_dfs(): graph = { 0: [1, 2], 1: [3, 4], 2: [5], 3: [], 4: [], 5: [] } assert does_path_exist_dfs(graph, 0, 4) is True assert does_path_exist_dfs(gra...
[ { "docstring": "Determine if a path exists from start to end using Depth-First Search (DFS).", "function_declaration": "def does_path_exist_dfs(graph, start, end):", "function_name": "does_path_exist_dfs", "parameter_list": "(graph, start, end)" }, { "docstring": "Determine if a path exists ...
[ 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 collections import deque\nfrom typing import Dict, List\n\ndef does_path_exist_dfs(graph: Dict[int, List[int]], start: int, end: int) -> bool:\n \"\"\...
trial_gpt4o_1
{ "original_instruction": "**Graph Traversal and Path Finding**\n\nAs a software engineer, you are tasked with implementing an algorithm to determine if there exists a path between two nodes in an unweighted graph. The graph is represented as an adjacency list.\n\nYour task involves the following:\n\n1. Implement an ...
0.566409
Data_Structure_22676
C
[ "does_path_exist_dfs", "does_path_exist_bfs", "compare_performance" ]
3
[ [ "compare_performance", "does_path_exist_bfs" ], [ "compare_performance", "does_path_exist_dfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a19fb7aa0694d16ce900f2572e00508362c5e082
ebd3a197250b14bd569cab63b571e57811be42a5
v1.0
complete
Data_Structure
Data_Structure_23697_C
def enhanced_quick_sort(arr): """ Sorts an array using quick sort with median-of-three pivot selection and falls back to insertion sort for small sub-arrays. Parameters: arr (list): The list of elements to be sorted. Returns: list: Sorted list in ascending order. """ from typin...
def insertion_sort(arr, left, right): for i in range(left + 1, right + 1): key = arr[i] j = i - 1 while j >= left and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def median_of_three(arr, left, right): mid = (left + right) // 2 if arr[lef...
# Test cases for the enhanced_quick_sort function def test_basic_sort(): assert enhanced_quick_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62] def test_empty_list(): assert enhanced_quick_sort([]) == [] def test_single_element(): assert enhanced_quick_sort([1]) == [1] def test_already_sorted(): ...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def median_of_three(arr, left, right):", "function_name": "median_of_three"...
[ 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 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 and arr[j] > key:...
trial_gpt4o_2
{ "original_instruction": "### Quick Sort Enhancement\n\nYou are required to enhance the quick sort algorithm to use the \"median-of-three\" technique to choose a pivot, which helps in improving the worst-case performance on nearly sorted data. Additionally, implement edge case handling and optimized base case for su...
0.602515
Data_Structure_23697
C
[ "insertion_sort", "median_of_three", "partition", "quick_sort", "enhanced_quick_sort" ]
5
[ [ "enhanced_quick_sort", "quick_sort" ], [ "partition", "median_of_three" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "partition" ] ]
4
[]
false
[]
false
pytest
false
[]
true
f1d8e894e919f2d0c3e7a5c71d9a86b87b014b58
6578ac7d56b77c52e4e44bcdb02a1a8838c35875
v1.0
complete
Data_Structure
Data_Structure_23944_C
def minimum_spanning_tree(vertex_count: int, edges: List[Tuple[int, int, int]]) -> int: """ Implement Kruskal's Algorithm to compute the minimum spanning tree of a connected, undirected, and weighted graph. Args: vertex_count (int): Number of vertices in the graph edges (List[Tuple[int, int, in...
def find(parent, i): """ Function to find the set of an element i with path compression. """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ Function to perform union of two sets x and y by ran...
from solution import minimum_spanning_tree def test_minimum_spanning_tree_basic_case(): vertex_count = 5 edges = [(0, 1, 3), (0, 2, 8), (1, 3, 5), (2, 3, 2), (2, 4, 4), (3, 4, 6)] assert minimum_spanning_tree(vertex_count, edges) == 14 def test_minimum_spanning_tree_single_edge(): vertex_count = 2 ...
[ { "docstring": "Function to find the set of an element i with path compression.", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "Function to perform union of two sets x and y by rank.", "function_declaration": "...
[ 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 minimum_spanning_tree(vertex_count, edges):\n # Function to find the root of a node\n def find(parent, i):\n if parent[i] == i:\n ...
trial_gpt4o_2
{ "original_instruction": "### Minimum Spanning Tree with Kruskal's Algorithm\n\n**Context**:\nYou are working as a network engineer for a smart city project. You need to design an efficient network to connect various infrastructure points (nodes) with the minimum cost. Each connection between nodes has a specified c...
0.731586
Data_Structure_23944
C
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
52ae293dfcdae66b10490e97f376a9c9c8f995ed
5ff02024e5769d6a02cc501d5e1fecc824556437
v1.0
complete
Data_Structure
Data_Structure_23989_C
from typing import List def word_squares(words: List[str]) -> List[List[str]]: """ Given a list of words, find all possible "word squares" that can be formed. A word square is a set of words that reads the same horizontally and vertically. >>> word_squares(["area","lead","wall","lady","ball"]) [[...
from typing import List, Dict from collections import defaultdict def build_prefix_dict(words: List[str]) -> Dict[str, List[str]]: prefix_dict = defaultdict(list) for word in words: for i in range(len(word)): prefix_dict[word[:i]].append(word) return prefix_dict def search_word_squares...
from solution import word_squares def test_word_squares_example_1(): input_words = ["area","lead","wall","lady","ball"] output = [ ["wall","area","lead","lady"], ["ball","area","lead","lady"] ] assert word_squares(input_words) == output def test_word_squares_example_2(): input_words = ...
[ { "docstring": null, "function_declaration": "def build_prefix_dict(words):", "function_name": "build_prefix_dict", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def search_word_squares(step, word_length, square, prefix_dict, results):", "function_name"...
[ 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": "from collections import defaultdict\nfrom typing import List\n\ndef build_prefix_hash(words: List[str]) -> dict:\n \"\"\" Build a hash map for storing word...
trial_gpt4o_3
{ "original_instruction": "### Word Square Construction\n\n**Scenario**: You are tasked with developing an algorithm to solve a crossword puzzle problem. Given a list of words, you need to find all possible \"word squares\" that can be formed. A word square is a set of words that reads the same horizontally and verti...
0.634975
Data_Structure_23989
C
[ "build_prefix_dict", "search_word_squares", "word_squares" ]
3
[ [ "word_squares", "build_prefix_dict" ], [ "word_squares", "search_word_squares" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b9f9cf5efba6d0b5cc7f0f154931ee4244a76211
cdc0b86b2176aa83f4a5411a072843374fcf913c
v1.0
complete
Data_Structure
Data_Structure_24129_C
from typing import List def transform_matrix(matrix: List[List[int]], operations: List[str]) -> List[List[int]]: """ Perform multiple transformations on a given matrix, incorporating both rotation and inversion operations. >>> matrix = [ ... [1, 2, 3], ... [4, 5, 6], ... [7, 8, 9], ...
from typing import List def rotate_clockwise(matrix: List[List[int]]) -> List[List[int]]: return [list(reversed(col)) for col in zip(*matrix)] def rotate_counterclockwise(matrix: List[List[int]]) -> List[List[int]]: return rotate_clockwise(rotate_clockwise(rotate_clockwise(matrix))) def top_left_invert(matri...
from solution import transform_matrix def test_rotate_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] operations = ["rotate_clockwise"] expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3], ] assert transform_matrix(matrix, operations) == expec...
[ { "docstring": null, "function_declaration": "def rotate_clockwise(matrix):", "function_name": "rotate_clockwise", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def rotate_counterclockwise(matrix):", "function_name": "rotate_counterclockwise", "par...
[ 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 rotate_clockwise(matrix: List[List[int]]) -> List[List[int]]:\n return [list(reversed(col)) for col in zip(*matrix)]\n\ndef ...
trial_gpt4o_0
{ "original_instruction": "You are tasked with designing a function that performs multiple transformations on a given matrix, incorporating both rotation and inversion operations. The goal is to amalgamate these operations in a single function, showcasing your understanding of matrix manipulation.\n\n### Function Def...
0.542115
Data_Structure_24129
C
[ "rotate_clockwise", "rotate_counterclockwise", "top_left_invert", "bottom_left_invert", "transform_matrix" ]
5
[ [ "rotate_counterclockwise", "rotate_clockwise" ], [ "transform_matrix", "bottom_left_invert" ], [ "transform_matrix", "rotate_clockwise" ], [ "transform_matrix", "rotate_counterclockwise" ], [ "transform_matrix", "top_left_invert" ] ]
5
[]
false
[]
false
pytest
true
[]
true
fcbae91b298c1136172db18e688b5a1f5a896164
658e00cd5ac025566e957234044d8312e19a418f
v1.0
complete
Data_Structure
Data_Structure_23371_C
def min_max_heap_sort(arr: list, simulation: bool=False) -> list: """ Sort an array in ascending order by alternating between a max heap and a min heap on successive iterations. Args: arr (list): A list of integers to sort. simulation (bool): A flag to print the state of the array after each i...
def heapify(arr, n, i, is_max_heap): largest_or_smallest = i left = 2 * i + 1 right = 2 * i + 2 if is_max_heap: if left < n and arr[i] < arr[left]: largest_or_smallest = left if right < n and arr[largest_or_smallest] < arr[right]: largest_or_smallest = right ...
from solution import min_max_heap_sort def test_min_max_heap_sort_standard(): arr = [14, 3, 2, 8, 15, 17, 9] result = min_max_heap_sort(arr) assert result == [2, 3, 8, 9, 14, 15, 17] def test_min_max_heap_sort_empty(): arr = [] result = min_max_heap_sort(arr) assert result == [] def test_min_...
[ { "docstring": null, "function_declaration": "def heapify(arr, n, i, is_max_heap):", "function_name": "heapify", "parameter_list": "(arr, n, i, is_max_heap)" }, { "docstring": null, "function_declaration": "def build_heap(arr, n, is_max_heap):", "function_name": "build_heap", "pa...
[ 0, 0, 0, 0, 0, 0, 1, 1, 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 heapify(arr, n, i, max_heap=True):\n largest_or_smallest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if max_heap:\n if left < n and ...
trial_gpt4o_7
{ "original_instruction": "#### Context\nYou are given two sorting algorithms: Max Heap Sort and Min Heap Sort. These algorithms sort an array using heap structures (max heap and min heap respectively). Your task is to implement a new variant of heap sort called \"Min-Max Heap Sort\" that combines elements of both ma...
0.686889
Data_Structure_23371
C
[ "heapify", "build_heap", "min_max_heap_sort" ]
3
[ [ "build_heap", "heapify" ], [ "min_max_heap_sort", "build_heap" ] ]
2
[]
false
[]
false
pytest
true
[]
true
aa0bd87ff251c5316eac0f44be3424ec20a041c3
baa6eabed04eaa230f5a1fbc8899f3cbeb46e145
v1.0
complete
Data_Structure
Data_Structure_24212_C
def power(a: int, n: int, mod: int = None) -> int: """ Computes the power a^n using binary exponentiation. If mod is provided, returns (a^n) % mod. >>> power(2, 10) 1024 >>> power(2, 10, 1000) 24 >>> power(3, 0) 1 >>> power(3, 7) 2187 >>> power(3, 7, 100) 87...
def power(a: int, n: int, mod: int = None) -> int: """ Computes the power a^n using binary exponentiation. If mod is provided, returns (a^n) % mod. """ result = 1 base = a if mod: base = base % mod while n > 0: if n % 2 == 1: result = (result * ...
from solution import power def test_power_regular_cases(): assert power(2, 10) == 1024 assert power(3, 7) == 2187 assert power(5, 3) == 125 assert power(10, 6) == 1000000 def test_power_with_mod(): assert power(2, 10, 1000) == 24 assert power(3, 7, 100) == 87 assert power(5, 3, 13) == 8 ...
[ { "docstring": "Computes the power a^n using binary exponentiation.\n\nIf mod is provided, returns (a^n) % mod.", "function_declaration": "def power(a, n, mod=None):", "function_name": "power", "parameter_list": "(a, n, mod=None)" }, { "docstring": null, "function_declaration": "def _tes...
[ 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": "def power(a: int, n: int, mod: int = None) -> int:\n result = 1\n base = a\n\n while n > 0:\n if n % 2 == 1:\n if mod:\n ...
trial_gpt4o_8
{ "original_instruction": "### Exponentiation Problem\n\n**Problem Statement:**\n\nYou are tasked with designing a function to compute the power of a given base using binary exponentiation method. Your solution should account for both regular and modular calculations efficiently.\n\n**Function Signature:**\n```python...
0.7277
Data_Structure_24212
C
[ "power", "_test" ]
2
[ [ "_test", "power" ] ]
1
[]
false
[]
false
pytest
true
[]
true
108506eb6e46c9ea3d059104fecaff8e2b60e35f
1a3ecadfb045e3d78b48ab57a979de4f0434982a
v1.0
complete
Data_Structure
Data_Structure_24254_C
from typing import List def find_primitive_root(n: int) -> List[int]: """ Returns all primitive roots of the given positive integer `n`. If `n` has no primitive roots, return an empty list. >>> find_primitive_root(7) [3, 5] >>> find_primitive_root(1) [0] >>> find_primitive_root(10) []...
from typing import List def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def euler_totient(n: int) -> int: result = n p = 2 while p * p <= n: if n % p == 0: while n % p == 0: n //= p result -= result // p p += 1 i...
from solution import find_primitive_root def test_find_primitive_root_prime(): assert find_primitive_root(7) == [3, 5] def test_find_primitive_root_one(): assert find_primitive_root(1) == [0] def test_find_primitive_root_no_roots(): assert find_primitive_root(10) == [] def test_find_primitive_root_small...
[ { "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, 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": "from typing import List\nimport math\n\ndef euler_totient(n: int) -> int:\n \"\"\"\n Calculate Euler's Totient function for an integer n.\n \"\"\"\n ...
trial_gpt4o_7
{ "original_instruction": "**Problem Statement:**\n\nWrite an efficient Python function `find_primitive_root(n)` that returns all primitive roots of the given positive integer `n`. If `n` has no primitive roots, return an empty list. This function determines the existence of primitive roots using Euler's Totient Func...
0.514579
Data_Structure_24254
C
[ "gcd", "euler_totient", "find_order", "find_primitive_root" ]
4
[ [ "find_order", "gcd" ], [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ], [ "find_primitive_root", "gcd" ] ]
4
[]
false
[]
false
pytest
true
[]
true
30de456135bed69ce3022f4a5bd374eb153e284a
4af7b2df5f303a0cb831500db2240563c75c1826
v1.0
complete
Data_Structure
Data_Structure_24013_C
from typing import List import math 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(-3) False >>> is_prime(0) False >>> is_prime(1) False """ ...
from typing import List import math def is_prime(n: int) -> bool: if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(math.sqrt(n)) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True...
from solution import filter_primes, is_prime 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(16) == False assert is_prime(17) == True assert is_prime(-3) == False assert is_prime(0) == Fals...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def filter_primes(nums):", "function_name": "filter_primes", "parameter_list": "(nums)" } ]
[ 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\nimport math\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2...
trial_gpt4o_0
{ "original_instruction": "Implement an optimized prime-checking function and utilize it to filter out all prime numbers from a given list of integers.\n\n**Objective**:\nWrite a function, `filter_primes(nums: List[int]) -> List[int]`, that utilizes an efficient algorithm to identify and return only the prime numbers...
0.774124
Data_Structure_24013
C
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
453015e7f1b355a0e8763777a8870379d2445e17
d6a7dbf52dae14c5eac90b86d1b287baec62eb2f
v1.0
complete
Data_Structure
Data_Structure_24104_C
def diffie_hellman_key_exchange(a: int, p: int) -> bool: """ Perform the Diffie-Hellman key exchange protocol and return True if both parties compute the same shared secret, else False. >>> diffie_hellman_key_exchange(5, 11) True >>> diffie_hellman_key_exchange(2, 97) True >>> diffie_h...
def diffie_hellman_key_exchange(a: int, p: int) -> bool: """ Perform the Diffie-Hellman key exchange protocol and return True if both parties compute the same shared secret, else False. """ # Check that p is a valid prime number. if not is_prime(p): return False # Check that a is a ...
from solution import diffie_hellman_key_exchange, is_prime 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(11) == True assert is_prime(13) == True assert is_prime(15) == False assert is_pri...
[ { "docstring": "Perform the Diffie-Hellman key exchange protocol and return True\nif both parties compute the same shared secret, else False.", "function_declaration": "def diffie_hellman_key_exchange(a, p):", "function_name": "diffie_hellman_key_exchange", "parameter_list": "(a, p)" }, { "d...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def diffie_hellman_key_exchange(a, p):\n \"\"\"\n Performs Diffie-Hellman key exchange to verify both parties compute the same shared secret.\n\n Arg...
trial_gpt4o_3
{ "original_instruction": "### Diffie-Hellman Key Exchange Implementation\n\nYou are tasked with implementing a secure key exchange mechanism using the Diffie-Hellman protocol. This protocol allows two parties, Alice and Bob, to establish a shared secret key over an unsecured communication channel. \n\n#### Problem S...
0.626111
Data_Structure_24104
C
[ "diffie_hellman_key_exchange", "is_prime" ]
2
[ [ "diffie_hellman_key_exchange", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ead0e9e43b35c6d01d10d70a52aa2f0267c6d378
6084cf2ea15f72cd00858a93a0b49b4237ce3f09
v1.0
complete
Data_Structure
Data_Structure_23473_C
from typing import Tuple def generate_key(k: int, seed: int = None) -> Tuple[int, int, int]: """Generate RSA public and private keys. Args: k (int): The number of bits in the modulus `n`. seed (int, optional): Random seed for reproducibility. Defaults to None. Returns: Tuple[int, int,...
import random from sympy import isprime, mod_inverse def generate_large_prime(bits): while True: prime_candidate = random.getrandbits(bits) if isprime(prime_candidate): return prime_candidate def generate_key(k, seed=None): if seed is not None: random.seed(seed) p ...
from solution import generate_key, encrypt, decrypt def test_generate_key_deterministic(): n1, e1, d1 = generate_key(16, seed=42) n2, e2, d2 = generate_key(16, seed=42) assert n1 == n2 assert e1 == e2 assert d1 == d2 def test_encrypt_decrypt_small_message(): n, e, d = generate_key(16) mess...
[ { "docstring": null, "function_declaration": "def generate_large_prime(bits):", "function_name": "generate_large_prime", "parameter_list": "(bits)" }, { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "parameter_list"...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom Crypto.Util import number\n\ndef generate_key(k, seed=None):\n \"\"\"\n Generates RSA public and private key components.\n \n ...
trial_gpt4o_7
{ "original_instruction": "### RSA Encryption Algorithm\nYou are required to implement a secure message exchange system using the RSA encryption algorithm. The system should allow the generation of public and private keys, encryption of messages using the public key, and decryption of messages using the corresponding...
0.768019
Data_Structure_23473
C
[ "generate_large_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_large_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
446ac91ced8604bf7dca8d58439a491f2f603ae6
6c265aadfe51e449144860412e001cd9cd544f4b
v1.0
complete
Data_Structure
Data_Structure_23929_C
from typing import List def hybrid_heap_sort(arr: List[int], simulation: bool = False) -> List[int]: """ You are tasked with writing an efficient Heap Sort function that sorts an array of integers. Unlike typical Heap Sort implementations which use either a max-heap or min-heap exclusively, your task requires you ...
import heapq from typing import List def hybrid_heap_sort(arr: List[int], simulation: bool = False) -> List[int]: def print_simulation(arr): if simulation: print(arr) # Phase 1: Max-Heap sort n = len(arr) # Build a max heap for i in range(n // 2 - 1, -1, -1): heapi...
from solution import hybrid_heap_sort def test_hybrid_heap_sort(): assert hybrid_heap_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] assert hybrid_heap_sort([5, 3, 1, 4, 6]) == [1, 3, 4, 5, 6] assert hybrid_heap_sort([]) == [] assert hybrid_heap_sort([1]) == [1] assert...
[ { "docstring": null, "function_declaration": "def hybrid_heap_sort(arr, simulation=False):", "function_name": "hybrid_heap_sort", "parameter_list": "(arr, simulation=False)" }, { "docstring": null, "function_declaration": "def heapify_max(arr, n, i):", "function_name": "heapify_max",...
[ 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": "import heapq\nfrom typing import List\n\ndef hybrid_heap_sort(arr: List[int], simulation: bool = False) -> List[int]:\n def print_simulation(arr):\n ...
trial_gpt4o_0
{ "original_instruction": "You are tasked with writing an efficient Heap Sort function that sorts an array of integers. Unlike typical Heap Sort implementations which use either a max-heap or min-heap exclusively, your task requires you to implement a hybrid approach that uses a max-heap to partially sort the array a...
0.627427
Data_Structure_23929
C
[ "hybrid_heap_sort", "heapify_max" ]
2
[ [ "hybrid_heap_sort", "heapify_max" ] ]
1
[]
false
[]
false
pytest
true
[]
true
245fbabc9204d97b4edfaf21a6cf554d6a61c5af
bcb482b1bf32c4568798c6c3d7c0f630ac02602a
v1.0
complete
Data_Structure
Data_Structure_24239_C
def count_common_elements(arr1, arr2): """ Determine the number of common elements between two sorted arrays using the Binary Search algorithm. >>> count_common_elements([1, 3, 4, 6, 7, 9], [1, 2, 4, 5, 9, 10]) 3 >>> count_common_elements([1, 3, 5, 7], [2, 4, 6, 8]) 0 >>> count_common_elements([1, 2, 3,...
def binary_search(arr, target): """ Function to perform binary search on a sorted array. Returns True if target is found, otherwise returns False. """ left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return True ...
from solution import count_common_elements def test_common_elements(): arr1 = [1, 3, 4, 6, 7, 9] arr2 = [1, 2, 4, 5, 9, 10] assert count_common_elements(arr1, arr2) == 3 def test_no_common_elements(): arr1 = [1, 3, 5, 7] arr2 = [2, 4, 6, 8] assert count_common_elements(arr1, arr2) == 0 def te...
[ { "docstring": "Function to perform binary search on a sorted array.\nReturns True if target is found, otherwise returns False.", "function_declaration": "def binary_search(arr, target):", "function_name": "binary_search", "parameter_list": "(arr, target)" }, { "docstring": "Returns the numb...
[ 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 count_common_elements(arr1, arr2):\n \"\"\"\n Returns the number of common elements in two sorted arrays using Binary Search.\n \"\"\"\n def b...
trial_gpt4o_2
{ "original_instruction": "### Binary Search Challenge\n\nYou are provided with two sorted arrays of integers. Your task is to determine the number of common elements between the two arrays using the Binary Search algorithm.\n\nImplement the function `count_common_elements(arr1, arr2)` that returns the number of comm...
0.710242
Data_Structure_24239
C
[ "binary_search", "count_common_elements" ]
2
[ [ "count_common_elements", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fd66b5a3f53859dbd61305cc02cd641e6b15ddc1
6489ca3021cfee6eb41311b588a4de29cd167444
v1.0
complete
Data_Structure
Data_Structure_24072_C
class UndirectedGraphNode: def __init__(self, label): self.label = label self.neighbors = [] def shallow_copy(self): return UndirectedGraphNode(self.label) def add_neighbor(self, node): self.neighbors.append(node) def clone_graph(node: UndirectedGraphNode) -> UndirectedGr...
class UndirectedGraphNode: def __init__(self, label): self.label = label self.neighbors = [] def shallow_copy(self): return UndirectedGraphNode(self.label) def add_neighbor(self, node): self.neighbors.append(node) def clone_graph(node): def dfs(node, dic): for...
from solution import UndirectedGraphNode, clone_undirected_graph def test_empty_graph(): assert clone_undirected_graph("") == "" def test_single_node_graph(): graph_str = "0" assert clone_undirected_graph(graph_str) == graph_str def test_two_nodes_graph(): graph_str = "0,1#1" clone = clone_undire...
[]
[ 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": "class UndirectedGraphNode:\n def __init__(self, label):\n self.label = label\n self.neighbors = []\n\ndef clone_graph(node):\n if not node...
trial_gpt4o_9
{ "original_instruction": "### Question: Clone an Undirected Graph\n\nGiven an undirected graph, write a function to clone the graph. Each node in the graph contains a unique label and a list of its neighbors. You need to implement the function `clone_graph(node: UndirectedGraphNode) -> UndirectedGraphNode` that retu...
0.51299
Data_Structure_24072
C
[ "clone_graph", "parse_graph", "serialize_graph", "clone_undirected_graph" ]
4
[ [ "clone_undirected_graph", "clone_graph" ], [ "clone_undirected_graph", "parse_graph" ], [ "clone_undirected_graph", "serialize_graph" ] ]
3
[]
false
[ "UndirectedGraphNode" ]
true
pytest
true
[]
true
bfdcf65ab6baa1b7b4d3d2310f24ddbee743d6c2
b4339b2e79f7e516d98b08b141877bcc00ccb13c
v1.0
complete
Data_Structure
Data_Structure_24192_C
from typing import List def sum_dig_pow(low: int, high: int) -> List[int]: """ Identifies special numbers within a given range, where the sum of each digit raised to consecutive powers (starting from 1) equals the number itself. These are called Eureka numbers. >>> sum_dig_pow(1, 10) [1, 2, 3, 4, ...
def sum_dig_pow(low, high): """ Finds and returns a list of numbers within the specified range such that the sum of each digit of the number raised to consecutive powers equals the number itself. """ result = [] for num in range(low, high + 1): if is_eureka(num): result.appen...
from solution import sum_dig_pow def test_basic_case(): assert sum_dig_pow(1, 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9] def test_case_with_89(): assert sum_dig_pow(1, 100) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 89] def test_large_range(): assert sum_dig_pow(50, 150) == [89, 135] def test_single_value(): assert sum...
[ { "docstring": "Finds and returns a list of numbers within the specified range such that\nthe sum of each digit of the number raised to consecutive powers equals the number itself.", "function_declaration": "def sum_dig_pow(low, high):", "function_name": "sum_dig_pow", "parameter_list": "(low, high)...
[ 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 sum_dig_pow(low, high):\n \"\"\"\n Returns list of Eureka numbers within the range [low, high].\n \"\"\"\n def is_eureka(num):\n digits...
trial_gpt4o_2
{ "original_instruction": "### Digit Power Sum Identification\n\n#### Scenario\nYou are tasked with writing a function that identifies special numbers within a given range. These are numbers for which the sum of each digit raised to consecutive powers (starting from 1) equals the number itself. This concept is named ...
0.602721
Data_Structure_24192
C
[ "sum_dig_pow", "is_eureka" ]
2
[ [ "sum_dig_pow", "is_eureka" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a994fb24c2630329eafd0948ba0e66fbafef4dd8
40f31ccaff285d6a76c63b0920f0a14707561306
v1.0
complete
Data_Structure
Data_Structure_24162_C
def modified_bitonic_sort(arr, reverse=False): """ Implement a modified version of the Bitonic Sort algorithm. This version will sort arrays of integers both in increasing and decreasing order. :param arr: List of integers to be sorted. :param reverse: Boolean flag to indicate descending order sort if...
import math def bitonic_merge(arr, low, cnt, direction): if cnt > 1: k = cnt // 2 for i in range(low, low + k): if (direction and arr[i] > arr[i + k]) or (not direction and arr[i] < arr[i + k]): arr[i], arr[i + k] = arr[i + k], arr[i] bitonic_merge(arr, low, k, d...
from solution import modified_bitonic_sort def test_modified_bitonic_sort_ascending(): assert modified_bitonic_sort([3, 7, 2, 8, 1, 5, 4], False) == [1, 2, 3, 4, 5, 7, 8] def test_modified_bitonic_sort_descending(): assert modified_bitonic_sort([3, 7, 2, 8, 1, 5, 4], True) == [8, 7, 5, 4, 3, 2, 1] def test_m...
[ { "docstring": null, "function_declaration": "def bitonic_merge(arr, low, cnt, direction):", "function_name": "bitonic_merge", "parameter_list": "(arr, low, cnt, direction)" }, { "docstring": null, "function_declaration": "def bitonic_sort(arr, low, cnt, direction):", "function_name"...
[ 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": "import math\n\ndef modified_bitonic_sort(arr, reverse=False):\n \"\"\"\n Sort an array in either ascending or descending order using a modified Bitonic ...
trial_gpt4o_2
{ "original_instruction": "You are tasked with implementing a modified version of the Bitonic Sort algorithm. This version will sort arrays of integers both in increasing and decreasing order. Additionally, it must handle edge cases where the array size is not a power of two by padding the array with a maximum intege...
0.70236
Data_Structure_24162
C
[ "bitonic_merge", "bitonic_sort", "next_power_of_two", "modified_bitonic_sort" ]
4
[ [ "bitonic_sort", "bitonic_merge" ], [ "modified_bitonic_sort", "bitonic_sort" ], [ "modified_bitonic_sort", "next_power_of_two" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b80e625fd907a7d19cabd545b5e336929a61d620
2637ad0a1b82026e62f80a86c2492e64f8f46e62
v1.0
complete
Data_Structure
Data_Structure_23888_C
from typing import List def maximum_flow_bfs(graph: List[List[int]]) -> int: """ Calculate the maximum flow in a directed, weighted graph using the Edmonds-Karp algorithm. :param graph: A list of lists, which is an n x n adjacency matrix of integers, where graph[i][j] is the capacity of the edge from vert...
from typing import List from collections import deque def bfs(graph: List[List[int]], s: int, t: int, parent: List[int]) -> bool: visited = [False] * len(graph) queue = deque([s]) visited[s] = True while queue: u = queue.popleft() for ind, val in enumerate(graph[u]): ...
from solution import maximum_flow_bfs def test_maximum_flow_simple_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 maximum_flow_bfs(graph) == 23 def test_...
[ { "docstring": null, "function_declaration": "def bfs(graph, s, t, parent):", "function_name": "bfs", "parameter_list": "(graph, s, t, parent)" }, { "docstring": null, "function_declaration": "def maximum_flow_bfs(graph):", "function_name": "maximum_flow_bfs", "parameter_list": "...
[ 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\nfrom collections import deque\n\ndef bfs(graph: List[List[int]], s: int, t: int, parent: List[int]) -> bool:\n visited = [False] *...
trial_gpt4o_0
{ "original_instruction": "### Maximum Flow Challenge: Implement the Edmonds-Karp Algorithm\n\n#### Introduction\n\nYou're given the task of finding the maximum flow in a directed, weighted graph. The graph is represented as an n x n adjacency matrix, where the value at `graph[i][j]` represents the capacity of the ed...
0.634401
Data_Structure_23888
C
[ "bfs", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
73383845d7e535cd0b72fe65f261e1905ce95a6b
884b9ffb4a1babba8b72e58d7a68908b97982d57
v1.0
complete
Data_Structure
Data_Structure_24433_C
def advanced_gcd(a: int, b: int) -> int: """ Returns the greatest common divisor of a and b using bitwise operations. """ pass def advanced_lcm(a: int, b: int) -> int: """ Returns the least common multiple of a and b using an advanced GCD calculation. >>> advanced_lcm(12, 15) == 60 >>> ...
def advanced_gcd(a: int, b: int) -> int: """ Returns the greatest common divisor of a and b using bitwise operations. """ if a == b: return a if a == 0: return b if b == 0: return a # a and b are both even if (a & 1) == 0 and (b & 1) == 0: return advanced...
from solution import advanced_gcd, advanced_lcm def test_advanced_gcd(): assert advanced_gcd(12, 15) == 3 assert advanced_gcd(6, 8) == 2 assert advanced_gcd(0, 5) == 5 assert advanced_gcd(10**6, 10**6) == 10**6 assert advanced_gcd(54, 24) == 6 def test_advanced_lcm(): assert advanced_lcm(12, 1...
[ { "docstring": "Returns the greatest common divisor of a and b using bitwise operations.", "function_declaration": "def advanced_gcd(a, b):", "function_name": "advanced_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple of a and b using the advanced gcd cal...
[ 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 advanced_gcd(a: int, b: int) -> int:\n \"\"\"\n Returns the greatest common divisor of a and b using bitwise operations.\n \"\"\"\n if a == b:...
trial_gpt4o_0
{ "original_instruction": "### Question: Advanced GCD and LCM Calculation\n\nYou are tasked with implementing a function that calculates the Least Common Multiple (LCM) of two non-negative integers using an advanced GCD calculation method based on bitwise operations. Below is the detailed requirement for the task.\n\...
0.80853
Data_Structure_24433
C
[ "advanced_gcd", "advanced_lcm" ]
2
[ [ "advanced_lcm", "advanced_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e71ba681bb9f9d4d5ce007d596b3485b47ed573
a5c21637cbb0f0de241be2cefed39d2a2da07f12
v1.0
complete
Data_Structure
Data_Structure_24447_C
def optimized_gcd(a, b): """Compute the greatest common divisor of a and b. Handles negative inputs and ensures at least one of the numbers is non-zero. >>> optimized_gcd(48, 18) 6 >>> optimized_gcd(-48, 18) 6 >>> optimized_gcd(0, 18) 18 >>> optimized_gcd(18, 0) 18 >>> optimi...
def optimized_gcd(a, b): """ Compute the greatest common divisor of a and b using the Euclidean algorithm. Handles negative inputs and ensures at least one of the numbers is non-zero. """ if a == 0 and b == 0: raise ValueError("At least one of the integers must be non-zero") a, b = abs(a...
from solution import optimized_gcd, advanced_lcm, count_trailing_zeros def test_optimized_gcd(): # Test gcd with positive numbers assert optimized_gcd(48, 18) == 6 assert optimized_gcd(54, 24) == 6 # Test gcd with negative numbers assert optimized_gcd(-48, 18) == 6 assert optimized_gcd(48, -18)...
[ { "docstring": "Compute the greatest common divisor of a and b using the Euclidean algorithm.\nHandles negative inputs and ensures at least one of the numbers is non-zero.", "function_declaration": "def optimized_gcd(a, b):", "function_name": "optimized_gcd", "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 optimized_gcd(a, b):\n \"\"\"\n Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.\n \"\"\"\n if a == 0 ...
trial_gpt4o_2
{ "original_instruction": "### Question: Enhanced Greatest Common Divisor and Trailing Zero Computation\n\n#### Problem Statement\n\nYou are tasked with enhancing and improving existing number-theoretic functions. Your task includes the development of optimized and robust versions for calculating the greatest common ...
0.691641
Data_Structure_24447
C
[ "optimized_gcd", "advanced_lcm", "count_trailing_zeros" ]
3
[ [ "advanced_lcm", "optimized_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d159bfcff1546ac919b0cc162fb822badbaa6102
aa5b4aa0bd457c0703bca31066ef9a95b523a5cf
v1.0
complete
Data_Structure
Data_Structure_24231_C
def max_heap_sort(arr: list, simulation: bool=False) -> list: """ Max-Heap Sort: Sort an array of integers using the max-heap approach. Args: - arr: List[int], the input array to be sorted. - simulation: Bool, if True, return additional performance metrics. Returns: A sorted array of integers (...
import time def max_heapify(arr, n, i, simulation_count): largest = i left = 2 * i + 1 right = 2 * i + 2 if simulation_count is not None: simulation_count[0] += 1 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: larg...
from solution import max_heap_sort, min_heap_sort, compare_heap_sorts def test_max_heap_sort(): arr = [3, 1, 5, 4, 2] sorted_arr = max_heap_sort(arr[:]) assert sorted_arr == sorted(arr, reverse=False) def test_min_heap_sort(): arr = [3, 1, 5, 4, 2] sorted_arr = min_heap_sort(arr[:]) assert sor...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation_count):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation_count)" }, { "docstring": null, "function_declaration": "def min_heapify(arr, n, i, simulation_count):", "function_n...
[ 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 time\n\ndef max_heapify(arr, n, i, iterations):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n \n if left < n and arr[i] < arr[l...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers that needs to be sorted using heap sort. However, the twist is that you must implement both max-heap sort and min-heap sort, and compare their performance under different input conditions.\n\n### Requirements\n\n1. Implement heap sorting using both max-hea...
0.629533
Data_Structure_24231
C
[ "max_heapify", "min_heapify", "max_heap_sort", "min_heap_sort", "compare_heap_sorts" ]
5
[ [ "compare_heap_sorts", "max_heap_sort" ], [ "compare_heap_sorts", "min_heap_sort" ], [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
4
[]
false
[]
false
pytest
true
[]
true
82c58c78462c63a527067ae54e3ffecb62a6e563
b96719583c618d3c9d7a2d3570a9e4ffd06e773a
v1.0
complete
Data_Structure
Data_Structure_24566_C
from typing import List def enhanced_interpolation_search(array: List[int], search_key: int) -> int: """ Implement a search algorithm that efficiently handles uniform and non-uniform distribution of data. >>> enhanced_interpolation_search([-25, -12, -1, 10, 12, 15, 20, 41, 55], -1) == 2 >>> enhanced_i...
def binary_search(array, search_key, low, high): while low <= high: mid = (low + high) // 2 if array[mid] == search_key: return mid elif array[mid] < search_key: low = mid + 1 else: high = mid - 1 return -1 def enhanced_interpolation_search(ar...
from solution import enhanced_interpolation_search def test_uniform_distribution(): array = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] assert enhanced_interpolation_search(array, 7) == 3 assert enhanced_interpolation_search(array, 19) == 9 assert enhanced_interpolation_search(array, 1) == 0 assert enhance...
[ { "docstring": null, "function_declaration": "def binary_search(array, search_key, low, high):", "function_name": "binary_search", "parameter_list": "(array, search_key, low, high)" }, { "docstring": null, "function_declaration": "def enhanced_interpolation_search(array, search_key):", ...
[ 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 binary_search(array: List[int], search_key: int, low: int, high: int) -> int:\n while low <= high:\n mid = low + (hig...
trial_gpt4o_2
{ "original_instruction": "Enhanced Search Implementation\n\n**Scenario:**\nYou are working in a data science company that deals with large datasets. To efficiently search through the datasets, you need to implement a search algorithm that performs well with uniformly distributed data. Your task is to implement an en...
0.56404
Data_Structure_24566
C
[ "binary_search", "enhanced_interpolation_search" ]
2
[ [ "enhanced_interpolation_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
1ce6c08711dd472f2e5290dc4ad799973f0f4914
8165c637f105916a2cf73c65c1b49705f761175f
v1.0
complete
Data_Structure
Data_Structure_24240_C
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sort an array of integers in ascending order using the merge sort algorithm. >>> merge_sort([4, 1, 7, 3, 2, 9, 8]) [1, 2, 3, 4, 7, 8, 9] >>> merge_sort([12]) [12] >>> merge_sort([]) [] """ pass # Test cases ...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left: List[int], right: List[int]) -> List[int]...
from solution import merge_sort def test_merge_sort_basic(): assert merge_sort([4, 1, 7, 3, 2, 9, 8]) == [1, 2, 3, 4, 7, 8, 9] def test_merge_sort_single_element(): assert merge_sort([12]) == [12] def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_sorted_array(): assert mer...
[ { "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 if len(arr) <= 1:\n return arr\n \n def merge(left: List[int], r...
trial_gpt4o_2
{ "original_instruction": "### Problem Description\nYou are given an array of integers which you need to sort in ascending order using the merge sort algorithm. The provided merge sort algorithm splits the array until each sub-array contains a single element, then merges the sub-arrays by comparing the elements and s...
0.607503
Data_Structure_24240
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
13ca90e11929b7faec86acbbca214b0b5d9de5bf
e22ce5ef26855237c8016bb66fceaf4536b9d523
v1.0
complete
Data_Structure
Data_Structure_24616_C
from typing import List def bucket_sort(arr: List[int]) -> List[int]: """ Implement the Bucket Sort algorithm to sort an array of non-negative integers. It should distribute the integers into buckets and then sort each bucket using insertion sort. >>> bucket_sort([3, 6, 8, 2, 5, 10, 15, 1, 14, 9]) [1,...
from typing import List def insertion_sort(arr): 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 arr[j + 1] = key return arr def bucket_sort(arr: List[int]) -> List[int]: if len(arr) == 0:...
from solution import bucket_sort def test_bucket_sort_normal_case(): assert bucket_sort([3, 6, 8, 2, 5, 10, 15, 1, 14, 9]) == [1, 2, 3, 5, 6, 8, 9, 10, 14, 15] def test_bucket_sort_reversed(): assert bucket_sort([4, 3, 2, 1]) == [1, 2, 3, 4] def test_bucket_sort_empty(): assert bucket_sort([]) == [] def...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_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 bucket_sort(arr: List[int]) -> List[int]:\n if not arr:\n return []\n\n max_value = max(arr)\n bucket_count = l...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers, which we assume are non-negative. Implement the Bucket Sort algorithm to sort this array. You will need to both distribute the integers into buckets and sort the values within each bucket using insertion sort.\n\n### Function Signature\n```python\ndef buc...
0.617056
Data_Structure_24616
C
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad4c679960bb09ff29075655c7081925aad55d42
231354c277b67cb6b40fcb31b8e8380b3e096023
v1.0
complete
Data_Structure
Data_Structure_24756_C
def enhanced_radix_sort(arr): """ Sort a list of integers using an enhanced radix sort that handles both positive and negative integers. >>> enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) [2, 24, 45, 66, 75, 90, 170, 802] >>> enhanced_radix_sort([-5, -10, 0, -3, 8, 5, -1]) [-10, -5, -3, ...
def radix_sort(arr): """ Helper function to perform radix sort on a list of non-negative integers. """ max_element = max(arr) exp = 1 while max_element // exp > 0: counting_sort(arr, exp) exp *= 10 def counting_sort(arr, exp): """ Helper function to perform counting sort...
from solution import enhanced_radix_sort def test_enhanced_radix_sort_mixed_positive_negative(): assert enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] assert enhanced_radix_sort([-5, -10, 0, -3, 8, 5, -1]) == [-10, -5, -3, -1, 0, 5, 8] def test_enhanced_radix_sort_...
[ { "docstring": "Helper function to perform radix sort on a list of non-negative integers.", "function_declaration": "def radix_sort(arr):", "function_name": "radix_sort", "parameter_list": "(arr)" }, { "docstring": "Helper function to perform counting sort based on exponent value `exp`.", ...
[ 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 radix_sort(arr):\n \"\"\"\n Helper function to perform radix sort on a list of non-negative integers.\n \"\"\"\n max_element = max(arr)\n e...
trial_gpt4o_0
{ "original_instruction": "### Question: Implement and Extend Radix Sort with Specific Edge Cases\n\n#### Context:\nYou are required to implement a sorting function to sort a list of positive integers using the radix sort algorithm detailed above. Additionally, you should extend the radix sort to handle edge cases li...
0.707711
Data_Structure_24756
C
[ "radix_sort", "counting_sort", "enhanced_radix_sort" ]
3
[ [ "enhanced_radix_sort", "radix_sort" ], [ "radix_sort", "counting_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
558484c46b0347c04f604c4b7744fc039b795399
ed6d995eca53bdcd512e73259a22524a7103876d
v1.0
complete
Data_Structure
Data_Structure_24865_C
def secure_shared_key(g: int, p: int) -> int: """ Confirms whether p is a prime number and g is a primitive root of p. If both checks pass, performs the Diffie-Hellman key exchange between Alice and Bob and returns the shared secret key, else returns None. >>> secure_shared_key(5, 23) != None T...
def is_prime(n): """ Efficiently checks if a number n 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: return False i += 6 ...
def test_is_prime(): assert is_prime(23) == True assert is_prime(24) == False assert is_prime(2) == True assert is_prime(1) == False assert is_prime(29) == True def test_find_primitive_root(): assert find_primitive_root(23) != None # should return a valid primitive root assert find_primiti...
[ { "docstring": "Efficiently checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds a primitive root modulo p. Returns None if no such root exists.", "function_declaration": "def find_primi...
[ 0, 0, 0, 0, 1, 0, 0, 0, 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 is_prime(n):\n \"\"\"Returns True if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ...
trial_gpt4o_8
{ "original_instruction": "Secure Communication using Diffie-Hellman Key Exchange\n\n**Scenario**:\nAlice and Bob wish to communicate securely over an unencrypted channel. They decide to use the Diffie-Hellman key exchange algorithm to establish a shared secret key. \n\n**Task**:\nWrite a Python function `secure_shar...
0.529464
Data_Structure_24865
C
[ "is_prime", "find_primitive_root", "prime_factors", "diffie_hellman", "secure_shared_key" ]
5
[ [ "find_primitive_root", "is_prime" ], [ "find_primitive_root", "prime_factors" ], [ "secure_shared_key", "diffie_hellman" ], [ "secure_shared_key", "find_primitive_root" ], [ "secure_shared_key", "is_prime" ] ]
5
[]
false
[]
false
pytest
false
[]
true
4c70c62427bb5cf1ec366de78691a81e3d366c58
8ef533aa2dd46ca3d49053d8db5bfacdb9b78ace
v1.0
complete
Data_Structure
Data_Structure_24223_C
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def serialize(root): """ Encodes a tree to a single string. :type root: TreeNode :rtype: str """ def helper(node): if node is None: return "#" retu...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def serialize(root): """ Encodes a tree to a single string. :type root: TreeNode :rtype: str """ def helper(node): if node is None: return "#" retu...
from solution import TreeNode, are_trees_identical def test_identical_trees(): root1 = TreeNode(1) root1.left = TreeNode(2) root1.right = TreeNode(3) root1.right.left = TreeNode(4) root1.right.right = TreeNode(5) root2 = TreeNode(1) root2.left = TreeNode(2) root2.right = TreeNode(3...
[]
[ 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, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef serialize(root):\n \"\"\"Enco...
trial_gpt4o_1
{ "original_instruction": "### Context:\nYou are given methods to serialize and deserialize a binary tree. Serialization converts the tree into a string, and deserialization converts the string back into the original tree structure. This serialization method uses pre-order traversal and denotes null nodes with \"#\"....
0.567157
Data_Structure_24223
C
[ "serialize", "are_trees_identical" ]
2
[ [ "are_trees_identical", "serialize" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
bb5bf70223db836b0883d5affaddb37d90e1530e
5b388d0e6d3d2d091757e368b3718d9a7f08d874
v1.0
complete
Data_Structure
Data_Structure_24326_C
def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: """ Calculate the greatest common divisor of a and b along with the coefficients of Bézout's identity. >>> extended_gcd(30, 20) (10, 1, -1) >>> extended_gcd(101, 103) (1, -51, 50) """ pass def modular_inverse(a: int, m: int) -> int: ...
from typing import List, 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(a: int, m: int) -> int: gcd, x, y = extended_gcd(a, m) if gcd !...
import pytest from solution import chinese_remainder_theorem def test_crt_example(): a = [2, 3, 2] m = [3, 5, 7] assert chinese_remainder_theorem(a, m) == 23 def test_crt_single_equation(): a = [4] m = [7] assert chinese_remainder_theorem(a, m) == 4 def test_crt_large_values(): a = [1, 2,...
[ { "docstring": null, "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def modular_inverse(a, m):", "function_name": "modular_inverse", "parameter_list": "(a, m)" }, ...
[ 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\n\ndef extended_gcd(a: int, b: int) -> Tuple[int, int, int]:\n \"\"\"\n Returns a tuple (g, x, y) such that g is gcd(a, b...
trial_gpt4o_2
{ "original_instruction": "### Question Statement\n\nYou are given two functions that implement the Extended Euclidean Algorithm and calculate the modular inverse. Your task is to extend this functionality to solve a set of linear congruences using the Chinese Remainder Theorem (CRT).\n\n### Problem Description\n\nGi...
0.524031
Data_Structure_24326
C
[ "extended_gcd", "modular_inverse", "chinese_remainder_theorem" ]
3
[ [ "chinese_remainder_theorem", "modular_inverse" ], [ "modular_inverse", "extended_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
95f8fc3af04772c162e050c401f98f4a714eb82b
15c67d464a51f47a0e0546399e799053238755ce
v1.0
complete
Data_Structure
Data_Structure_24793_C
from typing import List, Tuple def bogo_sort(arr: List[int], simulation: bool = False) -> Tuple[List[int], int, int]: """ Sort the array using Bogo Sort algorithm. Parameters: arr (List[int]): The array to sort. simulation (bool): If True, prints the array after each shuffle. Defaults ...
import random from typing import List, Tuple def is_sorted(arr: List[int]) -> bool: """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: List[int], simulation: bool = False) -> Tuple[Lis...
from solution import bogo_sort def test_bogo_sort_with_simulation(): sorted_array, iterations, shuffles = bogo_sort([3, 2, 1], simulation=True) assert sorted_array == [1, 2, 3] assert iterations > 0 assert shuffles > 0 def test_bogo_sort_with_empty_array(): sorted_array, iterations, shuffles = bog...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sort the array using Bogo Sort algorithm.\n\nParameters:\n arr (List[int]): The array to sort.\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 List, Tuple\n\ndef is_sorted(arr: List[int]) -> bool:\n for i in range(len(arr) - 1):\n if arr[i] > arr[i + 1]:\n ...
trial_gpt4o_2
{ "original_instruction": "### Question: Enhance and Analyze Bogo Sort\n\n#### Context\nYou are asked to implement and enhance a sorting algorithm known as Bogo Sort. Given its inefficiency, your task will also involve analyzing the performance under various conditions to understand and demonstrate its impracticality...
0.625728
Data_Structure_24793
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b48abd7d9b7715d07205c9bbcb676a0a307cc091
46e1547e14b75e6f6e8c21f9c6b374f3dd2911b0
v1.0
complete
Data_Structure
Data_Structure_24792_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(big: Optional[TreeNode], small: Optional[TreeNode]) -> bool: """ Determine if 'small' is a subtree of 'big'. Args: big (TreeNode): The root of the...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(big: TreeNode, small: TreeNode) -> bool: if not small: return True # An empty tree is always a subtree if not big: return False # Non...
from solution import TreeNode, is_subtree def test_is_subtree_case1(): # tree 1 setup big = TreeNode(3) big.left = TreeNode(4) big.right = TreeNode(5) big.left.left = TreeNode(1) big.left.right = TreeNode(2) # tree 2 setup small = TreeNode(4) small.left = TreeNode(1) small....
[]
[ 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 is...
trial_gpt4o_2
{ "original_instruction": "You are given two binary trees `T1` and `T2`. Your task is to determine if `T2` is a subtree of `T1`. A subtree of `T1` is a tree consisting of a node in `T1` and all of its descendants in `T1`.\n\n### Function Signature\n```python\ndef is_subtree(big: Optional[TreeNode], small: Optional[Tr...
0.573225
Data_Structure_24792
C
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
e9f9acbad710fd0215464227faffe2afd07d8c97
2648f0b0b94d8b1798558cb08c70b0c99ab0459d
v1.0
complete
Data_Structure
Data_Structure_24982_C
def caesar_cipher_encrypt(s: str, k: int) -> str: """ Encrypts the input text s using Caesar cipher with a shift of k. >>> caesar_cipher_encrypt('hello, World!', 3) 'khoor, Zruog!' >>> caesar_cipher_encrypt('Example', 0) 'Example' >>> caesar_cipher_encrypt('abc', -3) 'xyz' """ def c...
def caesar_cipher_encrypt(s, k): """ Encrypts the input text s using Caesar cipher with a shift of k. """ encrypted_text = [] for char in s: if char.isalpha(): base = ord('A') if char.isupper() else ord('a') encrypted_char = chr((ord(char) - base + k) % 26 + base) ...
from solution import caesar_cipher_encrypt, caesar_cipher_decrypt def test_caesar_cipher_encrypt(): assert caesar_cipher_encrypt('hello, World!', 3) == 'khoor, Zruog!' assert caesar_cipher_encrypt('Example', 0) == 'Example' assert caesar_cipher_encrypt('abc', -3) == 'xyz' assert caesar_cipher_encrypt(...
[ { "docstring": "Encrypts the input text s using Caesar cipher with a shift of k.", "function_declaration": "def caesar_cipher_encrypt(s, k):", "function_name": "caesar_cipher_encrypt", "parameter_list": "(s, k)" }, { "docstring": "Decrypts the input text s using Caesar cipher with a shift of...
[ 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 caesar_cipher_encrypt(s, k):\n \"\"\"\n Encrypt the given text using Caesar cipher with a shift of k.\n \n Parameters:\n s (str): The input...
trial_gpt4o_2
{ "original_instruction": "Implement and Extend Caesar Cipher\n\n#### Context\nYou have learned about the Caesar cipher and how it encrypts text by shifting characters. Now, as an exercise, you will implement the Caesar cipher and extend it to handle decryption as well. \n\n#### Objective\nWrite functions to encrypt ...
0.723013
Data_Structure_24982
C
[ "caesar_cipher_encrypt", "caesar_cipher_decrypt" ]
2
[ [ "caesar_cipher_decrypt", "caesar_cipher_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a331b84619779e0621083fd478badf80a7c3c48
2c5c07367267fc2078c0fe57c4764359ccf2c93a
v1.0
complete
Data_Structure
Data_Structure_25019_C
def prime_check(num: int) -> bool: """ Verify if a number is a prime. >>> prime_check(7) True >>> prime_check(4) False """ pass def euler_totient(n: int) -> int: """ Compute the Euler's Totient function for a given integer. >>> euler_totient(9) 6 >>> euler_totient(1) 1 """ pass ...
def prime_check(num: int) -> bool: """ Verify 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 F...
from solution import prime_check, euler_totient, find_order, find_primitive_root, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(7) == True assert prime_check(4) == False assert prime_check(2) == True assert prime_check(1) == False assert prime_check(0) == False assert p...
[ { "docstring": "Verify if a number is a prime.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Compute the Euler's Totient function for a given integer.", "function_declaration": "def euler_totient(n):", ...
[ 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 prime_check(num: int) -> bool:\n \"\"\"\n Verify if a number is a prime.\n \"\"\"\n if num <= 1:\n ...
trial_gpt4o_1
{ "original_instruction": "### Diffie-Hellman Key Exchange Coding Challenge\n\n**Objective**: Implement a secure Diffie-Hellman key exchange, and related supporting functions, to facilitate encrypted communication over a public channel. Your implementation should include steps to check primality, compute Euler's Toti...
0.569874
Data_Structure_25019
C
[ "prime_check", "euler_totient", "find_order", "find_primitive_root", "diffie_hellman_key_exchange" ]
5
[ [ "diffie_hellman_key_exchange", "prime_check" ], [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ], [ "find_primitive_root", "prime_check" ] ]
4
[]
false
[]
false
pytest
true
[]
true
2af0a1da4c74d95ae4586099c61f42aad215aca4
724de04c476ab4ae472cae5e61dc56ed3a8afaf5
v1.0
complete
Data_Structure
Data_Structure_24984_C
from typing import List def binary_insertion_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Optimized Insertion Sort implementation using Binary Search to find the correct position to insert each element. If simulation is True, prints the array at each iteration. >>> binary_inse...
from typing import List def binary_search(arr, val, start, end): """ Helper function to perform binary search. Find the index where 'val' should be inserted to keep 'arr' sorted. """ if start == end: if arr[start] > val: return start else: return start + 1 ...
from solution import binary_insertion_sort def test_binary_insertion_sort_unsorted(): assert binary_insertion_sort([12, 4, 3, 8, 4]) == [3, 4, 4, 8, 12] def test_binary_insertion_sort_sorted(): assert binary_insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_binary_insertion_sort_reversed(): ass...
[ { "docstring": "Helper function to perform binary search.\nFind the index where 'val' should be inserted to keep 'arr' sorted.", "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" }, { "docstring": ...
[ 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 binary_search(arr, val, start, end):\n \"\"\"\n Helper function to perform binary search.\n Find the index where 'val'...
trial_gpt4o_0
{ "original_instruction": "### Question: Improved Insertion Sort\n\nYou are provided with a simple implementation of the Insertion Sort algorithm. Your task is to optimize the Insertion Sort implementation to use Binary Search to find the correct position to insert each element. This should improve the time complexit...
0.638816
Data_Structure_24984
C
[ "binary_search", "binary_insertion_sort" ]
2
[ [ "binary_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd4af6ba36ca50deffea6da6e978306cbdd11718
786de808af248f838770de401cf569db2a264857
v1.0
complete
Data_Structure
Data_Structure_24875_C
from typing import Dict, List from enum import Enum class TraversalState(Enum): UNVISITED = 1 VISITING = 2 VISITED = 3 def is_in_cycle(graph: Dict[str, List[str]], traversal_states: Dict[str, TraversalState], vertex: str) -> bool: """Check if a given vertex is part of a cycle in the graph using DFS. ...
from typing import Dict, List from enum import Enum class TraversalState(Enum): UNVISITED = 1 VISITING = 2 VISITED = 3 def is_in_cycle(graph: Dict[str, List[str]], traversal_states: Dict[str, TraversalState], vertex: str) -> bool: # If the current vertex is being visited, a cycle is detected if tr...
import pytest from solution import contains_cycle, is_in_cycle def test_contains_cycle_with_cycle(): graph = { 'A': ['B', 'C'], 'B': ['D'], 'C': ['F'], 'D': ['E', 'F'], 'E': ['B'], 'F': [] } assert contains_cycle(graph) == True def test_contains_cycle_withou...
[]
[ 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 Dict, List\nfrom enum import Enum\n\nclass TraversalState(Enum):\n UNVISITED = 1\n VISITING = 2\n VISITED = 3\n\ndef is_in_cycle(g...
trial_gpt4o_0
{ "original_instruction": "**Question:**\nYou are given a directed graph represented as an adjacency list. Your task is to write a function that detects if there is a cycle in this graph using Depth-First Search (DFS) methodology.\n\n### Function Signature\n```python\ndef is_in_cycle(graph: Dict[str, List[str]], trav...
0.560868
Data_Structure_24875
C
[ "is_in_cycle", "contains_cycle" ]
2
[ [ "contains_cycle", "is_in_cycle" ] ]
1
[]
false
[ "TraversalState" ]
true
pytest
true
[]
true
dcd2c8456569b38d0b56f19a4fb86d009aafc9f3
b83a64e043e91891a5caf58a7b988fc35d36c2ef
v1.0
complete
Data_Structure
Data_Structure_25166_C
from typing import List, Tuple def enhanced_knuth_morris_pratt(text: str, pattern: str) -> Tuple[List[int], bool]: """ Implement an enhanced version of the Knuth-Morris-Pratt algorithm to find all occurrences of a pattern in a given text, and determine if the pattern is overlapped at any position. ...
from typing import List, Tuple def compute_lps(pattern: str) -> List[int]: """ Helper function to compute the longest prefix suffix (LPS) array """ length = 0 lps = [0] * len(pattern) i = 1 while i < len(pattern): if pattern[i] == pattern[length]: length += 1 lps[i]...
from solution import enhanced_knuth_morris_pratt def test_pattern_at_multiple_positions(): assert enhanced_knuth_morris_pratt('ababcababc', 'ababc') == ([0, 5], False) def test_overlapping_patterns(): assert enhanced_knuth_morris_pratt('aaaaaa', 'aaa') == ([0, 1, 2, 3], True) def test_no_occurrences(): a...
[ { "docstring": "Helper function to compute the longest prefix suffix (LPS) array ", "function_declaration": "def compute_lps(pattern):", "function_name": "compute_lps", "parameter_list": "(pattern)" }, { "docstring": null, "function_declaration": "def enhanced_knuth_morris_pratt(text, pa...
[ 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 enhanced_knuth_morris_pratt(text, pattern):\n \"\"\"\n Enhanced KMP algorithm that finds all occurrences of a pattern in a text and also detects ove...
trial_gpt4o_2
{ "original_instruction": "### Question: Enhanced Text Pattern Matching with Additional Conditions\n\nYou are asked to implement an enhanced version of the Knuth-Morris-Pratt algorithm. Besides finding all occurrences of a pattern in a given text, our enhanced function should also return an indication if the pattern ...
0.578307
Data_Structure_25166
C
[ "compute_lps", "enhanced_knuth_morris_pratt" ]
2
[ [ "enhanced_knuth_morris_pratt", "compute_lps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ffc927937501e46c37d3095cd0162d094a7738d5
1a5b15207ad38fae756087bb2cb165d98ce109cb
v1.0
complete
Data_Structure
Data_Structure_25047_C
def is_prime(num: int) -> bool: """ Check whether the given number is a prime. """ pass def modinv(a: int, m: int) -> int: """ Calculate the modular multiplicative inverse of a modulo m. """ pass def generate_key(k: int) -> Tuple[int, int, int]: """ Generate RSA public/private ...
import random from typing import Tuple def is_prime(num: int) -> bool: """ Check whether the given 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 %...
from solution import is_prime, modinv, generate_key, encrypt, decrypt, validate_rsa 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 assert is_prime(19) == True def test_modinv(): ...
[ { "docstring": "Check whether the given number is a prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Calculate the modular multiplicative inverse of a modulo m using the extended Euclidean algorithm.", "funct...
[ 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\nfrom typing import Tuple\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Check whether the given number is a prime.\n \"\"\"\n if num...
trial_gpt4o_0
{ "original_instruction": "**RSA Encryption Algorithm Implementation and Validation**\n\n### Objective\n\nAs a data security consultant, you are tasked with implementing the RSA encryption and decryption processes, along with a custom primality test and modular inverse function. You need to handle edge cases and ensu...
0.676519
Data_Structure_25047
C
[ "is_prime", "modinv", "generate_key", "encrypt", "decrypt", "validate_rsa" ]
6
[ [ "generate_key", "is_prime" ], [ "generate_key", "modinv" ], [ "validate_rsa", "decrypt" ], [ "validate_rsa", "encrypt" ], [ "validate_rsa", "generate_key" ] ]
5
[]
false
[]
false
pytest
true
[]
true
0faf99f9369463a95cc9280f8ba1ce1496018eb4
44beab60a534dfb7816fc7b2ee1162d4377fb1d1
v1.0
complete
Data_Structure
Data_Structure_25247_C
def radix_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Sort an array of non-negative integers using a non-comparative radix sorting algorithm. Args: arr (List[int]): A list of non-negative integers. simulation (bool, optional): A boolean flag indicating whether to print the a...
from typing import List def counting_sort(arr: List[int], exp: int, simulation: bool) -> None: 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] i = n - 1 ...
from solution import radix_sort def test_radix_sort(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] assert radix_sort([1, 10, 1000, 100, 10000]) == [1, 10, 100, 1000, 10000] assert radix_sort([5, 3, 7, 8, 2, 1, 4, 6]) == [1, 2, 3, 4, 5, 6, 7, 8] assert radix...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp, simulation):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", "function_name": "radix_sort...
[ 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(arr: List[int], exp: int, simulation: bool) -> None:\n n = len(arr)\n output = [0] * n \n count = [0] * ...
trial_gpt4o_0
{ "original_instruction": "You have been given the task to implement a function that sorts an array of non-negative integers using a non-comparative radix sorting algorithm.\n\n### Function Signature\n```python\ndef radix_sort(arr: List[int], simulation: bool = False) -> List[int]:\n```\n\n### Input\n* `arr`: A list ...
0.681688
Data_Structure_25247
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e06e2cc1c8dd3812904a3735989a5e653869242f
76854977427810a1cfceddfcf566ead85bd51d7b
v1.0
complete
Data_Structure
Data_Structure_24916_C
def multiply(matA: list, matB: list) -> list: """ Multiplies two square matrices matA and matB. >>> matA = [ ... [1, 2], ... [3, 4] ... ] >>> matB = [ ... [2, 0], ... [1, 2] ... ] >>> multiply(matA, matB) [[4, 4], [10, 8]] """ pass def identity(n...
def multiply(matA, matB): """ Multiplies two square matrices matA and matB. """ n = len(matA) # Initialize result matrix with zeros result = [[0] * n for _ in range(n)] # Perform multiplication for i in range(n): for j in range(n): for k in range(n): ...
from solution import multiply, identity, matrix_exponentiation def test_multiply_2x2_matrices(): matA = [ [1, 2], [3, 4] ] matB = [ [2, 0], [1, 2] ] expected = [ [4, 4], [10, 8] ] assert multiply(matA, matB) == expected def test_identity_3x3(...
[ { "docstring": "Multiplies two square matrices matA and matB.", "function_declaration": "def multiply(matA, matB):", "function_name": "multiply", "parameter_list": "(matA, matB)" }, { "docstring": "Returns the identity matrix of size n x n.", "function_declaration": "def identity(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": "def multiply(matA, matB):\n \"\"\"\n Multiplies two square matrices matA and matB.\n \"\"\"\n n = len(matA)\n result = [[0] * n for _ in range(...
trial_gpt4o_2
{ "original_instruction": "### Problem: Efficient Matrix Exponentiation and Multiplication\n\nYou are tasked with implementing a solution for efficiently computing powers of a given square matrix. The solution should also handle basic matrix multiplication and generation of an identity matrix.\n\n#### Function 1: `mu...
0.533637
Data_Structure_24916
C
[ "multiply", "identity", "matrix_exponentiation" ]
3
[ [ "matrix_exponentiation", "identity" ], [ "matrix_exponentiation", "multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a2c44aa883a2a5b98ca85dfffc099842acf4d9ba
58f498a13ca36f1ee374e8d8dbb9ccd2993f2669
v1.0
complete
Data_Structure
Data_Structure_25249_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(big: TreeNode, small: TreeNode) -> bool: """ Check if the tree `small` is a subtree of the tree `big`. >>> s = TreeNode(3) ... s.left = TreeNode(4)...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(big, small): if not small: return True if not big: return False if are_identical(big, small): return True return is_sub...
from solution import TreeNode, is_subtree def test_is_subtree_example_1(): s = TreeNode(3) s.left = TreeNode(4) s.right = TreeNode(5) s.left.left = TreeNode(1) s.left.right = TreeNode(2) t = TreeNode(4) t.left = TreeNode(1) t.right = TreeNode(2) assert is_subtree(s, t) == True...
[]
[ 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": "class TreeNode:\n \"\"\"\n Definition for a binary tree node.\n \"\"\"\n def __init__(self, val=0, left=None, right=None):\n self.val = val...
trial_gpt4o_2
{ "original_instruction": "### Question\n\nYou are given two binary trees `s` and `t`. Implement a function `is_subtree(s, t)` to check if `t` is a subtree of `s`. A subtree of a tree `t` is a tree consisting of a node in `t` and all of its descendants in `t`.\n\n### Function Signature\n```python\ndef is_subtree(big,...
0.57181
Data_Structure_25249
C
[ "is_subtree", "are_identical" ]
2
[ [ "is_subtree", "are_identical" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
240b3acd914b33659d8880b8be0a23b49c21ed1b
10f4e5c4f20c5c446fb9341bf38e6b222b476be0
v1.0
complete
Data_Structure
Data_Structure_25488_C
def gcd_bitwise(a, b): """ Compute the greatest common divisor (GCD) using bitwise operations. Args: a (int): First non-negative integer. b (int): Second non-negative integer. Returns: int: The GCD of a and b. Raises: ValueError: If both a and b are ze...
def gcd_bitwise(a, b): """ Compute the greatest common divisor (GCD) using bitwise operations. Args: a (int): First non-negative integer. b (int): Second non-negative integer. Returns: int: The GCD of a and b. Raises: ValueError: If both a and b are zer...
from solution import gcd_bitwise, lcm, optimized_trailing_zero import pytest def test_gcd_bitwise(): # Test cases from examples assert gcd_bitwise(48, 18) == 6 assert gcd_bitwise(0, 6) == 6 # Additional test cases assert gcd_bitwise(17, 0) == 17 assert gcd_bitwise(101, 103) == 1 assert gcd_...
[ { "docstring": "Compute the greatest common divisor (GCD) using bitwise operations.\n\nArgs:\n a (int): First non-negative integer.\n b (int): Second non-negative integer.\n\nReturns:\n int: The GCD of a and b.\n\nRaises:\n ValueError: If both a and b are zero.", "function_declaration": "def gcd...
[ 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 gcd_bitwise(a, b):\n \"\"\"\n Computes the greatest common divisor using bitwise operations.\n \"\"\"\n if a == 0 and b == 0:\n raise V...
trial_gpt4o_2
{ "original_instruction": "### Question: Advanced Greatest Common Divisor Calculation\n\n#### Context\nIn number theory and various applications of computing, finding the greatest common divisor (GCD) and least common multiple (LCM) of two integer numbers is a frequent operation. These operations are fundamental in s...
0.751499
Data_Structure_25488
C
[ "gcd_bitwise", "lcm", "optimized_trailing_zero" ]
3
[ [ "lcm", "gcd_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
56b580b494936380c4979cee6ad094aa69cb5c8c
93f4229537e071bd279898bd678aa33fd8d8c10d
v1.0
complete
Data_Structure
Data_Structure_25195_C
def find_word_squares(words): """ Given a list of words (without duplicates), find all the possible word squares that can be formed. Args: words: A list of strings where each string is a word of the same length. Returns: A list of lists, where each inner list is a valid word square formed ...
from collections import defaultdict def build_prefix_dict(words): prefix_dict = defaultdict(list) for word in words: for i in range(len(word)): prefix_dict[word[:i+1]].append(word) return prefix_dict def backtrack(step, word_len, solution, results, prefix_dict): if step == word_len...
from solution import find_word_squares def test_example(): words = ["area", "lead", "wall", "lady", "ball"] expected_output = [ ["wall", "area", "lead", "lady"], ["ball", "area", "lead", "lady"] ] result = find_word_squares(words) assert sorted(result) == sorted(expected_output) de...
[ { "docstring": null, "function_declaration": "def build_prefix_dict(words):", "function_name": "build_prefix_dict", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def backtrack(step, word_len, solution, results, prefix_dict):", "function_name": "backtrac...
[ 0, 0, 0, 0, 0, 1, 0, 0, 1 ]
2
hard
0.222
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TrieNode:\n def __init__(self):\n self.children = {}\n self.words = []\n\nclass Trie:\n def __init__(self):\n self.root = Tri...
trial_gpt4o_9
{ "original_instruction": "### Word Squares Generation\n\nGiven a list of words (without duplicates), you need to find all the possible word squares that can be formed. A valid word square is a sequence of words where the kth row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns).\n\n### De...
0.593388
Data_Structure_25195
C
[ "build_prefix_dict", "backtrack", "find_word_squares" ]
3
[ [ "find_word_squares", "backtrack" ], [ "find_word_squares", "build_prefix_dict" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ea79f60fd4e4c8267b84aa3bafba1f778d5e1fad
ba2d0314af60abde0adadb2598a14e8013545adc
v1.0
complete
Data_Structure
Data_Structure_24938_C
from typing import List def search_insert(arr: List[int], val: int, start: int, end: int) -> int: """ Performs binary search to find the index at which val should be inserted to keep the array sorted from start to end. """ if start == end: if arr[start] > val: return start ...
from typing import List def search_insert(arr: List[int], val: int, start: int, end: int) -> int: """ Performs binary search to find the index at which val should be inserted to keep the array sorted from start to end. """ if start == end: if arr[start] > val: return start ...
def test_optimized_insertion_sort_single_element(): assert optimized_insertion_sort([1]) == [1] def test_optimized_insertion_sort_sorted(): assert optimized_insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_optimized_insertion_sort_reverse_sorted(): assert optimized_insertion_sort([5, 4, 3, 2, 1...
[ { "docstring": "Performs binary search to find the index at which val should be inserted \nto keep the array sorted from start to end.", "function_declaration": "def search_insert(arr, val, start, end):", "function_name": "search_insert", "parameter_list": "(arr, val, start, end)" }, { "docs...
[ 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], left: int, right: int, key: int) -> int:\n \"\"\"\n Binary search to find the index to inse...
trial_gpt4o_2
{ "original_instruction": "**Scenario**: You are developing an optimized insertion sort algorithm for use in your software that processes small-sized or nearly sorted datasets. To boost efficiency, particularly in finding the correct insertion points, you decide to integrate a binary search approach.\n\n**Task**: Imp...
0.634126
Data_Structure_24938
C
[ "search_insert", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f9c91905a33cc8e22cbb420ca3a6738c93bcb736
4eb5342a6b3d42e5b9308af9c909481c0322c038
v1.0
complete
Data_Structure
Data_Structure_25211_C
def enhanced_bucket_sort(arr, num_buckets=10): """ Perform bucket sort using optimized sorting within each bucket. :param arr: List of non-negative integers to be sorted. :param num_buckets: Number of buckets to be used for sorting. :return: Sorted list of integers. Examples: >>> e...
def enhanced_bucket_sort(arr, num_buckets=10): """ Perform bucket sort using optimized sorting within each bucket. :param arr: List of non-negative integers to be sorted. :param num_buckets: Number of buckets to be used for sorting. :return: Sorted list of integers. """ if len(arr) <= 1...
from solution import enhanced_bucket_sort def test_enhanced_bucket_sort_empty_list(): assert enhanced_bucket_sort([]) == [] def test_enhanced_bucket_sort_single_element(): assert enhanced_bucket_sort([5]) == [5] def test_enhanced_bucket_sort_sorted_list(): assert enhanced_bucket_sort([1, 2, 3, 4, 5]) == ...
[ { "docstring": "Perform bucket sort using optimized sorting within each bucket.\n\n:param arr: List of non-negative integers to be sorted.\n:param num_buckets: Number of buckets to be used for sorting.\n:return: Sorted list of integers.", "function_declaration": "def enhanced_bucket_sort(arr, num_buckets=10...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def enhanced_bucket_sort(arr, num_buckets=10):\n \"\"\"\n Perform bucket sort using optimized sorting within each bucket.\n \n :param arr: List of...
trial_gpt4o_0
{ "original_instruction": "**Bucket Sort Implementation**\n\n### Task\nImplement the `enhanced_bucket_sort(arr, num_buckets)` function that performs the bucket sort using a more efficient sorting algorithm (e.g., mergesort) for sorting within each bucket.\n\n### Input\n- `arr`: a list of non-negative integers to be s...
0.585149
Data_Structure_25211
C
[ "enhanced_bucket_sort", "merge_sort", "merge" ]
3
[ [ "enhanced_bucket_sort", "merge_sort" ], [ "merge_sort", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3ae38376e950fbfad0ca456ad9b84dcacf5e898f
0c435ef8ba118b50a0f7d7afa033b4f574df7f75
v1.0
complete
Data_Structure
Data_Structure_25217_C
from typing import List def insertion_sort(arr: List[float]) -> List[float]: """ A simple implementation of insertion sort. """ 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 arr[j + 1] = key ...
from typing import List def insertion_sort(arr: List[float]) -> List[float]: """ A simple implementation of insertion sort. """ 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 arr[j + 1...
from solution import bucket_sort def test_bucket_sort_example_cases(): 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] assert bucket_sort([0.42, 0.32, 0.23, 0.52, 0.25, 0.47, 0.51]) == [0.23, 0.25, 0.32, 0.42, 0.47...
[ { "docstring": "A simple implementation of insertion sort.", "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": "Sorts a list of float numbers in the range [0, 1) using bucket sort.", "function_declaration": ...
[ 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 Helper function to perform insertion sort on a list.\n \"\...
trial_gpt4o_2
{ "original_instruction": "Your task is to implement a sorting algorithm based on the concept of **bucket sort**. You will need to distribute the elements of an array into separate \"buckets\", sort each bucket, and then concatenate these buckets to produce the final sorted array. For the purpose of sorting the indiv...
0.657648
Data_Structure_25217
C
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e66e1991d171cdf8df8df4701c1b4cfd677c1b9
deaeb5cdb9837baeafad38a854db0c4afc0d6a6f
v1.0
complete
Data_Structure
Data_Structure_25041_C
def merge_sort(arr): """ Merge Sort implementation that sorts a list of integers. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(arr[mid:]) return merge(left, right) def merge(left, right): """ Helper function to me...
def merge_sort(arr): """ Merge Sort implementation that sorts a list of integers. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(arr[mid:]) return merge(left, right) def merge(left, right): """ Helper function to me...
from solution import merge_sort def test_merge_sort_example_1(): assert merge_sort([38, 27, 43, 3, 9, 82, 10]) == [3, 9, 10, 27, 38, 43, 82] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_repeating_el...
[ { "docstring": "Merge Sort implementation that sorts a list of integers.\n ", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Helper function to merge two sorted lists.\n ", "function_declaration": "def mer...
[ 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 merge_sort(arr):\n \"\"\" Merge Sort implementation that sorts a list of integers.\n \"\"\"\n if len(arr) <= 1:\n return arr\n \n mi...
trial_gpt4o_2
{ "original_instruction": "### Merge Sort Algorithm Implementation\n\nYour task is to implement the Merge Sort algorithm to sort an array of integers. You need to write a function that divides the array into halves, recursively sorts each half, and then merges them back together in sorted order.\n\n### Function Speci...
0.564369
Data_Structure_25041
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9a7b2dd8cc4c21ca6660f2d9287437ac99dcb959
50d174cdc5d757ac6c6e35a2a3ebe2520bbab7d8
v1.0
complete
Data_Structure
Data_Structure_25710_C
from typing import List def radix_sort(arr: List[int]) -> List[int]: """ Radix Sort Implementation Sort an array of non-negative integers using the radix sort algorithm. Parameters: arr (List[int]): List of non-negative integers 0 <= arr[i] <= 1,000,000. Returns: List[int]: List of in...
from typing import List def counting_sort(arr: List[int], exp: int) -> List[int]: n = len(arr) output = [0] * n count = [0] * 10 # Store count of occurrences in count[] for i in range(n): index = arr[i] // exp count[(index % 10)] += 1 # Change count[i] so it contains the actua...
from solution import radix_sort def test_radix_sort(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] assert radix_sort([]) == [] assert radix_sort([5]) == [5] assert radix_sort([1, 1, 1, 1]) == [1, 1, 1, 1] assert radix_sort([3, 1, 2, 5, 4]) == [1, 2, 3, ...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp):", "function_name": "counting_sort", "parameter_list": "(arr, exp)" }, { "docstring": null, "function_declaration": "def radix_sort(arr):", "function_name": "radix_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 counting_sort(arr: List[int], exp: int) -> List[int]:\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n \n ...
trial_gpt4o_2
{ "original_instruction": "### Radix Sort Implementation and Edge Case Handling\n\nYou are tasked with implementing a radix sort algorithm in Python to sort an array of non-negative integers. Your function should handle the following edge cases and constraints:\n\n1. Arrays of varying lengths, including empty arrays....
0.735948
Data_Structure_25710
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ee865efad67e83780ac004286c3718718fc5210e
bc07b0c22acb48d3f8bad4bc500f1678ae5a3fa3
v1.0
complete
Data_Structure
Data_Structure_24690_C
def compute_max_flow(capacity: List[List[int]], source: int, sink: int) -> int: """ Computes the maximum flow from a source node to a sink node in a given network. Args: capacity (List[List[int]]): A 2D list representing the capacity of each edge in a graph. source (int): The index of the source no...
from collections import deque def bfs(capacity, source, sink, parent): """ Breadth-First Search to find if there's a path from source to sink. Returns True if there is a path, False otherwise. """ visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while qu...
def test_simple_case(): capacity = [ [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] ] source = 0 sink = 5 assert compute_max_flow(capacity, source, sink) == 23 def test_no_c...
[ { "docstring": "Breadth-First Search to find if there's a path from source to sink.\nReturns True if there is a path, False otherwise.", "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docs...
[ 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 collections import deque\n\ndef bfs(capacity, source, sink, parent):\n \"\"\"\n Perform BFS to find an augmenting path in the residual graph.\n ...
trial_gpt4o_2
{ "original_instruction": "### Question: Maximum Flow in a Transportation Network\n\n#### Context:\nA transportation company needs to optimize its freight routes to ensure that goods are transported from a central warehouse to multiple distribution centers with maximum efficiency. You are tasked with implementing a s...
0.577656
Data_Structure_24690
C
[ "bfs", "compute_max_flow" ]
2
[ [ "compute_max_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
145e5598e70d37a86c96ec36eec18ec86ad242f1
d80ddbde5e4c378031d8dff2fd6faa2d928cc53f
v1.0
complete
Data_Structure
Data_Structure_25615_C
def bottom_up_merge_sort(arr): """ Sorts the array using the bottom-up merge sort algorithm. >>> bottom_up_merge_sort([4, 2, 5, 1, 6, 3]) == [1, 2, 3, 4, 5, 6] >>> bottom_up_merge_sort([10, 8, 12, 3, 7, 15]) == [3, 7, 8, 10, 12, 15] >>> bottom_up_merge_sort([]) == [] >>> bottom_up_merge_sort([1]...
def bottom_up_merge_sort(arr): """ Sorts the array using the bottom-up merge sort algorithm. """ if not arr or len(arr) == 1: return arr n = len(arr) # Temporary array for merging temp_arr = [0]*n # Size represents the size of the subarrays to be merged size = 1 while s...
from solution import bottom_up_merge_sort def test_bottom_up_merge_sort_empty(): assert bottom_up_merge_sort([]) == [] def test_bottom_up_merge_sort_single_element(): assert bottom_up_merge_sort([1]) == [1] def test_bottom_up_merge_sort_sorted(): assert bottom_up_merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, ...
[ { "docstring": "Sorts the array using the bottom-up merge sort algorithm.", "function_declaration": "def bottom_up_merge_sort(arr):", "function_name": "bottom_up_merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted halves of the array.", "function_declaration": "de...
[ 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 bottom_up_merge_sort(arr):\n \"\"\"\n Performs a bottom-up merge sort on the input array arr.\n \n :param arr: List of integers to be sorted\n...
trial_gpt4o_1
{ "original_instruction": "### Coding Problem: Implement a Bottom-Up Merge Sort\n\n#### Problem Description\nYou have been tasked with implementing a bottom-up (iterative) version of the Merge Sort algorithm. Bottom-up merge sort does not use recursion; instead, it iteratively handles subarrays of increasing size to ...
0.651729
Data_Structure_25615
C
[ "bottom_up_merge_sort", "merge" ]
2
[ [ "bottom_up_merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b9d4e78fa181e5495cb5ce52791089f9753456c2
c74bafc4f23c73a787ff1a066ba426bf36353764
v1.0
complete
Data_Structure
Data_Structure_25082_C
from typing import List def solve_chinese_remainder(nums: List[int], rems: List[int]) -> int: """ Solves the system of congruences using the Chinese Remainder Theorem. :param nums: List of pairwise coprime integers. :param rems: List of remainders. :return: Smallest positive integer x that sat...
from typing import List from functools import reduce def solve_chinese_remainder(nums: List[int], rems: List[int]) -> int: """ Solves the system of congruences using the Chinese Remainder Theorem. :param nums: List of pairwise coprime integers. :param rems: List of remainders. :return: Smalles...
from solution import solve_chinese_remainder def test_solve_chinese_remainder_example(): nums = [3, 4, 5] rems = [2, 3, 1] assert solve_chinese_remainder(nums, rems) == 11 def test_solve_chinese_remainder_single_equation(): nums = [7] rems = [3] assert solve_chinese_remainder(nums, rems) == 3 ...
[ { "docstring": "Solves the system of congruences using the Chinese Remainder Theorem.\n\n:param nums: List of pairwise coprime integers.\n:param rems: List of remainders.\n:return: Smallest positive integer x that satisfies all given congruences.", "function_declaration": "def solve_chinese_remainder(nums, ...
[ 0, 0, 0, 0, 1, 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": "from typing import List\n\ndef extended_gcd(a: int, b: int):\n \"\"\"\n Extended Euclidean Algorithm that returns gcd of a and b, and the coefficients o...
trial_gpt4o_4
{ "original_instruction": "Solve Congruences with Chinese Remainder Theorem\n\nYou are provided with `n` modular equations in the form:\n\n\\[ x \\% nums[i] = rems[i] \\]\n\nwhere `i` ranges from `0` to `n-1`, and the integers in `nums` list are pairwise coprime. Your task is to implement a function that finds the sm...
0.546551
Data_Structure_25082
C
[ "solve_chinese_remainder", "gcd" ]
2
[ [ "solve_chinese_remainder", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a54f1028194b51c8b8617472e3cdf1f7db058be
88f125bb2df8d5129b16c80b2680c6dad2ff04bb
v1.0
complete
Data_Structure
Data_Structure_25028_C
def radix_sort(arr, simulation=False) -> list: """ Given an unsorted list of non-negative integers, implement the `radix_sort` function to sort the list in ascending order. Optionally, print each iteration's intermediate sorted list for debugging purposes. >>> radix_sort([170, 45, 75, 90, 80...
def counting_sort(arr, exp, simulation): 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] i = n - 1 while i >= 0: index = arr[i] // exp ...
from solution import radix_sort def test_radix_sort_simple(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_radix_sort_empty(): assert radix_sort([]) == [] def test_radix_sort_single_element(): assert radix_sort([5]) == [5] def test_radix_sort_all_sam...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp, simulation):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", "function_name": "radix_sort...
[ 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 counting_sort(arr, exp, simulation):\n n = len(arr)\n output = [0] * n \n count = [0] * 10 \n\n for i in range(n):\n index = arr[i] // ...
trial_gpt4o_0
{ "original_instruction": "### Question\nYou are required to implement the Radix Sort algorithm and validate its correctness and efficiency through the following tasks. \n\n#### Task\nGiven an unsorted list of non-negative integers, implement the `radix_sort` function to sort the list in ascending order. Additionally...
0.620421
Data_Structure_25028
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c519f3eae97ebff16edf24b02c8d6212b926cee4
de0609efd0ea990898176e856d2d6f9c8005ee23
v1.0
complete
Data_Structure
Data_Structure_25639_C
def perform_diffie_hellman(a: int, p: int) -> int: """ Securely exchange a secret key using a simplified version of the Diffie-Hellman Key Exchange algorithm. Validate prime number and primitive root, and execute key exchange steps. Args: a (int): A primitive root modulo p. p (int): A prim...
import random def is_prime(n): """ Basic check to verify 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: return False...
from solution import perform_diffie_hellman def test_valid_diffie_hellman(): # Testing with known primitive root and prime a = 2 p = 11 shared_key = perform_diffie_hellman(a, p) assert shared_key != -1 def test_invalid_prime(): # Testing with a non-prime number a = 3 p = 12 # Not a pr...
[ { "docstring": "Basic check to verify if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find a primitive root modulo p, if it exists.", "function_declaration": "def find_primitive_root(p):", "fu...
[ 0, 1 ]
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 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": "### Secure Key Exchange with Diffie-Hellman Algorithm\n\nIn this task, you are required to implement a simplified version of the Diffie-Hellman Key Exchange algorithm to securely exchange a secret key between two parties. Your task involves checking the necessary conditions and performing t...
0.524018
Data_Structure_25639
C
[ "is_prime", "find_primitive_root", "prime_factors", "perform_diffie_hellman" ]
4
[ [ "find_primitive_root", "prime_factors" ], [ "perform_diffie_hellman", "find_primitive_root" ], [ "perform_diffie_hellman", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4daf755a018ce5e385fa5af457a9cc18f9300c1e
50e371306b7bce7e97def289a57523cc36135445
v1.0
complete
Data_Structure
Data_Structure_25134_C
import math from typing import List def cosine_similarity(vecA, vecB): """ Calculate the cosine similarity between two vectors. """ pass def batch_cosine_similarity(vectorsA: List[List[float]], vectorsB: List[List[float]]) -> List[float]: """ Calculate cosine similarity for each pair of vector...
import math def cosine_similarity(vecA, vecB): """ Calculate the cosine similarity between two vectors. """ dot_product = sum(a * b for a, b in zip(vecA, vecB)) normA = math.sqrt(sum(a * a for a in vecA)) normB = math.sqrt(sum(b * b for b in vecB)) if normA == 0 or normB == 0: retur...
def test_batch_cosine_similarity(): vectorsA = [[1, 1, 1], [1, 2, 3]] vectorsB = [[1, 2, -1], [-1, -2, -3]] result = batch_cosine_similarity(vectorsA, vectorsB) assert result == [0.47140452079103173, -1.0], f"Expected [0.47140452079103173, -1.0] but got {result}" def test_zero_vector(): vectorsA = ...
[ { "docstring": "Calculate the cosine similarity between two vectors.", "function_declaration": "def cosine_similarity(vecA, vecB):", "function_name": "cosine_similarity", "parameter_list": "(vecA, vecB)" }, { "docstring": "Calculate cosine similarity for each pair of vectors from vectorsA an...
[ 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": "from typing import List\nimport math\n\ndef batch_cosine_similarity(vectorsA: List[List[float]], vectorsB: List[List[float]]) -> List[float]:\n def cosine_...
trial_gpt4o_7
{ "original_instruction": "### Question: Calculate Cosine Similarity Between Multiple Pairs of Vectors\n\nYou are tasked with writing a function to compute the cosine similarity between multiple pairs of vectors efficiently. Specifically, you need to implement a function that computes cosine similarity for each pair ...
0.539609
Data_Structure_25134
C
[ "cosine_similarity", "batch_cosine_similarity" ]
2
[ [ "batch_cosine_similarity", "cosine_similarity" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d2aa22a3b6637f5de4429ae99d7d81413b57af7c
6cc294ab1ddce921106b42c78582244ac887bc22
v1.0
complete
Data_Structure
Data_Structure_25330_C
def solve_diophantine(a: int, b: int, c: int) -> tuple: """ Find one particular solution (x, y) and the greatest common divisor (gcd) for the equation a*x + b*y = c. >>> solve_diophantine(30, 20, 10) (1, -1, 10) >>> solve_diophantine(35, 15, 5) (1, -2, 5) """ pass from solution im...
def extended_gcd(a, b): """ Apply the extended Euclidean algorithm to find x, y such that: a * x + b * y = gcd(a, b) Returns a tuple (gcd, x, y) where gcd is the greatest common divisor of a and b, and x, y are the coefficients such that a * x + b * y = gcd. """ if b == 0: return a, ...
from solution import solve_diophantine def test_solve_diophantine_positive(): x, y, g = solve_diophantine(30, 20, 10) assert 30 * x + 20 * y == 10 assert g == 10 def test_solve_diophantine_another_positive(): x, y, g = solve_diophantine(35, 15, 5) assert 35 * x + 15 * y == 5 assert g == 5 def...
[ { "docstring": "Apply the extended Euclidean algorithm to find x, y such that:\na * x + b * y = gcd(a, b)\nReturns a tuple (gcd, x, y) where gcd is the greatest common divisor of a and b,\nand x, y are the coefficients such that a * x + b * y = gcd.", "function_declaration": "def extended_gcd(a, b):", "...
[ 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 extended_gcd(a, b):\n \"\"\"\n Apply the extended Euclidean algorithm to find x, y such that:\n a * x + b * y = gcd(a, b)\n Returns a tuple (g...
trial_gpt4o_0
{ "original_instruction": "### Question:\n\n#### Problem Statement\nYou are tasked with implementing a function named `solve_diophantine(a, b, c)` that takes three integers `a`, `b`, and `c` as inputs, and returns a tuple `(x, y, gcd)` such that `a * x + b * y = gcd` where `gcd` is the greatest common divisor of `a` ...
0.618663
Data_Structure_25330
C
[ "extended_gcd", "solve_diophantine" ]
2
[ [ "solve_diophantine", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
aa82309d4c1081468160507e2eeba1edc401cd76
f31938f5ff9c8c9321c44ccd61e2b2c8cf0b540a
v1.0
complete
Data_Structure
Data_Structure_25295_C
import math def distance(x, y): assert len(x) == len(y), "The vectors must have the same length" sum = 0 for i in range(len(x)): sum += (x[i] - y[i]) ** 2 return math.sqrt(sum) def recommend_product(x: tuple, feature_vectors: dict) -> str: """ Recommends the product most similar to a given...
import math def distance(x, y): assert len(x) == len(y), "The vectors must have the same length" sum = 0 for i in range(len(x)): sum += (x[i] - y[i]) ** 2 return math.sqrt(sum) def recommend_product(x: tuple, feature_vectors: dict) -> str: min_distance = float('inf') recommended_produc...
from solution import recommend_product, distance def test_distance(): assert distance((1.0, 2.0), (1.0, 2.0)) == 0.0 assert distance((1.0, 2.0), (2.0, 3.0)) == math.sqrt(2) assert distance((3.0, 4.0), (0.0, 0.0)) == 5.0 def test_recommend_product(): feature_vectors = { (1.0, 2.0): "Product1", ...
[ { "docstring": null, "function_declaration": "def distance(x, y):", "function_name": "distance", "parameter_list": "(x, y)" }, { "docstring": null, "function_declaration": "def recommend_product(x, feature_vectors):", "function_name": "recommend_product", "parameter_list": "(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": "import math\n\ndef distance(x, y):\n assert len(x) == len(y), \"The vectors must have the same length\"\n sum = 0\n for i in range(len(x)):\n ...
trial_gpt4o_2
{ "original_instruction": "**Context**:\nYou have been hired to help develop a simple recommendation system for a small online retailer. This retailer assigns a feature vector to each product based on user reviews and other metrics. Each feature vector is stored in a dictionary where the key is the tuple representing...
0.576564
Data_Structure_25295
C
[ "distance", "recommend_product" ]
2
[ [ "recommend_product", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d953fb48d408b7dcea79c932384638d03116fe0
f8ec0f130941fa20ac8853dbac5a711d0a02d731
v1.0
complete
Data_Structure
Data_Structure_25234_C
from typing import List def is_sorted(arr: List[int]) -> bool: """ 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: List[int], simulation: bool = False) -> List[int]: """ ...
import random from typing import List def is_sorted(arr: List[int]) -> bool: """ 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: List[int], simulation: bool = False) -> List[i...
from solution import is_sorted, bogo_sort def test_is_sorted(): assert is_sorted([1, 2, 3, 4, 5]) == True assert is_sorted([5, 1, 2, 3, 4]) == False assert is_sorted([]) == True assert is_sorted([1]) == True assert is_sorted([2, 2, 2]) == True def test_bogo_sort_empty_array(): assert bogo_sort...
[ { "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 of integers using the highly inefficient Bogo Sort algorithm.\nIf 'simulation' is True, ...
[ 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 bogo_sort(arr: List[int], simulation: bool = False) -> List[int]:\n def is_sorted(arr: List[int]) -> bool:\n ...
trial_gpt4o_2
{ "original_instruction": "### Bogo Sorting Challenge\n\n**Context**: You have been assigned to demonstrate the inefficiencies of certain theoretical sorting algorithms. One such example is Bogo Sort, a highly inefficient and impractical sorting algorithm.\n\n### Problem Statement\nImplement the function `bogo_sort` ...
0.643046
Data_Structure_25234
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
722cee3698f5ce9c8a63634bd19580c70b2a9bee
a5b66fa40ea56f4dc26e2b249968518694c15bed
v1.0
complete
Data_Structure
Data_Structure_25650_C
from typing import List def efficient_merge_sort(arr: List[int]) -> List[int]: """ Efficiently sorts a list of integers using the merge sort algorithm. Parameters: arr (List[int]): A list of integers to be sorted. Returns: List[int]: A new list of integers sorted in ascending order. ...
from typing import List def efficient_merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = efficient_merge_sort(arr[:mid]) right_half = efficient_merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left: List[int], ...
from solution import efficient_merge_sort def test_empty_list(): assert efficient_merge_sort([]) == [] def test_single_element(): assert efficient_merge_sort([5]) == [5] def test_even_number_of_elements(): assert efficient_merge_sort([3, 1, 2, 4]) == [1, 2, 3, 4] def test_odd_number_of_elements(): a...
[ { "docstring": null, "function_declaration": "def efficient_merge_sort(arr):", "function_name": "efficient_merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)"...
[ 0, 0, 0, 1, 1, 1, 0, 1, 1, 0 ]
5
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 efficient_merge_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts a list of integers using the merge sort algorithm.\n ...
trial_gpt4o_8
{ "original_instruction": "### Problem: Efficient Sorting with Constraints\n\nYou have been given the task to sort a list of integers using the merge sort algorithm. Since this list can be very large, you need to ensure that your implementation is as efficient as possible in terms of space and time. \n\n**Function Si...
0.633729
Data_Structure_25650
C
[ "efficient_merge_sort", "merge" ]
2
[ [ "efficient_merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9e5ea3613f65ead4694dac00f4cb7e0e65f2e4ec
8103777042ad5db30d9394d217e70717b69d4752
v1.0
complete
Data_Structure
Data_Structure_25095_C
import sys from typing import List def extended_bitonic_sort(arr: List[int], reverse: bool = False) -> List[int]: """ Implement a bitonic sort algorithm that sorts an array of integers. The bitonic sort should handle arrays of arbitrary sizes by padding to the nearest power of two with the appro...
import sys from typing import List def bitonic_merge(arr, low, cnt, reverse): if cnt > 1: k = cnt // 2 for i in range(low, low + k): if reverse == (arr[i] > arr[i + k]): arr[i], arr[i + k] = arr[i + k], arr[i] bitonic_merge(arr, low, k, reverse) bitonic_m...
from solution import extended_bitonic_sort def test_bitonic_sort_empty(): assert extended_bitonic_sort([]) == [] def test_bitonic_sort_single_element(): assert extended_bitonic_sort([42]) == [42] def test_bitonic_sort_power_of_two_increasing(): assert extended_bitonic_sort([12, 4, 78, 22]) == [4, 12, 22,...
[ { "docstring": null, "function_declaration": "def bitonic_merge(arr, low, cnt, reverse):", "function_name": "bitonic_merge", "parameter_list": "(arr, low, cnt, reverse)" }, { "docstring": null, "function_declaration": "def bitonic_sort_recursive(arr, low, cnt, reverse):", "function_n...
[ 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 sys\n\ndef bitonic_sort_up(arr: List[int]) -> None:\n \"\"\"Helper function to perform a bitonic sort in ascending order.\"...
trial_gpt4o_2
{ "original_instruction": "### Context\nImagine you are a software engineer working on optimizing a large-scale data processing system that leverages parallel computing. Your task is to implement and extend a sorting algorithm that is efficient in parallel environments.\n\n### Problem Statement\n\nYou need to impleme...
0.660369
Data_Structure_25095
C
[ "bitonic_merge", "bitonic_sort_recursive", "nearest_power_of_two", "extended_bitonic_sort" ]
4
[ [ "bitonic_sort_recursive", "bitonic_merge" ], [ "extended_bitonic_sort", "bitonic_sort_recursive" ], [ "extended_bitonic_sort", "nearest_power_of_two" ] ]
3
[]
false
[]
false
pytest
true
[]
true
bbc9f74f2627d9e71f4a4d995ea3aea470f82fe9
97947766b3bce10bdef627d110532dd299ad317c
v1.0
complete
Data_Structure
Data_Structure_26052_C
from typing import List, Sequence def optimize_knuth_morris_pratt(text: Sequence[str], pattern: Sequence[str]) -> List[int]: """ Function that uses the Knuth-Morris-Pratt algorithm to find all occurrences of a pattern in a text >>> optimize_knuth_morris_pratt('hello there hero!', 'he') == [0, 7, 12] >>> op...
from typing import List, Sequence def build_lps(pattern: Sequence[str]) -> List[int]: """ Function to build the longest proper prefix which is also suffix (lps) array """ lps = [0] * len(pattern) length = 0 # length of the previous longest prefix suffix i = 1 while i < len(pattern): if pat...
from solution import optimize_knuth_morris_pratt def test_kmp_found_single_occurrence(): assert optimize_knuth_morris_pratt('hello there hero!', 'hero') == [12] def test_kmp_found_multiple_occurrences(): assert optimize_knuth_morris_pratt('hello there hero here', 'he') == [0, 7, 12, 17] def test_kmp_not_foun...
[ { "docstring": "Function to build the longest proper prefix which is also suffix (lps) array ", "function_declaration": "def build_lps(pattern):", "function_name": "build_lps", "parameter_list": "(pattern)" }, { "docstring": "Function that uses the Knuth-Morris-Pratt algorithm to find all oc...
[ 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, Sequence\n\ndef optimize_knuth_morris_pratt(text: Sequence[str], pattern: Sequence[str]) -> List[int]:\n \"\"\"\n Returns a lis...
trial_gpt4o_2
{ "original_instruction": "You are working on a text processing application, and one of the core features is the ability to find all instances of a specific search term (pattern) within a large document. You decide to use the Knuth-Morris-Pratt (KMP) algorithm for its efficiency. The function `knuth_morris_pratt` has...
0.564404
Data_Structure_26052
C
[ "build_lps", "optimize_knuth_morris_pratt" ]
2
[ [ "optimize_knuth_morris_pratt", "build_lps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64d62667cdb7217ab9ae0f4b103335eae65978f1
34b44961faa7cace566a34496fd973d124e5f9e4
v1.0
complete
Data_Structure
Data_Structure_25500_C
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None def serialize(root): def build_string(node): if node: vals.append(str(node.val)) build_string(node.left) build_string(node.right) else: ...
class TreeNode(object): def __init__(self, x): self.val = x self.left = None self.right = None def serialize(root): def build_string(node): if node: vals.append(str(node.val)) build_string(node.left) build_string(node.right) else: ...
from solution import TreeNode, serialize, deserialize, is_serialization_correct def test_is_serialization_correct_single_node(): root = TreeNode(1) assert is_serialization_correct(root) == True def test_is_serialization_correct_full_tree(): # Tree: # 1 # / \ # 2 3 # / \...
[]
[ 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(object):\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\n\ndef serialize(root):\n ...
trial_gpt4o_0
{ "original_instruction": "### Coding Challenge\n\nYou are provided with a binary tree node class `TreeNode` and two functions `serialize` and `deserialize`.\n\n1. **TreeNode class**:\n\n```python\nclass TreeNode(object):\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right ...
0.488339
Data_Structure_25500
C
[ "serialize", "deserialize", "is_serialization_correct" ]
3
[ [ "is_serialization_correct", "deserialize" ], [ "is_serialization_correct", "serialize" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
2c3e6a169ea3d9b4fa070a7eb35e36cf50183250
9064ba19c063f5ffe2ef4695768ce6f65970886e
v1.0
complete
Data_Structure
Data_Structure_25447_C
def radix_sort(arr: list, simulation: bool = False) -> list: """ Implement and Test Radix Sort Algorithm Sorts a list of non-negative integers efficiently using the Radix Sort algorithm. The function also has a simulation mode to output intermediate sorting steps. Parameters: arr (list): List ...
def counting_sort(arr, exp, simulation, iteration): n = len(arr) output = [0] * n # output array count = [0] * 10 # count array for digits 0-9 for i in range(n): index = arr[i] // exp count[index % 10] += 1 for i in range(1, 10): count[i] += count[i - 1] ...
from solution import radix_sort def test_radix_sort_example(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66], simulation=False) == [2, 24, 45, 66, 75, 90, 170, 802] def test_radix_sort_empty(): assert radix_sort([], simulation=False) == [] def test_radix_sort_single_element(): assert radix_sort([1]...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp, simulation, iteration):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation, iteration)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", "funct...
[ 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 counting_sort_for_radix(arr, exp, simulation, iteration):\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n\n # Store count of occurrence...
trial_gpt4o_1
{ "original_instruction": "### Question: Implement and Test Radix Sort Algorithm\n\n#### Scenario\nYou are given a list of non-negative integers that need to be sorted efficiently. Your task is to write a function `radix_sort` that sorts this list using the Radix Sort algorithm. The function should also have a simula...
0.624077
Data_Structure_25447
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9f0b9348d40d8799de2ebcc9fdeabf49c87b166a
7e62ed81075b8292dfb62b58bc9a71a3b168257a
v1.0
complete
Data_Structure
Data_Structure_25993_C
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two high-dimensional points. """ return math.sqrt(sum((a - b) ** 2 for a, b in zip(point1, point2))) def find_nearest_neighbor(query_point: tuple, training_set: dict) -> any: """ Find the label of the ...
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two high-dimensional points. """ return math.sqrt(sum((a - b) ** 2 for a, b in zip(point1, point2))) def find_nearest_neighbor(query_point, training_set): """ Find the nearest neighbor for the give...
from solution import find_nearest_neighbor def test_single_point_training_set(): query_point = (1, 2) training_set = {(1, 2): 'Label'} assert find_nearest_neighbor(query_point, training_set) == 'Label' def test_multiple_points_training_set(): query_point = (1, 2) training_set = { (2, 3): '...
[ { "docstring": "Calculate the Euclidean distance between two high-dimensional points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Find the nearest neighbor for the given qu...
[ 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": "import math\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Calculate Euclidean distance between two high-dimensional points.\n \"\"\"\n ret...
trial_gpt4o_1
{ "original_instruction": "You are tasked to implement a function that runs a nearest neighbor search algorithm. This function takes a high-dimensional query point and a training set, then returns the label of the nearest neighbor. The training set will be provided as a dictionary where the keys are high-dimensional ...
0.714443
Data_Structure_25993
C
[ "euclidean_distance", "find_nearest_neighbor" ]
2
[ [ "find_nearest_neighbor", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
76a9cde743796b66f3b82d4656f336b35c9be054
41211feb23bb23f5691f15757fa7fddfa07c9aa8
v1.0
complete
Data_Structure
Data_Structure_25441_C
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(s: TreeNode, t: TreeNode) -> bool: """Determine whether a saved snapshot (subtree) is present as a subtree within the current directory tree structure. ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(s: TreeNode, t: TreeNode) -> bool: if not s: return False if is_same_tree(s, t): return True return is_subtree(s.left, t) or is_sub...
import pytest from solution import TreeNode, is_subtree, is_same_tree def test_is_subtree_true_case(): # Tree s: 3 # / \ # 4 5 # / \ # 1 2 s = TreeNode(3) s.left = TreeNode(4) s.right = TreeNode(5) s.left.left = TreeNode(1) s.le...
[]
[ 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": "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 is...
trial_gpt4o_2
{ "original_instruction": "## Coding Assessment Question\n\n### Scenario\nYou are tasked with designing software for a company's file version control system. The system saves snapshots of different versions of the entire file directory tree structure. You need to implement a function that efficiently determines wheth...
0.570962
Data_Structure_25441
C
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
50c7222e44fbd42d93785cf8e80dbdc7ab2c2229
acccb16902bd8097caa48def2dd1f03a34486f1d
v1.0
complete
Data_Structure
Data_Structure_25862_C
def optimal_delivery_flow(route_matrix): """ Determines the maximum flow of delivery vans from the main warehouse (first node, index 0) to the central delivery hub (last node, index n-1) in a given city's route network. Parameters: route_matrix (List[List[int]]): A square matrix where route_ma...
from collections import deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: node = queue.popleft() for i, cap in enumerate(capacity[node]): if not visited[i] and cap > 0: ...
def test_optimal_delivery_flow_example(): route_matrix = [ [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 optimal_delivery_flow(route_matrix) == 23 def test_optimal_deliver...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def optimal_delivery_flow(route_matrix):", "function_name": "optimal_...
[ 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 collections import deque\n\ndef bfs(rGraph, s, t, parent):\n \"\"\"\n A BFS based function to check if there is a path from source 's' to \n sin...
trial_gpt4o_2
{ "original_instruction": "### Scenario:\nYou have been hired by a logistics company to optimize the transport routes within a new city-wide delivery network. The network is represented as a directed graph where nodes are intersections and edges are roads with certain capacities (the maximum number of delivery vans t...
0.595256
Data_Structure_25862
C
[ "bfs", "optimal_delivery_flow" ]
2
[ [ "optimal_delivery_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
1618246aa5e033fcee003f8b2a98cf6da4bf9d47
56a0d1f5f75a1e8b0a376c578099cb45aaa11687
v1.0
complete
Data_Structure
Data_Structure_25928_C
import random import time import copy def bogo_sort(arr): def is_sorted(arr): return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) attempts = 0 while not is_sorted(arr) and attempts < 10000: random.shuffle(arr) attempts += 1 return arr def merge_sort(arr): """...
import random import time import copy def bogo_sort(arr): def is_sorted(arr): return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) attempts = 0 while not is_sorted(arr) and attempts < 10000: random.shuffle(arr) attempts += 1 return arr def merge_sort(arr): if ...
from solution import compare_sorts, merge_sort def test_compare_sorts_sorted_array(): arr = [1, 2, 3, 4, 5] bogo_sorted_arr, merge_sorted_arr, bogo_time, efficient_time = compare_sorts(arr) assert bogo_sorted_arr == merge_sorted_arr == sorted(arr) def test_compare_sorts_reverse_sorted_array(): arr = [...
[ { "docstring": null, "function_declaration": "def bogo_sort(arr):", "function_name": "bogo_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": n...
[ 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": "import time\nimport random\n\ndef bogo_sort(arr):\n \"\"\"\n Bogo Sort: Randomly shuffles the array until it becomes sorted\n \"\"\"\n def is_sort...
trial_gpt4o_1
{ "original_instruction": "### Bogo Sort Analysis and Enhancement\n\n#### Scenario\nYou have come across an inefficient sorting algorithm called Bogo Sort which randomly shuffles the array until it becomes sorted. Your task is to understand its inefficiencies and then write a more practical approach.\n\n#### Task\n1....
0.559482
Data_Structure_25928
C
[ "bogo_sort", "merge_sort", "compare_sorts" ]
3
[ [ "compare_sorts", "bogo_sort" ], [ "compare_sorts", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0cc222de46a9b7cf285fd5d627caae910c1b6523
14fc59fc0e731741e41d6607b9dba28f8b4b7f98
v1.0
complete
Data_Structure
Data_Structure_25824_C
def caesar_encrypt(s: str, k: int) -> str: """ Encrypts the input string s by shifting each letter by k positions. Non-alphabetic characters remain unchanged. >>> caesar_encrypt("Hello, World!", 3) "Khoor, Zruog!" >>> caesar_encrypt("abc xyz", 2) "cde zab" """ pass def caesar_decryp...
def caesar_encrypt(s: str, k: int) -> str: """ Encrypts the input string s by shifting each letter by k positions. Non-alphabetic characters remain unchanged. """ def shift_char(c, k): if c.islower(): return chr(((ord(c) - ord('a') + k) % 26) + ord('a')) elif c.isupper():...
from solution import caesar_encrypt, caesar_decrypt def test_caesar_encrypt(): assert caesar_encrypt("Hello, World!", 3) == "Khoor, Zruog!" assert caesar_encrypt("abc xyz", 2) == "cde zab" assert caesar_encrypt("HELLO", 3) == "KHOOR" assert caesar_encrypt("Python3.6", 5) == "Udymts3.6" assert caesa...
[ { "docstring": "Encrypts the input string s by shifting each letter by k positions.\nNon-alphabetic characters remain unchanged.", "function_declaration": "def caesar_encrypt(s, k):", "function_name": "caesar_encrypt", "parameter_list": "(s, k)" }, { "docstring": "Decrypts the previously enc...
[ 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 caesar_encrypt(s: str, k: int) -> str:\n \"\"\"\n Encrypts the input string s by shifting each alphabetic character by k positions.\n Non-alphabe...
trial_gpt4o_2
{ "original_instruction": "### Caesar Cipher with Enhanced Features\n\nYou are tasked with implementing an enhanced version of Caesar Cipher that includes additional functionalities such as decrypting the encrypted text and handling customized shift values securely. Your solution should maintain efficiency and readab...
0.770172
Data_Structure_25824
C
[ "caesar_encrypt", "caesar_decrypt" ]
2
[ [ "caesar_decrypt", "caesar_encrypt" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f08eab73e257c434af25f2769bf44324c385eb1
dc5da9c548d4b312c71af47601b386702d1a1798
v1.0
complete
Data_Structure
Data_Structure_25670_C
def max_flow(adjacency_matrix): """ Calculate the maximum flow from the source node (first node) to the sink node (last node) in a directed graph represented by an adjacency matrix. :param adjacency_matrix: List[List[int]] : An n x n adjacency matrix representing the capacities of edges in the graph ...
def bfs(residual_graph, source, sink, parent): """ A utility function to perform BFS on the residual graph. Returns True if there is a path from source to sink in the residual graph. Additionally, fills parent to store the path. """ visited = [False] * len(residual_graph) queue = [] ...
from solution import max_flow def test_max_flow_simple(): 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_max_flow_singl...
[ { "docstring": "A utility function to perform BFS on the residual graph.\nReturns True if there is a path from source to sink in the residual graph.\nAdditionally, fills parent to store the path.", "function_declaration": "def bfs(residual_graph, source, sink, parent):", "function_name": "bfs", "par...
[ 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 max_flow(adjacency_matrix):\n \"\"\"\n Calculates the maximum flow from the source node (first node) to the sink node (last node)\n in a directed...
trial_gpt4o_2
{ "original_instruction": "### Maximum Flow Problem\n\n**Context**: You are working for a logistics company. They need to determine the maximum possible flow through their delivery network to optimize the routes taken by their trucks. The network is represented as a graph where each node is a distribution center, and...
0.599779
Data_Structure_25670
C
[ "bfs", "max_flow" ]
2
[ [ "max_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d242aa8864a09463ef7b77cb7d54192ee8fe6136
9ce726886b7cc4ae405018aefa0248fa8cd0901c
v1.0
complete
Data_Structure
Data_Structure_25584_C
def inplace_merge_sort(arr: List[int]) -> List[int]: """ Sorts an array in ascending order using in-place merge sort. Parameters: arr (List[int]): The list of integers to be sorted. Returns: List[int]: The sorted list. Example: >>> inplace_merge_sort([3, 1, 4, 1, 5, 9,...
def inplace_merge(arr, start, mid, end): """ Merges two sorted subarrays of arr in place. """ start2 = mid + 1 # If the direct merge is already sorted if arr[mid] <= arr[start2]: return while start <= mid and start2 <= end: if arr[start] <= arr[start2]: star...
from solution import inplace_merge_sort def test_empty_array(): assert inplace_merge_sort([]) == [] def test_single_element_array(): assert inplace_merge_sort([1]) == [1] def test_sorted_array(): assert inplace_merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert in...
[ { "docstring": "Merges two sorted subarrays of arr in place.", "function_declaration": "def inplace_merge(arr, start, mid, end):", "function_name": "inplace_merge", "parameter_list": "(arr, start, mid, end)" }, { "docstring": null, "function_declaration": "def inplace_merge_sort_helper(a...
[ 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 inplace_merge(arr, start, mid, end):\n \"\"\"\n Helper function to merge two sorted halves of an array `arr` in-place.\n \n Parameters:\n ...
trial_gpt4o_1
{ "original_instruction": "### Question\n\n**Merge Sort with In-Place Merge**\n\nYou are required to implement the Merge Sort algorithm but with an in-place merge operation to reduce auxiliary space usage.\n\n#### Requirements:\n- Implement the `inplace_merge_sort` function, which sorts an array in ascending order.\n...
0.628432
Data_Structure_25584
C
[ "inplace_merge", "inplace_merge_sort_helper", "inplace_merge_sort" ]
3
[ [ "inplace_merge_sort", "inplace_merge_sort_helper" ], [ "inplace_merge_sort_helper", "inplace_merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e1ed94765bf810cba3ebd598b785e7e5b79358d9
65bfaa5e338e0a3e7f7bf4de2b145954abd5bc59
v1.0
complete
Data_Structure
Data_Structure_25889_C
def generate_key(bits: int, seed: int = None) -> tuple: """ Generates an RSA keypair of size `bits`. - bits (int): The size of the key in bits. - seed (int): Seed for random prime generation (optional). Returns a tuple of three integers: (n, e, d). """ pass def encrypt(data: int, e: int, n...
import random from sympy import isprime, mod_inverse, nextprime def generate_prime(bits, seed=None): if seed is not None: random.seed(seed) prime_candidate = random.getrandbits(bits) while not isprime(prime_candidate): prime_candidate = nextprime(prime_candidate) return prime_candidate ...
from solution import generate_key, encrypt, decrypt def test_generate_key(): n, e, d = generate_key(16, seed=0) assert isinstance(n, int) and isinstance(e, int) and isinstance(d, int) assert n > 0 and e > 0 and d > 0 def test_encrypt_decrypt(): n, e, d = generate_key(16, seed=0) message = 42 e...
[ { "docstring": null, "function_declaration": "def generate_prime(bits, seed=None):", "function_name": "generate_prime", "parameter_list": "(bits, seed=None)" }, { "docstring": "Generates RSA keypair of size `bits`.", "function_declaration": "def generate_key(bits, seed=None):", "func...
[ 0, 0, 1, 0, 1, 1, 1, 0, 1 ]
5
medium
0.556
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime(bits, seed=None):\n if seed:\n random.seed(seed...
trial_gpt4o_9
{ "original_instruction": "### RSA Encryption and Decryption Implementation\n\nYou are required to implement a secure communication system based on the RSA encryption algorithm. RSA is a widely-used public-key cryptosystem that facilitates the encryption and decryption of data. You need to generate a public-private k...
0.763693
Data_Structure_25889
C
[ "generate_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
0ac2690020b5802eff70b0498af2556d7a8d1483
484416b1dc73e514fc4297afce765ed163fb805a
v1.0
complete
Data_Structure
Data_Structure_25588_C
import math def distance(x, y): """ Computes the Euclidean distance between two points x and y. >>> distance((0, 0), (0, 0)) 0.0 >>> distance((0, 0), (3, 4)) 5.0 >>> distance((1, 1), (4, 5)) 5.0 >>> distance((2, 3), (5, 7)) 5.0 """ def nearest_neighbor(x, tSet): ...
import math def distance(x, y): """ Computes the Euclidean distance between two points x and y. """ return math.sqrt(sum((xi - yi) ** 2 for xi, yi in zip(x, y))) def nearest_neighbor(x, tSet): """ Finds the label of the nearest neighbor for a given point x in the training set tSet. """ ...
from solution import distance, nearest_neighbor def test_distance_same_point(): assert distance((0, 0), (0, 0)) == 0 def test_distance_different_points(): assert distance((0, 0), (3, 4)) == 5 assert distance((1, 1), (4, 5)) == 5 assert distance((2, 3), (5, 7)) == 5 def test_nearest_neighbor_single_po...
[ { "docstring": "Computes the Euclidean distance between two points x and y.", "function_declaration": "def distance(x, y):", "function_name": "distance", "parameter_list": "(x, y)" }, { "docstring": "Finds the label of the nearest neighbor for a given point x in 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": "import math\n\ndef distance(x, y):\n \"\"\"\n Calculate the Euclidean distance between two points x and y.\n \"\"\"\n return math.sqrt(sum((xi - y...
trial_gpt4o_1
{ "original_instruction": "### Nearest Neighbor Classification\n\nYou are working on a pattern recognition system that uses the nearest neighbor algorithm to classify points in a two-dimensional space. You need to implement the `nearest_neighbor` function that will classify the new point based on the closest point in...
0.678388
Data_Structure_25588
C
[ "distance", "nearest_neighbor" ]
2
[ [ "nearest_neighbor", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9b23a6798bfc9af00e107c4e0fc98a1f06c955a1
ca0741f1c20c5c625ddbdf4ef57fe2b0a376f342
v1.0
complete
Data_Structure
Data_Structure_26281_C
def enhanced_radix_sort(arr: list[int], simulation: bool = False) -> list[int]: """ Radix sort implementation that sorts a list of non-negative integers. Optionally displays the sorting process after each digit iteration. >>> enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) [2, 24, 45, 66, 75, 90...
def enhanced_radix_sort(arr, simulation=False): if not arr: return arr # Get maximum number to figure out the number of digits max_num = max(arr) exp = 1 iteration = 0 while max_num // exp > 0: counting_sort(arr, exp) if simulation: print(f"iteration {it...
from solution import enhanced_radix_sort def test_enhanced_radix_sort_basic(): assert enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_enhanced_radix_sort_empty(): assert enhanced_radix_sort([]) == [] def test_enhanced_radix_sort_single_element(): asser...
[ { "docstring": null, "function_declaration": "def enhanced_radix_sort(arr, simulation=False):", "function_name": "enhanced_radix_sort", "parameter_list": "(arr, simulation=False)" }, { "docstring": null, "function_declaration": "def counting_sort(arr, exp):", "function_name": "counti...
[ 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 enhanced_radix_sort(arr, simulation=False):\n \"\"\"\n Sorts a list of non-negative integers using radix sort.\n Optionally prints the array afte...
trial_gpt4o_1
{ "original_instruction": "### Radix Sort Implementation Challenge\n\nYou are tasked with implementing a radix sort algorithm that efficiently sorts non-negative integers. Your goal is to ensure the function sorts the input array correctly and demonstrates an understanding of the radix sort's steps and mechanisms.\n\...
0.676248
Data_Structure_26281
C
[ "enhanced_radix_sort", "counting_sort" ]
2
[ [ "enhanced_radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
65806dbefd1d5fb878cc89a5ff44c3fd81d5758b
54ad0bdd7fda4c9318c0cac5b80795e60b9653c1
v1.0
complete
Data_Structure
Data_Structure_26201_C
from typing import List def is_prime(n: int) -> bool: """ Check if a number n is prime. >>> is_prime(2) == True >>> is_prime(3) == True >>> is_prime(4) == False >>> is_prime(17) == True >>> is_prime(18) == False >>> is_prime(19) == True """ pass def find_primitive_root(n:...
from math import gcd def is_prime(n): """ Check if a number n 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: return False ...
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(17) == True assert is_prime(18) == False assert is_prime(19) == True def test_find_primitive_ro...
[ { "docstring": "Check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find all primitive roots of a prime p.", "function_declaration": "def find_primitive_root(p):", "function_name": "find_p...
[ 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 is_prime(n):\n \"\"\"\n Determines if a number is a prime number.\n \n Args:\n n: int - the number to check\n \n Returns:\n bool -...
trial_gpt4o_2
{ "original_instruction": "### Scenario\nAlice and Bob wish to establish a secure communication channel using the Diffie-Hellman key exchange. You will write Python functions to automate this process. \n\n### Objective\nImplement the complete Diffie-Hellman key exchange algorithm, ensuring all aspects such as primali...
0.633854
Data_Structure_26201
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
5c1dc2b0adc7766cb25d5b174bed27d9a6579752
4b7fc7ab6084f4eeabf0de79355e5af7039d6663
v1.0
complete
Data_Structure
Data_Structure_26200_C
from typing import List def maximum_flow(graph: List[List[int]]) -> int: """ Computes the maximum flow in the given flow network. The flow network is represented as a 2D list where `graph[u][v]` indicates the capacity from node `u` to node `v`. Args: graph: A 2D list of integers representing ...
from typing import List from collections import deque def bfs(residual_graph: List[List[int]], source: int, sink: int, parent: List[int]) -> bool: """ BFS to find a path from source to sink in the residual graph. Updates parent[] to store the path. Returns True if there is a path from source to sink, False...
from solution import 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 maximum_flow(graph) == 23 def test_small_graph(): g...
[ { "docstring": "BFS to find a path from source to sink in the residual graph. Updates parent[] to store the path.\nReturns True if there is a path from source to sink, False otherwise.", "function_declaration": "def bfs(residual_graph, source, sink, parent):", "function_name": "bfs", "parameter_list...
[ 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\nfrom collections import deque\n\ndef bfs(residual_graph: List[List[int]], source: int, sink: int, parent: List[int]) -> bool:\n \"...
trial_gpt4o_0
{ "original_instruction": "#### Scenario:\nYou have been hired as a network engineer for a telecommunications company. Your task is to analyze the current network to determine how efficiently data flows from the data center (source) to the main server hub (sink) using the given graph. \n\n#### Problem Statement:\nWri...
0.592748
Data_Structure_26200
C
[ "bfs", "maximum_flow" ]
2
[ [ "maximum_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8629fd807349890f8be4189976e88328ebcd1319
a1353bc19ca5b29d896ff00410bd76a72206eef5
v1.0
complete
Data_Structure
Data_Structure_26026_C
import random from typing import Tuple def is_probably_prime(n: int, k: int) -> bool: """Rabin-Miller primality test to check if given number is probably prime.""" # (Implementation details of is_probably_prime function) def generate_prime(bit_length: int, k: int = 40) -> int: """Generates a prime num...
import random def is_probably_prime(n, k): """Rabin-Miller primality test.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False # Write (n - 1) as 2^r * d r, d = 0, n - 1 while d % 2 == 0: r += 1 d //= 2 def ...
from solution import generate_prime, is_probably_prime def test_generate_prime_bit_length(): prime = generate_prime(16, k=40) assert prime.bit_length() == 16, f"Expected bit length of 16, but got {prime.bit_length()}" def test_prime_is_probable(): prime = generate_prime(16, k=40) assert is_probably_pr...
[ { "docstring": "Rabin-Miller primality test.", "function_declaration": "def is_probably_prime(n, k):", "function_name": "is_probably_prime", "parameter_list": "(n, k)" }, { "docstring": "Generates a prime number of the given bit length.", "function_declaration": "def generate_prime(bit_l...
[ 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 miller_rabin_test(n: int, k: int) -> bool:\n \"\"\" Perform the Miller-Rabin Primality Test to check if n is a probable prime. \"\"\"\...
trial_gpt4o_1
{ "original_instruction": "## Problem Statement\n\nYou are provided with a probabilistic algorithm, the Rabin-Miller Primality Test, which helps determine if a number is probably prime. Your task is to implement a function that leverages this algorithm to generate prime numbers of a specified bit length.\n\n### Funct...
0.689697
Data_Structure_26026
C
[ "is_probably_prime", "generate_prime" ]
2
[ [ "generate_prime", "is_probably_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
dd8a55aa7c6a10281ce378328cca85f84a0b5531
572f5321200f73decdc2e2d8ba8f1f623b7f20f9
v1.0
complete
Data_Structure
Data_Structure_25291_C
from typing import List def search_insert(array: List[int], val: int) -> int: """ Find the index where `val` should be inserted to maintain sorted order. Uses binary search to determine the insertion point. """ low = 0 high = len(array) - 1 while low <= high: mid = low + (high - low...
from typing import List def search_insert(array: List[int], val: int) -> int: """ Find the index where `val` should be inserted to maintain sorted order. Uses binary search to determine the insertion point. """ low = 0 high = len(array) - 1 while low <= high: mid = low + (high - low...
from solution import optimized_insertion_sort def test_optimized_insertion_sort(): assert optimized_insertion_sort([4, 3, 2, 10, 12, 1, 5, 6]) == [1, 2, 3, 4, 5, 6, 10, 12] assert optimized_insertion_sort([1, 3, 5, 7, 9, 2, 4, 6, 8]) == [1, 2, 3, 4, 5, 6, 7, 8, 9] assert optimized_insertion_sort([]) == [] ...
[ { "docstring": "Find the index where `val` should be inserted to maintain sorted order.\nUses binary search to determine the insertion point.", "function_declaration": "def search_insert(array, val):", "function_name": "search_insert", "parameter_list": "(array, val)" }, { "docstring": "Sort...
[ 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], val: int) -> int:\n low, high = 0, len(array) - 1\n while low <= high:\n mid = low...
trial_gpt4o_2
{ "original_instruction": "#### Context\nYou are tasked with designing a more efficient insertion sort algorithm by utilizing binary search to find the insertion point quickly. This improvement helps reduce the time complexity of finding the insertion point from O(n) to O(log n) for each insertion, achieving overall ...
0.648017
Data_Structure_25291
C
[ "search_insert", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a5308811f371f4761381974e891ba3eb2222addb
3618b9bdad775dba80ba58c532ac5b050cc8a183
v1.0
complete
Data_Structure
Data_Structure_25573_C
from typing import List def maximum_flow_bfs(adjacency_matrix: List[List[int]]) -> int: """ Compute the maximum flow from the source (first node) to the sink (last node) in a given network represented by an `n x n` adjacency matrix. >>> graph = [ ... [0, 16, 13, 0, 0, 0], ... [0, 0, 10, 12, 0, ...
from collections import deque def bfs_find_augmenting_path(residual_graph, source, sink, parent): visited = [False] * len(residual_graph) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity in enumerate(residual_graph[u]): ...
from solution import maximum_flow_bfs def test_simple_case(): graph = [ [0, 1], [0, 0] ] assert maximum_flow_bfs(graph) == 1 def test_medium_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], ...
[ { "docstring": null, "function_declaration": "def bfs_find_augmenting_path(residual_graph, source, sink, parent):", "function_name": "bfs_find_augmenting_path", "parameter_list": "(residual_graph, source, sink, parent)" }, { "docstring": null, "function_declaration": "def maximum_flow_bf...
[ 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 bfs(residual_graph, source, sink, parent):\n visited = set()\n queue = [source]\n\n while queue:\n u = queue.pop(0)\n if u == sink:...
trial_gpt4o_1
{ "original_instruction": "## Maximum Flow Problem: Augmenting Path Algorithm Using BFS\n\n### Background:\nYou are given a network of pipelines that transport water between interconnected reservoirs. Each connection can be represented as an edge with a specific capacity. You need to determine the maximum amount of w...
0.610064
Data_Structure_25573
C
[ "bfs_find_augmenting_path", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs_find_augmenting_path" ] ]
1
[]
false
[]
false
pytest
true
[]
true
774b18d27f4a3f25f8cd8e27d6397e2e0a4b4985
a34637e2a8efcba4cdf60b21f233e6a082563fa7
v1.0
complete
Data_Structure
Data_Structure_25833_C
from typing import List def min_matrix_multiplications(dims: List[int]) -> int: """Find the minimum number of multiplications needed to multiply the chain of matrices. >>> min_matrix_multiplications([40, 20, 30, 10, 30]) 26000 >>> min_matrix_multiplications([10, 20, 30]) 6000 >>> min_matrix_mul...
def min_matrix_multiplications(dims): n = len(dims) - 1 m = [[0 for x in range(n)] for y in range(n)] s = [[0 for x in range(n)] for y in range(n)] for L in range(2, n+1): for i in range(n-L+1): j = i + L - 1 m[i][j] = float('inf') for k in range(i, j): ...
from solution import min_matrix_multiplications def test_matrix_chain_simple(): dims = [40, 20, 30, 10, 30] assert min_matrix_multiplications(dims) == 26000 def test_matrix_chain_two_matrices(): dims = [10, 20, 30] assert min_matrix_multiplications(dims) == 6000 def test_matrix_chain_three_matrices()...
[ { "docstring": null, "function_declaration": "def min_matrix_multiplications(dims):", "function_name": "min_matrix_multiplications", "parameter_list": "(dims)" }, { "docstring": null, "function_declaration": "def print_optimal_schedule(s, i, j):", "function_name": "print_optimal_sche...
[ 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": "def min_matrix_multiplications(dims):\n n = len(dims) - 1\n m = [[0 for _ in range(n)] for _ in range(n)]\n s = [[0 for _ in range(n)] for _ in range...
trial_gpt4o_8
{ "original_instruction": "### Question\n\n#### Problem Statement:\n\nWrite a Python function to solve the Matrix Chain Multiplication problem using dynamic programming. Your function should take an array of integers representing the dimensions of matrices and return an integer denoting the minimum number of multipli...
0.545182
Data_Structure_25833
C
[ "min_matrix_multiplications", "print_optimal_schedule" ]
2
[ [ "min_matrix_multiplications", "print_optimal_schedule" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3448be345af64eb464dd12424b5b95c69f1ba216
80c6fd50d3fe2f48da2fb1c7d5b55edd6c30e0f5
v1.0
complete
Data_Structure
Data_Structure_26429_C
def optimized_quick_sort(arr): """ Sorts the array in ascending order using an optimized Quick Sort algorithm. Parameters: arr (List[int]): The list of integers to sort. Returns: List[int]: The sorted list in ascending order. >>> optimized_quick_sort([3, 6, 8, 10, 1, 2, 1]) ...
def _median_of_three(arr, low, high): mid = (low + high) // 2 a, b, c = arr[low], arr[mid], arr[high] if a > b: if a < c: return low elif b > c: return mid else: return high else: if a > c: return low elif b < c: ...
from solution import optimized_quick_sort def test_sorted_array(): assert optimized_quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert optimized_quick_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_unsorted_array(): assert optimized_quick_sort([3, 6, 8, 10, 1, 2, 1]...
[ { "docstring": null, "function_declaration": "def _median_of_three(arr, low, high):", "function_name": "_median_of_three", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def _partition(arr, low, high):", "function_name": "_partition", "param...
[ 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 _median_of_three(arr, low, high):\n mid = (low + high) // 2\n a, b, c = arr[low], arr[mid], arr[high]\n if a > b:\n if a < c:\n ...
trial_gpt4o_0
{ "original_instruction": "**Context**:\nYou have been hired to enhance the performance of a company's data handling processes. A key area identified is the sorting of records based on various criteria. One specific challenge is ensuring efficient sorting of large datasets while maintaining optimal performance across...
0.656521
Data_Structure_26429
C
[ "_median_of_three", "_partition", "_quick_sort_helper", "optimized_quick_sort" ]
4
[ [ "_partition", "_median_of_three" ], [ "_quick_sort_helper", "_partition" ], [ "optimized_quick_sort", "_quick_sort_helper" ] ]
3
[]
false
[]
false
pytest
true
[]
true
5a7521551bbb5230c7c3d314e601bb65a389c2c7
417938417be4352f4fe5a8ab9143a4f6315dde5e
v1.0
complete
Data_Structure
Data_Structure_25909_C
class Node: def __init__(self, val=0, next=None): self.val = val self.next = next def intersection(h1: Node, h2: Node) -> Optional[Node]: """ Find the intersection node between two singly linked lists defined by reference. :param h1: Node - The head of the first linked list. :param...
class Node: def __init__(self, val=0, next=None): self.val = val self.next = next def get_length(head: Node) -> int: length = 0 current = head while current: length += 1 current = current.next return length def intersection(h1: Node, h2: Node) -> Node: if not h1...
from solution import Node, intersection def test_intersection_common_case(): a1 = Node(1) b1 = Node(3) c1 = Node(5) d = Node(7) e = Node(9) f = Node(11) a2 = Node(2) b2 = Node(4) c2 = Node(6) a1.next = b1 b1.next = c1 c1.next = d d.next = e e.next = f a2.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": "class Node:\n def __init__(self, value=0, next=None):\n self.value = value\n self.next = next\n\ndef intersection(h1: Node, h2: Node) -> Node...
trial_gpt4o_2
{ "original_instruction": "### Question: Find the Intersection Node of Two Singly Linked Lists\n\n#### Objective\nImplement a function to find the intersection node between two singly linked lists. The intersection is defined by reference, not by value.\n\n#### Problem Statement\nTwo linked lists intersect if they sh...
0.552854
Data_Structure_25909
C
[ "get_length", "intersection" ]
2
[ [ "intersection", "get_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
4500f8af1810d42f5d3efe99f143c888bb73c926
4aacda8f9c3db4e8696c2080b36f851e95c2f03b
v1.0
complete
Data_Structure
Data_Structure_25593_C
def optimized_factorial(n: int, mod: int) -> int: """ Calculate the factorial of a non-negative integer using an optimized approach to avoid large intermediate values during computation, particularly under modulus. Parameters: n (int): The non-negative integer whose factorial needs to be compu...
def optimized_factorial(n, mod): """ Returns n! % mod using an optimized approach. """ result = 1 for i in range(2, n + 1): result = (result * i) % mod return result def factorial_traditional(n): """ Returns n! using the traditional recursive approach. """ if n == 0 or n...
from solution import optimized_factorial, compare_factorials, factorial_traditional def test_optimized_factorial_small(): assert optimized_factorial(5, 13) == 3 # 5! % 13 == 120 % 13 == 3 def test_optimized_factorial_large(): assert optimized_factorial(100, 1000000007) == 437918130 # Known result def test_...
[ { "docstring": "Returns n! % mod using an optimized approach.", "function_declaration": "def optimized_factorial(n, mod):", "function_name": "optimized_factorial", "parameter_list": "(n, mod)" }, { "docstring": "Returns n! using the traditional recursive approach.", "function_declaration...
[ 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 optimized_factorial(n, mod):\n \"\"\"\n Calculate n! % mod using an optimized approach.\n \"\"\"\n if n == 0 or n == 1:\n return 1\n ...
trial_gpt4o_2
{ "original_instruction": "You are tasked with implementing a function to calculate the factorial of a non-negative integer using an optimized approach that avoids large intermediate values directly during computation, particularly under modulus. Your function should be optimized for handling inputs where `n` and `mo...
0.615733
Data_Structure_25593
C
[ "optimized_factorial", "factorial_traditional", "compare_factorials" ]
3
[ [ "compare_factorials", "factorial_traditional" ], [ "compare_factorials", "optimized_factorial" ] ]
2
[]
false
[]
false
pytest
true
[]
true
07f011104a838bf780751248459abc7f810e7900
1ab119e1669bdcb7e7331ed397867f2bd377d5a1
v1.0
complete
Data_Structure
Data_Structure_26040_C
import heapq import os from collections import defaultdict def huffman_encode(input_file, output_file): """Encode data from input_file using Huffman coding and write to output_file. Args: input_file (str): Path to the input file containing data to be compressed (binary format). output_file (st...
import heapq import os from collections import defaultdict class HuffmanNode: def __init__(self, symbol=None, freq=0, left=None, right=None): self.symbol = symbol self.freq = freq self.left = left self.right = right def __lt__(self, other): return self.freq < other....
import os import pytest from solution import huffman_encode, huffman_decode def test_huffman_empty_file(tmp_path): input_file = tmp_path / "input.txt" encoded_file = tmp_path / "encoded.bin" decoded_file = tmp_path / "decoded.txt" input_file.write_bytes(b"") huffman_encode(input_file, encoded...
[]
[ 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 heapq\nimport os\nfrom collections import defaultdict\n\nclass HuffmanNode:\n def __init__(self, symbol=None, freq=0, left=None, right=None):\n ...
trial_gpt4o_0
{ "original_instruction": "### Coding Challenge: Implement Huffman Encoding and Decoding\n\n#### Scenario\nImagine you are working on a software project that requires efficient storage and transfer of data files. To achieve this, you decide to implement Huffman Coding, a popular compression algorithm. Your task is to...
0.534893
Data_Structure_26040
C
[ "build_frequency_table", "build_huffman_tree", "build_codes_table", "huffman_encode", "decode_huffman_codes", "huffman_decode" ]
6
[ [ "huffman_decode", "decode_huffman_codes" ], [ "huffman_encode", "build_codes_table" ], [ "huffman_encode", "build_frequency_table" ], [ "huffman_encode", "build_huffman_tree" ] ]
4
[]
false
[ "HuffmanNode" ]
true
pytest
true
[]
true
42dc8438a2ac781c347465b23deb99b21c1b10ae
598963c1e6d12311d1b045e8cff1aebe23d04acc
v1.0
complete
Data_Structure
Data_Structure_26048_C
def multiply_bitwise_operator(a: int, b: int) -> int: """ Multiply two non-negative integers using bitwise operations. >>> multiply_bitwise_operator(3, 4) == 12 >>> multiply_bitwise_operator(7, 6) == 42 >>> multiply_bitwise_operator(0, 10) == 0 """ pass def test_multiply_positive_numbers(): ...
def multiply_bitwise_operator(a: int, b: int) -> int: """ Multiply two non-negative integers using bitwise operations. """ result = 0 while b > 0: # If the least significant bit of b is set, add `a` to the result if (b & 1) != 0: result = add_bitwise(result, a) ...
from solution import multiply_bitwise_operator def test_multiply_positive_numbers(): assert multiply_bitwise_operator(3, 4) == 12 assert multiply_bitwise_operator(7, 6) == 42 assert multiply_bitwise_operator(15, 15) == 225 def test_multiply_with_zero(): assert multiply_bitwise_operator(0, 10) == 0 ...
[ { "docstring": "Multiply two non-negative integers using bitwise operations.", "function_declaration": "def multiply_bitwise_operator(a, b):", "function_name": "multiply_bitwise_operator", "parameter_list": "(a, b)" }, { "docstring": "Add two non-negative integers using bitwise operations.",...
[ 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 multiply_bitwise_operator(a: int, b: int) -> int:\n \"\"\"\n Multiplies two non-negative integers using bitwise operations.\n \"\"\"\n result ...
trial_gpt4o_2
{ "original_instruction": "### Problem Description\n\nWrite a function `multiply_bitwise_operator` that multiplies two non-negative integers using bitwise operations. This function should not use the `*` operator. Instead, leverage the properties of bitwise operations. Below is the expected behavior of your function:...
0.606943
Data_Structure_26048
C
[ "multiply_bitwise_operator", "add_bitwise" ]
2
[ [ "multiply_bitwise_operator", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
19ecacd66c5b10c64ae99fbcf80b6c2919c797ea
d497e091cefb2c541e1d48880eb7c5d2b6272431
v1.0
complete
Data_Structure
Data_Structure_26513_C
def is_prime(num: int) -> bool: """ Checks 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 >>> is_prime(19) True >>> is_prime(1) False """ def primitive_root(p: int) -> int: """ Finds a primit...
import random import math def is_prime(num): if num < 2: return False for i in range(2, int(math.sqrt(num)) + 1): if num % i == 0: return False return True def primitive_root(p): if not is_prime(p): raise ValueError(f"{p} is not a prime number.") def is_pri...
import pytest from solution import is_prime, 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(17) == True assert is_prime(18) == False assert is_prime(19) == True assert is_prim...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def primitive_root(p):", "function_name": "primitive_root", "parameter_list": "(p)" }, { "docstring":...
[ 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": "import random\n\ndef is_prime(num):\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if num <= 3:\n ...
trial_gpt4o_1
{ "original_instruction": "### Coding Challenge: Implement a Robust Diffie-Hellman Key Exchange in Python\n\n#### Objective\nYour task is to implement a secure Diffie-Hellman key exchange algorithm that ensures both participants (Alice and Bob) can securely generate and share a secret key over an insecure communicati...
0.573096
Data_Structure_26513
C
[ "is_prime", "primitive_root", "diffie_hellman_key_exchange", "is_primitive_root" ]
4
[ [ "diffie_hellman_key_exchange", "is_prime" ], [ "diffie_hellman_key_exchange", "is_primitive_root" ], [ "primitive_root", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6a2864868ff0c72b97eeb1c840e108e2108615b6
a593cd7490594dc51486d96c0db32f4e55339e02
v1.0
complete
Data_Structure
Data_Structure_26905_C
def in_place_merge_sort(arr): """ Perform in-place merge sort on the input list. Parameters: arr (List[int]): The list of integers to sort. Returns: List[int]: Sorted list using in-place merge sort. """ pass def in_place_merge(arr, start, mid, end): """ ...
def in_place_merge_sort(arr): """ Perform in-place merge sort on the input list. Parameters: arr (List[int]): The list of integers to sort. Returns: List[int]: Sorted list using in-place merge sort. """ if arr is None or len(arr) <= 1: return arr def so...
from solution import in_place_merge_sort, in_place_merge def test_in_place_merge_sort_empty(): assert in_place_merge_sort([]) == [] def test_in_place_merge_sort_single_element(): assert in_place_merge_sort([1]) == [1] def test_in_place_merge_sort_sorted(): assert in_place_merge_sort([1, 2, 3, 4, 5]) == [...
[ { "docstring": "Perform in-place merge sort on the input list.\n\nParameters:\n arr (List[int]): The list of integers to sort.\n \nReturns:\n List[int]: Sorted list using in-place merge sort.", "function_declaration": "def in_place_merge_sort(arr):", "function_name": "in_place_merge_sort", ...
[ 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 in_place_merge_sort(arr):\n \"\"\"\n Perform in-place merge sort on the input list.\n \n Parameters:\n arr (List[int]): The list of int...
trial_gpt4o_2
{ "original_instruction": "### Merge Sort Implementation with In-Place Merge\n\n#### Scenario:\nYou are tasked with optimizing a merge sort algorithm for an embedded system with limited memory. To achieve this, you need to implement an in-place merge sort, minimizing additional memory usage while maintaining the core...
0.634364
Data_Structure_26905
C
[ "in_place_merge_sort", "in_place_merge" ]
2
[ [ "in_place_merge_sort", "in_place_merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
38c882e9afdcd8e5c926a1cfb3b0cfcb27d44ea2
68f9e36e8ebd18dfff29fd68355d4dc8ca36e5fa
v1.0
complete
Data_Structure
Data_Structure_26930_C
def min_heap_sort(arr): """ Sorts an array in ascending order using min-heap. Args: arr: A list of integers where 1 <= len(arr) <= 10^5. Returns: A sorted list of integers in ascending order. """ def is_sorted(arr): """ Checks if the array is sorted in ascending order. Args: ar...
def min_heapify(arr, n, i): """ Helper function to maintain the min-heap property """ smallest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] < arr[smallest]: smallest = left if right < n and arr[right] < arr[smallest]: smallest = right if smalles...
from solution import min_heap_sort, is_sorted def test_min_heap_sort_simple(): arr = [3, 2, 1, 4, 5] sorted_arr = min_heap_sort(arr) assert is_sorted(sorted_arr) == True assert sorted_arr == sorted(arr) def test_min_heap_sort_with_negatives(): arr = [3, -2, 1, -4, 5] sorted_arr = min_heap_sort...
[ { "docstring": "Helper function to maintain the min-heap property", "function_declaration": "def min_heapify(arr, n, i):", "function_name": "min_heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Sorts an array in ascending order using min-heap", "function_declaration": "def mi...
[ 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 min_heap_sort(arr):\n def heapify(arr, n, i):\n smallest = i\n l = 2 * i + 1\n r = 2 * i + 2\n \n if l < n and arr[l...
trial_gpt4o_2
{ "original_instruction": "You are given two functions, `max_heap_sort` and `min_heap_sort`, which sort an array in ascending order using heap sort with max-heap and min-heap respectively. However, it is observed that `min_heap_sort` does not sort the array correctly. Investigate the `min_heap_sort` function to ident...
0.637355
Data_Structure_26930
C
[ "min_heapify", "min_heap_sort", "is_sorted" ]
3
[ [ "min_heap_sort", "min_heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ddf8d82f797c18e2d19c328da1d6a97673f7d801
f1c5b29a0f22ec6371c0079623f9d72255f4385e
v1.0
complete
Data_Structure
Data_Structure_26462_C
def int_to_bytes_big_endian(num: int) -> bytes: """ Convert an integer to a byte sequence in big-endian format. >>> int_to_bytes_big_endian(1) == b'\x01' >>> int_to_bytes_big_endian(256) == b'\x01\x00' >>> int_to_bytes_big_endian(65536) == b'\x01\x00\x00' >>> int_to_bytes_big_endian(0) == b'' ""...
def int_to_bytes_big_endian(num: int) -> bytes: return num.to_bytes((num.bit_length() + 7) // 8, byteorder='big') def int_to_bytes_little_endian(num: int) -> bytes: return num.to_bytes((num.bit_length() + 7) // 8, byteorder='little') def bytes_to_int_big_endian(b: bytes) -> int: return int.from_bytes(b, b...
def test_int_to_bytes_big_endian(): assert int_to_bytes_big_endian(1) == b'\x01' assert int_to_bytes_big_endian(256) == b'\x01\x00' assert int_to_bytes_big_endian(65536) == b'\x01\x00\x00' assert int_to_bytes_big_endian(0) == b'' def test_int_to_bytes_little_endian(): assert int_to_bytes_little_end...
[ { "docstring": null, "function_declaration": "def int_to_bytes_big_endian(num):", "function_name": "int_to_bytes_big_endian", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def int_to_bytes_little_endian(num):", "function_name": "int_to_bytes_little_endian...
[ 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 int_to_bytes_big_endian(num: int) -> bytes:\n \"\"\"\n Convert an integer to a byte sequence in big-endian format.\n \"\"\"\n return num.to_by...
trial_gpt4o_2
{ "original_instruction": "Given the functions to convert integers to byte sequences (both big-endian and little-endian) and vice versa, write a new function that verifies if the conversions are performed correctly. The function `verify_conversion` should take an integer `num` and check that converting it to bytes an...
0.540163
Data_Structure_26462
C
[ "int_to_bytes_big_endian", "int_to_bytes_little_endian", "bytes_to_int_big_endian", "bytes_to_int_little_endian", "verify_conversion" ]
5
[ [ "verify_conversion", "bytes_to_int_big_endian" ], [ "verify_conversion", "bytes_to_int_little_endian" ], [ "verify_conversion", "int_to_bytes_big_endian" ], [ "verify_conversion", "int_to_bytes_little_endian" ] ]
4
[]
false
[]
false
pytest
false
[]
true
1b0e5626a01c45b2531de4d6a57641971987eb4d
bec62c95d8db4617b58fb0aae7f5c3a88fb60683
v1.0
complete
Data_Structure
Data_Structure_26627_C
import random from typing import List def is_sorted(arr: List[int]) -> bool: """ 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 modified_bogo_sort(arr: List[int], simulation: bool = False) ...
import random from typing import List def is_sorted(arr: List[int]) -> bool: """ 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 modified_bogo_sort(arr: List[int], simulation: bool = False) ...
from solution import modified_bogo_sort def test_modified_bogo_sort_small_list(): arr = [3, 1, 4, 2] sorted_arr = modified_bogo_sort(arr.copy()) assert sorted_arr == sorted(arr) def test_modified_bogo_sort_empty_list(): arr = [] sorted_arr = modified_bogo_sort(arr.copy()) assert sorted_arr == ...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Implements the Modified Bogo Sort algorithm.", "function_declaration": "def modified_bogo_sort(arr,...
[ 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 List\n\ndef is_sorted(arr: List[int]) -> bool:\n \"\"\"\n Returns True if the array is sorted in non-decreasing order,...
trial_gpt4o_1
{ "original_instruction": "### Bogo Sort Extension\n\n#### Context:\nBogo Sort is a highly inefficient algorithm due to its randomized approach to sorting. While Bogo Sort is not practical for real-world sorting tasks, it can be modified to create a new hypothetical sorting algorithm for educational purposes. Your ta...
0.610043
Data_Structure_26627
C
[ "is_sorted", "modified_bogo_sort" ]
2
[ [ "modified_bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
357397574377e0a5396af218a582ca2c86fc3774
97d6981e0514ad872135169510e9c6769ac2de47