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_11753_C
from typing import List def quick_sort(arr: List[int]) -> List[int]: """ Sorts the array `arr` in-place using the Quick Sort algorithm with enhancements for handling large arrays efficiently. >>> quick_sort([3, 6, 8, 10, 1, 2, 1]) [1, 1, 2, 3, 6, 8, 10] >>> quick_sort([5, 4, 3, 2, 1]) [1, 2, ...
from typing import List def insertion_sort(arr: List[int], low: int, high: int) -> None: for i in range(low + 1, high + 1): key = arr[i] j = i - 1 while j >= low and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def median_of_three(arr: List[int]...
import pytest from solution import quick_sort def test_quick_sort_empty_array(): assert quick_sort([]) == [] def test_quick_sort_single_element(): assert quick_sort([1]) == [1] def test_quick_sort_already_sorted(): assert quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_quick_sort_reverse_sorted(...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_sort", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def median_of_three(arr, low, high):", "function_name": "median_of_three", ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(arr: List[int], left: int, right: int):\n for i in range(left + 1, right + 1):\n key = arr[i]\n ...
trial_gpt4o_1
{ "original_instruction": "**Problem Statement**:\n\nYou are tasked with implementing the in-place sorting algorithm, Quick Sort, to help in organizing arrays of integers more efficiently. Your implementation should aim for average-case time complexity of O(n log(n)) and handle edge cases explicitly.\n\n**Requirement...
0.647808
Data_Structure_11753
C
[ "insertion_sort", "median_of_three", "partition", "quick_sort_recursive", "quick_sort" ]
5
[ [ "partition", "median_of_three" ], [ "quick_sort", "quick_sort_recursive" ], [ "quick_sort_recursive", "insertion_sort" ], [ "quick_sort_recursive", "partition" ] ]
4
[]
false
[]
false
pytest
true
[]
true
7bd5bec626f36a6fcf8d65902fa0f8e50cb1921e
aa3a12fa12f9e009d55700b61a0cb1b284f2ff46
v1.0
complete
Data_Structure
Data_Structure_12814_C
def decimal_to_binary_ip(ip: str) -> str: """ Convert a dotted-decimal IP address to its 32-bit binary representation. >>> decimal_to_binary_ip("192.168.0.1") '11000000.10101000.00000000.00000001' >>> decimal_to_binary_ip("255.255.255.255") '11111111.11111111.11111111.11111111' ...
def decimal_to_binary_util(val): """ Converts an 8-bit decimal number to its 8-bit binary representation. """ bits = [128, 64, 32, 16, 8, 4, 2, 1] val = int(val) binary_rep = '' for bit in bits: if val >= bit: binary_rep += str(1) val -= bit else: ...
import pytest from solution import decimal_to_binary_ip, decimal_to_binary_util def test_decimal_to_binary_util(): assert decimal_to_binary_util(192) == "11000000" assert decimal_to_binary_util(168) == "10101000" assert decimal_to_binary_util(0) == "00000000" assert decimal_to_binary_util(1) == "000000...
[ { "docstring": "Converts an 8-bit decimal number to its 8-bit binary representation.", "function_declaration": "def decimal_to_binary_util(val):", "function_name": "decimal_to_binary_util", "parameter_list": "(val)" }, { "docstring": "Convert a dotted-decimal IP address to its 32-bit binary ...
[ 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 decimal_to_binary_util(val):\n bits = [128, 64, 32, 16, 8, 4, 2, 1]\n val = int(val)\n binary_rep = ''\n for bit in bits:\n if val >= b...
trial_gpt4o_2
{ "original_instruction": "### Scenario\nYou are working on a networking tool that requires frequent conversion of dotted-decimal IP addresses to their binary representations to manage subnets effectively. Your task is to create utility functions that will take a valid IP address in dotted-decimal notation and produc...
0.681021
Data_Structure_12814
C
[ "decimal_to_binary_util", "decimal_to_binary_ip" ]
2
[ [ "decimal_to_binary_ip", "decimal_to_binary_util" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0beb84592bbea43798e67330c2f8e5f88222bd1e
6a284b6c11966806411a8880f470a81faf8b0c8c
v1.0
complete
Data_Structure
Data_Structure_12070_C
import random from typing import Optional, Tuple def rsa_generate_key(k: int, seed: Optional[int] = None) -> Tuple[int, int, int]: """ Generate RSA key pair. :param k: A positive integer representing the number of bits for the modulus `n`. :param seed: An optional integer seed for the random numbe...
import random from typing import Optional, Tuple from sympy import isprime, mod_inverse def generate_prime_candidate(bits: int) -> int: """ Generate an odd integer randomly """ p = random.getrandbits(bits) # Apply a mask to set MSB and LSB to 1 p |= (1 << bits - 1) | 1 return p def generate_prime(...
from solution import rsa_generate_key, rsa_encrypt, rsa_decrypt def test_rsa_key_generation(): n, e, d = rsa_generate_key(16, seed=42) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert n > 0 assert 1 < e < n assert 1 < d < n def test_rsa_encryption_decryp...
[ { "docstring": "Generate an odd integer randomly ", "function_declaration": "def generate_prime_candidate(bits):", "function_name": "generate_prime_candidate", "parameter_list": "(bits)" }, { "docstring": "Generate a prime number of given bits ", "function_declaration": "def generate_pri...
[ 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 random\nfrom typing import Optional, Tuple\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime_candidate(bits: int) -> int:\n \"\"\" Gener...
trial_gpt4o_0
{ "original_instruction": "You are required to implement the RSA key generation, encryption, and decryption process as described in the RSA algorithm. This entails generating a pair of keys (public and private) and using these keys to encrypt and decrypt data. Your task is to write three functions: `rsa_generate_key`...
0.76457
Data_Structure_12070
C
[ "generate_prime_candidate", "generate_prime", "rsa_generate_key", "rsa_encrypt", "rsa_decrypt" ]
5
[ [ "generate_prime", "generate_prime_candidate" ], [ "rsa_generate_key", "generate_prime" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
59db814602a62171556545356c14d5be4d1a89fb
e36d53b31a33a0e41f51cd871b54eeef79a4c8b4
v1.0
complete
Data_Structure
Data_Structure_13199_C
from typing import List def bucket_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the Bucket Sort algorithm. Each bucket is sorted using Merge Sort. Parameters: arr (List[int]): A list of integers to be sorted. Returns: List[int]: The sorted list of intege...
from typing import List import math def merge_sort(arr: List[int]) -> List[int]: 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: List[int], right: List[int]) -> List[int]: result = [] ...
from solution import bucket_sort def test_bucket_sort_with_positive_numbers(): assert bucket_sort([29, 25, 3, 49, 9, 37, 21, 43]) == [3, 9, 21, 25, 29, 37, 43, 49] def test_bucket_sort_with_negative_numbers(): assert bucket_sort([-5, -10, 0, -3, 8, 5, -1, 10]) == [-10, -5, -3, -1, 0, 5, 8, 10] def test_bucke...
[ { "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)" }, { "docst...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) > 1:\n mid = len(arr) // 2\n left_half = arr[:mid]\n ...
trial_gpt4o_1
{ "original_instruction": "### Bucket and Enhanced Sorting\n\nIn this task, you'll demonstrate your understanding of an advanced sorting technique by implementing Bucket Sort with a twist. The Bucket Sort algorithm provided uses a simple insertion sort for sorting individual buckets. Your goal is to enhance this by s...
0.624185
Data_Structure_13199
C
[ "merge_sort", "merge", "bucket_sort" ]
3
[ [ "bucket_sort", "merge_sort" ], [ "merge_sort", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ae46cc318093068e5100dc0bb6dd9f39ff89e82d
d95e3fe66f3d7d3c05b2fe63635eb064238661f2
v1.0
complete
Data_Structure
Data_Structure_11780_C
import random from typing import List, Optional, 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 enhanced_bogo_sort(arr: List[int], max_itera...
import random def is_sorted(arr): """ Helper function to check if the array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def enhanced_bogo_sort(arr, max_iterations): """ Enhanced Bogo Sort that adds a limit to the number ...
import pytest from solution import enhanced_bogo_sort, quick_sort, compare_sorts def test_is_sorted(): assert is_sorted([1, 2, 3, 4, 5]) assert not is_sorted([1, 3, 2, 4, 5]) def test_enhanced_bogo_sort_sorted(): arr = [1, 2, 3] sorted_arr, iterations = enhanced_bogo_sort(arr, 100) assert sorted_a...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Enhanced Bogo Sort that adds a limit to the number of iterations.\nIf the array is not sorted within th...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_sorted(arr):\n \"\"\"\n Helper function to check if the array is sorted.\n \"\"\"\n for i in range(len(arr) - 1):\n ...
trial_gpt4o_0
{ "original_instruction": "### Bogo Sort Enhancement and Comparative Analysis\n\nYou are tasked with enhancing the Bogo Sort algorithm provided above, and writing a comparative function to demonstrate the impracticality of Bogo Sort against another efficient sorting algorithm (e.g., Quick Sort).\n\n#### Task\n1. **En...
0.626955
Data_Structure_11780
C
[ "is_sorted", "enhanced_bogo_sort", "quick_sort", "compare_sorts" ]
4
[ [ "compare_sorts", "enhanced_bogo_sort" ], [ "compare_sorts", "quick_sort" ], [ "enhanced_bogo_sort", "is_sorted" ] ]
3
[]
false
[]
false
pytest
true
[]
true
501835b81c8c93915c780712d0703a7b188620ef
a24739e643084ac3e16f83a60998394acfb70e5f
v1.0
complete
Data_Structure
Data_Structure_13096_C
def next_prime(n: int) -> int: """ Find the smallest prime number greater than a given integer n. >>> next_prime(7) 11 >>> next_prime(10) 11 >>> next_prime(20) 23 >>> next_prime(0) 2 >>> next_prime(1) 2 >>> next_prime(1000000) 1000003 """
def is_prime(num): """ Returns True if the given number is prime, else returns False. """ if num < 2: return False if num == 2: return True if num % 2 == 0: return False for i in range(3, int(num**0.5) + 1, 2): if num % i == 0: return False ret...
from solution import next_prime def test_next_prime_after_7(): assert next_prime(7) == 11 def test_next_prime_after_10(): assert next_prime(10) == 11 def test_next_prime_after_20(): assert next_prime(20) == 23 def test_next_prime_after_0(): assert next_prime(0) == 2 def test_next_prime_after_1(): ...
[ { "docstring": "Returns True if the given number is prime, else returns False.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns the smallest prime number greater than n.", "function_declaration": "def next_p...
[ 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 is_prime(num):\n if num <= 1:\n return False\n if num <= 3:\n return True\n if num % 2 == 0 or num % 3 == 0:\n ...
trial_gpt4o_1
{ "original_instruction": "You are asked to write an efficient function `next_prime` that finds the smallest prime number greater than a given integer \\( n \\).\n\n### Function Signature\n```python\ndef next_prime(n: int) -> int:\n ...\n```\n\n### Input\n- \\( n \\) (1 ≤ \\( n \\) ≤ \\( 10^6 \\)): An integer \\( ...
0.762662
Data_Structure_13096
C
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6221673554c5869e903c78acaedd8f40abf5a614
a2d54a3fb65dd6f17d31a73b812e5d2e5d630bc0
v1.0
complete
Data_Structure
Data_Structure_12633_C
def optimized_matrix_exponentiation(mat: list, n: int) -> list: """ Optimizes matrix_exponentiation with enhancements for large n and sparse matrices. :param mat: list[list[int]]: The matrix to be raised to the power n. :param n: int: The power to which the matrix is raised. :return: list[...
def multiply(mat1, mat2): """ Multiplies two square matrices. """ size = len(mat1) result = [[0] * size for _ in range(size)] for i in range(size): for j in range(size): for k in range(size): result[i][j] += mat1[i][k] * mat2[k][j] return result def iden...
from solution import optimized_matrix_exponentiation, identity def test_identity_matrix(): assert optimized_matrix_exponentiation(identity(3), 5) == identity(3) def test_power_zero(): mat = [ [2, 3], [4, 5] ] assert optimized_matrix_exponentiation(mat, 0) == identity(2) def test_small...
[ { "docstring": "Multiplies two square matrices.", "function_declaration": "def multiply(mat1, mat2):", "function_name": "multiply", "parameter_list": "(mat1, mat2)" }, { "docstring": "Generates an identity matrix of given size.", "function_declaration": "def identity(size):", "functi...
[ 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 multiply(mat1, mat2):\n \"\"\"\n Multiplies two square matrices.\n \"\"\"\n n = len(mat1)\n result = [[0] * n for _ in range(n)]\n for i...
trial_gpt4o_2
{ "original_instruction": "### Matrix Exponentiation with Optimization\n\n#### Context\nMatrix exponentiation is a useful technique in various computational tasks. Your goal is to improve upon a basic matrix exponentiation algorithm by incorporating memory and computational optimizations. Specifically, you need to im...
0.45792
Data_Structure_12633
C
[ "multiply", "identity", "optimized_matrix_exponentiation" ]
3
[ [ "optimized_matrix_exponentiation", "identity" ], [ "optimized_matrix_exponentiation", "multiply" ] ]
2
[]
false
[]
false
pytest
true
[ "numpy" ]
false
aab89fc9c385fec966db08f57b36ad37b325c7cb
2b6b7beb5cee4fb711b885c2c2ba74aa6bf399b4
v1.0
complete
Data_Structure
Data_Structure_13234_C
def gcd(a: int, b: int) -> int: """ Computes the greatest common divisor (GCD) of two non-negative integers a and b using the Euclidean Algorithm. >>> gcd(48, 18) 6 >>> gcd(17, 13) 1 """ pass def gcd_bit(a: int, b: int) -> int: """ Computes the greatest common divisor (GCD) of two non-n...
def gcd(a: int, b: int) -> int: """ Computes the greatest common divisor (GCD) of two non-negative integers a and b using the Euclidean Algorithm. """ while b != 0: a, b = b, a % b return a def trailing_zero(x: int) -> int: """ Computes the number of trailing zeroes in the binary re...
from solution import gcd, trailing_zero, gcd_bit def test_gcd(): assert gcd(48, 18) == 6 assert gcd(0, 18) == 18 assert gcd(48, 0) == 48 assert gcd(17, 13) == 1 assert gcd(54, 24) == 6 def test_trailing_zero(): assert trailing_zero(40) == 3 assert trailing_zero(32) == 5 assert trailing...
[ { "docstring": "Computes the greatest common divisor (GCD) of two non-negative integers a and b using the Euclidean Algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Computes the number of trailing zeroes in the binar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a: int, b: int) -> int:\n \"\"\"\n Computes the GCD of two non-negative integers using Euclidean Algorithm.\n \"\"\"\n while b != 0:\n ...
trial_gpt4o_2
{ "original_instruction": "#### Objective:\nImplement a function that takes two non-negative integers and computes their greatest common divisor (GCD) using both Euclidean method and a variant with bitwise operators.\n\n#### Problem Statement:\nWrite the following three functions:\n1. `gcd(a, b)`: Computes the greate...
0.751914
Data_Structure_13234
C
[ "gcd", "trailing_zero", "gcd_bit" ]
3
[ [ "gcd_bit", "trailing_zero" ] ]
1
[]
false
[]
false
pytest
true
[]
true
29fd2b258f11b2729e61b89b832c0fb5a75f6b05
57913329abcfddd7607cdb746988d7fc764cbdbc
v1.0
complete
Data_Structure
Data_Structure_13308_C
from typing import List def check_prime_list(numbers: List[int], k: int) -> List[bool]: """ Determine the primality of a list of numbers using the Rabin-Miller primality test. Args: numbers (List[int]): A list of integers to check for primality. k (int): The number of iterations for the Rabin-Mill...
import random from typing import List def miller_rabin_test(d, n): a = 2 + random.randint(1, n - 4) x = pow(a, d, n) if x == 1 or x == n - 1: return True while d != n - 1: x = (x * x) % n d *= 2 if x == 1: return False if x == n - 1: ...
from solution import check_prime_list def test_check_prime_list_basic(): assert check_prime_list([2, 3, 4, 5, 16, 17, 18, 19], 5) == [True, True, False, True, False, True, False, True] def test_check_prime_list_large_primes(): assert check_prime_list([100000000003, 100000000019, 100000000027], 7) == [True, Tr...
[ { "docstring": null, "function_declaration": "def miller_rabin_test(d, n):", "function_name": "miller_rabin_test", "parameter_list": "(d, n)" }, { "docstring": null, "function_declaration": "def is_prime(n, k):", "function_name": "is_prime", "parameter_list": "(n, k)" }, { ...
[ 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\nfrom typing import List\n\ndef check_prime_list(numbers: List[int], k: int) -> List[bool]:\n \n def is_prime(n: int, k: int) -> bool:\n ...
trial_gpt4o_1
{ "original_instruction": "### Context\nIn various applications such as cryptography, it's vital to determine if a number is prime with high confidence while maintaining computational efficiency. The Rabin-Miller primality test is employed for such scenarios due to its probabilistic nature, providing a quick yet reli...
0.771908
Data_Structure_13308
C
[ "miller_rabin_test", "is_prime", "check_prime_list" ]
3
[ [ "check_prime_list", "is_prime" ], [ "is_prime", "miller_rabin_test" ] ]
2
[]
false
[]
false
pytest
true
[]
true
8638a1db8b61c36adcb54e099ac4235abe750681
870c1b324820ccdaa3cecd6efb647d33832737c8
v1.0
complete
Data_Structure
Data_Structure_12523_C
class Node(object): def __init__(self, val=None): self.val = val self.next = None def intersection(h1: Node, h2: Node) -> Node: """ Determine the node at which the two linked lists intersect. h1: Node - Head of the first linked list h2: Node - Head of the second linked list ...
class Node(object): def __init__(self, val=None): self.val = val self.next = None def get_length_and_tail(node): length = 0 while node: length += 1 if not node.next: return length, node node = node.next return length, node def intersection(h1: Node, ...
import pytest from solution import Node, intersection def test_intersection_found(): # Create nodes common = Node(7) common.next = Node(9) common.next.next = Node(11) # List 1 h1 = Node(1) h1.next = Node(3) h1.next.next = Node(5) h1.next.next.next = common # List 2 h2 ...
[]
[ 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, val=None):\n self.val = val\n self.next = None\n\ndef intersection(h1: Node, h2: Node) -> Node:\n \"\"\"\...
trial_gpt4o_1
{ "original_instruction": "### Linked List Intersection Problem\n\n#### Objective\nWrite a function `intersection` which takes the heads of two singly linked lists and returns the node at which the two linked lists intersect. If the lists don't intersect, return `None`. The intersection is determined based on the nod...
0.53245
Data_Structure_12523
C
[ "get_length_and_tail", "intersection" ]
2
[ [ "intersection", "get_length_and_tail" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
8f1ce7fa6cbc6a4cdde92a0ecb689dc6d27e8f81
182fdc454d907f6128ac5a81a32e04ccb4e43ea9
v1.0
complete
Data_Structure
Data_Structure_12348_C
def binary_search_insert(sorted_list, value): """ A helper function that uses binary search to find the correct insert position for `value` within `sorted_list`. """ left, right = 0, len(sorted_list) while left < right: mid = (left + right) // 2 if sorted_list[mid] < value: ...
def binary_search_insert(sorted_list, value): """ A helper function that uses binary search to find the correct insert position for `value` within `sorted_list`. """ left, right = 0, len(sorted_list) while left < right: mid = (left + right) // 2 if sorted_list[mid] < value: ...
from solution import insertion_sort def test_insertion_sort_with_positive_numbers(): assert insertion_sort([4, 2, 7, 1, 3]) == [1, 2, 3, 4, 7] def test_insertion_sort_with_negative_numbers(): assert insertion_sort([10, -1, 2, 5, 0]) == [-1, 0, 2, 5, 10] def test_insertion_sort_with_mixed_numbers(): asser...
[ { "docstring": "A helper function that uses binary search to find the correct insert position\nfor `value` within `sorted_list`.", "function_declaration": "def binary_search_insert(sorted_list, value):", "function_name": "binary_search_insert", "parameter_list": "(sorted_list, value)" }, { "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search_insert(sorted_list, item):\n \"\"\"\n Helper function to find the position where 'item' should be inserted in 'sorted_list'.\n This...
trial_gpt4o_2
{ "original_instruction": "You are tasked to design a function that helps in efficiently sorting a list of numbers using a modified version of insertion sort. The function `binary_search_insert` provided finds the right position for any given element in a sorted list. Using this helper function, implement a full inse...
0.662956
Data_Structure_12348
C
[ "binary_search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "binary_search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8cd02bea32da7d77e6afb9af70f836b17ada6592
e7b577bf19e93aa47b28fb00a047028ae4141676
v1.0
complete
Data_Structure
Data_Structure_10979_C
import math from random import randint def prime_check(num): if num <= 1: return False if num == 2 or num == 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
import math from random import randint def prime_check(num): if num <= 1: return False if num == 2 or num == 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return False ...
import pytest from solution import secure_diffie_hellman, prime_check, find_primitive_root def test_prime_check(): assert prime_check(23) == True assert prime_check(10) == False assert prime_check(2) == True assert prime_check(1) == False def test_find_primitive_root(): assert set(find_primitive_r...
[ { "docstring": null, "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def find_order(a, n):", "function_name": "find_order", "parameter_list": "(a, n)" }, { "docstri...
[ 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 random import randint\n\ndef prime_check(num):\n if num <= 1:\n return False\n if num == 2 or num == 3:\n return True\n ...
trial_gpt4o_1
{ "original_instruction": "Implement a Simple Diffie-Hellman Key Exchange Process\n\n#### Context\nAlice and Bob want to securely communicate with each other over an insecure network. To do this, they decide to use the Diffie-Hellman key exchange method to establish a shared secret key. However, they need your help t...
0.480777
Data_Structure_10979
C
[ "prime_check", "find_order", "euler_totient", "find_primitive_root", "secure_diffie_hellman" ]
5
[ [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ], [ "secure_diffie_hellman", "find_primitive_root" ], [ "secure_diffie_hellman", "prime_check" ] ]
4
[]
false
[]
false
pytest
true
[]
true
5a734b97f2bdb5ed2889633a86501ffb6c11952c
4c0810f69441d33f0d180e349cfcf224093831ad
v1.0
complete
Data_Structure
Data_Structure_11566_C
from typing import List def maximum_flow_bfs(adjacency_matrix: List[List[int]]) -> int: """Compute the maximum possible flow from the source node to the sink node in a directed graph using BFS. Args: adjacency_matrix (List[List[int]]): An n*n matrix where adjacency_matrix[i][j] is the capacity of the ...
from collections import deque def bfs(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]): if visited[v] =...
from solution import maximum_flow_bfs def test_general_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_no_capacity_...
[ { "docstring": null, "function_declaration": "def bfs(residual_graph, source, sink, parent):", "function_name": "bfs", "parameter_list": "(residual_graph, source, sink, parent)" }, { "docstring": null, "function_declaration": "def maximum_flow_bfs(adjacency_matrix):", "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": "from collections import deque\n\ndef bfs_search(source, sink, parent, residual_graph):\n \"\"\"\n Perform BFS to find the shortest augmenting path in re...
trial_gpt4o_2
{ "original_instruction": "### Context:\nYou are working on a networking project where data packets need to be transmitted from one server to another along the maximum possible data routes. The network is represented as a directed graph, where the nodes are servers and edges represent bandwidth capacities. You need t...
0.588046
Data_Structure_11566
C
[ "bfs", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db82b4ba06c36fe1bba947867ca0b64c3d81aa3b
81228cf763691dab0a71bf46f12fe51f67b748df
v1.0
complete
Data_Structure
Data_Structure_13469_C
def gcd(a, b): """ Compute the Greatest Common Divisor using Euclid's algorithm. """ pass def gcd_bit(a, b): """ Compute the Greatest Common Divisor using binary (bitwise) GCD algorithm. """ pass def lcm(a, b): """ Compute the Least Common Multiple. """ pass def traili...
def gcd(a, b): """ Compute the Greatest Common Divisor using Euclid's algorithm. """ while b: a, b = b, a % b return a def gcd_bit(a, b): """ Compute the Greatest Common Divisor using binary (bitwise) GCD algorithm. """ if a == 0: return b if b == 0: retu...
from solution import gcd_lcm_trailing def test_1(): result = gcd_lcm_trailing(54, 24) assert result == { "gcd": 6, "gcd_bit": 6, "lcm": 216, "trailing_zeros_gcd": 1, "trailing_zeros_gcd_bit": 1 } def test_2(): result = gcd_lcm_trailing(17, 31) assert result ...
[ { "docstring": "Compute the Greatest Common Divisor using Euclid's algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Compute the Greatest Common Divisor using binary (bitwise) GCD algorithm.", "function_declaratio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Compute the Greatest Common Divisor using Euclid's algorithm.\n \"\"\"\n while b:\n a, b = b, a % b\n return a...
trial_gpt4o_0
{ "original_instruction": "#### Context\nIn various computational problems, efficiently determining the greatest common divisor (GCD), the least common multiple (LCM), and trailing zero bits plays a critical role. Understanding and optimizing these algorithms are essential skills in both competitive programming and s...
0.718783
Data_Structure_13469
C
[ "gcd", "gcd_bit", "lcm", "trailing_zero", "gcd_lcm_trailing" ]
5
[ [ "gcd_lcm_trailing", "gcd" ], [ "gcd_lcm_trailing", "gcd_bit" ], [ "gcd_lcm_trailing", "lcm" ], [ "gcd_lcm_trailing", "trailing_zero" ], [ "lcm", "gcd" ] ]
5
[]
false
[]
false
pytest
true
[]
true
a1685b31ebfaa59e60ab45329a460da945f0b924
1472ef2548513df6b282563dd42960e7b87d95c7
v1.0
complete
Data_Structure
Data_Structure_13247_C
from typing import Tuple def gcd_bit(a: int, b: int) -> int: """ Compute the greatest common divisor of two integers using bitwise operations. >>> gcd_bit(48, 18) 6 >>> gcd_bit(101, 103) 1 """ def trailing_zero(x: int) -> int: count = 0 while x and not x & 1: cou...
def gcd_bit(a, b): # Provided optimized GCD function utilizing bitwise operations def trailing_zero(x): count = 0 while x and not x & 1: count += 1 x >>= 1 return count if a == 0: return b if b == 0: return a tza = trailing_zero(a) ...
from solution import gcd_bit, lcm_optimized, modular_inverse def test_gcd_bit_simple(): assert gcd_bit(48, 18) == 6 assert gcd_bit(101, 103) == 1 def test_gcd_bit_edge_cases(): assert gcd_bit(0, 7) == 7 assert gcd_bit(7, 0) == 7 assert gcd_bit(0, 0) == 0 def test_lcm_optimized(): assert lcm_o...
[ { "docstring": null, "function_declaration": "def gcd_bit(a, b):", "function_name": "gcd_bit", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm_optimized(a, b):", "function_name": "lcm_optimized", "parameter_list": "(a, b)" }, { "docstri...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_bit(a, b):\n \"\"\"\n Computes the GCD using bitwise operations.\n \"\"\"\n if a == 0:\n return b\n if b == 0:\n return a...
trial_gpt4o_4
{ "original_instruction": "Title: Implement LCM and Modular Inverse using GCD\n\n#### Context:\nYou are developing a software that requires frequent computation of the least common multiple (LCM) and modular inverse using the greatest common divisor (GCD). The GCD computations need to be efficient and utilize bitwise...
0.713035
Data_Structure_13247
C
[ "gcd_bit", "lcm_optimized", "modular_inverse" ]
3
[ [ "lcm_optimized", "gcd_bit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
23028127ab0a4d8c4031e59d970e25f5e82d53c8
10b8413408c54e8a3ebd06643714ca3c512c0447
v1.0
complete
Data_Structure
Data_Structure_11750_C
def rotate_simple(array, k): """ Rotate the array to the right by k steps using the simple shift method. >>> rotate_simple([1, 2, 3, 4, 5, 6, 7], 3) [5, 6, 7, 1, 2, 3, 4] >>> rotate_simple([1, 2, 3, 4, 5], 2) [4, 5, 1, 2, 3] >>> rotate_simple([1, 2, 3, 4], 0) [1, 2, 3, 4] >>> rotate_simp...
def rotate_simple(array, k): n = len(array) k %= n for _ in range(k): temp = array[n - 1] for j in range(n - 1, 0, -1): array[j] = array[j - 1] array[0] = temp return array def rotate_reverse(array, k): def reverse(arr, start, end): while start < end: ...
from solution import rotate_simple, rotate_reverse, rotate_slice, rotate_array def test_rotate_simple(): assert rotate_simple([1, 2, 3, 4, 5, 6, 7], 3) == [5, 6, 7, 1, 2, 3, 4] assert rotate_simple([1, 2, 3, 4, 5], 2) == [4, 5, 1, 2, 3] assert rotate_simple([1, 2, 3, 4], 0) == [1, 2, 3, 4] assert rotat...
[ { "docstring": null, "function_declaration": "def rotate_simple(array, k):", "function_name": "rotate_simple", "parameter_list": "(array, k)" }, { "docstring": null, "function_declaration": "def rotate_reverse(array, k):", "function_name": "rotate_reverse", "parameter_list": "(ar...
[ 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 rotate_array(array, k):\n def rotate_simple(array, k):\n n = len(array)\n k %= n\n for _ in range(k):\n temp = array.po...
trial_gpt4o_2
{ "original_instruction": "### Array Rotation Challenge\n\n#### Objectives:\nGiven an array of integers and a non-negative integer k, rotate the array to the right by k steps. Implement the function `rotate_array(array, k)` using different approaches:\n1. Simple shift method.\n2. Reverse segment method.\n3. Slicing c...
0.618032
Data_Structure_11750
C
[ "rotate_simple", "rotate_reverse", "rotate_slice", "rotate_array" ]
4
[ [ "rotate_array", "rotate_reverse" ], [ "rotate_array", "rotate_simple" ], [ "rotate_array", "rotate_slice" ] ]
3
[]
false
[]
false
pytest
true
[]
true
6d644aea910ecf0e3d32dc3e5f39f95415ed924a
dfe25f129dfa6eb9c1a2b6bbbedc78f3c8062e7c
v1.0
complete
Data_Structure
Data_Structure_13785_C
from typing import List def rotate_array(array: List[int], k: int) -> None: """ Rotate the elements of the array to the right by k positions. >>> array = [1, 2, 3, 4, 5, 6, 7] >>> rotate_array(array, 3) >>> array [5, 6, 7, 1, 2, 3, 4] >>> array = [-1, -100, 3, 99] >>> rotate_array(array, 2...
from typing import List def rotate_array(array: List[int], k: int) -> None: """ Rotate the elements of the array to the right by k positions. """ n = len(array) if n == 0: return k = k % n # In case k is greater than the length of the array # Reverse the whole array array....
from solution import rotate_array def test_rotate_generic_case(): array = [1, 2, 3, 4, 5, 6, 7] rotate_array(array, 3) assert array == [5, 6, 7, 1, 2, 3, 4] def test_rotate_large_k(): array = [1, 2, 3, 4, 5, 6, 7] rotate_array(array, 10) # 10 % 7 == 3 assert array == [5, 6, 7, 1, 2, 3, 4] de...
[ { "docstring": "Rotate the elements of the array to the right by k positions.", "function_declaration": "def rotate_array(array, k):", "function_name": "rotate_array", "parameter_list": "(array, k)" }, { "docstring": "Helper function to reverse elements in array from index start to end.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef rotate_array(array: List[int], k: int) -> None:\n \"\"\"\n Rotates the array to the right by k positions.\n This funct...
trial_gpt4o_2
{ "original_instruction": "### Problem Description\n\nYou are given an array of integers and a non-negative integer `k`. Write a function `rotate_array` to rotate the array elements to the right by `k` positions.\n\n#### Function Definition\n```python\ndef rotate_array(array: List[int], k: int) -> None:\n```\n\n#### ...
0.646381
Data_Structure_13785
C
[ "rotate_array", "reverse_sub_array" ]
2
[ [ "rotate_array", "reverse_sub_array" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ad4975899c6350954b18ff6f769018746f5f87f6
b7574aed3562faa18cebfbb6c92af585524e7056
v1.0
complete
Data_Structure
Data_Structure_13280_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, small): """ Determine if `small` is a subtree of `big`. :param big: TreeNode - The root of the larger binary tree. :param small: TreeNode...
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): """ Determine if `small` is a subtree of `big`. """ if not small: return True # An empty tree is always a subtree if ...
from solution import TreeNode, is_subtree def test_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 d...
[]
[ 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": "### Coding Assessment: Subtree Validation\n\n#### Objective\nWrite a function to determine if one binary tree is a subtree of another binary tree.\n\n#### Problem Definition\nTwo binary trees are given:\n1. `big`, a potentially large binary tree.\n2. `small`, a binary tree which you need to...
0.600736
Data_Structure_13280
C
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
265e725a724520ebccf33add91ccdbdc17590696
b708e1aadcc17f32fe55c761f12b8ae539d93ddf
v1.0
complete
Data_Structure
Data_Structure_12510_C
from typing import List def highlight_symbols_in_words(words: List[str], symbols: List[str]) -> List[str]: """ Highlight the longest matching symbols in each word by surrounding them with square brackets. Args: words (List[str]): The list of words to be processed. symbols (List[str]): The ...
class TrieNode: def __init__(self): self.children = {} self.end_of_word = False def build_trie(symbols): root = TrieNode() for symbol in symbols: current = root for char in symbol: if char not in current.children: current.children[char] = TrieNode...
from solution import highlight_symbols_in_words def test_single_symbol_match(): words = ['apple'] symbols = ['a'] assert highlight_symbols_in_words(words, symbols) == ['[a]pple'] def test_multiple_symbols(): words = ['apple', 'banana', 'grape'] symbols = ['a', 'na', 'ra'] assert highlight_symb...
[]
[ 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\nclass TrieNode:\n def __init__(self):\n self.children = {}\n self.end_of_word = False\n\nclass Trie:\n def __in...
trial_gpt4o_4
{ "original_instruction": "You are working on a text processing application where you need to highlight specific parts of words with predefined symbols. Your task is to implement a function that finds and replaces the longest symbols found within each word from a given list, marking them with square brackets (`[]`).\...
0.561548
Data_Structure_12510
C
[ "build_trie", "find_longest_symbol", "highlight_symbols_in_words" ]
3
[ [ "highlight_symbols_in_words", "build_trie" ], [ "highlight_symbols_in_words", "find_longest_symbol" ] ]
2
[]
false
[ "TrieNode" ]
true
pytest
true
[]
true
2126b9720b2243ae440acabf5193494f215d24b5
a05bbe84e0b430eab5a9d25231482eb01a5da231
v1.0
complete
Data_Structure
Data_Structure_12062_C
from typing import List def max_heap_sort(arr: List[int], simulation: bool = False) -> List[int]: """Implements max heap sort algorithm to sort an array in ascending order. Optionally visualizes each step of the heapification and sorting process. Args: arr (List[int]): The list of integers to be sorte...
from typing import List def max_heapify(arr: List[int], n: int, i: int, simulation: bool) -> None: largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[largest] < arr[left]: largest = left if right < n and arr[largest] < arr[right]: largest = right if la...
from solution import max_heap_sort def test_heap_sort_basic(): arr = [3, -1, 2, 8, 4, -3, 5] sorted_arr = [-3, -1, 2, 3, 4, 5, 8] assert max_heap_sort(arr) == sorted_arr def test_heap_sort_empty(): arr = [] sorted_arr = [] assert max_heap_sort(arr) == sorted_arr def test_heap_sort_single_elem...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr, simulation=False):", "function_name": "max_heap_...
[ 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 max_heap_sort(arr, simulation=False):\n def heapify(arr, n, i):\n largest = i # Initialize largest as root\n l = 2 * i + 1 # left = 2*i +...
trial_gpt4o_2
{ "original_instruction": "### Question\n\nHeap Sort is a comparison-based sorting technique based on a Binary Heap data structure. In this exercise, students are required to implement Heap Sort with the option to visualize each step of the sorting process for better understanding of the internals of the heap sort me...
0.662421
Data_Structure_12062
C
[ "max_heapify", "max_heap_sort" ]
2
[ [ "max_heap_sort", "max_heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f63468c9adf942c5972566e4d8164541e0920021
1ea0b9c7cbb88dc0ffb8eb6649a0cce1cff6f276
v1.0
complete
Data_Structure
Data_Structure_12155_C
import random from sympy import isprime, gcd, mod_inverse def generate_key(k, seed=None): """ Generates an RSA key pair with the specified bit length. Parameters: k (int): Bit length of the modulus, must be greater than 1. seed (int, optional): Seed for random number generation (for reproduci...
import random from sympy import isprime, gcd, mod_inverse def generate_large_prime(k): while True: # Generate a random prime of bit length k num = random.getrandbits(k) if isprime(num): return num def generate_key(k, seed=None): if k <= 1: raise ValueError("Bit leng...
import pytest from solution import generate_key, encrypt, decrypt def test_generate_key(): n, e, d = generate_key(16, seed=42) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) def test_generate_key_bit_length(): n, e, d = generate_key(16, seed=42) assert n.bit_leng...
[ { "docstring": null, "function_declaration": "def generate_large_prime(k):", "function_name": "generate_large_prime", "parameter_list": "(k)" }, { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "parameter_list": "(k,...
[ 1, 0 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime, gcd, mod_inverse\n\ndef generate_large_prime(k):\n while True:\n # Generate a random prime of bit length k...
trial_gpt4o_0
{ "original_instruction": "### Task:\n\nYour task is to implement the functions for generating RSA keys (`generate_key`), encrypting data (`encrypt`), and decrypting data (`decrypt`), provided a given bit-length for the keys.\n\n### Details:\n\nImplement three functions in Python:\n\n1. `generate_key(k, seed=None)`: ...
0.696913
Data_Structure_12155
C
[ "generate_large_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_large_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
9dfe99b890090023e2b8c61d02ac8c231d31688b
30e6170c25d62b1bcd74a1f5c06cb1f47ff5211e
v1.0
complete
Data_Structure
Data_Structure_11310_C
def enhanced_tree_print(tree: dict) -> None: """ Recursively print the tree structure in a readable nested format. Args: tree (dict): The tree structure to print. >>> tree = { ... 'a': ['Adam', 'Book', 4], ... 'b': ['Bill', {'Computer': 5, 'TV': 6}], ... 'c': ['Bill', {...
def enhanced_tree_print(tree, indent=0): """ Recursively print the tree structure in a readable nested format. Args: tree (dict): The tree structure to print. indent (int): The current indentation level (used for recursive calls). """ for key, value in tree.items(): print(" " * ...
def test_empty_tree(): assert enhanced_tree_print({}) == None def test_single_level_tree(): tree = { 'a': ['Adam', 'Book', 4], } assert enhanced_tree_print(tree) == None def test_nested_tree(): tree = { 'a': ['Adam', 'Book', 4], 'b': ['Bill', {'Computer': 5, 'TV': 6}], ...
[ { "docstring": "Recursively print the tree structure in a readable nested format.\n\nArgs:\ntree (dict): The tree structure to print.\nindent (int): The current indentation level (used for recursive calls).", "function_declaration": "def enhanced_tree_print(tree, indent=0):", "function_name": "enhanced_...
[ 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 enhanced_tree_print(tree: dict, indent: str = '') -> None:\n \"\"\"\n Prints the tree structure in a readable nested format with clear indentation.\...
trial_gpt4o_2
{ "original_instruction": "Tree Traversal and Printing\n\nYou are given a hierarchical tree data structure representing different categories and their corresponding objects. Each object in the tree can have sub-objects denoted either by strings or further nested dictionaries. Your task is to implement a function `enh...
0.53863
Data_Structure_11310
C
[ "enhanced_tree_print", "print_list" ]
2
[ [ "enhanced_tree_print", "print_list" ] ]
1
[]
false
[]
false
pytest
false
[]
true
419376c62205ce5e6a9cc2b967e60a448fddd932
23d825843cb49daba307f7143ecbb4314f0c70cb
v1.0
complete
Data_Structure
Data_Structure_10681_C
from typing import List def maximum_flow_bfs(graph: List[List[int]]) -> int: """Compute the maximum flow from a source node (node 0) to a sink node (last node, n-1) in a directed graph represented by an n x n adjacency matrix using the BFS approach. >>> graph = [ ... [0, 16, 13, 0, 0, 0], ... [0, 0, 10...
from collections import deque def bfs(graph, source, sink, parent): visited = [False] * len(graph) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v, capacity in enumerate(graph[u]): if not visited[v] and capacity > 0: ...
from solution import maximum_flow_bfs def test_simple_path(): graph = [ [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], [0, 0, 0, 0] ] assert maximum_flow_bfs(graph) == 1 def test_example_case(): graph = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0...
[ { "docstring": null, "function_declaration": "def bfs(graph, source, sink, parent):", "function_name": "bfs", "parameter_list": "(graph, source, sink, parent)" }, { "docstring": null, "function_declaration": "def maximum_flow_bfs(graph):", "function_name": "maximum_flow_bfs", "pa...
[ 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(graph, source, sink, parent):\n visited = [False] * len(graph)\n queue = deque([source])\n visited[source] =...
trial_gpt4o_2
{ "original_instruction": "**Question**: Write a function `maximum_flow_bfs` that computes the maximum flow from a source node (node 0) to a sink node (last node, n-1) in a directed graph represented by a n x n adjacency matrix. Your function should use the Breadth-First Search (BFS) approach to find augmenting paths...
0.607705
Data_Structure_10681
C
[ "bfs", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b30483597252ba41ef5f69a64aab8e7641db752e
cbd1b6d2d2c7498cd9e28777bb34abf61678046d
v1.0
complete
Data_Structure
Data_Structure_12893_C
import math from typing import Tuple, Dict def euclidean_distance(point1: Tuple[float, ...], point2: Tuple[float, ...]) -> float: """ Calculate the Euclidean distance between two points. """ return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2))) def classify_point(query_point: Tuple[float...
import math def euclidean_distance(point1, point2): """ Calculate the Euclidean distance between two points. """ return math.sqrt(sum((x - y) ** 2 for x, y in zip(point1, point2))) def classify_point(query_point, training_set): """ Classifies a new point by finding the label of its nearest nei...
from solution import classify_point, euclidean_distance def test_euclidean_distance(): assert euclidean_distance((0, 0), (3, 4)) == 5.0 assert euclidean_distance((1, 1), (4, 5)) == 5.0 def test_classify_point(): query_point = (1.5, 2.5) training_set = { (1, 2): 'A', (3, 3): 'B', ...
[ { "docstring": "Calculate the Euclidean distance between two points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "Classifies a new point by finding the label of its nearest ...
[ 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\n\ndef distance(point1, point2):\n \"\"\"\n Calculates the Euclidean distance between two points.\n \"\"\"\n return math.sqrt(sum((p1 ...
trial_gpt4o_1
{ "original_instruction": "### Nearest Neighbor Classification Challenge\n\nYou are given a set of labeled points representing a training set and a function that computes the Euclidean distance between two points. Your task is to implement a function that classifies a new point by finding the label of its nearest nei...
0.632684
Data_Structure_12893
C
[ "euclidean_distance", "classify_point" ]
2
[ [ "classify_point", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8fd5456178275a5282075deccb48f2950eee9d44
17665b1160f440856776eb84995e66335e251807
v1.0
complete
Data_Structure
Data_Structure_12221_C
import random def __choose_state(transition_map): """ Helper function to choose the next state based on transition probabilities. Parameters: transition_map (dict): A dictionary where keys are states and values are the probabilities of transitioning to those states. Returns: str: ...
import random def __choose_state(transition_map): """ Helper function to choose the next state based on transition probabilities. Parameters: transition_map (dict): A dictionary where keys are states and values are the probabilities of transitioning to those states. Returns: str: ...
import pytest from solution import generate_sequence def test_generate_sequence_length(): chain = { 'A': {'A': 0.6, 'E': 0.4}, 'E': {'A': 0.7, 'E': 0.3} } initial_state = 'A' length = 5 result = generate_sequence(chain, initial_state, length) assert len(result) == length def te...
[ { "docstring": "Helper function to choose the next state based on transition probabilities.\n\nParameters:\n transition_map (dict): A dictionary where keys are states and values are the probabilities of transitioning to those states.\n\nReturns:\n str: The next state chosen based on the transition probabi...
[ 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 ]
5
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 __choose_state(prob_dict):\n \"\"\"\n Helper function to choose the next state based on current state's transition probabilities.\n...
trial_gpt4o_8
{ "original_instruction": "### Markov Chain Sequence Generation\n\n#### Problem Statement\nYou are provided with an implementation of a Markov chain, a mathematical system that transitions between states based on a given set of probabilistic rules. The implementation includes functions for choosing the next state and...
0.573361
Data_Structure_12221
C
[ "__choose_state", "next_state", "generate_sequence" ]
3
[ [ "generate_sequence", "next_state" ], [ "next_state", "__choose_state" ] ]
2
[]
false
[]
false
pytest
true
[]
true
401cb0cc902a0482759318f3158d296fc113716e
8b21856e8d5a555ccc9e033a1dfa7d98dff7d7d4
v1.0
complete
Data_Structure
Data_Structure_13976_C
def k_nearest_neighbors(x: tuple, tSet: dict, k: int) -> list: """ This function finds the k nearest neighbors for a given vector `x` from a training set `tSet`. Arguments: x -- A tuple representing the input vector. tSet -- A dictionary where keys are tuples (training vectors) and values are l...
import math from heapq import nsmallest def euclidean_distance(point1, point2): """ Helper function to calculate the Euclidean distance between two points. """ return math.sqrt(sum((coord1 - coord2) ** 2 for coord1, coord2 in zip(point1, point2))) def k_nearest_neighbors(x: tuple, tSet: dict, k: int) ...
from solution import k_nearest_neighbors def test_k_nearest_neighbors(): x = (2, 2) tSet = { (1, 1): 0, (2, 3): 1, (3, 4): 0, (6, 6): 1 } k = 2 result = k_nearest_neighbors(x, tSet, k) assert result == [0, 1] or result == [1, 0] # order can differ def test_k_nearest_neighbors_with_more_neighbors(...
[ { "docstring": "Helper function to calculate the Euclidean distance between two points.", "function_declaration": "def euclidean_distance(point1, point2):", "function_name": "euclidean_distance", "parameter_list": "(point1, point2)" }, { "docstring": "This function finds the k nearest neighb...
[ 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 math\nfrom heapq import nsmallest\n\ndef euclidean_distance(point1, point2):\n \"\"\"\n Helper function to calculate the Euclidean distance betwe...
trial_gpt4o_0
{ "original_instruction": "You are requested to implement a function to extend the nearest neighbor algorithm. Instead of selecting the single nearest neighbor, you need to find the **k nearest neighbors** to the given vector and return their associated labels.\n\n### Function Signature\n```python\ndef k_nearest_neig...
0.707769
Data_Structure_13976
C
[ "euclidean_distance", "k_nearest_neighbors" ]
2
[ [ "k_nearest_neighbors", "euclidean_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
94f2c77b975683f331d16e58c73d165bf7409e0a
d280fbba3ecc9fcd1adf0661c20f807fe61bacff
v1.0
complete
Data_Structure
Data_Structure_11874_C
from typing import Optional def mod_exp(base: int, exp: int, mod: int) -> int: """Helper function to perform modular exponentiation. >>> mod_exp(5, 3, 23) 10 """ pass def diffie_hellman_key_exchange(a: int, p: int, option: Optional[int] = None) -> bool: """ Securely exchange a secret key b...
import random from typing import Optional def mod_exp(base: int, exp: int, mod: int) -> int: """Helper function to perform modular exponentiation.""" result = 1 base = base % mod while exp > 0: if exp % 2: result = (result * base) % mod exp = exp >> 1 base = (base * ...
from solution import diffie_hellman_key_exchange def test_diffie_hellman_basic(): assert diffie_hellman_key_exchange(5, 23) == True def test_diffie_hellman_edge_case_primitive_root_at_lower_bound(): assert diffie_hellman_key_exchange(2, 23) == True def test_diffie_hellman_invalid_input_primitive_root(): ...
[ { "docstring": "Helper function to perform modular exponentiation.", "function_declaration": "def mod_exp(base, exp, mod):", "function_name": "mod_exp", "parameter_list": "(base, exp, mod)" }, { "docstring": "Implementation of the Diffie-Hellman key exchange protocol.", "function_declara...
[ 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 mod_exp(base, exp, mod):\n result = 1\n while exp > 0:\n if exp % 2 == 1:\n result = (result * base) % mod\n base = (base *...
trial_gpt4o_1
{ "original_instruction": "### **Assessing Your Understanding of Diffie-Hellman Key Exchange**\n\nYou are given the following task to implement a function to securely exchange a secret key between two parties (Alice and Bob) using the steps of the Diffie-Hellman key exchange protocol. Given a prime number \\( p \\) a...
0.590255
Data_Structure_11874
C
[ "mod_exp", "diffie_hellman_key_exchange" ]
2
[ [ "diffie_hellman_key_exchange", "mod_exp" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0919c165baf299ef2ff8463e70cfef3bb2a3ada5
a067ff543156a22a7ec404e095e849ec9117bade
v1.0
complete
Data_Structure
Data_Structure_13444_C
def search_insert(arr, val): """ Helper function to find the index where val should be inserted to keep arr sorted. Uses binary search. Parameters: arr (list): The sorted list of integers. val (int): The value to find the insertion index for. Returns: int: The index where val shoul...
def search_insert(arr, val): """ Helper function to find the index where val should be inserted to keep arr sorted. Uses binary search. Parameters: arr (list): The sorted list of integers. val (int): The value to find the insertion index for. Returns: int: The index where val shoul...
from solution import insertion_sort_with_binary_search def test_simple_case(): assert insertion_sort_with_binary_search([8, 2, 4, 9, 3, 6]) == [2, 3, 4, 6, 8, 9] def test_negative_numbers(): assert insertion_sort_with_binary_search([-3, -1, -2, -4]) == [-4, -3, -2, -1] def test_sorted_list(): assert inse...
[ { "docstring": "Helper function to find the index where val should be inserted to keep arr sorted.\nUses binary search.\n\nParameters:\narr (list): The sorted list of integers.\nval (int): The value to find the insertion index for.\n\nReturns:\nint: The index where val should be inserted.", "function_declar...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def search_insert(arr, target, start, end):\n \"\"\"\n Helper function to determine the index at which the target should be inserted\n such that the ...
trial_gpt4o_2
{ "original_instruction": "### Question: Insertion Sort with Binary Search\n\nTo enhance your understanding of sorting algorithms and binary search, implement the insertion sort algorithm using the provided binary search helper function. This exercise will showcase your ability to systematically combine searching and...
0.65166
Data_Structure_13444
C
[ "search_insert", "insertion_sort_with_binary_search" ]
2
[ [ "insertion_sort_with_binary_search", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f67ac3436f64bf0b411c6c9e3a6de5f7502ac24
e469f1bed3835018a52c86fa482819523a75c127
v1.0
complete
Data_Structure
Data_Structure_14315_C
def merge_sort(arr): """ Sorts an array of integers using the merge sort algorithm. >>> merge_sort([38, 27, 43, 3, 9, 82, 10]) [3, 9, 10, 27, 38, 43, 82] >>> merge_sort([]) [] >>> merge_sort([1]) [1] >>> merge_sort([5, 2, 2, 3]) [2, 2, 3, 5] """ # your code here def...
def merge_sort(arr): """ Sorts an array of integers using the merge sort algorithm. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) sorted_array = [] merge(left_half, right_half, sorted_array)...
from solution import merge_sort def test_merge_sort_basic(): assert merge_sort([38, 27, 43, 3, 9, 82, 10]) == [3, 9, 10, 27, 38, 43, 82] def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_identical_elements...
[ { "docstring": "Sorts an array of integers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted subarrays (left and right) into a single sorted array.", "function_de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array of integers using the Merge Sort algorithm.\n \n Parameters:\n arr (list): A list of integers to...
trial_gpt4o_2
{ "original_instruction": "**Context**:\nYou are given an array of integers which needs to be sorted in non-decreasing order. You have learned about various sorting algorithms and are tasked with implementing the Merge Sort algorithm.\n\n**Objective**:\nWrite a Python function `merge_sort(arr)` that takes in a list o...
0.663565
Data_Structure_14315
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a90edefadd5036c2f8277ea1014ffa88f2a8f902
b91181b20b5995e3c841a651994b5946fff09c2e
v1.0
complete
Data_Structure
Data_Structure_14009_C
from typing import List def reconstruct_inorder(preorder: List[int], postorder: List[int]) -> List[int]: """ Reconstruct the binary tree from preorder and postorder traversal lists and return its inorder traversal. >>> reconstruct_inorder([1, 2, 4, 5, 3, 6, 7], [4, 5, 2, 6, 7, 3, 1]) [4, 2, 5, 1, 6, 3, 7] ...
from typing import List class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(preorder: List[int], postorder: List[int]) -> TreeNode: if not preorder or not postorder: return None if len(preorder) == 1: return TreeNode...
from solution import reconstruct_inorder def test_reconstruct_inorder_example(): preorder = [1, 2, 4, 5, 3, 6, 7] postorder = [4, 5, 2, 6, 7, 3, 1] assert reconstruct_inorder(preorder, postorder) == [4, 2, 5, 1, 6, 3, 7] def test_single_node(): preorder = [1] postorder = [1] assert reconstruct...
[]
[ 0, 0, 0, 0, 1, 0, 1, 1, 1, 1 ]
5
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def reconstruct_inorder(preorder, postorder):\n \"\"\"\n Reconstructs a full binary tree from its preorder and postorder traversals and returns its inor...
trial_gpt4o_8
{ "original_instruction": "### Question\n\n#### Scenario:\nYou are working on a project that involves serializing and deserializing binary trees for network communication. One particular case involves full binary trees, where each node has either zero or two children. Given the preorder and postorder traversal arrays...
0.540023
Data_Structure_14009
C
[ "build_tree", "inorder_traversal", "reconstruct_inorder" ]
3
[ [ "reconstruct_inorder", "build_tree" ], [ "reconstruct_inorder", "inorder_traversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
dc0cdf2f976a91a198fe896b054afdafe340b0b0
661f26788681dc0b1f45d0f4bec45c0b0238863e
v1.0
complete
Data_Structure
Data_Structure_14642_C
from typing import List def library_sort(ids: List[int]) -> List[int]: """Sort a list of book IDs using the radix sort algorithm. >>> library_sort([170, 45, 75, 90, 802, 24, 2, 66]) [2, 24, 45, 66, 75, 90, 170, 802] >>> library_sort([]) [] >>> library_sort([10]) [10] ...
from typing import List def counting_sort(arr: List[int], exp: int) -> List[int]: n = len(arr) output = [0] * n count = [0] * 10 for i in range(n): index = (arr[i] // exp) % 10 count[index] += 1 for i in range(1, 10): count[i] += count[i - 1] i = n - 1 ...
from solution import library_sort def test_library_sort_with_various_numbers(): assert library_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_library_sort_empty_list(): assert library_sort([]) == [] def test_library_sort_single_element(): assert library_sort([10]) =...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp):", "function_name": "counting_sort", "parameter_list": "(arr, exp)" }, { "docstring": null, "function_declaration": "def library_sort(ids):", "function_name": "library_sort", "parameter_list": "(ids)" } ]
[ 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 library_sort(ids: List[int]) -> List[int]:\n \"\"\"\n Sorts a list of book IDs using the radix sort algorithm.\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "### Scenario\n\nIn a digital library system, book IDs are stored as large integers in an array. The library management system requires these IDs to be sorted for efficient cataloging and searching.\n\n### Problem Statement\n\nWrite a function `library_sort(ids: List[int]) -> List[int]` that...
0.649882
Data_Structure_14642
C
[ "counting_sort", "library_sort" ]
2
[ [ "library_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
14aeb533deed62b64430641207a8bdf4031fa37f
80dbebd036d2d81835de97411d500f589ce73ce0
v1.0
complete
Data_Structure
Data_Structure_14192_C
def optimized_jump_search(arr: list, target: int) -> int: """ Find the index of a target value in a sorted array using an optimized version of Jump Search. The function dynamically calculates the block size based on the array length and applies a binary search within the identified block for furt...
import math def binary_search(arr, target, left, right): while left <= right: mid = left + (right - left) // 2 if arr[mid] == target: return mid elif arr[mid] < target: left = mid + 1 else: right = mid - 1 return -1 def optimized_jump_search(...
from solution import optimized_jump_search def test_found(): assert optimized_jump_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 11) == 5 def test_not_found(): assert optimized_jump_search([1, 3, 5, 7, 9, 11, 13, 15, 17, 19], 10) == -1 def test_empty_array(): assert optimized_jump_search([], 1) == -1 def ...
[ { "docstring": null, "function_declaration": "def binary_search(arr, target, left, right):", "function_name": "binary_search", "parameter_list": "(arr, target, left, right)" }, { "docstring": null, "function_declaration": "def optimized_jump_search(arr, target):", "function_name": "o...
[ 0, 0, 0, 0, 1, 1, 1, 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": "import math\n\ndef optimized_jump_search(arr, target):\n n = len(arr)\n if n == 0:\n return -1\n\n # Calculate the optimal block size to jump\...
trial_gpt4o_8
{ "original_instruction": "Optimized Jump Search\n\n#### Context\nYou are working on a software system that processes large volumes of sorted data. To speed up search operations, you decide to implement a search algorithm that leverages Jump Search's principles but also optimizes the block size dynamically based on t...
0.663702
Data_Structure_14192
C
[ "binary_search", "optimized_jump_search" ]
2
[ [ "optimized_jump_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5256bd018bfb7e0f5bd90960aee4d36b5dd1a858
4073a7fd4c6888c28c3c42b81c27658b97258e65
v1.0
complete
Data_Structure
Data_Structure_13687_C
from typing import List def pancake_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in non-decreasing order using the Pancake Sort algorithm. Args: arr (List[int]): A list of integers to be sorted. Returns: List[int]: A new list of integers sorted in non-decreasing o...
from typing import List def flip(arr: List[int], k: int) -> None: """ Reverses the order of the first k elements of the array. """ left = 0 right = k - 1 while left < right: arr[left], arr[right] = arr[right], arr[left] left += 1 right -= 1 def find_largest(arr: List[in...
from solution import pancake_sort def test_sorted_array(): assert pancake_sort([1, 2, 3, 4]) == [1, 2, 3, 4] def test_reverse_sorted_array(): assert pancake_sort([4, 3, 2, 1]) == [1, 2, 3, 4] def test_unsorted_array(): assert pancake_sort([3, 2, 4, 1]) == [1, 2, 3, 4] def test_single_element_array(): ...
[ { "docstring": "Reverses the order of the first k elements of the array.", "function_declaration": "def flip(arr, k):", "function_name": "flip", "parameter_list": "(arr, k)" }, { "docstring": "Finds the index of the largest element in the first n elements of arr.", "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 flip(arr: List[int], k: int) -> None:\n \"\"\"\n Helper function to reverse the order of the first k elements in arr.\n ...
trial_gpt4o_2
{ "original_instruction": "### Pancake Sorting with Constraints and Edge Case Handling\n\n#### Context\nYou have been provided with an unsorted array of integers that needs to be sorted using an unconventional algorithm known as Pancake Sort. Your implementation should ensure that the array is sorted by \"flipping\" ...
0.792102
Data_Structure_13687
C
[ "flip", "find_largest", "pancake_sort" ]
3
[ [ "pancake_sort", "find_largest" ], [ "pancake_sort", "flip" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4dba388d87a2bf73de0975300116bea09debfea8
4548c127ce44acb9b9d7def289a503d4554fbc9e
v1.0
complete
Data_Structure
Data_Structure_13382_C
def secure_diffie_hellman_exchange(p: int, a: int) -> (int, int): """ Perform Diffie-Hellman Key Exchange and return both shared keys (Alice's and Bob's). :param p: A large prime number. :param a: A primitive root of p. :return: Tuple containing shared keys of Alice and Bob. >>> p = 23 ...
def is_prime(n): """ Check if number n is a prime number. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return Tru...
from solution import secure_diffie_hellman_exchange, is_prime, find_primitive_root def test_secure_diffie_hellman_exchange(): p = 23 a = 5 alice_key, bob_key = secure_diffie_hellman_exchange(p, a) assert alice_key == bob_key def test_non_prime_p(): try: p = 15 a = 5 secure_...
[ { "docstring": "Check if number n is a prime number. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find a primitive root for prime p. ", "function_declaration": "def find_primitive_root(p):", "function_name": "f...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\" Check if number n is a prime number. \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n ...
trial_gpt4o_0
{ "original_instruction": "### Question: Implement Secure Key Exchange with Diffie-Hellman\n\n#### Scenario:\nTwo users, Alice and Bob, want to communicate securely over an open network. They decide to use the Diffie-Hellman Key Exchange protocol to establish a shared secret key.\n\n#### Your Task:\nYou are required ...
0.499974
Data_Structure_13382
C
[ "is_prime", "find_primitive_root", "secure_diffie_hellman_exchange" ]
3
[ [ "find_primitive_root", "is_prime" ], [ "secure_diffie_hellman_exchange", "find_primitive_root" ], [ "secure_diffie_hellman_exchange", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
b3ec5bd9d1f0a7d52184881ef6ac3b32f5e32e89
49b35392cce54c1f058714de6f13c8c11c5460bb
v1.0
complete
Data_Structure
Data_Structure_13686_C
import random from sympy import isprime, mod_inverse 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): Number of bits in the modulus n. seed (int, optional): Random seed for reproducibility. ...
import random from sympy import isprime, mod_inverse def generate_prime_candidate(length): """Generate an odd integer randomly.""" candidate = random.getrandbits(length) candidate |= (1 << length - 1) | 1 # Ensure it's odd and of the desired bit length return candidate def generate_prime_number(lengt...
from solution import generate_key, encrypt, decrypt def test_generate_key(): n, e, d = generate_key(16, seed=42) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert n > 0 assert e > 0 assert d > 0 def test_encrypt_decrypt(): k = 16 n, e, d = gen...
[ { "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 bit length 'length'.", "function_declaration": "def...
[ 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\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime_candidate(length):\n \"\"\"Generate an odd integer randomly.\"\"\"\n candida...
trial_gpt4o_0
{ "original_instruction": "### Question: RSA Encryption Algorithm\n\nDesign an RSA encryption system by implementing the following functions `generate_key`, `encrypt`, and `decrypt`.\n\n**Function Signatures**:\n```python\ndef generate_key(k: int, seed: int = None) -> tuple:\n \"\"\"Generate RSA public and private...
0.684247
Data_Structure_13686
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
6325f1040bd70b7a657067286ec3031a683eb6f3
0e9c2f85a3ee665d63c4363c4e15fc3ff9fdff6c
v1.0
complete
Data_Structure
Data_Structure_13029_C
def is_prime_optimized(num: int) -> bool: """ Checks if a number is prime using a more efficient method. >>> is_prime_optimized(2) True >>> is_prime_optimized(15) False >>> is_prime_optimized(29) True """ pass import random def generate_key(k: int, seed=None): def modinv(a, m):...
def is_prime_optimized(num): """ Checks if a number is prime using a more efficient method. Implements the Miller-Rabin primality test. """ if num in (2, 3): return True if num <= 1 or num % 2 == 0: return False def miller_rabin_test(d, num): a = random.randint(2...
from solution import is_prime_optimized, generate_key, encrypt, decrypt def test_is_prime_optimized(): assert is_prime_optimized(2) == True assert is_prime_optimized(3) == True assert is_prime_optimized(4) == False assert is_prime_optimized(5) == True assert is_prime_optimized(29) == True asser...
[ { "docstring": "Checks if a number is prime using a more efficient method.\nImplements the Miller-Rabin primality test.", "function_declaration": "def is_prime_optimized(num):", "function_name": "is_prime_optimized", "parameter_list": "(num)" }, { "docstring": null, "function_declaration...
[ 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": "import random\n\ndef is_prime_optimized(num):\n \"\"\"Helper function to determine if the number is a prime using the Miller-Rabin test.\"\"\"\n if num ...
trial_gpt4o_7
{ "original_instruction": "### Scenario:\nYou are working on implementing a secure communication system using the RSA algorithm. After studying the key generation and encryption process, your task is to complete and optimize a simplified RSA encryption system. Specifically, you have to handle encryption, decryption f...
0.672279
Data_Structure_13029
C
[ "is_prime_optimized", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "is_prime_optimized" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb3956090154d1e441dfe935582bc5c56b114dbd
abac25fde2bde7a9a74134eb169a3a7415a72506
v1.0
complete
Data_Structure
Data_Structure_11957_C
from typing import List, Tuple import time def enhanced_radix_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the radix sort algorithm. Raises ValueError for empty lists and lists containing non-integer values. >>> enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) [...
from typing import List, Tuple import time def enhanced_radix_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers using the radix sort algorithm. Raises ValueError for empty lists and lists containing non-integer values. """ if not arr: raise ValueError("Input array is empty") ...
from solution import enhanced_radix_sort, measure_performance import pytest def test_enhanced_radix_sort_empty_array(): with pytest.raises(ValueError, match="Input array is empty"): enhanced_radix_sort([]) def test_enhanced_radix_sort_non_integer_values(): with pytest.raises(ValueError, match="All ele...
[ { "docstring": "Sorts a list of integers using the radix sort algorithm. \nRaises ValueError for empty lists and lists containing non-integer values.", "function_declaration": "def enhanced_radix_sort(arr):", "function_name": "enhanced_radix_sort", "parameter_list": "(arr)" }, { "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, Tuple\nimport time\n\ndef enhanced_radix_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts a list of integers using radix sor...
trial_gpt4o_2
{ "original_instruction": "### Radix Sort Enhancement and Analysis\n\nYou are tasked with enhancing the provided radix sort implementation and analyzing its performance with various datasets. Here, you need to:\n\n1. **Improve the Function**: Modify the given radix sort function to handle potential edge cases such as...
0.608772
Data_Structure_11957
C
[ "enhanced_radix_sort", "measure_performance" ]
2
[ [ "measure_performance", "enhanced_radix_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6f419f8009c7aabb36475ccb6b2e14e4e6cedac9
c440b135acc8cdda4574cc5bec39a7f74073469a
v1.0
complete
Data_Structure
Data_Structure_14715_C
from typing import List def find_primes_in_list(numbers: List[int]) -> List[int]: """ Given a list of integers, return a list containing all the prime numbers from the input list. :param numbers: A list of integers to check for prime numbers. :return: A list of prime numbers found in the input list. ...
from typing import List def is_prime(n: int) -> bool: """ Helper function to check if a given number is prime. """ if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(n ** 0.5) + 1 for d in range(3, max_divisor, 2): ...
from solution import find_primes_in_list def test_find_primes_in_list_all_primes(): assert find_primes_in_list([2, 3, 5, 7, 11, 13, 17, 19]) == [2, 3, 5, 7, 11, 13, 17, 19] def test_find_primes_in_list_with_non_primes(): assert find_primes_in_list([4, 6, 8, 9, 10, 12, 14, 15, 16]) == [] def test_find_primes_...
[ { "docstring": "Helper function to check if a given number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given a list of integers, return a list containing all the prime numbers from the input list.", "func...
[ 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\nfrom typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if n <=...
trial_gpt4o_1
{ "original_instruction": "#### Objective\nWrite a function that verifies if a list of numbers contains any primes and returns a list of the prime numbers found.\n\n#### Context\nYour team is working on a cryptographic application that requires verification of prime numbers for key generation. To ensure efficient ver...
0.700736
Data_Structure_14715
C
[ "is_prime", "find_primes_in_list" ]
2
[ [ "find_primes_in_list", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
90d6fe0c2803cdef4b39fa677803846388d683e0
e184e94f8b4aa3ff383ff257029a784966498059
v1.0
complete
Data_Structure
Data_Structure_13979_C
def insertion_sort(array: List[int]) -> List[int]: """Sorts the array using the insertion sort algorithm with binary search to find the correct insertion point. >>> insertion_sort([4, 3, 2, 1]) == [1, 2, 3, 4] >>> insertion_sort([1, 2, 3, 4]) == [1, 2, 3, 4] >>> insertion_sort([3, 1, 4, 1, 5, 9, 2,...
from typing import List def search_insert(array: List[int], value: int) -> int: """ Binary search to find the position to insert the value. Returns the index where the value should be inserted to keep the array sorted. """ low = 0 high = len(array) - 1 while low <= high: mid = (low...
from solution import insertion_sort def test_insertion_sort_empty(): assert insertion_sort([]) == [] def test_insertion_sort_single_element(): assert insertion_sort([1]) == [1] def test_insertion_sort_sorted_array(): assert insertion_sort([1, 2, 3, 4]) == [1, 2, 3, 4] def test_insertion_sort_unsorted_ar...
[ { "docstring": "Binary search to find the position to insert the value.\nReturns the index where the value should be inserted to keep the array sorted.", "function_declaration": "def search_insert(array, value):", "function_name": "search_insert", "parameter_list": "(array, value)" }, { "doc...
[ 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(sorted_array: List[int], value: int) -> int:\n \"\"\"\n This function returns the index where 'value' shoul...
trial_gpt4o_2
{ "original_instruction": "#### Context\nYou are tasked with integrating binary search with an insertion sort algorithm. The insertion sort algorithm typically requires shifting elements to insert a new value in its correct place. The provided function `search_insert` is crucial for finding the correct position of th...
0.641307
Data_Structure_13979
C
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa265f498665fcf1690c3fb6eb121d6baca3eeee
9acafe6cb90bdc5487895eef52fa096c0a67dc11
v1.0
complete
Data_Structure
Data_Structure_13403_C
from typing import List, Optional def prime_check(num: int) -> bool: """ Check if a given number is a prime. >>> prime_check(2) == True >>> prime_check(4) == False >>> prime_check(1013) == True >>> prime_check(1001) == False """ pass def euler_totient(n: int) -> int: """ Comput...
import random from typing import List, Optional def prime_check(num: int) -> bool: if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or num % (i + 2) == 0: return Fal...
from solution import prime_check, euler_totient, find_primitive_root, alice_private_key, alice_public_key, bob_private_key, bob_public_key, alice_shared_key, bob_shared_key, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(2) == True assert prime_check(4) == False assert prime_check(1...
[ { "docstring": null, "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def euler_totient(n):", "function_name": "euler_totient", "parameter_list": "(n)" }, { "docstri...
[ 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 List, Optional\n\ndef prime_check(num: int) -> bool:\n if num <= 1:\n return False\n if num <= 3:\n retu...
trial_gpt4o_0
{ "original_instruction": "### Secure Chat Application Key Exchange\n\nYou are tasked to create a secure chat application that enables two users, Alice and Bob, to share a secret encryption key over an insecure network using a Diffie-Hellman key exchange. The application should perform the following tasks:\n\n1. Veri...
0.622226
Data_Structure_13403
C
[ "prime_check", "euler_totient", "find_primitive_root", "alice_private_key", "alice_public_key", "bob_private_key", "bob_public_key", "alice_shared_key", "bob_shared_key", "diffie_hellman_key_exchange" ]
10
[ [ "diffie_hellman_key_exchange", "alice_private_key" ], [ "diffie_hellman_key_exchange", "alice_public_key" ], [ "diffie_hellman_key_exchange", "alice_shared_key" ], [ "diffie_hellman_key_exchange", "bob_private_key" ], [ "diffie_hellman_key_exchange", "bob_pu...
9
[]
false
[]
false
pytest
true
[]
true
9e181e9ed50820fa04a88839fe10fc5610284c70
0d4b66de111cb6ffbe3307552e90439465f947cf
v1.0
complete
Data_Structure
Data_Structure_14481_C
from typing import List def maximum_flow(capacity: List[List[int]], source: int, sink: int) -> int: """ Calculates the maximum flow in a flow network from a source to a sink using Edmonds-Karp algorithm. Args: capacity (List[List[int]]): A 2D list where capacity[i][j] represents the maximum capaci...
from collections import deque from typing import List def bfs(C: List[List[int]], F: List[List[int]], source: int, sink: int, parent: List[int]) -> bool: """ Performs a BFS to find an augmenting path in the residual graph. """ visited = [False] * len(C) queue = deque([source]) visited[source] =...
from solution import maximum_flow def test_small_network(): 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 maximum_flow(capacity, s...
[ { "docstring": "Performs a BFS to find an augmenting path in the residual graph.", "function_declaration": "def bfs(C, F, source, sink, parent):", "function_name": "bfs", "parameter_list": "(C, F, source, sink, parent)" }, { "docstring": "Returns the maximum flow from the source to the sink ...
[ 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 collections import deque\nfrom typing import List\n\n# We'll use the BFS version of the Ford-Fulkerson algorithm known as the Edmonds-Karp algorithm\ndef...
trial_gpt4o_1
{ "original_instruction": "**Title**: Maximum Flow Computation in a Flow Network\n\n**Objective**:\nYou are asked to implement a function that calculates the maximum flow in a flow network using one of the maximum flow algorithms discussed (Ford-Fulkerson, Edmonds-Karp, or Dinic). This will assess your understanding ...
0.589848
Data_Structure_14481
C
[ "bfs", "maximum_flow" ]
2
[ [ "maximum_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0f31da9d66e95bdc66ab839aebae102109ca4001
aa39d1830c34fcd783e52ad6f6dc58b465fa2be7
v1.0
complete
Data_Structure
Data_Structure_12989_C
def find_magic_numbers(start: int, limit: int) -> list: """ Find all magic numbers between start and limit (inclusive). A "Magic Number" is defined as a number which, when summing its digits repeatedly until a single-digit number results, yields 1. Example: >>> find_magic_numbers(1, 20) [1, 10, 19]...
def sum_digits(n): """ Sums the digits of a number. """ return sum(int(digit) for digit in str(n)) def is_magic_number(n): """ Returns True if the number is a magic number. """ while n >= 10: n = sum_digits(n) return n == 1 def find_magic_numbers(start: int, limit: int) -> ...
from solution import find_magic_numbers def test_magic_numbers_small_range(): assert find_magic_numbers(1, 20) == [1, 10, 19] def test_magic_numbers_zero_to_ten(): assert find_magic_numbers(0, 10) == [1, 10] def test_magic_numbers_large_range(): assert find_magic_numbers(190, 200) == [190, 199] def test...
[ { "docstring": "Sums the digits of a number.", "function_declaration": "def sum_digits(n):", "function_name": "sum_digits", "parameter_list": "(n)" }, { "docstring": "Returns True if the number is a magic number.", "function_declaration": "def is_magic_number(n):", "function_name": "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_magic_numbers(start: int, limit: int) -> list:\n def is_magic_number(num: int) -> bool:\n while num >= 10:\n num = sum(int(digit...
trial_gpt4o_2
{ "original_instruction": "### Magic Number Sequence Problem\n\n### Context:\nA \"Magic Number\" is defined as a number which, when summing its digits repeatedly until a single-digit number results, yields 1. We want to generate a sequence of such magic numbers starting from a given number up to a certain limit.\n\n#...
0.592543
Data_Structure_12989
C
[ "sum_digits", "is_magic_number", "find_magic_numbers" ]
3
[ [ "find_magic_numbers", "is_magic_number" ], [ "is_magic_number", "sum_digits" ] ]
2
[]
false
[]
false
pytest
true
[]
true
df8c30bd5983fbe0fe0e8b8d92daeda68987a3b7
bf3275daf7acb4531ee90f9c6fc22d559db8f8fe
v1.0
complete
Data_Structure
Data_Structure_14901_C
class Node(object): def __init__(self, val=None): self.val = val self.next = None def intersection(h1: Node, h2: Node) -> Node: """ Function to find the intersection point of two singly linked lists. >>> a1 = Node(1) >>> b1 = Node(3) >>> c1 = Node(5) >>> d = Node(7) >>> a2 =...
class Node(object): def __init__(self, val=None): self.val = val self.next = None def get_length(head: Node) -> int: """ Helper function to calculate the length of a linked list starting from head. """ length = 0 current = head while current: length += 1 cur...
from solution import Node, intersection def test_no_intersection(): h1 = Node(1) h1.next = Node(2) h1.next.next = Node(3) h2 = Node(4) h2.next = Node(5) assert intersection(h1, h2) is None def test_intersection(): a1 = Node(1) b1 = Node(3) c1 = Node(5) d = Node(7) ...
[]
[ 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(object):\n def __init__(self, val=None):\n self.val = val\n self.next = None\n\ndef get_list_length(head: Node) -> int:\n lengt...
trial_gpt4o_1
{ "original_instruction": "Given the following problem statement and function signature, implement the function `intersection` that identifies the intersection node of two singly linked lists, if any.\n\n### Problem Statement\nYou are given two singly linked lists that merge at some point into a single list. Your tas...
0.508319
Data_Structure_14901
C
[ "get_length", "intersection" ]
2
[ [ "intersection", "get_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
5c6865ad144ae832fc79f8e697a6d28765bebfc2
0be7f52a95f237e2555fb18da77c6202347d2859
v1.0
complete
Data_Structure
Data_Structure_13489_C
def merge_sort(arr): """ Sorts an array in non-decreasing order using the Merge Sort algorithm. Parameters: arr (list): A list of comparable elements to be sorted. Returns: list: A sorted list containing all elements from the input list. >>> merge_sort([4, 2, 7, 1, 3]) [1, 2, ...
def merge_sort(arr): """ Sorts an array in non-decreasing order using the Merge Sort algorithm. Parameters: arr (list): A list of comparable elements to be sorted. Returns: list: A sorted list containing all elements from the input list. """ if len(arr) <= 1: return arr...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted(): assert merge_sort([5,...
[ { "docstring": "Sorts an array in non-decreasing order using the Merge Sort algorithm.\n\nParameters:\narr (list): A list of comparable elements to be sorted.\n\nReturns:\nlist: A sorted list containing all elements from the input list.", "function_declaration": "def merge_sort(arr):", "function_name": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge_sort(arr):\n \"\"\"\n Sorts an array in non-decreasing order using the Merge Sort algorithm.\n \n Parameters:\n arr (list): A list of...
trial_gpt4o_2
{ "original_instruction": "### Question: Implement an Improved Sorting Algorithm\n\nYou have learned about the Exchange Sort algorithm, which is simple but inefficient for large datasets due to its O(n^2) time complexity. To improve performance, you will implement the Merge Sort algorithm, which has a better time com...
0.653408
Data_Structure_13489
C
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
24a2fb2202b4a7179398cc5194b49fc0a8e6a663
70656db45937c045c1e8709b7e132378e9c35130
v1.0
complete
Data_Structure
Data_Structure_12051_C
def enhanced_gcd(a, b): """ Compute the greatest common divisor (GCD) of two integers, handling both negative and zero inputs gracefully. If both inputs are zero, return None. >>> enhanced_gcd(0, 0) == None >>> enhanced_gcd(0, 5) == 5 >>> enhanced_gcd(-12, 15) == 3 >>> enhanced_gcd(25, 15) ...
def enhanced_gcd(a, b): """ Compute the greatest common divisor (GCD) of two integers, handling both negative and zero inputs gracefully. If both inputs are zero, return None. """ if a == 0 and b == 0: return None while b: a, b = b, a % b return abs(a) def enhanced_lcm(a, b)...
import pytest from solution import enhanced_gcd, enhanced_lcm, add_results, sub_results, mul_results, div_results def test_enhanced_gcd(): assert enhanced_gcd(0, 0) == None assert enhanced_gcd(0, 5) == 5 assert enhanced_gcd(5, 0) == 5 assert enhanced_gcd(-12, 15) == 3 assert enhanced_gcd(25, 15) ==...
[ { "docstring": "Compute the greatest common divisor (GCD) of two integers, handling both negative and zero inputs gracefully.\nIf both inputs are zero, return None.", "function_declaration": "def enhanced_gcd(a, b):", "function_name": "enhanced_gcd", "parameter_list": "(a, b)" }, { "docstrin...
[ 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_gcd(a, b):\n \"\"\"\n Returns the greatest common divisor (GCD) of two integers.\n If both integers are zero, returns None.\n \"\"\"\...
trial_gpt4o_2
{ "original_instruction": "Enhanced GCD and LCM Functions\n\nAs an experienced programmer, you are tasked with enhancing the existing GCD and LCM functions provided. Your task includes improving error handling, optimizing performance, and extending functionality.\n\n#### Task\n\n1. **Enhanced GCD Function (`enhanced_...
0.767235
Data_Structure_12051
C
[ "enhanced_gcd", "enhanced_lcm", "add_results", "sub_results", "mul_results", "div_results" ]
6
[ [ "enhanced_lcm", "enhanced_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f3a67ddcfdc86434819b53e21aa206fe7d77c91d
b223c6efe5550bff171bfca6aee2eb4fc127e711
v1.0
complete
Data_Structure
Data_Structure_13209_C
def optimized_insertion_sort(arr: list, simulation=False) -> list: """ Perform insertion sort with early exit and binary search optimizations. Args: arr (list): List of integers to be sorted. simulation (bool): If True, prints the array at each iteration. Returns: list: Sorted list of ...
def binary_search(arr, val, start, end): # Perform binary search to find the position for val in arr while start < end: mid = (start + end) // 2 if arr[mid] < val: start = mid + 1 else: end = mid return start def optimized_insertion_sort(arr, simulation=False...
from solution import optimized_insertion_sort def test_already_sorted_array(): arr = [1, 2, 3, 4, 5] sorted_arr = optimized_insertion_sort(arr.copy()) assert sorted_arr == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): arr = [5, 4, 3, 2, 1] sorted_arr = optimized_insertion_sort(arr.copy()) a...
[ { "docstring": null, "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" }, { "docstring": null, "function_declaration": "def optimized_insertion_sort(arr, simulation=False):", "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": "def binary_search(arr, val, start, end):\n # Perform binary search to find the position for val in arr\n while start < end:\n mid = (start + end)...
trial_gpt4o_0
{ "original_instruction": "### Coding Assessment: Insertion Sort with Early Exit and Binary Search\n\n#### Question\nYou are tasked with improving the performance of the traditional insertion sort algorithm by implementing two optimizations:\n\n1. **Early Exit**: During each pass, check if no elements were swapped in...
0.645592
Data_Structure_13209
C
[ "binary_search", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fb9aa3bede337b658fd387e611d2ec4fbe1f4738
4e99c64e091462b11846e862aa798a7b8596e370
v1.0
complete
Data_Structure
Data_Structure_15565_C
from typing import List def enhanced_radix_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Sorts a list of non-negative integers using Radix Sort with optional simulation/debugging. Args: arr (List[int]): The list of non-negative integers to sort. simulation (bool): If True, ...
from typing import List def enhanced_radix_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Sorts a list of non-negative integers using Radix Sort with optional simulation/debugging. Args: arr (List[int]): The list of non-negative integers to sort. simulation (bool): If True, p...
import pytest from solution import enhanced_radix_sort def test_enhanced_radix_sort_standard(): 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_small_numbers(): assert enhanced_radix_sort([5, 3, 8, 6, 2, 7, 4, 1]) == [1, 2, 3, 4, ...
[ { "docstring": "Sorts a list of non-negative integers using Radix Sort with optional simulation/debugging.\n\nArgs:\narr (List[int]): The list of non-negative integers to sort.\nsimulation (bool): If True, print debug information for each iteration.\n\nReturns:\nList[int]: The sorted list of integers in ascendi...
[ 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_radix_sort(arr: List[int], simulation: bool = False) -> List[int]:\n if not arr:\n return []\n\n # Utilit...
trial_gpt4o_2
{ "original_instruction": "### Question: Implement an Enhanced Radix Sort\n\n**Background**:\nYou are tasked with implementing an enhanced version of Radix Sort. This sort algorithm is particularly beneficial for sorting large datasets of fixed-length integers due to its linear time complexity under these circumstanc...
0.686496
Data_Structure_15565
C
[ "enhanced_radix_sort", "counting_sort" ]
2
[ [ "enhanced_radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
79a5f2d5abd28bd269fb84c934d536e35c8f8480
5fbf853adbed72a0427b147a8181051dc8d720f5
v1.0
complete
Data_Structure
Data_Structure_13429_C
from typing import List def swap(arr: List[int], i: int, j: int): """ Swap the elements at index i and j in the list arr. """ pass def enhanced_selection_sort(arr: List[int], descending: bool = False) -> List[int]: """ Sorts the array using an enhanced version of the selection sort algorithm. ...
from typing import List def swap(arr: List[int], i: int, j: int): """ Swap the elements at index i and j in the list arr. """ arr[i], arr[j] = arr[j], arr[i] def enhanced_selection_sort(arr: List[int], descending: bool = False) -> List[int]: """ Sorts the array using an enhanced version of the...
from solution import enhanced_selection_sort def test_enhanced_selection_sort_ascending(): assert enhanced_selection_sort([4, 2, 7, 1, 3]) == [1, 2, 3, 4, 7] def test_enhanced_selection_sort_descending(): assert enhanced_selection_sort([4, 2, 7, 1, 3], descending=True) == [7, 4, 3, 2, 1] def test_empty_list(...
[ { "docstring": "Swap the elements at index i and j in the list arr.", "function_declaration": "def swap(arr, i, j):", "function_name": "swap", "parameter_list": "(arr, i, j)" }, { "docstring": "Sorts the array using an enhanced version of the selection sort algorithm.\nIt can sort in ascendi...
[ 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 swap(arr: List[int], i: int, j: int):\n \"\"\"\n A helper function that swaps the elements at index i and j in the list a...
trial_gpt4o_2
{ "original_instruction": "### Task: Enhanced Selection Sort with Custom Swapping\n\n### Objective\nYou are required to implement an enhanced version of the selection sort algorithm. Instead of directly swapping elements within the array, you should implement a custom swap function. Furthermore, the algorithm should ...
0.654887
Data_Structure_13429
C
[ "swap", "enhanced_selection_sort" ]
2
[ [ "enhanced_selection_sort", "swap" ] ]
1
[]
false
[]
false
pytest
true
[]
true
34c5966eeb8a4156f7655f11b31e4a06e0408b15
7a7ece139003e4ac94cc016da11c433cc8519564
v1.0
complete
Data_Structure
Data_Structure_14822_C
from typing import Tuple def compute(a: int, b: int) -> Tuple[int, int]: """ Calculate the greatest common divisor (GCD) of `a` and `b` using bitwise operators, and count the number of trailing zeros in the binary representation of the calculated GCD. Args: a (int): The first non-negative integer...
from typing import Tuple def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def count_trailing_zeros(n: int) -> int: if n == 0: return 0 count = 0 while n % 2 == 0: n //= 2 count += 1 return count def compute(a: int, b: int) -> Tuple[int, int]: ...
import pytest from solution import compute def test_gcd_and_trailing_zeros(): assert compute(8, 12) == (4, 2) assert compute(15, 25) == (5, 0) assert compute(0, 20) == (20, 2) assert compute(0, 0) == (0, 0) assert compute(10, 5) == (5, 0) assert compute(14, 21) == (7, 0) assert compute(2, 4...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def count_trailing_zeros(n):", "function_name": "count_trailing_zeros", "parameter_list": "(n)" }, { "docstri...
[ 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 Tuple\n\ndef gcd(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n\ndef count_trailing_zeros(n: int) -> int:\n...
trial_gpt4o_0
{ "original_instruction": "#### Context\nA software system deals with large datasets where numbers require frequent simplification and manipulation. Your task is to create a function capable of calculating both the greatest common divisor (GCD) and the trailing zero count in the binary representation of numbers withi...
0.768098
Data_Structure_14822
C
[ "gcd", "count_trailing_zeros", "compute" ]
3
[ [ "compute", "count_trailing_zeros" ], [ "compute", "gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7a6282ed3172819c1f5c17cfa4ad21e0f9536ab3
abe05610bbb21c8ddfb1833c370e65cbaeb3edd0
v1.0
complete
Data_Structure
Data_Structure_12334_C
def matrix_power(mat: list, power: int) -> list: """ Compute the power of a given square matrix raised to the given power using matrix exponentiation by squaring. Args: mat (list): A list of lists where each inner list represents a row of an n x n matrix. power (int): A non-negative integer representin...
def matrix_multiply(mat1, mat2): n = len(mat1) res = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): res[i][j] += mat1[i][k] * mat2[k][j] return res def identity_matrix(n): return [[1 if i == j else 0 for j in range(n)] for i ...
from solution import matrix_power def test_matrix_power_single_element(): assert matrix_power([[2]], 3) == [[8]] def test_matrix_power_identity(): assert matrix_power([[2, 0], [0, 2]], 0) == [[1, 0], [0, 1]] def test_matrix_power_two_by_two(): assert matrix_power([[2, 0], [0, 2]], 3) == [[8, 0], [0, 8]] ...
[ { "docstring": null, "function_declaration": "def matrix_multiply(mat1, mat2):", "function_name": "matrix_multiply", "parameter_list": "(mat1, mat2)" }, { "docstring": null, "function_declaration": "def identity_matrix(n):", "function_name": "identity_matrix", "parameter_list": "...
[ 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 matrix_multiply(mat1, mat2):\n n = len(mat1)\n result = [[0] * n for _ in range(n)]\n for i in range(n):\n for j in range(n):\n ...
trial_gpt4o_1
{ "original_instruction": "### Scenario\nYou are working on a software project for a scientific computation module that heavily relies on matrix operations. As part of the project, you need to implement a feature that determines the state of a system after a series of transformations, each described by a transformati...
0.53958
Data_Structure_12334
C
[ "matrix_multiply", "identity_matrix", "matrix_power" ]
3
[ [ "matrix_power", "identity_matrix" ], [ "matrix_power", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f4b79e1533b5c5f99c17dc49d59819b0720b424b
a1f4b0bcbe2fab67025a405a0562cb14d97c4c9a
v1.0
complete
Data_Structure
Data_Structure_14515_C
def transform_matrix(matrix, transformation): """ Given a matrix, perform a specified transformation. Args: matrix (List[List[int]]): The original matrix to be transformed. transformation (str): The type of transformation ('rotate_clockwise', 'rotate_counterclockwise', ...
def transform_matrix(matrix, transformation): if transformation == 'rotate_clockwise': return rotate_clockwise(matrix) elif transformation == 'rotate_counterclockwise': return rotate_counterclockwise(matrix) elif transformation == 'top_left_invert': return top_left_invert(matrix) ...
import pytest from solution import transform_matrix def test_rotate_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] result = transform_matrix(matrix, 'rotate_clockwise') expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3] ] assert result == ex...
[ { "docstring": null, "function_declaration": "def transform_matrix(matrix, transformation):", "function_name": "transform_matrix", "parameter_list": "(matrix, transformation)" }, { "docstring": null, "function_declaration": "def rotate_clockwise(matrix):", "function_name": "rotate_cl...
[ 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 transform_matrix(matrix, transformation):\n if transformation == 'rotate_clockwise':\n return rotate_clockwise(matrix)\n elif transformation ...
trial_gpt4o_0
{ "original_instruction": "### Matrix Transformation Implementation\n\n#### Problem Statement\nGiven a matrix, implement a function `transform_matrix` that performs a specified transformation on the matrix. You are required to support the following transformations:\n\n1. `rotate_clockwise`: Rotate the matrix by 90 de...
0.552702
Data_Structure_14515
C
[ "transform_matrix", "rotate_clockwise", "rotate_counterclockwise", "top_left_invert", "bottom_left_invert" ]
5
[ [ "transform_matrix", "bottom_left_invert" ], [ "transform_matrix", "rotate_clockwise" ], [ "transform_matrix", "rotate_counterclockwise" ], [ "transform_matrix", "top_left_invert" ] ]
4
[]
false
[]
false
pytest
true
[]
true
4a59868f2816be31fba459864d9f08b52e364201
e2bcfc9078d8961eb2734ce05b335f8a1adacc37
v1.0
complete
Data_Structure
Data_Structure_11036_C
def exchange_sort(arr): """ Implements the Exchange Sort algorithm. :param arr: A list of integers that need to be sorted. :return: A sorted list of integers in non-decreasing order. """ n = len(arr) for i in range(n): for j in range(i + 1, n): if arr[i] > arr[j]: ...
def exchange_sort(arr): """ Implements the Exchange Sort algorithm. :param arr: A list of integers that need to be sorted. :return: A sorted list of integers in non-decreasing order. """ n = len(arr) for i in range(n): for j in range(i + 1, n): if arr[i] > arr[j]: ...
from solution import optimized_sort def test_optimized_sort_small_array(): assert optimized_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9] assert optimized_sort([3]) == [3] assert optimized_sort([10, -1, 2, 8, 0, 5, 4]) == [-1, 0, 2, 4, 5, 8, 10] def test_optimized_sort_large_array(): assert optimized...
[ { "docstring": "Implements the Exchange Sort algorithm.\n\n:param arr: A list of integers that need to be sorted.\n:return: A sorted list of integers in non-decreasing order.", "function_declaration": "def exchange_sort(arr):", "function_name": "exchange_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": "def exchange_sort(arr):\n n = len(arr)\n for i in range(n):\n for j in range(i + 1, n):\n if arr[i] > arr[j]:\n arr[i],...
trial_gpt4o_1
{ "original_instruction": "### Exchange Sort Optimization Challenge\n\n**Scenario**: \nYou are working on optimizing a sorting routine in a legacy system where algorithms are chosen based on specific dataset characteristics. The system currently employs the Exchange Sort algorithm, which is efficient on small arrays...
0.61987
Data_Structure_11036
C
[ "exchange_sort", "merge_sort", "merge", "optimized_sort" ]
4
[ [ "merge_sort", "merge" ], [ "optimized_sort", "exchange_sort" ], [ "optimized_sort", "merge_sort" ] ]
3
[]
false
[]
false
pytest
true
[]
true
cfc548b858d882c6fd5ed3f61f40de2720441c96
b2c8630f9e320ede10264f9150ad5aa1ac7f7fcd
v1.0
complete
Data_Structure
Data_Structure_14795_C
def generate_rsa_key(bit_length: int, seed: Optional[int] = None) -> Tuple[int, int, int]: """ Generate RSA keys. :param bit_length: Number of bits for the modulus n. Should be at least 16. :param seed: Optional seed for the random number generator to ensure reproducibility. :return: A tuple (n, e,...
import random from sympy import isprime, mod_inverse def generate_prime_candidate(bit_length): """ Generate a random odd integer of the given bit length. """ p = random.getrandbits(bit_length) # Ensure the candidate is odd and has the correct bit length p |= (1 << bit_length - 1) | 1 return p def ...
from solution import generate_rsa_key def test_generate_rsa_key(): # Test a standard case bit_length = 16 n, e, d = generate_rsa_key(bit_length, seed=42) assert n > 0 assert e > 0 assert d > 0 assert e != d def test_key_generation_reproducible(): # Test for reproducibility with the sam...
[ { "docstring": "Generate a random odd integer of the given bit length. ", "function_declaration": "def generate_prime_candidate(bit_length):", "function_name": "generate_prime_candidate", "parameter_list": "(bit_length)" }, { "docstring": "Generate a prime number of the specified bit length....
[ 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": "import random\nfrom typing import Tuple, Optional\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime_candidate(bit_length: int) -> int:\n # Gene...
trial_gpt4o_9
{ "original_instruction": "### RSA Key Generation and Encryption\n\n#### Scenario:\nYou are asked to develop a secure communication system using the RSA encryption algorithm. Your task is to implement the key generation component, which is critical for setting up secure encryption and decryption channels.\n\n#### Pro...
0.678792
Data_Structure_14795
C
[ "generate_prime_candidate", "generate_prime_number", "generate_rsa_key" ]
3
[ [ "generate_prime_number", "generate_prime_candidate" ], [ "generate_rsa_key", "generate_prime_number" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
6396ad0338f697371fd50eea113f05a807aa6fbd
169bea48d7d83da987e8cd8d56dad3d662a8b87f
v1.0
complete
Data_Structure
Data_Structure_14870_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 bogo_sort(arr: List[int], simulation: bool = False) -> List[i...
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 bogo_sort def test_bogo_sort_already_sorted(): assert bogo_sort([1, 2, 3]) == [1, 2, 3] def test_bogo_sort_reverse_sorted(): assert bogo_sort([3, 2, 1]) == [1, 2, 3] def test_bogo_sort_unsorted(): assert bogo_sort([2, 3, 1]) == [1, 2, 3] def test_bogo_sort_same_elements(): asser...
[ { "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 the array using Bogo Sort algorithm which randomly shuffles\nthe array until it is sorted.", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef is_sorted(arr: List[int]) -> bool:\n \"\"\"\n Helper function to check if the array is sorted.\n \"\"\"...
trial_gpt4o_1
{ "original_instruction": "You are given an array of integers and you need to sort this array using Bogo Sort, despite its inefficiency. The Bogo Sort algorithm randomly shuffles the array until it is sorted. You need to implement the Bogo Sort algorithm and ensure that the result meets the required sorted order.\n\n...
0.660682
Data_Structure_14870
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ebfc4af4da65f492ba83c9cc852444022ed72a18
e4606e6debb95d37b915938881ee4c745c0edb27
v1.0
complete
Data_Structure
Data_Structure_14549_C
import random from sympy import mod_inverse from sympy.ntheory.generate import randprime import math def generate_prime(bits, seed=None): """ Generate a prime number of specified bit length. """ pass def generate_key(k, seed=None): """ Generate RSA key components. Input: - k: Integer in...
import random from sympy import isprime, mod_inverse from sympy.ntheory.generate import randprime import math def generate_prime(bits, seed=None): if seed is not None: random.seed(seed) lower_bound = 2**(bits - 1) upper_bound = 2**bits - 1 while True: candidate = randprime(lower_bound, ...
from solution import generate_key, encrypt, decrypt def test_generate_key(): n, e, d = generate_key(16) assert n > 0 and e > 0 and d > 0 def test_encrypt_decrypt(): k = 16 n, e, d = generate_key(k) data = 42 encrypted = encrypt(data, e, n) decrypted = decrypt(encrypted, d, n) assert d...
[ { "docstring": null, "function_declaration": "def generate_prime(bits, seed=None):", "function_name": "generate_prime", "parameter_list": "(bits, seed=None)" }, { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "param...
[ 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\nfrom sympy import isprime, mod_inverse\nfrom sympy.ntheory.generate import randprime\nimport math\n\ndef generate_prime(bits, seed=None):\n ...
trial_gpt4o_0
{ "original_instruction": "You have been given the task to implement a simplified version of the RSA encryption algorithm, focusing on the key components of key generation, encryption, and decryption. Ensure the implementation is secure and correctly handles edge cases.\n\n### Function Specifications:\n\n#### 1. `gen...
0.655278
Data_Structure_14549
C
[ "generate_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
13db07ee45f2c37edf5b2bc843bdd47f9f6a1cc8
6152df5c1e7e9d2ec22d5d5f5f02c03af76f7471
v1.0
complete
Data_Structure
Data_Structure_15726_C
def kruskal(n, edges): """ Find the Minimum Spanning Tree (MST) of the given graph using Kruskal’s algorithm and compute the sum of the weights of the edges in this MST. n: int, number of vertices edges: List[Tuple[int, int, int]], list of edges where each edge is represented as (u, v, w), ...
def find(parent, i): if parent[i] == i: return i else: return find(parent, parent[i]) def union(parent, rank, x, y): xroot = find(parent, x) yroot = find(parent, y) if rank[xroot] < rank[yroot]: parent[xroot] = yroot elif rank[xroot] > rank[yroot]: parent[yr...
from solution import kruskal def test_simple_graph(): assert kruskal(5, [ (1, 2, 3), (1, 3, 8), (2, 4, 5), (3, 4, 2), (3, 5, 4), (4, 5, 6) ]) == 14 def test_single_edge(): assert kruskal(2, [ (1, 2, 1) ]) == 1 def test_disconnected_graph(): # Even though the problem guara...
[ { "docstring": null, "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": null, "function_declaration": "def union(parent, rank, x, y):", "function_name": "union", "parameter_list": "(parent, rank, x, y)" }, ...
[ 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 find(parent, i):\n if parent[i] == i:\n return i\n else:\n return find(parent, parent[i])\n\ndef union(parent, rank, x, y):\n xroot...
trial_gpt4o_0
{ "original_instruction": "### Kruskal's Algorithm: Find the Minimum Spanning Tree\n\n#### Problem Statement:\nGiven a connected, undirected graph with `n` vertices and `m` edges, find the Minimum Spanning Tree (MST) of the graph using Kruskal’s algorithm and compute the sum of the weights of the edges in this MST.\n...
0.695364
Data_Structure_15726
C
[ "find", "union", "kruskal" ]
3
[ [ "kruskal", "find" ], [ "kruskal", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
0bacc529d863c82330c4f849acdc47f1a98fa5d5
aee1eb012fddf0e6254462d1079b632ead47d0f1
v1.0
complete
Data_Structure
Data_Structure_13452_C
from typing import List from collections import deque def dinic(capacity: List[List[int]], source: int, sink: int) -> int: """ Compute the maximum flow in a directed graph using the Dinic algorithm. Args: capacity (List[List[int]]): A 2D list representing the capacity of the edges. source (int): T...
from typing import List from collections import deque def dinic_bfs(capacity: List[List[int]], source: int, sink: int, level: List[int]) -> bool: n = len(capacity) for i in range(n): level[i] = -1 queue = deque([source]) level[source] = 0 while queue: u = queue.popleft() ...
from solution import dinic def test_dinic_example(): 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 dinic(capacity, source, sink) =...
[ { "docstring": null, "function_declaration": "def dinic_bfs(capacity, source, sink, level):", "function_name": "dinic_bfs", "parameter_list": "(capacity, source, sink, level)" }, { "docstring": null, "function_declaration": "def dinic_dfs(u, flow_in, sink, capacity, level):", "functi...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef dinic_bfs(capacity, source, sink, level):\n n = len(capacity)\n queue = deque([source])\n level[source] = 0\n ...
trial_gpt4o_4
{ "original_instruction": "### Objective:\nYour task is to implement the Dinic algorithm for computing the maximum flow in a directed graph. You need to write the functions for BFS and DFS which are used within the main Dinic algorithm function. \n\n### Function Signature:\n```python\ndef dinic(capacity: List[List[in...
0.535736
Data_Structure_13452
C
[ "dinic_bfs", "dinic_dfs", "dinic" ]
3
[ [ "dinic", "dinic_bfs" ], [ "dinic", "dinic_dfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0264e770e468c10dc0761aebc9fe26e202d003b3
c9ad6bc8f6d5b7f7aec88c3ebf02cef42b14e7b5
v1.0
complete
Data_Structure
Data_Structure_14593_C
def secure_diffie_hellman_key_exchange(a: int, p: int) -> int: """ Securely performs the Diffie-Hellman key exchange and returns the shared secret key. Args: a (int): A primitive root mod p. p (int): A large prime number. Returns: int: The shared secret key. Raises: Va...
import random def is_prime(n): """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 return...
import pytest from solution import secure_diffie_hellman_key_exchange, is_prime, find_primitive_root def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(11) == True assert is_prime(15) == False assert is_prime(17) == True d...
[ { "docstring": "Check if a number is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstr...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\nclass ValidationError(Exception):\n pass\n\ndef is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n ...
trial_gpt4o_2
{ "original_instruction": "### Diffie-Hellman Key Exchange Implementation with Enhanced Security\n\n**Objective**: Implement a function to securely perform Diffie-Hellman Key Exchange algorithm and return the shared secret key, while ensuring appropriate validation and error handling mechanisms.\n\n### Problem Statem...
0.570049
Data_Structure_14593
C
[ "is_prime", "gcd", "find_primitive_root", "secure_diffie_hellman_key_exchange" ]
4
[ [ "find_primitive_root", "is_prime" ], [ "secure_diffie_hellman_key_exchange", "find_primitive_root" ], [ "secure_diffie_hellman_key_exchange", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
bc85fd8d2b99092435be2dd68b7cef4f9269f369
2b59221c668e5f14d0717f14ea9f1bd9606af007
v1.0
complete
Data_Structure
Data_Structure_14376_C
def optimized_sort(arr: list) -> tuple: """ Sort the array and return the sorted array along with performance statistics. This function uses an optimized version of Bogo Sort by applying a selection shuffle to progressively move towards a sorted array. Parameters: arr (list): List of ...
import random def is_sorted(arr): """Helper function to check if the array is sorted.""" return all(arr[i] <= arr[i + 1] for i in range(len(arr) - 1)) def optimized_sort(arr): """ Sort the array and return the sorted array along with performance statistics. This function uses an optimized ver...
from solution import optimized_sort def test_already_sorted(): arr = [1, 2, 3, 4, 5] sorted_arr, iterations, shuffles = optimized_sort(arr) assert sorted_arr == [1, 2, 3, 4, 5] assert iterations == 0 assert shuffles == 0 def test_reverse_sorted(): arr = [5, 4, 3, 2, 1] sorted_arr, iteratio...
[ { "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 and return the sorted array along with performance statistics.\n\nThis function uses an ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_sorted(arr):\n \"\"\"Helper function to check if the array is sorted.\"\"\"\n return all(arr[i] <= arr[i + 1] for i in range(len...
trial_gpt4o_0
{ "original_instruction": "### Bogo Sort with Optimization Constraints\n\nYou have been given an unoptimized sorting algorithm, Bogo Sort, which relies on random shuffling to sort an array. The algorithm is both inefficient and impractical as it can potentially run indefinitely.\n\nTo assess your understanding of sor...
0.62326
Data_Structure_14376
C
[ "is_sorted", "optimized_sort" ]
2
[ [ "optimized_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fa713c963e6f0b78fefb550dde66d007337390b6
00bd08c81e958cbb5f4bf5133e42735ac49a9302
v1.0
complete
Data_Structure
Data_Structure_15711_C
from typing import List def maximum_flow_bfs(adjacency_matrix: List[List[int]]) -> int: """ Finds the maximum flow in the given graph from the source node (0) to the sink node (last node). Parameters: adjacency_matrix (List[List[int]]): A 2D list representing the capacity graph. Returns: ...
from collections import deque from typing import List def bfs(residual_graph: List[List[int]], source: int, sink: int, parent: List[int]) -> bool: """ Perform BFS to find a path from source to sink in the residual graph. Updates the parent array to store the path. Returns True if a path is found, ...
from solution import maximum_flow_bfs def test_maximum_flow_example(): 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_maxi...
[ { "docstring": "Perform BFS to find a path from source to sink in the residual graph.\nUpdates the parent array to store the path.\n\nReturns True if a path is found, False otherwise.", "function_declaration": "def bfs(residual_graph, source, sink, parent):", "function_name": "bfs", "parameter_list"...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nfrom typing import List\n\ndef bfs(residual_graph: List[List[int]], source: int, sink: int, parent: List[int]) -> bool:\n \"...
trial_gpt4o_2
{ "original_instruction": "### Scenario\nYou are given a city's road network represented as a directed graph, where intersections are nodes and roads are edges with certain capacities. Your task is to compute the maximum amount of traffic that can flow from the central intersection (source) to the main exit (sink) us...
0.587729
Data_Structure_15711
C
[ "bfs", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a709ce95bc99ad01c290e322f3157354b438f2a
c6d956740aa213c88015c1bd305d0ac8aab8f466
v1.0
complete
Data_Structure
Data_Structure_15160_C
def search_insert(array, value): """ Uses binary search to find the index at which value should be inserted to maintain sorted order. Parameters: array (List[int]): A sorted list of integers. value (int): The value to find the insert position for. Returns: int: The index where the value sh...
def search_insert(array, value): """ Uses binary search to find the index at which value should be inserted to maintain sorted order. Parameters: array (List[int]): A sorted list of integers. value (int): The value to find the insert position for. Returns: int: The index where the value sh...
from solution import binary_insertion_sort, search_insert def test_search_insert(): assert search_insert([1, 3, 5, 7], 4) == 2 assert search_insert([10, 20, 30], 25) == 2 assert search_insert([], 1) == 0 assert search_insert([1, 2, 3], 0) == 0 def test_binary_insertion_sort(): assert binary_insert...
[ { "docstring": "Uses binary search to find the index at which value should be inserted to maintain sorted order.\n\nParameters:\narray (List[int]): A sorted list of integers.\nvalue (int): The value to find the insert position for.\n\nReturns:\nint: The index where the value should be inserted.", "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": "def search_insert(array, value, low, high):\n \"\"\"\n Helper function to determine the index where a value should be inserted \n in a sorted portion...
trial_gpt4o_2
{ "original_instruction": "### Insertion Sort with Binary Search Helper Function\n\nYou are tasked with implementing the Insertion Sort algorithm. To optimize your implementation, use the provided `search_insert` function which utilizes binary search to find the correct insert position.\n\n### Function to Implement\n...
0.623595
Data_Structure_15160
C
[ "search_insert", "binary_insertion_sort" ]
2
[ [ "binary_insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
12925c90cec9919d9f1abfc4cd7049dca1693254
d38fc760bf8960e76361acc575740a71d9215ac9
v1.0
complete
Data_Structure
Data_Structure_15265_C
def find_any_path(graph, start, end): """ Return any single path from the start node to the end node using recursive traversal and backtracking. >>> graph = { >>> 'A': ['B', 'D'], >>> 'B': ['A', 'C', 'D'], >>> 'C': ['B', 'D'], >>> 'D': ['A', 'B', 'C'] >>> } >>> find_any_path(graph, 'A...
def find_any_path(graph, start, end, path=[]): path = path + [start] if start == end: return path for node in graph[start]: if node not in path: new_path = find_any_path(graph, node, end, path) if new_path: return new_path return None def find_all...
from solution import find_any_path, find_all_paths, find_shortest_path graph = { 'A': ['B', 'D'], 'B': ['A', 'C', 'D'], 'C': ['B', 'D'], 'D': ['A', 'B', 'C'] } def test_find_any_path(): path = find_any_path(graph, 'A', 'C') assert path is not None assert path[0] == 'A' assert path[-1] ...
[ { "docstring": null, "function_declaration": "def find_any_path(graph, start, end, path=[]):", "function_name": "find_any_path", "parameter_list": "(graph, start, end, path=[])" }, { "docstring": null, "function_declaration": "def find_all_paths(graph, start, end, path=[]):", "functi...
[ 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 find_any_path(graph, start, end, path=None):\n if path is None:\n path = []\n path = path + [start]\n\n if start == end:\n return p...
trial_gpt4o_1
{ "original_instruction": "### Question:\nYou are given a connected, undirected graph as an adjacency list where each key represents a node, and the associated value is a list of nodes connected to it. Implement the following functions:\n\n1. `find_any_path(graph, start, end)`: This function should return any single ...
0.603669
Data_Structure_15265
C
[ "find_any_path", "find_all_paths", "find_shortest_path" ]
3
[ [ "find_shortest_path", "find_all_paths" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a6f2bd280b02c0d80a231202560891d34d6370de
b2290ff31b48f9af7e8a870d4577d31235b6fc6f
v1.0
complete
Data_Structure
Data_Structure_13963_C
def rotate_clockwise(matrix): return [list(reversed(col)) for col in zip(*matrix)] def rotate_counterclockwise(matrix): return [list(row) for row in zip(*matrix)][::-1] def top_left_invert(matrix): size = len(matrix) return [[matrix[i][j] for j in range(size)] for i in range(size)][::-1] def bottom_l...
def rotate_clockwise(matrix): return [list(reversed(col)) for col in zip(*matrix)] def rotate_counterclockwise(matrix): return [list(row) for row in zip(*matrix)][::-1] def top_left_invert(matrix): size = len(matrix) return [[matrix[i][j] for j in range(size)] for i in range(size)][::-1] def bottom_l...
def test_validate_transformation_rotate_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3], ] assert validate_transformation(matrix, 'rotate_clockwise', expected) == True def test_validate_transform...
[ { "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...
[ 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 rotate_clockwise(matrix):\n \"\"\"\n Rotates the input matrix 90 degrees clockwise.\n \"\"\"\n return [list(row) for row in zip(*matrix[::-1])...
trial_gpt4o_1
{ "original_instruction": "### Matrix Transformation and Validation\n\nYou are given a set of matrix transformation functions that can rotate and invert a square matrix. Your task is to write a new function that validates a matrix transformation against the expected output.\n\n1. **Function Signature**: `def validate...
0.532549
Data_Structure_13963
C
[ "rotate_clockwise", "rotate_counterclockwise", "top_left_invert", "bottom_left_invert", "validate_transformation" ]
5
[ [ "validate_transformation", "bottom_left_invert" ], [ "validate_transformation", "rotate_clockwise" ], [ "validate_transformation", "rotate_counterclockwise" ], [ "validate_transformation", "top_left_invert" ] ]
4
[]
false
[]
false
pytest
false
[]
true
03e5f9f186c09886fbb682bc0b93088cd44d0074
2c587b07f9156ffc55d49ad739e80b9bfb05781c
v1.0
complete
Data_Structure
Data_Structure_13155_C
def euler_totient(n: int) -> int: """ Computes Euler's Totient Function for a given integer n. >>> euler_totient(1) == 1 >>> euler_totient(2) == 1 >>> euler_totient(7) == 6 >>> euler_totient(9) == 6 >>> euler_totient(10) == 4 >>> euler_totient(15) == 8 """ pass def find_order(a:...
import math def euler_totient(n: int) -> int: """ Computes Euler's Totient Function for a given integer n. """ result = n p = 2 while p * p <= n: if n % p == 0: while n % p == 0: n //= p result -= result // p p += 1 if n > 1: r...
import pytest from solution import euler_totient, find_order, find_primitive_root def test_euler_totient(): assert euler_totient(1) == 1 assert euler_totient(2) == 1 assert euler_totient(7) == 6 assert euler_totient(9) == 6 assert euler_totient(10) == 4 assert euler_totient(15) == 8 def test_f...
[ { "docstring": "Computes Euler's Totient Function for a given integer n.", "function_declaration": "def euler_totient(n):", "function_name": "euler_totient", "parameter_list": "(n)" }, { "docstring": "Finds the order of a modulo n.\nOrder is the smallest integer k such that (a^k) % n == 1", ...
[ 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 gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef euler_totient(n):\n result = n\n p = 2\n while p * p <= n:\n if n %...
trial_gpt4o_2
{ "original_instruction": "### Primitive Roots Finder\n\n**Objective**: Implement the function `find_primitive_root(n)` that returns a list of all primitive roots of a given positive integer n.\n\n#### Function Signature\n```python\ndef find_primitive_root(n: int) -> list:\n pass\n```\n\n#### Input\n* An integer `...
0.610921
Data_Structure_13155
C
[ "euler_totient", "find_order", "find_primitive_root" ]
3
[ [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ] ]
2
[]
false
[]
false
pytest
true
[]
true
bce72c670d54e90703b2c0e3143555725507f0f4
a5e5b00983f778d45c2e5f454aceceae1fe9befc
v1.0
complete
Data_Structure
Data_Structure_15568_C
def enhanced_quick_sort(arr): """Enhanced Quick Sort Implementation. This function sorts a list of integers using an optimized Quick Sort algorithm. The enhancements include: 1. Pivot Selection using 'median-of-three' strategy. 2. Insertion Sort for small sub-arrays (size <= 10). 3. Efficie...
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 a = arr[le...
from solution import enhanced_quick_sort def test_sorted_array(): assert enhanced_quick_sort([1, 2, 3, 4, 5, 6]) == [1, 2, 3, 4, 5, 6] def test_reverse_sorted_array(): assert enhanced_quick_sort([6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 6] def test_random_array(): assert enhanced_quick_sort([3, 6, 1, 5, 2, ...
[ { "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"...
[ 0, 0, 0, 1, 1, 0, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def enhanced_quick_sort(arr):\n \"\"\"\n Sorts the array using an optimized Quick Sort algorithm with median-of-three pivot selection and insertion sort...
trial_gpt4o_6
{ "original_instruction": "Enhanced Quick Sort Implementation\n\n**Scenario**:\n\nYou have been hired by a tech company to optimize their data processing software. One critical module is responsible for sorting large datasets efficiently. The current implementation uses Quick Sort, and while performant, it encounters...
0.628564
Data_Structure_15568
C
[ "insertion_sort", "median_of_three", "quick_sort", "enhanced_quick_sort" ]
4
[ [ "enhanced_quick_sort", "quick_sort" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "median_of_three" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4fd42db8f9c0074d28fcff92d4b20a776158cdd7
fcba00a5c29bf381b36854a9bc2fbee0f009c5fb
v1.0
complete
Data_Structure
Data_Structure_13645_C
def add_bitwise_operator(x: int, y: int) -> int: """ Adds two positive integers using bitwise operations. >>> add_bitwise_operator(2, 3) 5 >>> add_bitwise_operator(0, 0) 0 >>> add_bitwise_operator(100, 100) 200 >>> add_bitwise_operator(12345, 67890) 80235 """ while y: carry = x & y ...
def add_bitwise_operator(x: int, y: int) -> int: """ Adds two numbers using bitwise operations. """ while y: carry = x & y x = x ^ y y = carry << 1 return x def multiply_bitwise_operator(x: int, y: int) -> int: """ Multiplies two numbers using bitwise operations. ...
from solution import add_bitwise_operator, multiply_bitwise_operator def test_add_bitwise_operator(): assert add_bitwise_operator(2, 3) == 5 assert add_bitwise_operator(0, 0) == 0 assert add_bitwise_operator(100, 100) == 200 assert add_bitwise_operator(12345, 67890) == 80235 def test_multiply_bitwise_...
[ { "docstring": "Adds two numbers using bitwise operations.", "function_declaration": "def add_bitwise_operator(x, y):", "function_name": "add_bitwise_operator", "parameter_list": "(x, y)" }, { "docstring": "Multiplies two numbers using bitwise operations.", "function_declaration": "def m...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def add_bitwise_operator(x: int, y: int) -> int:\n \"\"\"\n Adds two integers using bitwise operations.\n \n :param x: First integer\n :param y...
trial_gpt4o_2
{ "original_instruction": "Addition with Bitwise Operations\n\nGiven the provided code, which adds two positive integers using bitwise operations, your task is to extend this functionality. Implement a function that not only performs bitwise addition of two positive integers but also performs bitwise multiplication o...
0.646777
Data_Structure_13645
C
[ "add_bitwise_operator", "multiply_bitwise_operator" ]
2
[ [ "multiply_bitwise_operator", "add_bitwise_operator" ] ]
1
[]
false
[]
false
pytest
true
[]
true
21cf56ca06b7e54032cc45cfe52e92ae2a0d2b55
46b3bc98f9ba7cc5e13227edaf778e3100cdc28f
v1.0
complete
Data_Structure
Data_Structure_13019_C
from typing import List def prime_check(n: int) -> bool: """Check if a given number is a prime number.""" if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0:...
from typing import List def prime_check(n): if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: return False j += 6 return True def veri...
from solution import verify_prime_list def test_all_primes(): assert verify_prime_list([2, 3, 5, 7, 11, 13, 17, 19, 23]) == True def test_contains_non_prime(): assert verify_prime_list([2, 4, 5, 7]) == False def test_large_prime_numbers(): assert verify_prime_list([1000003, 1000033]) == True def tes...
[ { "docstring": null, "function_declaration": "def prime_check(n):", "function_name": "prime_check", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def verify_prime_list(numbers):", "function_name": "verify_prime_list", "parameter_list": "(numbers)" } ]
[ 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 prime_check(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2...
trial_gpt4o_2
{ "original_instruction": "### Challenge: Verify List of Prime Numbers\n\nYou are tasked with implementing a function that will verify if all the numbers in a list are prime numbers. Given the nature of prime number verification, you will use the provided `prime_check` function as part of your solution. \n\n### Task\...
0.845025
Data_Structure_13019
C
[ "prime_check", "verify_prime_list" ]
2
[ [ "verify_prime_list", "prime_check" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e015105aaa2bb618511957c3b73d5f138a89f046
af92ded785e92eac5f190a82de29d4d42d9a93c7
v1.0
complete
Data_Structure
Data_Structure_15749_C
def optimized_quick_sort(arr, k): """ Sorts an array using an optimized version of QuickSort. Parameters: arr (List[int]): The array to be sorted. k (int): The size of sub-arrays below which insertion sort should be used. Returns: List[int]: The sorted array. Examples: >>>...
def insertion_sort(arr, low, high): for i in range(low + 1, high + 1): key = arr[i] j = i - 1 while j >= low and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def median_of_three(arr, low, mid, high): if arr[low] > arr[mid]: arr[low], ...
from solution import optimized_quick_sort def test_sorted_array(): arr = [1, 2, 3, 4, 5] sorted_arr = optimized_quick_sort(arr, 3) assert sorted_arr == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): arr = [5, 4, 3, 2, 1] sorted_arr = optimized_quick_sort(arr, 3) assert sorted_arr == [1, 2, 3...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_sort", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def median_of_three(arr, low, mid, high):", "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_0
{ "original_instruction": "### Question: Optimizing Quick Sort for Improved Performance\n\nThe QuickSort algorithm is efficient for sorting large datasets but suffers from poor performance in certain cases, such as when the input array is already sorted or contains many duplicate elements. A common optimization invol...
0.587575
Data_Structure_15749
C
[ "insertion_sort", "median_of_three", "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
09c717e8d1cedbb0cbd93902b88317b5ba6bd816
7c5861c704d213d936f2e28a2c1649e1f238edbf
v1.0
complete
Data_Structure
Data_Structure_12020_C
def efficient_sort(arr): """ Sorts an array of integers in non-decreasing order using an efficient sorting algorithm. @param arr: A list of integers to be sorted. @return: A sorted list of integers in non-decreasing order. >>> efficient_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) [1, 1, 2, 3, ...
def efficient_sort(arr): """ This function uses the Merge Sort algorithm to sort an array in non-decreasing order. Merge Sort has a time complexity of O(n log n), which is significantly better than Bogo Sort, which has an average time complexity of O((n*n!)). Merge Sort is chosen due to i...
from solution import efficient_sort def test_empty_array(): assert efficient_sort([]) == [] def test_single_element(): assert efficient_sort([1]) == [1] def test_sorted_array(): assert efficient_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert efficient_sort([5, 4, 3,...
[ { "docstring": "This function uses the Merge Sort algorithm to sort an array in non-decreasing order.\n\nMerge Sort has a time complexity of O(n log n), which is significantly better than Bogo Sort, \nwhich has an average time complexity of O((n*n!)).\n\nMerge Sort is chosen due to its stable sort nature and it...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def efficient_sort(arr):\n \"\"\"\n Implements the Merge Sort algorithm to sort the array in non-decreasing order.\n Merge Sort is chosen for its eff...
trial_gpt4o_2
{ "original_instruction": "### Coding Challenge: Implement a Custom Sort Algorithm\n\n### Objective\nDesign and implement a sorting algorithm that is more efficient than Bogo Sort. You can choose any deterministic sorting algorithm (e.g., Quick Sort, Merge Sort, etc.) and explain why it is an improvement over Bogo So...
0.596507
Data_Structure_12020
C
[ "efficient_sort", "_merge" ]
2
[ [ "efficient_sort", "_merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6d9f824dfc6d6c65036fbfcdead85ae0d69dc596
5fff391acdf34c2048201a18ba0ae0267a303b53
v1.0
complete
Data_Structure
Data_Structure_15937_C
from typing import List def radix_sort(arr: List[int], simulation: bool=False) -> List[int]: """ Implement the Radix Sort algorithm to sort a list of non-negative integers. Args: arr (List[int]): A list of non-negative integers to be sorted. simulation (bool): A flag to print the state of the list...
from typing import List def counting_sort(arr, exp, simulation): 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 that count[i] contains actual position...
from solution import radix_sort def test_radix_sort_basic(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_radix_sort_with_empty_list(): assert radix_sort([]) == [] def test_radix_sort_single_element(): assert radix_sort([5]) == [5] def test_radix_sor...
[ { "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": "def radix_sort(arr, simulation=False):\n \"\"\"\n Perform radix sort on a list of non-negative integers.\n \n Parameters:\n arr (List[int]): A ...
trial_gpt4o_2
{ "original_instruction": "**Radix Sort Implementation and Enhancements**\n\nIn this exercise, you are required to implement the Radix Sort algorithm, as well as handle some additional constraints to test your understanding of the algorithm.\n\n#### Task\n1. Implement the `radix_sort` function to sort an input list o...
0.694762
Data_Structure_15937
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bc547818bfed86ab62a928c733c474f506c6de83
6ec3a78060c8fed05aee16c1361672ff518b5e21
v1.0
complete
Data_Structure
Data_Structure_15694_C
import random from typing import List def bogo_sort(nums: List[int], simulation: bool = False) -> List[int]: """ Sorts the given list of integers using the Bogo Sort algorithm, which randomly shuffles the array until it is sorted. :param nums: List of integers to be sorted :param simulation: ...
import random from typing import List def is_sorted(nums: List[int]) -> bool: """ Helper function to check if the list is sorted. """ for i in range(len(nums) - 1): if nums[i] > nums[i + 1]: return False return True def bogo_sort(nums: List[int], simulation: bool = False) -> Li...
from solution import bogo_sort def test_bogo_sort_sorted_input(): assert bogo_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_bogo_sort_reversed_input(): assert bogo_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_bogo_sort_unsorted_input(): assert bogo_sort([3, 2, 5, 1, 4]) == [1, 2, 3, 4, 5] def t...
[ { "docstring": "Helper function to check if the list is sorted.", "function_declaration": "def is_sorted(nums):", "function_name": "is_sorted", "parameter_list": "(nums)" }, { "docstring": "Function to sort the array using the Bogo Sort algorithm.\nIt shuffles the array until it gets sorted....
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef is_sorted(nums: List[int]) -> bool:\n \"\"\"\n Helper function to check if the list is sorted.\n \"\"\"...
trial_gpt4o_0
{ "original_instruction": "**Problem Statement**:\n\nYou are given an integer array `nums`. Implement the `bogo_sort` function that sorts the array using the Bogo Sort algorithm—a highly inefficient sorting algorithm that randomly shuffles the array until it is sorted. This is mainly educational to understand algorit...
0.674511
Data_Structure_15694
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
be110ba15e991de0f2db4aedc82e9584215f0abe
a268cc1420049c41131fe9b5f3fd95738a7f97ec
v1.0
complete
Data_Structure
Data_Structure_12949_C
from typing import Optional class Node: def __init__(self, val=0, next=None): self.val = val self.next = next def find_intersection(head1: Optional[Node], head2: Optional[Node]) -> Optional[Node]: """ Identify the node at which two singly linked lists intersect. Args: head1: Node ...
class Node: def __init__(self, val=0, next=None): self.val = val self.next = next def get_length(head): length = 0 while head: length += 1 head = head.next return length def find_intersection(head1, head2): len1 = get_length(head1) len2 = get_length(head2) ...
from solution import Node, find_intersection def test_no_intersection(): # List1: 1 -> 2 -> 3 # List2: 4 -> 5 -> 6 a1 = Node(1) b1 = Node(2) c1 = Node(3) a2 = Node(4) b2 = Node(5) c2 = Node(6) a1.next = b1 b1.next = c1 a2.next = b2 b2.next = c2 assert find_inter...
[]
[ 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, val=0, next=None):\n self.val = val\n self.next = next\n\ndef get_length(head):\n length = 0\n while h...
trial_gpt4o_0
{ "original_instruction": "You are given two singly linked lists that intersect at some node. Write a function `find_intersection(head1, head2)` to identify the node at which these two linked lists intersect. The node of intersection itself (rather than its value) is the key identifier. If the lists do not intersect,...
0.560956
Data_Structure_12949
C
[ "get_length", "find_intersection" ]
2
[ [ "find_intersection", "get_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
d89f3bd388d984e5110c419a2fa24a52dd6f6ae2
a814a48f10be944569776b99e914f69890f7a0f9
v1.0
complete
Data_Structure
Data_Structure_15391_C
def int_to_bytes_big_endian(num): pass def int_to_bytes_little_endian(num): pass def bytes_big_endian_to_int(byte_data): pass def bytes_little_endian_to_int(byte_data): pass def validate_endian_conversion(num: int) -> bool: """ Validates the correctness of integer-to-byte and byte-to-integer con...
def int_to_bytes_big_endian(num): return num.to_bytes((num.bit_length() + 7) // 8, 'big') def int_to_bytes_little_endian(num): return num.to_bytes((num.bit_length() + 7) // 8, 'little') def bytes_big_endian_to_int(byte_data): return int.from_bytes(byte_data, 'big') def bytes_little_endian_to_int(byte_dat...
from solution import validate_endian_conversion def test_validate_endian_conversion_basic(): assert validate_endian_conversion(305419896) == True def test_validate_endian_conversion_zero(): assert validate_endian_conversion(0) == True def test_validate_endian_conversion_max_value(): assert validate_endia...
[ { "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, length=8):\n return num.to_bytes(length, byteorder='big')\n\ndef int_to_bytes_little_endian(num, length=8):\n return nu...
trial_gpt4o_2
{ "original_instruction": "### Coding Problem: Endian Conversion Validator\n\n#### Problem Description\nYou are required to write a function that verifies the correctness of integer-to-byte and byte-to-integer conversion processes. This function should validate that the original integer value remains the same after c...
0.460179
Data_Structure_15391
C
[ "int_to_bytes_big_endian", "int_to_bytes_little_endian", "bytes_big_endian_to_int", "bytes_little_endian_to_int", "validate_endian_conversion" ]
5
[ [ "validate_endian_conversion", "bytes_big_endian_to_int" ], [ "validate_endian_conversion", "bytes_little_endian_to_int" ], [ "validate_endian_conversion", "int_to_bytes_big_endian" ], [ "validate_endian_conversion", "int_to_bytes_little_endian" ] ]
4
[]
false
[]
false
pytest
true
[]
true
1358e956aedc776e502ed67a7a5897feeb110c55
a5e15a14fff1c520ecc4685469ab9febb631fc27
v1.0
complete
Data_Structure
Data_Structure_14364_C
def radix_sort(arr, simulate=False) -> list: """Perform LSD Radix Sort on the provided list of non-negative integers. If simulate is True, print the array at each step of the sorting process. >>> radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) [2, 24, 45, 66, 75, 90, 170, 802] >>> radix_sort([170...
def get_digit(number, digit_index): # Get digit at the specific place (0-based from right to left) return (number // (10 ** digit_index)) % 10 def counting_sort(arr, digit_index, simulate): n = len(arr) output = [0] * n # Output array to hold sorted elements count = [0] * 10 #...
def test_radix_sort_basic(): arr = [170, 45, 75, 90, 802, 24, 2, 66] expected = [2, 24, 45, 66, 75, 90, 170, 802] assert radix_sort(arr) == expected def test_radix_sort_reverse_order(): arr = [5, 4, 3, 2, 1] expected = [1, 2, 3, 4, 5] assert radix_sort(arr) == expected def test_radix_sort_sing...
[ { "docstring": null, "function_declaration": "def get_digit(number, digit_index):", "function_name": "get_digit", "parameter_list": "(number, digit_index)" }, { "docstring": null, "function_declaration": "def counting_sort(arr, digit_index, simulate):", "function_name": "counting_sor...
[ 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 counting_sort(arr, exp):\n n = len(arr)\n output = [0] * n # output array that will have the sorted result\n count = [0] * 10 # there are 10 di...
trial_gpt4o_2
{ "original_instruction": "### Radix Sort Simulation\n\nYou are an engineer at a tech company, and your team is responsible for building efficient data processing pipelines. One task involves sorting large streams of log timestamps represented as integers. To achieve this, you decide to use the Radix Sort algorithm d...
0.637877
Data_Structure_14364
C
[ "get_digit", "counting_sort", "radix_sort" ]
3
[ [ "counting_sort", "get_digit" ], [ "radix_sort", "counting_sort" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c561d36fc067465386f945e99cd95ca08511a758
22016b493bf3464739bd0bb8d1839ce671f72a13
v1.0
complete
Data_Structure
Data_Structure_16188_C
def insertion_sort(array: list) -> list: """ Sorts the given list of integers using an improved insertion sort algorithm with binary search for finding the insertion point. >>> insertion_sort([5, 2, 9, 1, 5, 6]) [1, 2, 5, 5, 6, 9] >>> insertion_sort([1, 2, 3, 4, 5]) [1, 2, 3, 4, 5] >>> inse...
def search_insert(array, val): low = 0 high = len(array) - 1 while low <= high: mid = low + (high - low) // 2 if val > array[mid]: low = mid + 1 else: high = mid - 1 return low def insertion_sort(array): """ Sorts the given list of integers using ...
from solution import insertion_sort, search_insert def test_insertion_sort_example_cases(): assert insertion_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9] assert insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] assert insertion_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] assert insertion_sort([]) == []...
[ { "docstring": null, "function_declaration": "def search_insert(array, val):", "function_name": "search_insert", "parameter_list": "(array, val)" }, { "docstring": "Sorts the given list of integers using an improved insertion sort algorithm with binary search\nfor finding the insertion point...
[ 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 search_insert(array, val):\n low = 0\n high = len(array) - 1\n while low <= high:\n mid = low + (high - low) // 2\n if val > array[...
trial_gpt4o_2
{ "original_instruction": "### Problem: Efficient Insertion Sort\n\n#### Scenario:\nYou have been hired by a tech company to optimize their sorting module, which frequently needs to sort small or nearly sorted datasets. Your task is to implement an improved version of the Insertion Sort algorithm that exploits a bina...
0.62168
Data_Structure_16188
C
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c18c865e8ce34e44281a9646b043dc2d5d83750
74c5293b4bb73ef10a190f105b41d3b1be6196e1
v1.0
complete
Data_Structure
Data_Structure_13417_C
from typing import List def add_bitwise(a: int, b: int) -> int: """ Add two integers using bitwise operations. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def sum_without_plus_operator(nums: List[int]) -> int: """ Sums up all integers in the li...
def add_bitwise(a, b): """ Add two integers using bitwise operations. """ while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def sum_without_plus_operator(nums): """ Sums up all integers in the list `nums` using bitwise operations. """ total_sum = ...
from solution import sum_without_plus_operator def test_sum_multiple_numbers(): assert sum_without_plus_operator([2, 3, 5]) == 10 def test_sum_different_numbers(): assert sum_without_plus_operator([10, 20, 30, 40]) == 100 def test_sum_repeated_numbers(): assert sum_without_plus_operator([1, 1, 1, 1, 1]) ...
[ { "docstring": "Add two integers using bitwise operations.", "function_declaration": "def add_bitwise(a, b):", "function_name": "add_bitwise", "parameter_list": "(a, b)" }, { "docstring": "Sums up all integers in the list `nums` using bitwise operations.", "function_declaration": "def su...
[ 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 bitwise_add(a: int, b: int) -> int:\n \"\"\"\n Function to add two numbers using bitwise operations.\n \"\"\"\n whi...
trial_gpt4o_2
{ "original_instruction": "You are given an integer array where each element represents a positive integer. Your task is to implement a function that sums up all these integers without using the '+' operator. Instead, you must use bitwise operations (as shown in the provided code snippet).\n\n### Input\n* An integer ...
0.685061
Data_Structure_13417
C
[ "add_bitwise", "sum_without_plus_operator" ]
2
[ [ "sum_without_plus_operator", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0a397dc26a30c4e7dbb38027c97d4d00c83068cc
3f61ab0ffee111b5d330f0ca47c5cf87f6711f14
v1.0
complete
Data_Structure
Data_Structure_13752_C
from typing import List def optimized_bucket_sort(arr: List[float]) -> List[float]: """ Sorts an array of floating-point numbers between [0.0, 1.0) using the Bucket Sort algorithm with optimized bucketing where each bucket is sorted using Merge Sort. >>> optimized_bucket_sort([]) == [] >>> optimized_bu...
from typing import List def merge_sort(arr: List[float]) -> List[float]: if len(arr) <= 1: return arr mid = len(arr) // 2 left = arr[:mid] right = arr[mid:] left = merge_sort(left) right = merge_sort(right) return merge(left, right) def merge(left: List[float], r...
from solution import optimized_bucket_sort def test_empty_array(): assert optimized_bucket_sort([]) == [] def test_single_element(): assert optimized_bucket_sort([0.5]) == [0.5] def test_sorted_array(): assert optimized_bucket_sort([0.1, 0.2, 0.3, 0.4, 0.5]) == [0.1, 0.2, 0.3, 0.4, 0.5] def test_reverse...
[ { "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)" }, { "docst...
[ 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[float]) -> List[float]:\n if len(arr) <= 1:\n return arr\n \n mid = len(arr) // 2\n lef...
trial_gpt4o_2
{ "original_instruction": "**Context**:\nYou are tasked with developing a sorting utility for a high-frequency trading system where the input dataset can be very large and involves timestamps represented as floating-point numbers between `[0.0, 1.0)`.\n\n**Task**:\nImplement the `optimized_bucket_sort` function, whic...
0.593762
Data_Structure_13752
C
[ "merge_sort", "merge", "optimized_bucket_sort" ]
3
[ [ "merge_sort", "merge" ], [ "optimized_bucket_sort", "merge_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3a993f88e36ab6feb1613e3b6f80c9d8d2db66c0
05ee38656e4c2b130d2c09f5b15b325a66f98586
v1.0
complete
Data_Structure
Data_Structure_14798_C
def optimized_quick_sort(arr): """Implement an enhanced version of the Quick Sort algorithm that optimizes pivot selection to improve performance on already sorted or nearly sorted arrays, and switches to Insertion Sort for smaller sub-arrays. Args: arr (List[int]): A list of integers to be sorte...
import random def insertion_sort(arr, low, high): for i in range(low + 1, high + 1): key = arr[i] j = i - 1 while j >= low and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def partition(arr, low, high): pivot = arr[high] i = low - 1 ...
from solution import optimized_quick_sort def test_optimized_quick_sort_regular_case(): assert optimized_quick_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62] def test_optimized_quick_sort_with_duplicates(): assert optimized_quick_sort([1, 2, 2, 3, 1, 4, 1, 3, 5]) == [1, 1, 1, 2, 2, 3, 3, 4, 5] def te...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_sort", "parameter_list": "(arr, low, high)" }, { "docstring": null, "function_declaration": "def partition(arr, low, high):", "function_name": "partition", "parameter_l...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef insertion_sort(arr, low, high):\n for i in range(low + 1, high + 1):\n key = arr[i]\n j = i - 1\n while j >= low ...
trial_gpt4o_0
{ "original_instruction": "### Question: Implement an Optimized Quick Sort\n\n**Objective**: Implement an enhanced version of the Quick Sort algorithm that optimizes pivot selection to improve performance on already sorted or nearly sorted arrays, and switches to Insertion Sort for smaller sub-arrays.\n\n**Requiremen...
0.602606
Data_Structure_14798
C
[ "insertion_sort", "partition", "optimized_quick_sort" ]
3
[ [ "optimized_quick_sort", "insertion_sort" ], [ "optimized_quick_sort", "partition" ] ]
2
[]
false
[]
false
pytest
true
[]
true
683a108a99cf7a018f2fdeb46b859adbeb03c8d8
44b3ecb675fac3b7aaa57e28d6c152f827070515
v1.0
complete
Data_Structure
Data_Structure_12294_C
from typing import List def optimal_matrix_chain_order(dimensions: List[int]) -> int: """ Find the minimal number of scalar multiplications needed for matrix chain multiplication. >>> optimal_matrix_chain_order([30, 35, 15, 5, 10, 20, 25]) 15125 """ pass def optimal_parenthesization(optimal_soluti...
from typing import List def optimal_matrix_chain_order(dimensions: List[int]) -> int: n = len(dimensions) - 1 matrix = [[0 for _ in range(n)] for _ in range(n)] sol = [[0 for _ in range(n)] for _ in range(n)] for chain_length in range(2, n+1): for i in range(n - chain_length + 1): ...
def test_optimal_matrix_chain_order(): dimensions = [30, 35, 15, 5, 10, 20, 25] cost_matrix, _ = optimal_matrix_chain_order(dimensions) assert cost_matrix[0][5] == 15125 def test_optimal_parenthesization(): dimensions = [30, 35, 15, 5, 10, 20, 25] _, solution_matrix = optimal_matrix_chain_order(dim...
[ { "docstring": null, "function_declaration": "def optimal_matrix_chain_order(dimensions):", "function_name": "optimal_matrix_chain_order", "parameter_list": "(dimensions)" }, { "docstring": null, "function_declaration": "def optimal_parenthesization(optimal_solution, i, j):", "functi...
[ 0, 0, 0, 1, 0, 0, 0, 1, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef optimal_matrix_chain_order(dimensions: List[int]) -> int:\n n = len(dimensions)\n matrix = [[0 for x in range(n)] for x i...
trial_gpt4o_8
{ "original_instruction": "### Matrix Chain Multiplication Optimization\n\n#### Context\nGiven a sequence of matrices, find the most efficient way to multiply these matrices together. The problem is to determine the order of matrix multiplications to minimize the total number of scalar multiplications. \n\nThe `matri...
0.525718
Data_Structure_12294
C
[ "optimal_matrix_chain_order", "optimal_parenthesization", "minimal_scalar_multiplications_and_order" ]
3
[ [ "minimal_scalar_multiplications_and_order", "optimal_matrix_chain_order" ], [ "minimal_scalar_multiplications_and_order", "optimal_parenthesization" ] ]
2
[]
false
[]
false
pytest
false
[]
true
f59f0c4a1cbb273194a4d65c71d2a45f6c4845f5
be3cd0447438f97455957c6328d713f04e962c98
v1.0
complete
Data_Structure
Data_Structure_15941_C
from typing import Tuple def generate_key(k: int, seed: int = None) -> Tuple[int, int, int]: """ Generate a key for RSA encryption with specified bit length. >>> n, e, d = generate_key(16, seed=42) >>> isinstance(n, int) True >>> isinstance(e, int) True >>> isinstance(d, int) True >...
from typing import Tuple import random import sympy def is_prime(num: int) -> bool: return sympy.isprime(num) def generate_large_prime(bits: int) -> int: while True: candidate = random.getrandbits(bits) if is_prime(candidate): return candidate def egcd(a: int, b: int) -> Tuple[int...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(16, seed=42) 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, seed=42) data = 12...
[ { "docstring": null, "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": null, "function_declaration": "def generate_large_prime(bits):", "function_name": "generate_large_prime", "parameter_list": "(bits)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import Tuple\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime(bits: int) -> int:\n \"\"\"Generate a prime number wi...
trial_gpt4o_2
{ "original_instruction": "You are to implement a modified version of the RSA encryption algorithm that ensures better performance for key generation and encryption/decryption process. Specifically, you will use efficient algorithms for selecting prime numbers and calculating the modular multiplicative inverse.\n\n##...
0.723686
Data_Structure_15941
C
[ "is_prime", "generate_large_prime", "egcd", "modinv", "generate_key", "encrypt", "decrypt" ]
7
[ [ "generate_key", "generate_large_prime" ], [ "generate_key", "modinv" ], [ "generate_large_prime", "is_prime" ], [ "modinv", "egcd" ] ]
4
[]
false
[]
false
pytest
true
[ "sympy" ]
false
03ecc3ff951df5cf48a4acd2722d0cbb097e5a98
c5bba33405ca071444bf149086e8ac5642348fe9
v1.0
complete
Data_Structure
Data_Structure_15122_C
import random import math from typing import List def is_prime(n: int) -> bool: """ Check if a number n is a prime number. >>> is_prime(23) True >>> is_prime(1) False >>> is_prime(4) False >>> is_prime(97) True """ pass def primitive_root(p: int) -> int: """ Fin...
import random import math def is_prime(n: int) -> bool: """ Check if a number n is a prime number. """ 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: ...
import pytest from solution import is_prime, primitive_root, private_key, public_key, shared_secret, diffie_hellman def test_is_prime(): assert is_prime(23) == True assert is_prime(1) == False assert is_prime(4) == False assert is_prime(97) == True def test_primitive_root(): assert primitive_root(...
[ { "docstring": "Check if a number n is a prime number.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find a primitive root of a prime number p.", "function_declaration": "def primitive_root(p):", "function_name":...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "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: int) -> bool:\n \"\"\"\n Check if a number n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n ...
trial_gpt4o_9
{ "original_instruction": "### Diffie-Hellman Key Exchange Simulation\n\n### Scenario:\nYou are tasked with implementing a simulation of the Diffie-Hellman key exchange process. Two parties, Alice and Bob, want to securely agree on a shared secret key using an insecure channel. Alice and Bob will generate their own p...
0.586589
Data_Structure_15122
C
[ "is_prime", "primitive_root", "private_key", "public_key", "shared_secret", "diffie_hellman" ]
6
[ [ "diffie_hellman", "private_key" ], [ "diffie_hellman", "public_key" ], [ "diffie_hellman", "shared_secret" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8bb9d813e31b4f8af712776871319d7eae36764c
b79430e11fee881a1ed635ce6c19c8243fcb01da
v1.0
complete
Data_Structure
Data_Structure_13058_C
def optimized_matrix_exponentiation(mat: list, n: int, memo=None) -> list: """ Computes the matrix `mat` raised to the power of `n` using memoization to cache intermediate results. Args: - mat: A list of lists (2D array) representing a square matrix of size `d x d` with integer elements - n: A non...
def mat_mult(A, B): """ Multiples two square matrices A and B. """ size = len(A) C = [[0] * size for _ in range(size)] for i in range(size): for j in range(size): for k in range(size): C[i][j] += A[i][k] * B[k][j] return C def optimized_matrix_exponentiat...
from solution import optimized_matrix_exponentiation def test_exponentiation_zero_power(): mat = [ [1, 2], [3, 4] ] expected = [ [1, 0], [0, 1] ] assert optimized_matrix_exponentiation(mat, 0) == expected def test_exponentiation_one_power(): mat = [ [1, ...
[ { "docstring": "Multiples two square matrices A and B.", "function_declaration": "def mat_mult(A, B):", "function_name": "mat_mult", "parameter_list": "(A, B)" }, { "docstring": "Computes mat^n using memoization to cache intermediate results.", "function_declaration": "def optimized_matr...
[ 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 mat_mult(A, B):\n \"\"\"\n Multiples two square matrices A and B.\n \"\"\"\n size = len(A)\n C = [[0] * size for _ in range(size)]\n for...
trial_gpt4o_0
{ "original_instruction": "### Matrix Exponentiation Enhancement\n\nYou are tasked to develop a function that enhances matrix exponentiation by adding memoization. The goal is to minimize redundant calculations for exponentiation by caching intermediate results.\n\nWrite a function `optimized_matrix_exponentiation(ma...
0.512794
Data_Structure_13058
C
[ "mat_mult", "optimized_matrix_exponentiation" ]
2
[ [ "optimized_matrix_exponentiation", "mat_mult" ] ]
1
[]
false
[]
false
pytest
true
[]
true
22d7f73df53d3b5582717e8354079d3b43b5f10d
6d13db0f45d2265e0a9875d6a30e0fe969d5a578
v1.0
complete
Data_Structure
Data_Structure_16150_C
def compute_fibonacci(n: int, method: str) -> int: """ Compute the n-th Fibonacci number using the specified method. Parameters: n (int): The index in the Fibonacci sequence. method (str): The method to use for computation ("recursive", "dynamic", "iterative"). Returns: int: The n-th Fibon...
def compute_fibonacci(n, method): """ Compute the n-th Fibonacci number using the specified method. Parameters: n (int): The index in the Fibonacci sequence. method (str): The method to use for computation ("recursive", "dynamic", "iterative"). Returns: int: The n-th Fibonacci numb...
def test_compute_fibonacci_recursive(): assert compute_fibonacci(10, "recursive") == 55 assert compute_fibonacci(0, "recursive") == 0 assert compute_fibonacci(1, "recursive") == 1 assert compute_fibonacci(5, "recursive") == 5 def test_compute_fibonacci_dynamic(): assert compute_fibonacci(100, "dyna...
[ { "docstring": "Compute the n-th Fibonacci number using the specified method.\n\nParameters:\nn (int): The index in the Fibonacci sequence.\nmethod (str): The method to use for computation (\"recursive\", \"dynamic\", \"iterative\").\n\nReturns:\nint: The n-th Fibonacci number.", "function_declaration": "de...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_fibonacci(n, method):\n \"\"\"\n Computes the n-th Fibonacci number using given method (recursive, dynamic, or iterative).\n \n :param...
trial_gpt4o_2
{ "original_instruction": "### Problem Description\n\nYou are given a task to compute the n-th Fibonacci number using different methods. The Fibonacci sequence is defined as follows:\n\n F(0) = 0, F(1) = 1\n F(n) = F(n-1) + F(n-2) for n >= 2\n\nWrite a function `compute_fibonacci` that takes an integer n and a ...
0.833557
Data_Structure_16150
C
[ "compute_fibonacci", "fibonacci_recursive", "fibonacci_dynamic", "fibonacci_iterative" ]
4
[ [ "compute_fibonacci", "fibonacci_dynamic" ], [ "compute_fibonacci", "fibonacci_iterative" ], [ "compute_fibonacci", "fibonacci_recursive" ] ]
3
[]
false
[]
false
pytest
false
[]
true
f3d0c15ef49cd6a484522e0d519fa7fb5d7ffe09
dfde0d027667e32d96df07eace4a677ba9b96522
v1.0
complete
Data_Structure
Data_Structure_15463_C
def pancake_sort(arr: List[int]) -> List[int]: """Sort an array of integers using the pancake sorting method. The method allows only flipping the top k pancakes in the stack. Args: arr (List[int]): A list of integers representing the diameters of pancakes. Returns: List[int]: A sorted ...
def flip(arr, k): return arr[:k][::-1] + arr[k:] def find_max_index(arr, n): max_index = 0 for i in range(1, n): if arr[i] > arr[max_index]: max_index = i return max_index def pancake_sort(arr): n = len(arr) for size in range(n, 1, -1): max_index = find_max_index(ar...
from solution import pancake_sort def test_pancake_sort_empty(): assert pancake_sort([]) == [] def test_pancake_sort_single_element(): assert pancake_sort([1]) == [1] def test_pancake_sort_sorted_array(): assert pancake_sort([1, 2, 3, 4]) == [1, 2, 3, 4] def test_pancake_sort_reverse_sorted_array(): ...
[ { "docstring": null, "function_declaration": "def flip(arr, k):", "function_name": "flip", "parameter_list": "(arr, k)" }, { "docstring": null, "function_declaration": "def find_max_index(arr, n):", "function_name": "find_max_index", "parameter_list": "(arr, n)" }, { "doc...
[ 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 pancake_sort(arr):\n \"\"\"\n Sorts the array using the pancake sorting algorithm.\n \"\"\"\n \n def flip(sub_arr, k):\n \"\"\"Helpe...
trial_gpt4o_2
{ "original_instruction": "You are given an array of integers representing a stack of pancakes, each with a different diameter. Your task is to sort the pancakes in order of their size, with the smallest pancake at the top (index 0) and the largest at the bottom (index N-1). You can only flip pancakes from the top of...
0.732208
Data_Structure_15463
C
[ "flip", "find_max_index", "pancake_sort" ]
3
[ [ "pancake_sort", "find_max_index" ], [ "pancake_sort", "flip" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e74d6f56f4afdf2b0667381bd55cc036e6b2bd53
834120a2ce1c2c2ac5aaec087784e90ee45799c9
v1.0
complete
Data_Structure
Data_Structure_14396_C
def modinv(a: int, m: int) -> int: """ Calculate the inverse of a mod m using the Extended Euclidean Algorithm. >>> modinv(3, 11) 4 >>> modinv(10, 17) 12 """ # Implementation here from solution import generate_key, encrypt, decrypt def test_modinv(): assert modinv(3, 11) == 4 ...
def egcd(a, b): """ Extended Euclidean Algorithm. Returns a tuple of gcd, x, y such that a*x + b*y = gcd. """ if a == 0: return b, 0, 1 gcd, x1, y1 = egcd(b % a, a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y def modinv(a, m): """ Calculate the modular inverse of ...
from solution import modinv, generate_key, encrypt, decrypt def test_modinv(): assert modinv(3, 11) == 4 assert modinv(10, 17) == 12 assert modinv(1, 2) == 1 assert modinv(7, 40) == 23 def test_generate_key(): n, e, d = generate_key(16) assert n > 0 assert e > 0 assert d > 0 def test_...
[ { "docstring": "Extended Euclidean Algorithm.\nReturns a tuple of gcd, x, y such that a*x + b*y = gcd.", "function_declaration": "def egcd(a, b):", "function_name": "egcd", "parameter_list": "(a, b)" }, { "docstring": "Calculate the modular inverse of a under modulus m using the Extended Euc...
[ 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 egcd(a, b):\n \"\"\"\n Extended Euclidean Algorithm.\n Returns a tuple of gcd, x, y such that a*x + b*y = gcd.\n \"\"\"\n if a == 0:\n ...
trial_gpt4o_0
{ "original_instruction": "### RSA Encryption Enhancement\n\nThe RSA algorithm provided can generate keys, encrypt, and decrypt data effectively. However, the current implementation of the `modinv` function to calculate the modular inverse is inefficient. \n\nYour task is to enhance the RSA implementation by optimizi...
0.550985
Data_Structure_14396
C
[ "egcd", "modinv", "generate_key", "encrypt", "decrypt" ]
5
[ [ "generate_key", "modinv" ], [ "modinv", "egcd" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
6d04c359517e0a0acf438735dce304e75b522e27
76dee6ad05513bc2e8d56864bf1bc8f322bd706e
v1.0
complete
Data_Structure
Data_Structure_13022_C
from typing import List def gcd(a: int, b: int) -> int: """ Computes the greatest common divisor of two integers a and b using Euclid's algorithm. >>> gcd(270, 192) == 6 >>> gcd(48, 18) == 6 >>> gcd(101, 103) == 1 """ def trailing_zero(x: int) -> int: """ Calculates the number of trail...
def gcd(a, b): """ Computes the greatest common divisor of two integers a and b using Euclid's algorithm. """ while b: a, b = b, a % b return abs(a) def trailing_zero(x): """ Calculates the number of trailing zeros in the binary representation of a given positive integer x. """ ...
from solution import gcd, trailing_zero, gcd_bit def test_gcd_positive_numbers(): assert gcd(270, 192) == 6 assert gcd(48, 18) == 6 assert gcd(101, 103) == 1 def test_gcd_negative_numbers(): assert gcd(-270, 192) == 6 assert gcd(48, -18) == 6 assert gcd(-101, -103) == 1 def test_gcd_edge_case...
[ { "docstring": "Computes the greatest common divisor of two integers a and b using Euclid's algorithm.", "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Calculates the number of trailing zeros in the binary representation of a g...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd(a, b):\n \"\"\"\n Computes the greatest common divisor of two integers a and b using Euclid's algorithm.\n \"\"\"\n while b != 0:\n ...
trial_gpt4o_2
{ "original_instruction": "#### Context\n\nGiven a certain set of operations useful for numerical computations, you are to implement functions that not only calculate greatest common divisors (GCD), least common multiples (LCM), and trailing zero counts of binary representations but also optimize these calculations u...
0.686877
Data_Structure_13022
C
[ "gcd", "trailing_zero", "gcd_bit" ]
3
[ [ "gcd_bit", "trailing_zero" ] ]
1
[]
false
[]
false
pytest
true
[]
true
593ca154576aa57d4a9f16778754e44055d707b8
3ef520d4fd3c41a44669f333daafdce247188f9e
v1.0
complete
Data_Structure
Data_Structure_15842_C
import random def bogo_sort_optimized(arr: list) -> list: """ Sort an array using the Bogo Sort algorithm with an upper limit on shuffle attempts. Parameters: - arr (list): A list of integers to sort. Returns: - list: The sorted list, or None if the list cannot be sorted within a given number...
import random import time def is_sorted(arr): for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort_optimized(arr, max_attempts=1000000): """ Sorts an array using Bogo Sort algorithm with an upper limit on shuffle attempts. Parameters: ...
from solution import bogo_sort_optimized def test_bogo_sort_optimized_sorted_list(): assert bogo_sort_optimized([1, 2, 3, 4]) == [1, 2, 3, 4] def test_bogo_sort_optimized_reverse_list(): assert bogo_sort_optimized([4, 3, 2, 1]) == [1, 2, 3, 4] def test_bogo_sort_optimized_unsorted_list(): sorted_list = b...
[ { "docstring": null, "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sorts an array using Bogo Sort algorithm with an upper limit on shuffle attempts.\n\nParameters:\narr (list): The list of integers to sort.\nmax_atte...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.111
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_results_combined.jsonl", "solution_code": "import random\n\ndef is_sorted(arr):\n \"\"\"Helper function to check if the array is sorted.\"\"\"\n return all(arr[i] <= arr[...
trial_gpt4o_9
{ "original_instruction": "### Bogo Sort Challenge\n\nIn this challenge, you are asked to implement a highly inefficient sorting algorithm known as Bogo Sort. While this algorithm serves more as a cautionary tale of inefficiency, it provides a useful educational example of randomness in algorithmic operations.\n\n###...
0.562733
Data_Structure_15842
C
[ "is_sorted", "bogo_sort_optimized" ]
2
[ [ "bogo_sort_optimized", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d1eea11c97b1dfe05054955ce067331daa4a506a
5881d6a190d4f834c775dc9d0424de2fb15a3b1c
v1.0
complete
Data_Structure
Data_Structure_14654_C
def enhanced_diffie_hellman_key_exchange(a: int, p: int) -> Union[bool, str]: """ Perform enhanced Diffie-Hellman key exchange. Args: a (int): A purported primitive root of the prime number `p`. p (int): A large prime number. Returns: Union[bool, str]: Returns `True` if the sha...
import random def is_prime(n): """ 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 retu...
from solution import enhanced_diffie_hellman_key_exchange def test_diffie_hellman_valid(): assert enhanced_diffie_hellman_key_exchange(5, 23) == True def test_diffie_hellman_invalid_a(): assert enhanced_diffie_hellman_key_exchange(3, 23) == "a is not a valid primitive root of p." def test_diffie_hellman_inva...
[ { "docstring": "Check if a number is prime. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Find a primitive root for prime p. ", "function_declaration": "def find_primitive_root(p):", "function_name": "find_primi...
[ 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 sympy import isprime, primitive_root\nfrom typing import Union\nimport secrets\n\ndef is_primitive_root(a: int, p: int) -> bool:\n if not isprime(p):\...
trial_gpt4o_1
{ "original_instruction": "### Question: Implement Diffie-Hellman Key Exchange with Security Enhancements\n\n**Context**: The Diffie-Hellman key exchange is widely used to establish a shared secret between two parties over an insecure communication channel. Alice and Bob wish to use it to agree upon a common secret k...
0.435725
Data_Structure_14654
C
[ "is_prime", "find_primitive_root", "enhanced_diffie_hellman_key_exchange" ]
3
[ [ "enhanced_diffie_hellman_key_exchange", "find_primitive_root" ], [ "enhanced_diffie_hellman_key_exchange", "is_prime" ], [ "find_primitive_root", "is_prime" ] ]
3
[]
false
[]
false
pytest
true
[]
true
1a1dbd80d711e4ef65855b9d860964092f668a5f
1c8c6bf3f72d55012b6446988f1bf5a1bfa4bd14
v1.0
complete
Data_Structure
Data_Structure_16890_C
import random def is_sorted(arr: list) -> bool: """ Check if the array is sorted. >>> is_sorted([1, 2, 3, 4]) True >>> is_sorted([1, 3, 2, 4]) False """ pass def bogo_sort(arr: list, simulation: bool = False) -> list: """ Implement the Bogo Sort algorithm which repeatedly shuffles the ...
import random def is_sorted(arr): for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr, simulation=False): def shuffle(arr): random.shuffle(arr) return arr iteration = 0 while not is_sorted(arr): if simulation...
from solution import bogo_sort, is_sorted def test_is_sorted(): assert is_sorted([1, 2, 3, 4]) == True assert is_sorted([1, 3, 2, 4]) == False assert is_sorted([]) == True assert is_sorted([1]) == True assert is_sorted([2, 2, 2, 2]) == True def test_bogo_sort(): # Note: These tests might take ...
[ { "docstring": null, "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bogo_sort(arr, simulation=False):", "function_name": "bogo_sort", "parameter_list": "(arr, simulation=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 random\n\ndef is_sorted(arr):\n for i in range(len(arr) - 1):\n if arr[i] > arr[i + 1]:\n return False\n return True\n\ndef bog...
trial_gpt4o_0
{ "original_instruction": "**Context:**\nYou are working with a highly inefficient sorting algorithm known as Bogo Sort. Although impractical for real applications due to its random nature and excessive time complexity, Bogo Sort is a useful academic example to illustrate the importance of choosing efficient algorith...
0.613936
Data_Structure_16890
C
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
bd4663a7021b766af5ee72577769ca7fc7e56d77
098f68bfbfc7504d4467cf0104cc28ebc746519d
v1.0
complete
Data_Structure
Data_Structure_16518_C
from typing import List def enhanced_selection_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Sorts an array of integers using an optimized selection sort that incorporates binary search. >>> enhanced_selection_sort([64, 25, 12, 22, 11]) [11, 12, 22, 25, 64] >>> enhanced_selection_sor...
from typing import List def binary_search_min(arr: List[int], start: int, end: int) -> int: """ Perform a binary search to find the index of the minimum element in the array between indices start and end. """ min_index = start min_value = arr[start] for i in range(start + 1, end + 1):...
from solution import enhanced_selection_sort def test_enhanced_selection_sort_basic(): assert enhanced_selection_sort([64, 25, 12, 22, 11]) == [11, 12, 22, 25, 64] def test_enhanced_selection_sort_empty(): assert enhanced_selection_sort([]) == [] def test_enhanced_selection_sort_single_element(): assert ...
[ { "docstring": "Perform a binary search to find the index of the minimum element \nin the array between indices start and end.", "function_declaration": "def binary_search_min(arr, start, end):", "function_name": "binary_search_min", "parameter_list": "(arr, start, end)" }, { "docstring": "S...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef binary_search_min(arr: List[int], start: int, end: int) -> int:\n \"\"\"\n Perform a binary search to find the index of t...
trial_gpt4o_0
{ "original_instruction": "### Selection Sort - Binary Search Enhancement\n\nSelection sort is a basic algorithm with suboptimal performance for larger datasets. Your task is to improve the selection sort by incorporating binary search during the selection phase to find the minimum element more efficiently.\n\n### Ta...
0.657764
Data_Structure_16518
C
[ "binary_search_min", "enhanced_selection_sort" ]
2
[ [ "enhanced_selection_sort", "binary_search_min" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7604ab0ebf11fb59cc871db7c849adc292743a14
1fd08dab8a12a308e85a2b4ed1c1248a01f4e36f
v1.0
complete
Data_Structure
Data_Structure_12290_C
from typing import List def insertion_sort(bucket: List[float]) -> List[float]: """ Function to perform insertion sort on the bucket. """ ... def bucket_sort(arr: List[float]) -> List[float]: """ Function to sort an array of floating point numbers using Bucket Sort. Args: arr: A l...
from typing import List def insertion_sort(bucket: List[float]) -> List[float]: """ Function to perform insertion sort on the bucket. """ for i in range(1, len(bucket)): key = bucket[i] j = i - 1 while j >= 0 and bucket[j] > key: bucket[j + 1] = bucket[j] ...
from solution import bucket_sort def test_bucket_sort_empty(): assert bucket_sort([]) == [] def test_bucket_sort_single_element(): assert bucket_sort([0.5]) == [0.5] def test_bucket_sort_sorted(): assert bucket_sort([0.1, 0.2, 0.3, 0.4, 0.5]) == [0.1, 0.2, 0.3, 0.4, 0.5] def test_bucket_sort_reverse_sor...
[ { "docstring": "Function to perform insertion sort on the bucket.", "function_declaration": "def insertion_sort(bucket):", "function_name": "insertion_sort", "parameter_list": "(bucket)" }, { "docstring": "Function to sort an array of floating point numbers using Bucket Sort.", "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 insertion_sort(bucket: List[float]) -> List[float]:\n # Sort a bucket using insertion sort\n for i in range(1, len(bucket...
trial_gpt4o_2
{ "original_instruction": "### Programming Assessment Question\n\n#### Context and Task\nYou have been given the task to implement a Bucket Sort algorithm to sort an array of floating point numbers efficiently. You are required to distribute the elements of the array into a suitable number of buckets, sort the indivi...
0.64012
Data_Structure_12290
C
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
061fc6756d14ac946d8707da603dd22fda7a309d
367d42bbeec28fcd43308393fb9b9bf5f5859637
v1.0
complete
Data_Structure
Data_Structure_16656_C
def product_lcm_gcd(a: int, b: int) -> int: """ Compute the product of the least common multiple (LCM) and the greatest common divisor (GCD) for two given positive integers. Args: a (int): First positive integer b (int): Second positive integer Returns: int: The product of LCM and GCD of t...
def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def lcm(a: int, b: int, gcd_value: int) -> int: return a // gcd_value * b def product_lcm_gcd(a: int, b: int) -> int: gcd_value = gcd(a, b) lcm_value = lcm(a, b, gcd_value) return gcd_value * lcm_value
from solution import product_lcm_gcd def test_example_1(): assert product_lcm_gcd(12, 18) == 216 def test_example_2(): assert product_lcm_gcd(48, 180) == 8640 def test_same_numbers(): assert product_lcm_gcd(10, 10) == 100 def test_prime_numbers(): assert product_lcm_gcd(13, 29) == 377 def test_one_...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm(a, b, gcd_value):", "function_name": "lcm", "parameter_list": "(a, b, gcd_value)" }, { "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": "def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b, gcd_val):\n return (a // gcd_val) * b\n\ndef product_lcm_gcd(a: int, b...
trial_gpt4o_1
{ "original_instruction": "#### Scenario:\nYou are tasked with creating a utility to help mathematicians with computing GCD, LCM, and analyzing binary representations. You need to write an efficient function to compute the **product of LCM and GCD** for two given positive integers using advanced bitwise operations co...
0.777887
Data_Structure_16656
C
[ "gcd", "lcm", "product_lcm_gcd" ]
3
[ [ "product_lcm_gcd", "gcd" ], [ "product_lcm_gcd", "lcm" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1978faba80d4db3fcf4e7da18ead19836f8a3e20
8026c28fc0246d3e88930c2e90c3b0bff3601f9d
v1.0
complete
Data_Structure
Data_Structure_14863_C
def gcd_standard(a: int, b: int) -> int: """Calculate the greatest common divisor (GCD) of two positive integers using the Euclidean algorithm. >>> gcd_standard(48, 18) 6 >>> gcd_standard(7, 13) 1 >>> gcd_standard(1000000000, 1) 1 >>> gcd_standard(12, 8) 4 >>> gcd_standard(56, 56...
def gcd_standard(a: int, b: int) -> int: while b: a, b = b, a % b return a def lcm(a: int, b: int) -> int: return a * b // gcd_standard(a, b) def gcd_bitwise(a: int, b: int) -> int: if a == 0: return b if b == 0: return a shift = 0 while ((a | b) & 1) == 0: ...
from solution import gcd_standard, lcm, gcd_bitwise def test_gcd_standard(): assert gcd_standard(48, 18) == 6 assert gcd_standard(7, 13) == 1 assert gcd_standard(1000000000, 1) == 1 assert gcd_standard(12, 8) == 4 assert gcd_standard(56, 56) == 56 def test_lcm(): assert lcm(48, 18) == 144 ...
[ { "docstring": null, "function_declaration": "def gcd_standard(a, b):", "function_name": "gcd_standard", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def lcm(a, b):", "function_name": "lcm", "parameter_list": "(a, b)" }, { "docstring": null,...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_standard(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a: int, b: int) -> int:\n return a * b // gcd_stan...
trial_gpt4o_0
{ "original_instruction": "## Question: Implement an Optimized GCD and LCM Function\n\nGiven two positive integers `a` and `b`, write a Python function to calculate both the greatest common divisor (GCD) and the least common multiple (LCM) using both standard and bitwise methods. \n\nYour task is to implement the fol...
0.776443
Data_Structure_14863
C
[ "gcd_standard", "lcm", "gcd_bitwise" ]
3
[ [ "lcm", "gcd_standard" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b6044a156eaf2e0ff047cf66681fe0092427d9a1
a8a17261258d8424b1bcc4b172f8fa7efd2ee100
v1.0
complete
Data_Structure
Data_Structure_16528_C
import random def is_sorted(arr): """ Helper function to check if the array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort_with_limit(arr, max_iterations): """ Sorts an array using the Bogo Sort algorithm, but...
import random def is_sorted(arr): """ Helper function to check if the array is sorted. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort_with_limit(arr, max_iterations): """ Sorts an array using the Bogo Sort algorithm, but...
from solution import bogo_sort_with_limit def test_bogo_sort_with_limit_sorted_array(): arr = [1, 2, 3, 4] max_iterations = 1000 sorted_arr, iterations, success = bogo_sort_with_limit(arr, max_iterations) assert sorted_arr == [1, 2, 3, 4] assert iterations >= 0 and iterations <= max_iterations ...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sorts an array using the Bogo Sort algorithm, but stops if the number of iterations exceeds the limit.\...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef bogo_sort_with_limit(arr, max_iterations):\n \"\"\"\n Sorts an array using the Bogo Sort algorithm, but stops if the number of iter...
trial_gpt4o_2
{ "original_instruction": "### Context\nBogo Sort is a notoriously inefficient sorting algorithm that works by generating random permutations of the input array until the array happens to be sorted. Despite its impractical nature, it is an excellent educational tool for illustrating the importance of algorithm effici...
0.672844
Data_Structure_16528
C
[ "is_sorted", "bogo_sort_with_limit" ]
2
[ [ "bogo_sort_with_limit", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
72004c83aea03a542aff4353fa266d3c1a0f014c
1b2a5fbaa17788ec5c7edbfcc3b3debbf02340c4
v1.0
complete
Data_Structure
Data_Structure_13320_C
from typing import List def invert_matrix(matrix: List[List[float]]) -> List[List[float]]: """ Implement a function to invert a square matrix (n x n) using the cofactor expansion method. The function should handle the edge cases and return appropriate error messages for invalid inputs. Parameters: ...
from typing import List def determinant(matrix: List[List[float]], n: int) -> float: """Recursive function to calculate the determinant of a square matrix.""" if n == 1: return matrix[0][0] if n == 2: return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0] det = ...
def test_invert_valid_matrix_2x2(): matrix = [ [4, 7], [2, 6] ] result = invert_matrix(matrix) expected = [ [0.6, -0.7], [-0.2, 0.4] ] for r in range(len(result)): for c in range(len(result[r])): assert round(result[r][c], 1) == expected[r][c] ...
[ { "docstring": "Recursive function to calculate the determinant of a square matrix.", "function_declaration": "def determinant(matrix, n):", "function_name": "determinant", "parameter_list": "(matrix, n)" }, { "docstring": "Function to get a cofactor of the matrix.", "function_declaratio...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef invert_matrix(matrix: List[List[float]]) -> List[List[float]]:\n def get_cofactor(m, row, col):\n return [\n ...
trial_gpt4o_1
{ "original_instruction": "You are required to implement a function to invert a square matrix (n x n) using the cofactor expansion method. Your function should handle the edge cases and return appropriate error messages for invalid inputs.\n\n### Function Signature\n```python\ndef invert_matrix(matrix: List[List[floa...
0.527334
Data_Structure_13320
C
[ "determinant", "get_cofactor", "adjoint", "invert_matrix" ]
4
[ [ "adjoint", "determinant" ], [ "adjoint", "get_cofactor" ], [ "invert_matrix", "adjoint" ], [ "invert_matrix", "determinant" ] ]
4
[]
false
[]
false
pytest
false
[]
true
aa33ac158b5c20f89939741c02f58bda62f6da29
706bc00b10e31ccd6c0e7735bc3338eecf3290cd
v1.0
complete
Data_Structure
Data_Structure_17296_C
def is_prime(n): """ Returns True if n is a prime number, else False. >>> is_prime(17) True >>> is_prime(4) False """ def count_primes_in_range(start, end): """ Returns the count of prime numbers in the range [start, end]. >>> count_primes_in_range(10, 20) 4 >>> count_primes_in_...
import math def is_prime(n): """ Returns True if n is a prime number, else False. """ 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 Fa...
# Test cases for is_prime from solution import is_prime, count_primes_in_range def test_is_prime_negative_numbers(): assert is_prime(-1) == False def test_is_prime_zero_and_one(): assert is_prime(0) == False assert is_prime(1) == False def test_is_prime_two_and_three(): assert is_prime(2) == True ...
[ { "docstring": "Returns True if n is a prime number, else False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the count of prime numbers in the range [start, end].", "function_declaration": "def count_primes...
[ 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 is_prime(n):\n \"\"\"\n Check if a number n is a prime number.\n :param n: Integer to check for primality.\n :return: True if n is prime, Fals...
trial_gpt4o_2
{ "original_instruction": "### Prime Number Verification and Count\n\nYou are tasked with writing a function that not only verifies whether given numbers are prime but also counts the number of prime numbers within a specified range.\n\n#### Function 1: `is_prime(n)`\nImplement the provided algorithm to check if a nu...
0.801038
Data_Structure_17296
C
[ "is_prime", "count_primes_in_range" ]
2
[ [ "count_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ca31ac772da50065cda3bf3b02fe3b525221da5a
4365eb1d126a2d96158fd0246396e7dadc4169f1
v1.0
complete
Data_Structure
Data_Structure_15899_C
def longestCommonPrefix_horizontal_scanning(strs): """ Finds the longest common prefix among a list of strings using horizontal scanning. """ pass def longestCommonPrefix_vertical_scanning(strs): """ Finds the longest common prefix among a list of strings using vertical scanning. """ pa...
def longestCommonPrefix_horizontal_scanning(strs): """ Finds the longest common prefix among a list of strings using horizontal scanning. """ if not strs: return "" prefix = strs[0] for string in strs[1:]: while string[:len(prefix)] != prefix: prefix = prefix[:-1] ...
from solution import longestCommonPrefix, longestCommonPrefix_horizontal_scanning, longestCommonPrefix_vertical_scanning def test_longestCommonPrefix_example1(): assert longestCommonPrefix(["flower", "flow", "flight"]) == "fl" def test_longestCommonPrefix_example2(): assert longestCommonPrefix(["dog", "raceca...
[ { "docstring": "Finds the longest common prefix among a list of strings using horizontal scanning.", "function_declaration": "def longestCommonPrefix_horizontal_scanning(strs):", "function_name": "longestCommonPrefix_horizontal_scanning", "parameter_list": "(strs)" }, { "docstring": "Finds t...
[ 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 longestCommonPrefix_horizontal_scanning(strs):\n \"\"\"\n Finds the longest common prefix among a list of strings using horizontal scanning.\n \"...
trial_gpt4o_0
{ "original_instruction": "You are given an array of strings `strs`. Write a function `longestCommonPrefix(strs)` to find the longest common prefix string among these strings.\n\n#### Input:\n- An array of strings `strs` (1 ≤ length of each string ≤ 200, 1 ≤ number of strings ≤ 200).\n\n#### Output:\n- A single strin...
0.726829
Data_Structure_15899
C
[ "longestCommonPrefix_horizontal_scanning", "longestCommonPrefix_vertical_scanning", "longestCommonPrefix" ]
3
[ [ "longestCommonPrefix", "longestCommonPrefix_horizontal_scanning" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b55341519dddd74e922ffc8510fc738ff967c203
763a87a3a8938f1e5be766cc6f0f410d8fbd5113
v1.0
complete
Data_Structure
Data_Structure_14854_C
import random from sympy.ntheory import isprime, primitive_root def diffie_hellman_simulation(p: int) -> str: """ Perform the Diffie-Hellman key exchange protocol to securely establish a shared secret key over an insecure channel. Args: p (int): A candidate prime number. Returns: str:...
import random from sympy.ntheory import isprime, primitive_root def prime_check(p): return isprime(p) def find_primitive_root(p): return primitive_root(p) def diffie_hellman_simulation(p: int) -> str: if not prime_check(p): return f"{p} is not a prime number." a = find_primitive_root(p) ...
import pytest from solution import diffie_hellman_simulation def test_diffie_hellman_simulation_valid_prime(): output = diffie_hellman_simulation(23) assert "Prime: 23" in output assert "Primitive Root: 5" in output or "Primitive Root: 2" in output # known primitive roots of 23 assert "Both keys match...
[ { "docstring": null, "function_declaration": "def prime_check(p):", "function_name": "prime_check", "parameter_list": "(p)" }, { "docstring": null, "function_declaration": "def find_primitive_root(p):", "function_name": "find_primitive_root", "parameter_list": "(p)" }, { ...
[ 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\nfrom sympy.ntheory import isprime, primitive_root\n\ndef prime_check(p):\n return isprime(p)\n\ndef find_primitive_root(p):\n return prim...
trial_gpt4o_0
{ "original_instruction": "Diffie-Hellman Key Exchange is a cryptographic protocol that allows two parties to establish a shared secret over an insecure channel. To implement this securely, it is essential to use large prime numbers and their respective primitive roots. Your task is to implement a secure key exchange...
0.523122
Data_Structure_14854
C
[ "prime_check", "find_primitive_root", "diffie_hellman_simulation" ]
3
[ [ "diffie_hellman_simulation", "find_primitive_root" ], [ "diffie_hellman_simulation", "prime_check" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
43acb7d9106a148b2ab12bd0ca6bc1d465f4d4c3
7128227c7880d306ceeca9586cb72b691ce139a2
v1.0
complete
Data_Structure
Data_Structure_16913_C
def max_heap_sort_with_simulation(arr, simulation=False): """ Sort an array using the max heap sort algorithm with optional simulation output. :param arr: List of integers to sort. :param simulation: Boolean flag for printing the array at each iteration. :return: Sorted list in ascending order. ...
def max_heapify(arr, n, i, simulation): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[largest] < arr[left]: largest = left if right < n and arr[largest] < arr[right]: largest = right if largest != i: arr[i], arr[largest] = arr[largest], arr[i] ...
from solution import max_heap_sort_with_simulation, min_heap_sort_with_simulation def test_max_heap_sort_with_simulation_unsorted_array(): arr = [3, 1, 5, 2, 4] sorted_arr = max_heap_sort_with_simulation(arr[:], simulation=False) assert sorted_arr == [1, 2, 3, 4, 5] def test_max_heap_sort_with_simulation_...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation)" }, { "docstring": null, "function_declaration": "def max_heap_sort_with_simulation(arr, simulation=False):", "function_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": "def heapify(arr, n, i, is_max_heap, simulation):\n largest_or_smallest = i # Initialize largest/smallest as root\n left = 2 * i + 1 # left = 2*i + ...
trial_gpt4o_2
{ "original_instruction": "### Heap Sort Implementation and Analysis\n\nAs a data scientist, you are working on a feature that requires the efficient sorting of large datasets. Given your understanding of the Heap Sort algorithm, we would like you to implement a function that sorts an array using a max heap, and anot...
0.60908
Data_Structure_16913
C
[ "max_heapify", "max_heap_sort_with_simulation", "min_heapify", "min_heap_sort_with_simulation" ]
4
[ [ "max_heap_sort_with_simulation", "max_heapify" ], [ "min_heap_sort_with_simulation", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0f07d23d468d98860859ab7807bb55934f5d4d93
858d8d44f71d91db670aafc061894f1790d99713
v1.0
complete
Data_Structure
Data_Structure_15945_C
from typing import List def radix_sort(arr: List[int], simulation: bool = False) -> List[int]: """ Implement the Radix Sort algorithm to sort a list of non-negative integers. Parameters: arr (List[int]): An unsorted list of non-negative integers. simulation (bool): An optional parameter to print ...
from typing import List def counting_sort(arr, exp, simulation): n = len(arr) output = [0] * n count = [0] * 10 for i in range(n): index = (arr[i] // exp) % 10 count[index] += 1 for i in range(1, 10): count[i] += count[i - 1] for i in range(n - 1, -1, -1): ind...
from solution import radix_sort def test_radix_sort_on_empty(): assert radix_sort([]) == [] def test_radix_sort_on_single_element(): assert radix_sort([1]) == [1] def test_radix_sort_on_identical_elements(): assert radix_sort([7, 7, 7, 7]) == [7, 7, 7, 7] def test_radix_sort_on_multiple_elements(): ...
[ { "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...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort(arr: List[int], exp: int, simulation: bool) -> List[int]:\n n = len(arr)\n output = [0] * n\n count = [0...
trial_gpt4o_2
{ "original_instruction": "### Question: Implement and Analyze Radix Sort\n\nYour task is to implement the Radix Sort algorithm to sort a list of non-negative integers. You have been given an unsorted array of integers, and you are required to output a sorted array.\n\n### Requirements:\n\n1. Implement the provided `...
0.628995
Data_Structure_15945
C
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83ce950894e0f1060a659ab2541cd4715b36ce11
0327b6e6f788b1cca478f805d7bc424d4a43f9f3