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
instruct
Data_Structure
Data_Structure_34314_I
### RSA Key Pair Generation and Encryption/Decryption #### Problem Statement You are to implement an RSA encryption and decryption functionality, including key pair generation, using RSA principles. The implementation must include enhancements over the provided primality testing mechanism. #### Function Signature Imp...
import random from typing import Optional, Tuple def is_prime(n, k=128): """ Test if a number is prime using the Miller-Rabin primality test. """ if n == 2 or n == 3: return True if n <= 1 or n % 2 == 0: return False # Write n-1 as 2^r * d r, s = 0, n - 1 while s % 2 == 0: ...
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) def test_encrypt_decrypt(): n, e, d = generate_key(16, seed=42) data = 20 encrypted = encrypt(dat...
[ { "docstring": "Test if a number is prime using the Miller-Rabin primality test. ", "function_declaration": "def is_prime(n, k=128):", "function_name": "is_prime", "parameter_list": "(n, k=128)" }, { "docstring": "Generate an odd integer randomly. ", "function_declaration": "def generate...
[ 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 Tuple, Optional\nfrom sympy import primerange\n\ndef is_prime(n: int) -> bool:\n \"\"\"Returns True if n is a prime numbe...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034314", "row_id": 34314, "seed_ids": "[154]" }
0.547708
Data_Structure_34314
I
[ "is_prime", "generate_prime_candidate", "generate_prime_number", "gcd", "modinv", "generate_key", "encrypt", "decrypt" ]
8
[ [ "generate_key", "gcd" ], [ "generate_key", "generate_prime_number" ], [ "generate_key", "modinv" ], [ "generate_prime_number", "generate_prime_candidate" ], [ "generate_prime_number", "is_prime" ] ]
5
[]
false
[]
false
pytest
true
[]
true
fce480ee46acaf953531f7ef70ab06ccce4f6d4d
b7ed9c3a25cd1ca6a08002875b0617b1dee46d4c
v1.0
instruct
Data_Structure
Data_Structure_34352_I
### Problem Description In this task, you are required to extend and optimize the Sieve of Eratosthenes for generating prime numbers. Particularly, your task is to further reduce the space complexity by implementing a segmented sieve approach. ### Task Extend the `get_primes` function to generate all prime numbers les...
from math import isqrt from typing import List def simple_sieve(limit: int) -> List[int]: """Generates all prime numbers up to limit using the simple Sieve of Eratosthenes""" sieve = [True] * (limit + 1) sieve[0] = sieve[1] = False for start in range(2, isqrt(limit) + 1): if sieve[start]: ...
from solution import segmented_sieve def test_segmented_sieve_small(): assert segmented_sieve(2) == [] assert segmented_sieve(3) == [2] assert segmented_sieve(10) == [2, 3, 5, 7] assert segmented_sieve(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_segmented_sieve_large(): assert segmented_s...
[ { "docstring": "Generates all prime numbers up to limit using the simple Sieve of Eratosthenes", "function_declaration": "def simple_sieve(limit):", "function_name": "simple_sieve", "parameter_list": "(limit)" }, { "docstring": "Generates all prime numbers less than n using the segmented sie...
[ 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 segmented_sieve(n: int):\n \"\"\"\n Generates all prime numbers less than n using a segmented sieve approach.\n \"\"\"\n import math\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034352", "row_id": 34352, "seed_ids": "[133]" }
0.638373
Data_Structure_34352
I
[ "simple_sieve", "segmented_sieve" ]
2
[ [ "segmented_sieve", "simple_sieve" ] ]
1
[]
false
[]
false
pytest
true
[]
true
802af703e85aff6d8bdfbea2e2380fa90ad14f96
776c39f2cededac47efcbc82e4d13173ca456509
v1.0
instruct
Data_Structure
Data_Structure_34355_I
Alice and Bob want to establish a secure communication channel using the Diffie-Hellman key exchange protocol. However, they suspect that there may be issues with the prime number \( p \) they are using or the primitive root \( a \). You are to write a function that verifies whether the prime number and primitive root...
def is_prime(n: int) -> bool: """Returns True if n is a prime number, otherwise 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 False ...
from solution import validate_diffie_hellman def test_valid_diffie_hellman(): assert validate_diffie_hellman(5, 23) == pow(5, 6 * 15, 23) assert validate_diffie_hellman(2, 13) == pow(2, 6 * 15, 13) def test_invalid_prime(): try: validate_diffie_hellman(2, 16) except ValueError as e: as...
[ { "docstring": "Returns True if n is a prime number, otherwise False.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Returns the value of Euler's Totient function phi(n).", "function_declaration": "def euler_totient(n...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00034355", "row_id": 34355, "seed_ids": "[146]" }
0.535166
Data_Structure_34355
I
[ "is_prime", "euler_totient", "find_order", "is_primitive_root", "diffie_hellman_shared_secret", "validate_diffie_hellman" ]
6
[ [ "is_primitive_root", "euler_totient" ], [ "is_primitive_root", "is_prime" ], [ "validate_diffie_hellman", "is_prime" ], [ "validate_diffie_hellman", "is_primitive_root" ] ]
4
[]
false
[]
false
pytest
true
[]
true
9bd6833759931df6f70272b30fc1c00b086c3ab6
35ef2f77ca1bd711a493f4c27b53ba6c6e473edb
v1.0
instruct
Data_Structure
Data_Structure_34357_I
### Question: Matrix Exponentiation and Power Calculation Given three functions that handle matrix multiplication, identity matrix generation, and matrix exponentiation using repeated squaring, you are tasked with solving the following problem: #### Problem Statement: Given an integer `k` and an initial \(2 \times 2\...
def multiply(m1, m2): """ Multiplies two 2x2 matrices. """ return [ [ m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0], m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1] ], [ m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0], m1[1][0] * m2[0][1] + m1[1][1...
from solution import matrix_power_two_by_k def test_matrix_power_two_by_k_identity(): assert matrix_power_two_by_k(1, 0, 0, 1, 0) == [[1, 0], [0, 1]] def test_matrix_power_two_by_k_basic(): assert matrix_power_two_by_k(1, 1, 1, 0, 1) == [[1, 1], [1, 0]] def test_matrix_power_two_by_k_square(): assert mat...
[ { "docstring": "Multiplies two 2x2 matrices.", "function_declaration": "def multiply(m1, m2):", "function_name": "multiply", "parameter_list": "(m1, m2)" }, { "docstring": "Returns a 2x2 identity matrix.", "function_declaration": "def identity():", "function_name": "identity", "p...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(A, B):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n return [\n [\n A[0][0] * B[0][0] + A[0][1]...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00034357", "row_id": 34357, "seed_ids": "[340]" }
0.560506
Data_Structure_34357
I
[ "multiply", "identity", "matrix_exponentiation", "matrix_power_two_by_k" ]
4
[ [ "matrix_exponentiation", "identity" ], [ "matrix_exponentiation", "multiply" ], [ "matrix_power_two_by_k", "matrix_exponentiation" ] ]
3
[]
false
[]
false
pytest
true
[]
true
66241bb11cf8a1285cf9e300ecfa89fb760ab622
c5a89c63b05764e3e1f4ca4ae33f39ac53deb469
v1.0
instruct
Data_Structure
Data_Structure_34367_I
## Problem Statement: You are tasked with implementing a lossless universal integer coding scheme using the Elias γ and δ codes. Your implementation should compress a list of integers into a single encoded string and be able to decode that string back to the original list of integers. ## Function Signatures: ```python...
from typing import List def elias_gamma_encode(number: int) -> str: if number <= 0: raise ValueError("Number must be positive") binary = bin(number)[2:] # Get the binary representation of the number without the '0b' prefix n = len(binary) - 1 prefix = '0' * n return prefix + binary d...
from solution import compress_integers, decompress_integers def test_compress_and_decompress(): original = [13, 5, 1] encoded = compress_integers(original) assert decompress_integers(encoded) == original def test_large_range(): original = [1, 2, 3, 4, 5, 100, 1000, 10000, 999999, 1000000] encoded ...
[ { "docstring": null, "function_declaration": "def elias_gamma_encode(number):", "function_name": "elias_gamma_encode", "parameter_list": "(number)" }, { "docstring": null, "function_declaration": "def elias_gamma_decode(encoded_string, index):", "function_name": "elias_gamma_decode",...
[ 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 elias_gamma_encode(number: int) -> str:\n if number <= 0:\n raise ValueError(\"Elias Gamma encoding is only defined f...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034367", "row_id": 34367, "seed_ids": "[333]" }
0.527286
Data_Structure_34367
I
[ "elias_gamma_encode", "elias_gamma_decode", "compress_integers", "decompress_integers" ]
4
[ [ "compress_integers", "elias_gamma_encode" ], [ "decompress_integers", "elias_gamma_decode" ] ]
2
[]
false
[]
false
pytest
true
[]
true
2a010755d7f00badeef5dadef57b89381699832d
712590e2eb9d16b77f73da8c5eb5f6b8728e1bd8
v1.0
instruct
Data_Structure
Data_Structure_34372_I
### RSA Encryption System Implementation **Objective**: Implement an RSA encryption/decryption system with specific focus on generating keys efficiently. You are given a partially completed RSA encryption algorithm. Your task is to implement an optimized version of the `generate_key()` function, which should generate...
import random from math import gcd from sympy import isprime def mod_inverse(e, phi): """ Use the Extended Euclidean Algorithm to find the multiplicative inverse of e mod phi. """ def egcd(a, b): x0, x1, y0, y1 = 0, 1, 1, 0 while a != 0: q, a, b = b // a, b % a, a ...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(128, seed=42) assert isinstance(n, int) and n > 0 assert isinstance(e, int) and e > 0 assert isinstance(d, int) and d > 0 def test_encryption_decryption(): n, e, d = generate_key(128, seed=42) ...
[ { "docstring": "Use the Extended Euclidean Algorithm to find the multiplicative inverse of e mod phi.", "function_declaration": "def mod_inverse(e, phi):", "function_name": "mod_inverse", "parameter_list": "(e, phi)" }, { "docstring": "Generate a prime number of specified bit length.", "...
[ 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 math import gcd\nfrom sympy import isprime\n\ndef mod_inverse(e, phi):\n \"\"\"\n Use the Extended Euclidean Algorithm to find the m...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034372", "row_id": 34372, "seed_ids": "[154]" }
0.566186
Data_Structure_34372
I
[ "mod_inverse", "generate_prime", "generate_key", "encrypt", "decrypt" ]
5
[ [ "generate_key", "generate_prime" ], [ "generate_key", "mod_inverse" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
c6f9d1c2b0bacaa9e78fc3e6af35b30a8723dfc3
a030ce52ac793634608f7c3e8ce8d7c2e8947378
v1.0
instruct
Data_Structure
Data_Structure_34387_I
### Diffie-Hellman Key Exchange Exercise Alice and Bob want to securely share a secret key over a public network using Diffie-Hellman key exchange. They agree on a large prime number \(p\) and its primitive root \(a\). Your task is to implement a Python function that demonstrates this key exchange and ensures both par...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i ** 2 <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def gcd(a, b): while b: a, b = b,...
from solution import diffie_hellman_key_exchange def test_diffie_hellman_valid(): assert diffie_hellman_key_exchange(5, 23) == True def test_non_prime_p(): assert diffie_hellman_key_exchange(5, 20) == False def test_invalid_primitive_root(): assert diffie_hellman_key_exchange(4, 23) == False def test_sm...
[ { "docstring": null, "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)" }, { "docstring": null, "function...
[ 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 is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n i = 5...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034387", "row_id": 34387, "seed_ids": "[146]" }
0.529102
Data_Structure_34387
I
[ "is_prime", "gcd", "is_primitive_root", "mod_exp", "diffie_hellman_key_exchange" ]
5
[ [ "diffie_hellman_key_exchange", "is_prime" ], [ "diffie_hellman_key_exchange", "is_primitive_root" ], [ "diffie_hellman_key_exchange", "mod_exp" ], [ "is_primitive_root", "gcd" ], [ "is_primitive_root", "is_prime" ] ]
5
[]
false
[]
false
pytest
true
[]
true
5662763999a88d8fb51581441167dff35c9774ff
e5a97db3a4784cd3927e04b5b32627962593d298
v1.0
instruct
Data_Structure
Data_Structure_34402_I
Bitonic Sort Implementation #### Objective Your task is to implement a modified version of the `bitonic_sort` function. This modified version should handle arrays of any size by padding the array to the next power of two with a specified padding value before sorting and then removing the padding after sorting. #### F...
from typing import List import math def bitonic_compare_and_swap(arr: List[int], i: int, j: int, direction: bool): if direction == (arr[i] > arr[j]): arr[i], arr[j] = arr[j], arr[i] def bitonic_merge(arr: List[int], low: int, cnt: int, direction: bool): if cnt > 1: k = cnt // 2 for i i...
from solution import modified_bitonic_sort def test_sorted_array(): assert modified_bitonic_sort([3, 1, 5, 7, 2]) == [1, 2, 3, 5, 7] assert modified_bitonic_sort([3, 1, 5, 7, 2], reverse=True) == [7, 5, 3, 2, 1] def test_single_element(): assert modified_bitonic_sort([1]) == [1] assert modified_bitoni...
[ { "docstring": null, "function_declaration": "def bitonic_compare_and_swap(arr, i, j, direction):", "function_name": "bitonic_compare_and_swap", "parameter_list": "(arr, i, j, direction)" }, { "docstring": null, "function_declaration": "def bitonic_merge(arr, low, cnt, direction):", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nimport math\n\ndef bitonic_compare_and_swap(arr: List[int], i: int, j: int, direction: bool):\n if direction == (arr[i] > arr[j]):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034402", "row_id": 34402, "seed_ids": "[17]" }
0.685189
Data_Structure_34402
I
[ "bitonic_compare_and_swap", "bitonic_merge", "bitonic_sort_rec", "next_power_of_two", "modified_bitonic_sort" ]
5
[ [ "bitonic_merge", "bitonic_compare_and_swap" ], [ "bitonic_sort_rec", "bitonic_merge" ], [ "modified_bitonic_sort", "bitonic_sort_rec" ], [ "modified_bitonic_sort", "next_power_of_two" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3a6d1950ea3f0b2f88b449bc30e3683eb5faa36c
65d0ad5b7067981bdf580d2cf40b5e0f8c32b45b
v1.0
instruct
Data_Structure
Data_Structure_34475_I
## Question ### Scenario A company manages a dynamically changing collection of sorted numerical data that needs constant querying for the next higher element. The data is stored in a Binary Search Tree (BST) for efficiency. An important feature in their application is to find the in-order successor of any element in ...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def find_successor(root: TreeNode, node: TreeNode) -> TreeNode: """ Finds the in-order successor of the given node in the BST. Parameters: root (TreeNode): The root of the BST nod...
from solution import TreeNode, find_successor def test_find_successor_on_right_subtree(): root = TreeNode(20) root.left = TreeNode(10) root.right = TreeNode(30) root.right.left = TreeNode(25) root.right.right = TreeNode(35) node = root assert find_successor(root, node).val == 25 def test_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": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef find_successor(root: TreeNode, n...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00034475", "row_id": 34475, "seed_ids": "[323]" }
0.520152
Data_Structure_34475
I
[ "find_successor", "find_min" ]
2
[ [ "find_successor", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
8f041cdcb50f9eef6153fcdc8d213f3875c0d136
4f2450f3914cf07876ad86e8fdff14a112113890
v1.0
instruct
Data_Structure
Data_Structure_34523_I
You have been tasked with implementing the `radix_sort` function to help a logistics company efficiently sort large arrays of parcel tracking numbers. Each tracking number is a non-negative integer. To ensure correctness and performance, please adhere to the specifications provided: #### Function Description ```pyth...
from typing import List def counting_sort(arr: List[int], exp: int, simulation: bool): """ A function to do counting sort of arr[] according to the digit represented by exp (exp is 10^i where i is the current digit number) """ n = len(arr) output = [0] * n count = [0] * 10 # Stor...
from solution import radix_sort def test_basic_case(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_single_element(): assert radix_sort([5]) == [5] def test_already_sorted(): assert radix_sort([1, 2, 3, 4, 5, 6, 7, 8, 9]) == [1, 2, 3, 4, 5, 6, 7, 8, 9...
[ { "docstring": "A function to do counting sort of arr[] according to \nthe digit represented by exp (exp is 10^i where i is \nthe current digit number)", "function_declaration": "def counting_sort(arr, exp, simulation):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation)" ...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort(arr: List[int], exp: int, simulation: bool = False) -> None:\n n = len(arr)\n output = [0] * n\n count =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034523", "row_id": 34523, "seed_ids": "[15]" }
0.5925
Data_Structure_34523
I
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7cfbc12d0fbd80aa8222dc68cc5c96089f8f09ea
6c795f9fc076e1960c61dbc6ca10c98a17e0a474
v1.0
instruct
Data_Structure
Data_Structure_34590_I
### Hailstone Sequence Analysis and Extension Given the hailstone sequence defined by the following rules: * If the number is 1, the sequence ends. * If the number is even, the next number is `n / 2`. * If the number is odd, the next number is `3n + 1`. Implement a function `hailstone(n: int) -> List[int]` that gener...
from typing import List, Dict, Any def hailstone(n: int) -> List[int]: """ Generates and returns the hailstone sequence starting from the given number `n`. :param n: Starting integer (n > 0) :return: List of integers representing the hailstone sequence. """ sequence = [] while n != 1: ...
from solution import hailstone, analyze_hailstone def test_hailstone_example1(): assert hailstone(5) == [5, 16, 8, 4, 2, 1] def test_hailstone_example2(): assert hailstone(1) == [1] def test_hailstone_example3(): assert hailstone(7) == [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] def t...
[ { "docstring": "Generates and returns the hailstone sequence starting from the given number `n`.\n\n:param n: Starting integer (n > 0)\n:return: List of integers representing the hailstone sequence.", "function_declaration": "def hailstone(n):", "function_name": "hailstone", "parameter_list": "(n)" ...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_results_combined.jsonl", "solution_code": "def hailstone(n: int) -> list:\n \"\"\"\n Generates and returns the hailstone sequence starting from the given number `n`.\n\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034590", "row_id": 34590, "seed_ids": "[167]" }
0.557372
Data_Structure_34590
I
[ "hailstone", "analyze_hailstone" ]
2
[ [ "analyze_hailstone", "hailstone" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c9788f49e35f921e871f41bd3ec29874daff27e2
db897844bd1b97545087b5f6726cf79aff6b9886
v1.0
instruct
Data_Structure
Data_Structure_34656_I
**Question: Implement Binary Exponentiation with Matrix Representation** ### Context: Binary exponentiation is a powerful technique to compute large powers efficiently. This approach can be extended to other mathematical structures like matrices. For example, computing the nth power of a matrix can be beneficial in ce...
def matrix_multiply(matrix1, matrix2, mod=None): """ Multiplies two 2x2 matrices and returns the resulting matrix. """ a11 = matrix1[0][0] * matrix2[0][0] + matrix1[0][1] * matrix2[1][0] a12 = matrix1[0][0] * matrix2[0][1] + matrix1[0][1] * matrix2[1][1] a21 = matrix1[1][0] * matrix2[0][0] + mat...
from solution import matrix_multiply, matrix_power_iter, matrix_power_recur def test_matrix_multiply_no_mod(): matrix1 = [[1, 2], [3, 4]] matrix2 = [[2, 0], [1, 2]] expected = [[4, 4], [10, 8]] assert matrix_multiply(matrix1, matrix2) == expected def test_matrix_multiply_with_mod(): matrix1 = [[1,...
[ { "docstring": "Multiplies two 2x2 matrices and returns the resulting matrix.", "function_declaration": "def matrix_multiply(matrix1, matrix2, mod=None):", "function_name": "matrix_multiply", "parameter_list": "(matrix1, matrix2, mod=None)" }, { "docstring": "Computes the nth power of a 2x2 ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_multiply(A, B, mod=None):\n \"\"\"\n Multiplies two 2x2 matrices A and B.\n \"\"\"\n a11 = (A[0][0] * B[0][0] + A[0][1] * B[1][0]) % mo...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00034656", "row_id": 34656, "seed_ids": "[151]" }
0.580476
Data_Structure_34656
I
[ "matrix_multiply", "matrix_power_iter", "matrix_power_recur" ]
3
[ [ "matrix_power_iter", "matrix_multiply" ], [ "matrix_power_recur", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ef8ad08d2d4021686565c093f978fdff643a3819
7cb1734f25e8f7b79fbdb1bebf9e7316979251cd
v1.0
instruct
Data_Structure
Data_Structure_34689_I
### RSA Encryption Algorithm Implementation You are required to implement a function to securely generate RSA keys and to encrypt/decrypt messages using these keys. The RSA key generation involves selecting two large prime numbers, computing the modulus, and finding modular inverses. You will then use the generated ke...
import random def gcd(a, b): while b != 0: a, b = b, a % b return a def modinv(a, m): m0, x0, x1 = m, 0, 1 if m == 1: return 0 while a > 1: q = a // m m, a = a % m, m x0, x1 = x1 - q * x0, x0 if x1 < 0: x1 += m0 return x1 def is_prime(num): ...
from solution import generate_key, encrypt, decrypt def test_rsa_key_generation(): n, e, d = generate_key(16) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert n > 0 assert e > 0 assert d > 0 def test_rsa_encryption_decryption(): n, e, d = generate_ke...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def modinv(a, m):", "function_name": "modinv", "parameter_list": "(a, m)" }, { "docstring": null, "functi...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef modinv(a, m):\n m0, x0, x1 = m, 0, 1\n if m == 1:\n r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00034689", "row_id": 34689, "seed_ids": "[154]" }
0.599728
Data_Structure_34689
I
[ "gcd", "modinv", "is_prime", "get_random_prime", "generate_key", "encrypt", "decrypt" ]
7
[ [ "generate_key", "gcd" ], [ "generate_key", "get_random_prime" ], [ "generate_key", "modinv" ], [ "get_random_prime", "is_prime" ] ]
4
[]
false
[]
false
pytest
true
[]
true
35c76360bdd3a269f1b876f028b67f8d8b09073d
00cf881914bc6198a9d07b518a1c26413d4c8735
v1.0
instruct
Data_Structure
Data_Structure_34772_I
### Question: Implement an Enhanced Merge Sort Given an array of integers, implement an optimized version of the Merge Sort algorithm. The algorithm should: 1. Use a threshold to switch to Insertion Sort for small subarrays. 2. Be stable. 3. Be efficient in both time and space. ### Function Signature ```python def op...
from typing import List def insertion_sort(arr: List[int], left: int, right: int) -> None: for i in range(left + 1, right + 1): key = arr[i] j = i - 1 while j >= left and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def merge(arr: List[int], lef...
from solution import optimized_merge_sort def test_optimized_merge_sort(): assert optimized_merge_sort([34, 7, 23, 32, 5, 62, 32], 4) == [5, 7, 23, 32, 32, 34, 62] assert optimized_merge_sort([], 4) == [] assert optimized_merge_sort([1], 4) == [1] assert optimized_merge_sort([2, 1], 4) == [1, 2] as...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def merge(arr, left, mid, right):", "function_name": "merge", "paramete...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef 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_2
{ "original_instruction": "", "prompt_id": "00034772", "row_id": 34772, "seed_ids": "[12]" }
0.646698
Data_Structure_34772
I
[ "insertion_sort", "merge", "optimized_merge_sort" ]
3
[ [ "optimized_merge_sort", "insertion_sort" ], [ "optimized_merge_sort", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
34b872df532573a5497f31b19bd339511b20640a
b3e5ca789128cb85f2d78c613bb3abc89ab95b2e
v1.0
instruct
Data_Structure
Data_Structure_34808_I
**Problem Statement**: You've been assigned a task to help optimize a scheduling system. Two subsystems utilize timer interrupts that reset based on their respective counts. To achieve synchronization in their executions, you need to calculate the Least Common Multiple (LCM) of their interrupt counts. However, your s...
import math def remove_trailing_zeros(n): """ Removes trailing zeros from the binary representation of n. """ while n % 2 == 0: n //= 2 return n def synchronize_interrupts(a, b): """ Returns the least common multiple of a and b, considering any trailing zeros in the binary forms of...
from solution import synchronize_interrupts def test_synchronize_interrupts_basic(): assert synchronize_interrupts(8, 20) == 40 assert synchronize_interrupts(4, 5) == 20 assert synchronize_interrupts(6, 8) == 24 assert synchronize_interrupts(9, 12) == 36 def test_synchronize_interrupts_with_trailing_z...
[ { "docstring": "Removes trailing zeros from the binary representation of n.", "function_declaration": "def remove_trailing_zeros(n):", "function_name": "remove_trailing_zeros", "parameter_list": "(n)" }, { "docstring": "Returns the least common multiple of a and b, considering any trailing z...
[ 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(x, y):\n while y:\n x, y = y, x % y\n return x\n\ndef lcm(x, y):\n return x * y // gcd(x, y)\n\ndef remove_trailing_zeros(x):\n whi...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034808", "row_id": 34808, "seed_ids": "[166]" }
0.520442
Data_Structure_34808
I
[ "remove_trailing_zeros", "synchronize_interrupts" ]
2
[ [ "synchronize_interrupts", "remove_trailing_zeros" ] ]
1
[]
false
[]
false
pytest
true
[]
true
600f937f8792e12a75bf6e49f272a9b3f21f0018
6a5d54bc1d3e125000d750ab3174b915af107416
v1.0
instruct
Data_Structure
Data_Structure_34892_I
Ordered Insert Position You are provided with a helper method `search_insert` that implements binary search to find the appropriate insertion position of a target value in a given sorted array. Your task is to create a function that uses this helper method to insert multiple values into an initially empty sorted array...
from typing import List def search_insert(arr: List[int], target: int) -> int: """ Helper method to find the insertion position for a target value in a sorted array. """ left, right = 0, len(arr) while left < right: mid = (left + right) // 2 if arr[mid] < target: left = ...
from solution import ordered_insert def test_insert_single_value(): arr = [] values = [5] expected = [5] assert ordered_insert(arr, values) == expected def test_insert_multiple_values(): arr = [] values = [5, 1, 4, 2, 3] expected = [1, 2, 3, 4, 5] assert ordered_insert(arr, values) == ...
[ { "docstring": "Helper method to find the insertion position for a target value in a sorted array.", "function_declaration": "def search_insert(arr, target):", "function_name": "search_insert", "parameter_list": "(arr, target)" }, { "docstring": "Insert each value from the list 'values' into...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(arr: List[int], target: int) -> int:\n \"\"\"\n Given a sorted array of integers arr and a target value, re...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034892", "row_id": 34892, "seed_ids": "[199]" }
0.674025
Data_Structure_34892
I
[ "search_insert", "ordered_insert" ]
2
[ [ "ordered_insert", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4f720285d591f4d42e0918c5942ac8e32af818ba
a7fe081d5fd25dfa2567e4b0641efd85b8c8c9dd
v1.0
instruct
Data_Structure
Data_Structure_34912_I
You are given an implementation of the Bitonic Sort algorithm, a parallelizable sorting algorithm that can sort arrays of sizes that are powers of two in both increasing and decreasing order. The provided implementation is non-parallel and works for arrays where the length is a power of two. Your task is to implement ...
from multiprocessing import Process, Manager def compare_and_swap(arr, i, j, direction): if direction == (arr[i] > arr[j]): arr[i], arr[j] = arr[j], arr[i] def bitonic_merge(arr, start, length, direction): if length > 1: mid = length // 2 for i in range(start, start + mid): ...
from solution import parallel_bitonic_sort def test_bitonic_sort_ascending(): assert parallel_bitonic_sort([3, 7, 2, 8, 6, 4, 5, 1]) == [1, 2, 3, 4, 5, 6, 7, 8] def test_bitonic_sort_descending(): assert parallel_bitonic_sort([3, 7, 2, 8, 6, 4, 5, 1], reverse=True) == [8, 7, 6, 5, 4, 3, 2, 1] def test_bitoni...
[ { "docstring": null, "function_declaration": "def compare_and_swap(arr, i, j, direction):", "function_name": "compare_and_swap", "parameter_list": "(arr, i, j, direction)" }, { "docstring": null, "function_declaration": "def bitonic_merge(arr, start, length, direction):", "function_n...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from multiprocessing import Pool\nimport math\n\ndef compare_and_swap(arr, i, j, reverse):\n if (arr[i] > arr[j]) == reverse:\n arr[i], arr[j] = arr...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034912", "row_id": 34912, "seed_ids": "[17]" }
0.621168
Data_Structure_34912
I
[ "compare_and_swap", "bitonic_merge", "bitonic_sort_subarray", "parallel_bitonic_sort" ]
4
[ [ "bitonic_merge", "compare_and_swap" ], [ "bitonic_sort_subarray", "bitonic_merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
5e1567b429dc2f122ff44e125ba741e970ea146a
e4b719dfb834635962d4f0b1f61b470f421f9b69
v1.0
instruct
Data_Structure
Data_Structure_34934_I
### Background You are given a simple sorting algorithm called "Exchange Sort" which compares each pair of elements in the list and swaps them if they are in the wrong order. However, due to its quadratic time complexity, this algorithm is quite inefficient for large datasets. Your task is to implement this algorithm a...
def exchange_sort(arr): """ Sorts the array using the Exchange Sort algorithm. """ n = len(arr) for i in range(n): for j in range(i+1, n): if arr[i] > arr[j]: arr[i], arr[j] = arr[j], arr[i] return arr def optimized_sort(arr): """ Sorts the array usin...
from solution import exchange_sort, optimized_sort def test_exchange_sort_empty(): assert exchange_sort([]) == [] def test_exchange_sort_single_element(): assert exchange_sort([1]) == [1] def test_exchange_sort_sorted(): assert exchange_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_exchange_sort_uns...
[ { "docstring": "Sorts the array using the Exchange Sort algorithm.", "function_declaration": "def exchange_sort(arr):", "function_name": "exchange_sort", "parameter_list": "(arr)" }, { "docstring": "Sorts the array using Python's built-in Timsort algorithm.", "function_declaration": "def...
[ 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 time\nfrom typing import List\n\ndef exchange_sort(arr: List[int]) -> List[int]:\n \"\"\"\n Sorts an array using the Exchange Sort algorithm.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00034934", "row_id": 34934, "seed_ids": "[28]" }
0.612461
Data_Structure_34934
I
[ "exchange_sort", "optimized_sort", "compare_sorts" ]
3
[ [ "compare_sorts", "exchange_sort" ], [ "compare_sorts", "optimized_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
c32f567b97952f8e5c187d6a59f1225778487b34
27513aade67c2d8bb6c1453cdab204408b2a4acb
v1.0
instruct
Data_Structure
Data_Structure_35002_I
### Objective Conduct a comprehensive analysis of your understanding of Tries and Backtracking algorithms by implementing a function that finds all the words from a given list that can be formed in a word search grid. ### Problem Description You're given a 2D board of characters and a list of words. Find all words in ...
class TrieNode: def __init__(self): self.children = {} self.word = None def add_word(root, word): node = root for char in word: if char not in node.children: node.children[char] = TrieNode() node = node.children[char] node.word = word def find_words(board, w...
from solution import find_words def test_example_case(): board = [ ['o','a','a','n'], ['e','t','a','e'], ['i','h','k','r'], ['i','f','l','v'] ] words = ["oath", "pea", "eat", "rain"] assert sorted(find_words(board, words)) == sorted(["oath", "eat"]) def test_no_matches(...
[]
[ 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": "class TrieNode:\n def __init__(self):\n self.children = {}\n self.word = None\n\ndef add_word(root, word):\n node = root\n for char in ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035002", "row_id": 35002, "seed_ids": "[115]" }
0.616354
Data_Structure_35002
I
[ "add_word", "find_words" ]
2
[ [ "find_words", "add_word" ] ]
1
[]
false
[ "TrieNode" ]
true
pytest
true
[]
true
6b349293985ca1795becf729ab2887d54195e11d
74c4a9f6992d193bc573535a2e0678a41b2a99b8
v1.0
instruct
Data_Structure
Data_Structure_35011_I
### Rotate Array Problem #### Scenario You are developing a feature in a game where players can move an array of prizes to the right by a certain number of steps. This feature should be efficient and handle various edge cases. #### Task Write a function `rotate_array` that rotates an array of `n` elements to the righ...
from typing import List def rotate_array(array: List[int], k: int) -> None: """ Rotates the array to the right by k steps in-place. """ n = len(array) if n == 0: return k = k % n # Normalize k to handle cases where k > n if k == 0: return # Reverse the whole array...
from solution import rotate_array def test_rotate_array_example_1(): array = [1, 2, 3, 4, 5, 6, 7] k = 3 rotate_array(array, k) assert array == [5, 6, 7, 1, 2, 3, 4] def test_rotate_array_example_2(): array = [-1, -100, 3, 99] k = 2 rotate_array(array, k) assert array == [3, 99, -1, -1...
[ { "docstring": "Rotates the array to the right by k steps in-place.", "function_declaration": "def rotate_array(array, k):", "function_name": "rotate_array", "parameter_list": "(array, k)" }, { "docstring": "Helper function to reverse elements in the array from index start to end.", "fun...
[ 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 rotate_array(array, k):\n \"\"\"\n Rotates an array to the right by k steps in-place.\n \n :param array: List[int] - The array to rotate\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035011", "row_id": 35011, "seed_ids": "[283]" }
0.645493
Data_Structure_35011
I
[ "rotate_array", "reverse" ]
2
[ [ "rotate_array", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0889e0248e501e38021c1e0ae45f3c122ce51f80
1f54cc1a9d806630f93dc12e13cd77d21977eee9
v1.0
instruct
Data_Structure
Data_Structure_35041_I
### Question You are given an unsorted list of integers. Your task is to implement the Pancake Sort algorithm to sort the list. Pancake Sorting is a variation of the selection sort wherein you repeatedly flip (reverse) subarrays to move the largest unsorted element to its correct position. Write a function `pancake_s...
def flip(arr, k): """ Reverses the order of the first k elements in the array arr. """ arr[:k] = arr[:k][::-1] def find_max_index(arr, n): """ Finds the index of the maximum element in arr upto the first n elements. """ return max(range(n), key=lambda i: arr[i]) def pancake_sort(arr): ...
from solution import pancake_sort def test_already_sorted(): assert pancake_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted(): assert pancake_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_mixed_elements(): assert pancake_sort([3, 2, 4, 1]) == [1, 2, 3, 4] assert pancake_sort([10,...
[ { "docstring": "Reverses the order of the first k elements in the array arr.", "function_declaration": "def flip(arr, k):", "function_name": "flip", "parameter_list": "(arr, k)" }, { "docstring": "Finds the index of the maximum element in arr upto the first n elements.", "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 pancake_sort(arr):\n \"\"\"\n Sorts a list using the Pancake Sort algorithm.\n \n Args:\n arr (list): The list of integers to be sorted.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035041", "row_id": 35041, "seed_ids": "[9]" }
0.800475
Data_Structure_35041
I
[ "flip", "find_max_index", "pancake_sort" ]
3
[ [ "pancake_sort", "find_max_index" ], [ "pancake_sort", "flip" ] ]
2
[]
false
[]
false
pytest
true
[]
true
168e67c0c4549f16086b4e6fea158501ec8dd9c6
4a68b27a36f66eb94031593962f410376085df86
v1.0
instruct
Data_Structure
Data_Structure_35043_I
### Problem: Enhanced Bogo Sort **Background**: Alice is learning about sorting algorithms in her computer science class. She has encountered the Bogo Sort algorithm and finds it fascinating despite its impracticality. She wants to explore it further by implementing a slightly modified version that stops after a certa...
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 enhanced_bogo_sort(arr, max_iterations): """ Sort the array using an enhanced version of Bogo Sort. If the array is not sorted within...
from solution import enhanced_bogo_sort def test_enhanced_bogo_sort_sorted_array(): assert enhanced_bogo_sort([1, 2, 3, 4, 5], 1000) == [1, 2, 3, 4, 5] def test_enhanced_bogo_sort_unsorted_array_negative_iterations(): assert enhanced_bogo_sort([5, 4, 3, 2, 1], 0) == [5, 4, 3, 2, 1] def test_enhanced_bogo_sor...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sort the array using an enhanced version of Bogo Sort.\nIf the array is not sorted within the given num...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef enhanced_bogo_sort(arr: list, max_iterations: int) -> list:\n def is_sorted(arr):\n \"\"\" Helper function to check if the arra...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035043", "row_id": 35043, "seed_ids": "[16]" }
0.577948
Data_Structure_35043
I
[ "is_sorted", "enhanced_bogo_sort" ]
2
[ [ "enhanced_bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4a1dab5e29a697ec15f75c78552d3ea11d122fc
2fd4a5149fb797dec4ee34c05cbadb14cce42201
v1.0
instruct
Data_Structure
Data_Structure_35124_I
### Merge Sort Implementation and Extension You are tasked to implement the Merge Sort algorithm with a slight twist. Instead of sorting a list of integers, you are required to sort a list of tuples based on the sum of the elements in the tuples. Your implementation should maintain the stability of the original sortin...
from typing import List, Tuple def merge_sort_tuples(arr: List[Tuple[int, int]]) -> List[Tuple[int, int]]: if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort_tuples(arr[:mid]) right = merge_sort_tuples(arr[mid:]) return merge(left, right) def merge(left: List[Tupl...
from solution import merge_sort_tuples def test_merge_sort_empty_list(): assert merge_sort_tuples([]) == [] def test_merge_sort_single_element(): assert merge_sort_tuples([(5, 2)]) == [(5, 2)] def test_merge_sort_already_sorted(): assert merge_sort_tuples([(1, 3), (2, 2), (5, 1)]) == [(1, 3), (2, 2), (5,...
[ { "docstring": null, "function_declaration": "def merge_sort_tuples(arr):", "function_name": "merge_sort_tuples", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef merge_sort_tuples(arr: List[Tuple[int, int]]) -> List[Tuple[int, int]]:\n if len(arr) <= 1:\n return arr\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035124", "row_id": 35124, "seed_ids": "[12]" }
0.615834
Data_Structure_35124
I
[ "merge_sort_tuples", "merge" ]
2
[ [ "merge_sort_tuples", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3b501d6f6153e67985b174294f75ca6af957007e
e1c606c3ebe11c10072de31df819ba64a1bb0a7a
v1.0
instruct
Data_Structure
Data_Structure_35179_I
**Goal**: Construct a full binary tree from given preorder and postorder traversal arrays and obtain its inorder traversal. **Scenario**: A software company is working on a new feature for their web-based visualization tool. The tool is supposed to reconstruct a full binary tree using preorder and postorder traversal...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def build_tree(pre, pre_start, pre_end, post, post_start, post_end): if pre_start > pre_end or post_start > post_end: return None root = TreeNode(pre[pre_start]) if pre_start == pre_e...
def test_construct_inorder_tree_example_case(): pre = [1, 2, 4, 5, 3, 6, 7] post = [4, 5, 2, 6, 7, 3, 1] assert construct_inorder_tree(pre, post) == [4, 2, 5, 1, 6, 3, 7] def test_construct_inorder_tree_single_node(): pre = [1] post = [1] assert construct_inorder_tree(pre, post) == [1] def tes...
[]
[ 0, 0, 0, 0, 1, 0, 1, 1, 1 ]
4
medium
0.444
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Dict\n\nclass TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035179", "row_id": 35179, "seed_ids": "[300]" }
0.557454
Data_Structure_35179
I
[ "build_tree", "inorderTraversal", "construct_inorder_tree" ]
3
[ [ "construct_inorder_tree", "build_tree" ], [ "construct_inorder_tree", "inorderTraversal" ] ]
2
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
24d95957eb85cfd8dcd9dc72ea1e7d9a12c1a52e
614815fe597d5c8e7756b863ac566218cb92ae8d
v1.0
instruct
Data_Structure
Data_Structure_35188_I
### Diffie-Hellman Key Exchange Function and Testing #### Introduction Alice and Bob want to establish a secure communication channel. They will use the Diffie-Hellman Key Exchange protocol to share a secret key. Your task is to complete the implementation of this protocol, considering efficiency and correctness. ###...
import random from math import gcd # Function to check if a number is prime def prime_check(num: int) -> bool: 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 nu...
from solution import ( prime_check, euler_totient, find_order, 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(3) == Tr...
[ { "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...
[ 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 prime_check(num: int) -> bool:\n \"\"\"\n Checks if a number is prime.\n \"\"\"\n if num <= 1:\n return False\n if ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035188", "row_id": 35188, "seed_ids": "[146]" }
0.484648
Data_Structure_35188
I
[ "prime_check", "euler_totient", "find_order", "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" ]
11
[ [ "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...
11
[]
false
[]
false
pytest
true
[]
true
70521038e943acbadf44504a17f61db9609b00c0
56b60a6d7e33c2a46f8f0853e50b194ca470433f
v1.0
instruct
Data_Structure
Data_Structure_35287_I
### RSA Encryption Coding Challenge #### Objective Implement functions to generate RSA keys, encrypt, and decrypt text messages. This exercise will test your understanding of RSA encryption, prime number generation, and modular arithmetic. #### Scenario You are working on a secure communication application. To ensure...
import random from sympy import isprime, mod_inverse def generate_prime_candidate(length): """Generate an odd integer randomly""" p = random.getrandbits(length) # apply a mask to set MSB and LSB to 1 p |= (1 << length - 1) | 1 return p def generate_prime_number(length=1024): """Generate a prim...
import pytest from solution import generate_key_pairs, encrypt_message, decrypt_message def test_generate_key_pairs(): public_key, private_key = generate_key_pairs(16) assert len(public_key) == 2 assert len(private_key) == 2 assert public_key[1] == private_key[1] def test_encrypt_decrypt_message(): ...
[ { "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 'length' bits", "function_declaration": "def generat...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef gcd(a, b):\n while b != 0:\n a, b = b, a % b\n return a\n\ndef mod_inverse(a, m):\n m0, x0, x1 = m, 0, 1\n if m == 1:\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035287", "row_id": 35287, "seed_ids": "[154]" }
0.586276
Data_Structure_35287
I
[ "generate_prime_candidate", "generate_prime_number", "generate_key_pairs", "gcd", "encrypt_message", "decrypt_message" ]
6
[ [ "generate_key_pairs", "gcd" ], [ "generate_key_pairs", "generate_prime_number" ], [ "generate_prime_number", "generate_prime_candidate" ] ]
3
[]
false
[]
false
pytest
true
[ "sympy" ]
false
9111b225071cc4ffb1ebf87f3b1703c498932d14
e67b819c452758c8f6cd6f60a2cc452df83ecdf3
v1.0
instruct
Data_Structure
Data_Structure_35309_I
#### Context: You are developing a cryptographic tool that relies on number theory. To complete this tool, you need to implement two critical mathematical functions. One will compute the modular inverse, which is essential for decrypting messages. #### Task: Implement the following two functions: 1. `extended_gcd(a: ...
def extended_gcd(a, b): """ Implements the Extended Euclidean Algorithm. Returns a tuple (s, t, gcd) where s and t are such that a * s + b * t = gcd(a, b). """ if a == 0: return (0, 1, b) else: s1, t1, gcd = extended_gcd(b % a, a) s = t1 - (b // a) * s1 t = s1 ...
from solution import extended_gcd, modular_inverse def test_extended_gcd(): # Test cases for extended_gcd assert extended_gcd(30, 20) == (1, -1, 10) assert extended_gcd(20, 30) == (-1, 1, 10) assert extended_gcd(7, 3) == (1, -2, 1) assert extended_gcd(3, 7) == (-2, 1, 1) assert extended_gcd(10,...
[ { "docstring": "Implements the Extended Euclidean Algorithm.\nReturns a tuple (s, t, gcd) where s and t are such that a * s + b * t = gcd(a, b).", "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the mod...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def extended_gcd(a, b):\n \"\"\"\n Implements the Extended Euclidean Algorithm.\n Returns a tuple (s, t, gcd) where a * s + b * t = gcd(a, b).\n \...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00035309", "row_id": 35309, "seed_ids": "[161]" }
0.572855
Data_Structure_35309
I
[ "extended_gcd", "modular_inverse" ]
2
[ [ "modular_inverse", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
40b0a301a1d4bb118ca80e0660adc53a9a1e9d2e
76ac66e9a83d27e2c175f9b949c91b8c721a94a0
v1.0
instruct
Data_Structure
Data_Structure_35310_I
### Scenario You are developing a system that processes large datasets, and sorting these datasets efficiently is crucial. You've decided to use Merge Sort due to its consistent performance and stability. ### Task Implement the Merge Sort algorithm in Python following the principles described. The function should take...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts the given array using the merge sort algorithm with optimized in-place merge. """ if len(arr) > 1: mid = len(arr) // 2 left_half = arr[:mid] right_half = arr[mid:] merge_sort(left_half) ...
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 the given array using the merge sort algorithm with optimized in-place merge.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(arr, left_half, right_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n\n def merge(left: List[int], right: Li...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035310", "row_id": 35310, "seed_ids": "[12]" }
0.644296
Data_Structure_35310
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2f950c5c98af8bcc0e04f807a62c410f5771deb9
9e6d0ccea155918634e251a021e030e0cac64d37
v1.0
instruct
Data_Structure
Data_Structure_35426_I
### Pancake Sorting Assessment Question #### Scenario You have been hired as an intern at a software company. Your first task is to implement a classic sorting algorithm that sorts a stack of pancakes by size. Specifically, you need to sort arbitrary arrays using the Pancake Sort algorithm. The goal is to familiarize ...
from typing import List def flip(arr: List[int], k: int) -> None: """ Helper function to reverse the order of the first k elements of the array. """ arr[:k] = arr[:k][::-1] def find_max_index(arr: List[int], n: int) -> int: """ Helper function to find the index of the maximum element in the ar...
from solution import pancake_sort def test_pancake_sort_example_1(): assert pancake_sort([3, 2, 4, 1]) == [1, 2, 3, 4] def test_pancake_sort_example_2(): assert pancake_sort([0, -1, 5, 3, 2]) == [-1, 0, 2, 3, 5] def test_pancake_sort_empty(): assert pancake_sort([]) == [] def test_pancake_sort_single_el...
[ { "docstring": "Helper function to reverse the order of the first k elements of the array.", "function_declaration": "def flip(arr, k):", "function_name": "flip", "parameter_list": "(arr, k)" }, { "docstring": "Helper function to find the index of the maximum element in the arr[0:n].", "...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef flip(arr: List[int], k: int) -> None:\n \"\"\"\n Reverses the order of the first k elements in the given list.\n \"\"\...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035426", "row_id": 35426, "seed_ids": "[9]" }
0.751676
Data_Structure_35426
I
[ "flip", "find_max_index", "pancake_sort" ]
3
[ [ "pancake_sort", "find_max_index" ], [ "pancake_sort", "flip" ] ]
2
[]
false
[]
false
pytest
true
[]
true
29c498b44defcb81bd8e12d02d035f66b7a00ba0
58b04c8e6cd75a9820e52e5f0c7e797acd0b83b1
v1.0
instruct
Data_Structure
Data_Structure_35474_I
### Diffie-Hellman Key Exchange Implementation #### Scenario Alice and Bob want to securely share a secret key using the Diffie-Hellman key exchange method. You are required to implement the algorithm to facilitate this secure key exchange. #### Function Implementation **Function 1: Prime Check** ```python def prime...
from math import isqrt def prime_check(num): """ Return True if num is a prime number else return False. """ 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 ...
from solution import prime_check, euler_totient, find_order, find_primitive_root, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(2) is True assert prime_check(17) is True assert prime_check(18) is False assert prime_check(29) is True def test_euler_totient(): assert euler_t...
[ { "docstring": "Return True if num is a prime number else return False.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Return the count of numbers coprime to n.", "function_declaration": "def euler_totient(n...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_check(num):\n \"\"\"\n Return True if num is a prime number else return False.\n \"\"\"\n if num <= 1:\n return False\n if num...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00035474", "row_id": 35474, "seed_ids": "[146]" }
0.532493
Data_Structure_35474
I
[ "prime_check", "euler_totient", "gcd", "find_order", "find_primitive_root", "diffie_hellman_key_exchange" ]
6
[ [ "diffie_hellman_key_exchange", "find_primitive_root" ], [ "diffie_hellman_key_exchange", "prime_check" ], [ "euler_totient", "gcd" ], [ "find_order", "prime_check" ], [ "find_primitive_root", "gcd" ], [ "find_primitive_root", "prime_check" ] ]
6
[]
false
[]
false
pytest
true
[]
true
cb48199e7733e56a9c163e12fd355cc099d476ee
1a8c0d3f885ea9a3b6636d7a36ce7233fbc69716
v1.0
instruct
Data_Structure
Data_Structure_35496_I
### Pancake Sort Implementation You have been tasked to implement the **Pancake Sort** algorithm, which sorts an array by repetitively flipping subarrays. Write a function `pancake_sort(arr: List[int]) -> List[int]` that sorts the provided list of integers using the Pancake Sort technique. #### Input - `arr`: A list...
def flip(arr, k): """ Helper function to reverse the order of the first k elements of the array. """ arr[:k] = arr[:k][::-1] def pancake_sort(arr): """ Function to sort the array using Pancake Sort technique. """ n = len(arr) for size in range(n, 1, -1): # Find index of the ...
from solution import pancake_sort def test_pancake_sort_example(): assert pancake_sort([3, 2, 4, 1]) == [1, 2, 3, 4] assert pancake_sort([8, 5, 7, 3, 2]) == [2, 3, 5, 7, 8] def test_pancake_sort_single_element(): assert pancake_sort([1]) == [1] def test_pancake_sort_empty(): assert pancake_sort([]) =...
[ { "docstring": "Helper function to reverse the order of the first k elements of the array.", "function_declaration": "def flip(arr, k):", "function_name": "flip", "parameter_list": "(arr, k)" }, { "docstring": "Function to sort the array using Pancake Sort technique.", "function_declarat...
[ 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 flip(arr, k):\n \"\"\"\n Helper function to reverse the order of the first k elements of the list.\n \"\"\"\n left = 0\n right = k - 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035496", "row_id": 35496, "seed_ids": "[9]" }
0.73995
Data_Structure_35496
I
[ "flip", "pancake_sort" ]
2
[ [ "pancake_sort", "flip" ] ]
1
[]
false
[]
false
pytest
true
[]
true
858e752069557ced5f03818bbd889cee6abbbcb3
89b1351985ca2e985deeb8cbb16141843f520847
v1.0
instruct
Data_Structure
Data_Structure_35518_I
Heap Sort is a well-known algorithm that sorts an array in-place using the properties of the heap data structure. We have two variations: `max_heap_sort` and `min_heap_sort`, which use max-heap and min-heap respectively to achieve ascending order sorting. #### Task Given the following partial implementations of heap s...
def max_heapify(arr, n, i): """ Helper function to maintain the max-heap property. """ largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: largest = right if...
import pytest from solution import max_heap_sort, min_heap_sort def test_max_heap_sort_basic(): assert max_heap_sort([4, 10, 3, 5, 1]) == [1, 3, 4, 5, 10] def test_min_heap_sort_basic(): assert min_heap_sort([4, 10, 3, 5, 1]) == [1, 3, 4, 5, 10] def test_max_heap_sort_empty(): assert max_heap_sort([]) ==...
[ { "docstring": "Helper function to maintain the max-heap property.", "function_declaration": "def max_heapify(arr, n, i):", "function_name": "max_heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Sorts an array using max-heap.", "function_declaration": "def max_heap_sort(arr):...
[ 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "# Helper function to maintain the max heap property.\ndef max_heapify(arr, end, i):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if le...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00035518", "row_id": 35518, "seed_ids": "[8]" }
0.745255
Data_Structure_35518
I
[ "max_heapify", "max_heap_sort", "min_heapify", "min_heap_sort" ]
4
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
abd0c798d75a985934847f3acc7a53a2945e0653
177091341b6670f9f14a531f189b38344d9a779b
v1.0
instruct
Data_Structure
Data_Structure_35529_I
### Insertion Sort Enhancements Using the Insertion Sort algorithm above as a foundation, enhance the algorithm to handle larger datasets more efficiently. Implement a function `enhanced_insertion_sort` that: 1. Uses binary search to find the correct position of the element to be inserted, reducing the number of compa...
from typing import List def binary_search(arr: List[int], val: int, start: int, end: int) -> int: """ Perform a binary search to find the insertion position for val in arr[start:end] """ while start < end: mid = (start + end) // 2 if arr[mid] < val: start = mid + 1 e...
from solution import enhanced_insertion_sort def test_enhanced_insertion_sort_simple(): assert enhanced_insertion_sort([64, 34, 25, 12, 22, 11, 90]) == [11, 12, 22, 25, 34, 64, 90] def test_enhanced_insertion_sort_with_duplicates(): assert enhanced_insertion_sort([5, 2, 9, 1, 5, 6]) == [1, 2, 5, 5, 6, 9] def...
[ { "docstring": "Perform a binary search to find the insertion position for val in arr[start:end]", "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" }, { "docstring": "Sorts the array of integers i...
[ 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 binary_search(arr: List[int], val: int, start: int, end: int) -> int:\n \"\"\"Use binary search to find the correct insertio...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035529", "row_id": 35529, "seed_ids": "[7]" }
0.586442
Data_Structure_35529
I
[ "binary_search", "enhanced_insertion_sort" ]
2
[ [ "enhanced_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
86f81035674e57ebbceee8c8ff70c90c9e33be4e
aedfc378e1c53a312e8216f68455d77ecfe66c9b
v1.0
instruct
Data_Structure
Data_Structure_35567_I
### Merge Sort and Array Shuffling #### Context You're creating a large dataset of records that need to be sorted and later analyzed. The dataset is generated randomly, sorted for specific analyses, and shuffled again for testing purposes. #### Task Write two functions: 1. **merge_sort(arr)** 2. **shuffle_array(arr)*...
def merge_sort(arr): if len(arr) <= 1: return arr mid = len(arr) // 2 left, right = merge_sort(arr[:mid]), merge_sort(arr[mid:]) merge(left, right, arr) return arr def merge(left, right, merged): left_cursor, right_cursor = 0, 0 while left_cursor < len(left) and right_cursor < len(r...
from solution import merge_sort, shuffle_array def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_array():...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right, merged):", "function_name": "merge", "parameter_list": "(left, right, merged)" }...
[ 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 if len(arr) <= 1:\n return arr\n mid = len(arr) // 2\n left, right = merge_sort(arr[:mid]), merge_sort(arr[mid:])\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035567", "row_id": 35567, "seed_ids": "[12]" }
0.566704
Data_Structure_35567
I
[ "merge_sort", "merge", "shuffle_array" ]
3
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f5cc5ff531f6b044358045cbcae3eea85f17e33c
6106d87db70ca87b413af0a313c1a92d9308d349
v1.0
instruct
Data_Structure
Data_Structure_35581_I
### Problem: Maximum Flow with Intermediate Constraints You are provided with a flow network represented by a capacity matrix. Compute the maximum flow from a given source to a sink using the algorithms discussed. Additionally, incorporate an intermediate constraint where a certain node must be visited exactly once wi...
from collections import deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: current = queue.popleft() for next in range(len(capacity)): if not visited[next] and capacity[current][n...
import pytest from solution import constrained_max_flow def test_example_case(): capacity = [ [0, 10, 10, 0], [0, 0, 1, 10], [0, 0, 0, 10], [0, 0, 0, 0] ] source = 0 sink = 3 intermediate = 2 assert constrained_max_flow(capacity, source, sink, intermediate) == 10...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom collections import deque\n\ndef bfs(rGraph, s, t, parent):\n visited = [False] * len(rGraph)\n queue = deque([s])\n vis...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035581", "row_id": 35581, "seed_ids": "[240]" }
0.606429
Data_Structure_35581
I
[ "bfs", "edmonds_karp", "constrained_max_flow" ]
3
[ [ "constrained_max_flow", "edmonds_karp" ], [ "edmonds_karp", "bfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
197f87a3f8f5180d4a48c130613a4f57bc1f03c8
496d9c7e12e8c816c9584d587ab29239d076ef29
v1.0
instruct
Data_Structure
Data_Structure_35660_I
### Diophantine Equation Solver **Problem Statement**: Implement a function to solve the Diophantine equation \( ax + by = gcd(a, b) \) using the Extended Euclidean Algorithm. **Function Signature**: ```python def solve_diophantine(a: int, b: int) -> Tuple[int, int, int]: """ Solves the equation ax + by = gcd...
from typing import Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: """ Implementation of the Extended Euclidean Algorithm. Returns x, y, and gcd such that a*x + b*y = gcd. """ if b == 0: return (1, 0, a) else: x1, y1, gcd = extended_gcd(b, a % b) x = y1 ...
from solution import solve_diophantine def test_solve_diophantine_common_case(): x, y, g = solve_diophantine(30, 12) assert g == 6 assert 30 * x + 12 * y == g def test_solve_diophantine_coprime_case(): x, y, g = solve_diophantine(101, 10) assert g == 1 assert 101 * x + 10 * y == g def test_so...
[ { "docstring": "Implementation of the Extended Euclidean Algorithm.\nReturns x, y, and gcd such that a*x + b*y = gcd.", "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": "Solves the equation ax + by = gcd(a, b) to...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import Tuple\n\ndef extended_gcd(a: int, b: int) -> Tuple[int, int, int]:\n if a == 0:\n return (b, 0, 1)\n else:\n gcd, x1, y...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00035660", "row_id": 35660, "seed_ids": "[156]" }
0.632636
Data_Structure_35660
I
[ "extended_gcd", "solve_diophantine" ]
2
[ [ "solve_diophantine", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f40e3cbdf322c583d27aa679340a30e76cf2583
a890ce88f07e108a849a2d2b066fe31d622dd1eb
v1.0
instruct
Data_Structure
Data_Structure_35669_I
**Prime Sequence Generator** ### Description You are tasked with creating an algorithm to generate a sequence of the first `k` prime numbers. The function should utilize the primality checking logic to ensure each number in the sequence is prime. ### Function Signature ```python def generate_primes(k: int) -> List[in...
from typing import List def is_prime(n: int) -> bool: if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def gene...
from solution import generate_primes def test_generate_primes_example_cases(): assert generate_primes(5) == [2, 3, 5, 7, 11] assert generate_primes(10) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] def test_generate_primes_smallest_k(): assert generate_primes(1) == [2] def test_generate_primes_known_values(): ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def generate_primes(k):", "function_name": "generate_primes", "parameter_list": "(k)" } ]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035669", "row_id": 35669, "seed_ids": "[143]" }
0.668805
Data_Structure_35669
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7a827554363aa2c37936203841f0776eceb36ec2
3c4d0171965390b896c15ec1bb3ee7157e54896e
v1.0
instruct
Data_Structure
Data_Structure_35688_I
In graph theory, a *strongly connected component* (SCC) of a directed graph is a maximal subset of vertices such that every vertex in the subset is reachable from every other vertex in the subset. A graph is said to be *strongly connected* if every vertex is part of a single SCC. Your task is to implement a function to...
from typing import List, Tuple def dfs(graph: List[List[int]], v: int, visited: List[bool]): """Depth first search""" stack = [v] while stack: node = stack.pop() if not visited[node]: visited[node] = True for neighbor in graph[node]: if not visited[ne...
from solution import is_strongly_connected def test_is_strongly_connected_case_1(): assert is_strongly_connected(5, [(0, 1), (1, 2), (2, 0), (1, 3), (3, 4), (4, 1)]) == True def test_is_strongly_connected_case_2(): assert is_strongly_connected(4, [(0, 1), (1, 2), (2, 0), (2, 3)]) == False def test_is_strongl...
[ { "docstring": "Depth first search", "function_declaration": "def dfs(graph, v, visited):", "function_name": "dfs", "parameter_list": "(graph, v, visited)" }, { "docstring": null, "function_declaration": "def is_strongly_connected(vertex_count, edges):", "function_name": "is_strongly...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import collections\nfrom typing import List, Tuple\n\ndef is_strongly_connected(vertex_count: int, edges: List[Tuple[int, int]]) -> bool:\n '''\n Determ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035688", "row_id": 35688, "seed_ids": "[225]" }
0.54725
Data_Structure_35688
I
[ "dfs", "is_strongly_connected" ]
2
[ [ "is_strongly_connected", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83d6ff1c4c3137c95eeb4b8911777158c9befb1c
b2c4115765bb71f26cf1e467feb0a6a9e8f9dbf4
v1.0
instruct
Data_Structure
Data_Structure_35735_I
You are given a directed network graph where each edge has a positive integer capacity. Your task is to compute the maximum flow from the source node to the sink node using one of the algorithms discussed: Ford-Fulkerson, Edmonds-Karp, or Dinic's algorithm. ### Input: - The graph is represented as a matrix `capacity` ...
from collections import deque def bfs(capacity, source, sink, parent): """ Perform BFS to find a path from source to sink with available capacity. Returns True if a path is found and False otherwise. """ visited = [False] * len(capacity) queue = deque([source]) visited[source] = True ...
def test_max_flow_simple_case(): capacity = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0] ] source = 0 sink = 5 assert max_flow(capacity, source, sink) == 23 def test_max...
[ { "docstring": "Perform BFS to find a path from source to sink with available capacity.\nReturns True if a path is found and False otherwise.", "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = [False] * len(capacity)\n queue = deque([source])\n visited[sou...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035735", "row_id": 35735, "seed_ids": "[240]" }
0.561949
Data_Structure_35735
I
[ "bfs", "max_flow" ]
2
[ [ "max_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
d62a00c9c181b7198275276974ff4d2d7ce6f0c9
ac54cb0f0e6c2fa9cf731e7287b1321ee76be55f
v1.0
instruct
Data_Structure
Data_Structure_35742_I
#### Context: Imagine you are developing a low-level system where standard arithmetic operations are restricted. Instead, you must use bitwise operations to compute results. #### Task: Implement a function to multiply two non-negative integers without using the '*' operator. Similar to the provided bitwise addition c...
def bitwise_add(a, b): while b != 0: carry = a & b a = a ^ b b = carry << 1 return a def multiply(x: int, y: int) -> int: result = 0 while y > 0: if y & 1: result = bitwise_add(result, x) x <<= 1 y >>= 1 return result
from solution import multiply def test_multiply_basic(): assert multiply(3, 5) == 15 assert multiply(0, 7) == 0 assert multiply(4, 6) == 24 assert multiply(1, 1) == 1 assert multiply(7, 8) == 56 def test_multiply_large_numbers(): assert multiply(123, 456) == 56088 assert multiply(1000, 100...
[ { "docstring": null, "function_declaration": "def bitwise_add(a, b):", "function_name": "bitwise_add", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def multiply(x, y):", "function_name": "multiply", "parameter_list": "(x, y)" } ]
[ 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 bitwise_add(a, b):\n \"\"\"\n Adds two integers using bitwise operations.\n \n Parameters:\n a (int): An integer.\n b (int): Another int...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035742", "row_id": 35742, "seed_ids": "[209]" }
0.667113
Data_Structure_35742
I
[ "bitwise_add", "multiply" ]
2
[ [ "multiply", "bitwise_add" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0d89c600295c72f47d276033c0d6054a13893cb9
3be025428a13b5d1c5ec3e2480b6850a22fe32ba
v1.0
instruct
Data_Structure
Data_Structure_35780_I
### Code Assessment: Radix Sort Custom Implementation #### Objective Given a list of non-negative integers, implement a custom variant of Radix Sort that sorts the list in descending order. #### Task Requirements 1. Implement a function `custom_radix_sort(arr: List[int]) -> List[int]` that: * Sorts the list using...
def counting_sort(arr, exp): n = len(arr) output = [0] * n count = [0] * 10 for i in range(n): index = arr[i] // exp count[(index % 10)] += 1 for i in range(8, -1, -1): count[i] += count[i + 1] for i in range(n - 1, -1, -1): index = arr[i] // exp ...
from solution import custom_radix_sort def test_custom_radix_sort_example_1(): assert custom_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [802, 170, 90, 75, 66, 45, 24, 2] def test_custom_radix_sort_example_2(): assert custom_radix_sort([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1] def test_custom_radix_sort_empty...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp):", "function_name": "counting_sort", "parameter_list": "(arr, exp)" }, { "docstring": null, "function_declaration": "def custom_radix_sort(arr):", "function_name": "custom_radix_sort", "parameter_list": "(a...
[ 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 counting_sort(arr: List[int], exp: int) -> List[int]:\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n\n # Co...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00035780", "row_id": 35780, "seed_ids": "[15]" }
0.634937
Data_Structure_35780
I
[ "counting_sort", "custom_radix_sort" ]
2
[ [ "custom_radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0b5a902c57ccc41b355cb4785b1b27c0a12ed73c
1f4b62097351d1b22ec27a061efcf4773f4fd06d
v1.0
instruct
Data_Structure
Data_Structure_35782_I
### Radix Sort with Custom Base **Context**: You have been tasked with implementing a version of the radix sort algorithm that sorts an array of non-negative integers but allows for the digits to be interpreted in any arbitrary base `b` (2-10). **Objective**: Write a function `custom_base_radix_sort(arr, base)` that...
def custom_base_radix_sort(arr, base): if len(arr) == 0: return arr max_value = max(arr) exp = 1 # Exponent to extract digit while max_value // exp > 0: arr = counting_sort_by_digit(arr, exp, base) exp *= base return arr def counting_sort_by_digit(arr, exp, base):...
from solution import custom_base_radix_sort def test_custom_base_radix_sort_base10(): arr = [170, 45, 75, 90, 802, 24, 2, 66] base = 10 assert custom_base_radix_sort(arr, base) == [2, 24, 45, 66, 75, 90, 170, 802] def test_custom_base_radix_sort_base2(): arr = [13, 1, 7, 20, 5] base = 2 assert...
[ { "docstring": null, "function_declaration": "def custom_base_radix_sort(arr, base):", "function_name": "custom_base_radix_sort", "parameter_list": "(arr, base)" }, { "docstring": null, "function_declaration": "def counting_sort_by_digit(arr, exp, base):", "function_name": "counting_...
[ 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 custom_base_radix_sort(arr: List[int], base: int) -> List[int]:\n if not arr:\n return arr\n\n def counting_sort(a...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035782", "row_id": 35782, "seed_ids": "[15]" }
0.642286
Data_Structure_35782
I
[ "custom_base_radix_sort", "counting_sort_by_digit" ]
2
[ [ "custom_base_radix_sort", "counting_sort_by_digit" ] ]
1
[]
false
[]
false
pytest
true
[]
true
77ebcaf47db575e64652b0b3a713fef5a4ec305f
fccc1c5305b7e96c8115d0c8770577f192933856
v1.0
instruct
Data_Structure
Data_Structure_35786_I
### Question #### Problem Statement You are asked to implement a simple RSA encryption system. Your program will generate RSA keys, encrypt a message using the public key, and decrypt it using the private key. You are provided with template functions, and your task is to complete them, ensuring they handle edge cases ...
import random from sympy import isprime, mod_inverse def generate_key(k, seed=None): if seed: random.seed(seed) def get_prime(bits): while True: num = random.getrandbits(bits) if isprime(num): return num e = 65537 half_bits = k // 2 ...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(32) 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 = 32 data = 42 n, e, d = ...
[ { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "parameter_list": "(k, seed=None)" }, { "docstring": null, "function_declaration": "def modinv(a, m):", "function_name": "modinv", "parameter_list": "(a, m)" }, { ...
[ 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_key(k, seed=None):\n if seed:\n random.seed(seed)\n \n def get_prime...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00035786", "row_id": 35786, "seed_ids": "[154]" }
0.64364
Data_Structure_35786
I
[ "generate_key", "modinv", "egcd", "encrypt", "decrypt" ]
5
[ [ "modinv", "egcd" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
ed724b3d3096d4d168bed8e18f35904897af2f00
6f18c59f1eece4fa51bfb365c29a2f7d75895fcf
v1.0
instruct
Data_Structure
Data_Structure_35837_I
Optimized GCD and LCM Calculator #### Context You are a developer tasked with enhancing the performance of a numeric utility library. Your goal is to write highly optimized functions for calculating the greatest common divisor (GCD) and the least common multiple (LCM) of given integers. Your functions should also corr...
def optimized_gcd(a, b): """ Computes the greatest common divisor (GCD) of two integers a and b. Uses the Euclidean algorithm. Parameters: a (int): first integer b (int): second integer Returns: int: the GCD of a and b """ while b: a, b = b, a % b return abs...
from solution import optimized_gcd, optimized_lcm def test_optimized_gcd(): assert optimized_gcd(54, 24) == 6 assert optimized_gcd(-54, 24) == 6 assert optimized_gcd(0, 24) == 24 assert optimized_gcd(24, 0) == 24 assert optimized_gcd(101, 103) == 1 def test_optimized_gcd_negatives(): assert op...
[ { "docstring": "Computes the greatest common divisor (GCD) of two integers a and b.\nUses the Euclidean algorithm.\n\nParameters:\na (int): first integer\nb (int): second integer\n\nReturns:\nint: the GCD of a and b", "function_declaration": "def optimized_gcd(a, b):", "function_name": "optimized_gcd", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_gcd(a, b):\n \"\"\"\n Computes the greatest common divisor (GCD) of two integers using the Euclidean algorithm.\n \"\"\"\n if a == 0...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00035837", "row_id": 35837, "seed_ids": "[166]" }
0.596589
Data_Structure_35837
I
[ "optimized_gcd", "optimized_lcm" ]
2
[ [ "optimized_lcm", "optimized_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8f40dce946051be72667903c5718861aeb70a48d
30d378882a957546abcbb31538844aa5ce92901a
v1.0
instruct
Data_Structure
Data_Structure_35910_I
### Coding Challenge: Implement a Robust Maximum Flow Solver Given the implementations of three different maximum flow algorithms (Ford-Fulkerson, Edmonds-Karp, and Dinic's Algorithm), your task is to implement a function which can decide which algorithm to use based on the given graph parameters. #### Function Signa...
from typing import List from collections import deque def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v in range(len(capacity)): if visited[v] == Fals...
def test_max_flow_solver_no_flow(): capacity = [ [0, 0], [0, 0] ] assert max_flow_solver(capacity, 0, 1) == 0 def test_max_flow_solver_simple(): capacity = [ [0, 1], [0, 0] ] assert max_flow_solver(capacity, 0, 1) == 1 def test_max_flow_solver_edmonds_karp_s...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.111
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = [False] * len(capacity)\n queue = deque([...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00035910", "row_id": 35910, "seed_ids": "[240]" }
0.595113
Data_Structure_35910
I
[ "bfs", "edmonds_karp", "dinic_bfs", "dinic_dfs", "dinics_algorithm", "graph_density", "max_flow_solver" ]
7
[ [ "dinics_algorithm", "dinic_bfs" ], [ "dinics_algorithm", "dinic_dfs" ], [ "edmonds_karp", "bfs" ], [ "max_flow_solver", "dinics_algorithm" ], [ "max_flow_solver", "edmonds_karp" ], [ "max_flow_solver", "graph_density" ] ]
6
[]
false
[]
false
pytest
false
[]
true
5fb7532c05f0a6a5e5e27f4c2f68c2c1df983fd1
bc7c25809be3ea9e684de99cd8c190eacc66fa4c
v1.0
instruct
Data_Structure
Data_Structure_36007_I
### Array Rotation Challenge You are tasked with rotating an array of `n` elements to the right by `k` steps. Implement the rotation function in at least two different ways, demonstrating an in-depth understanding of time and space complexity considerations. You need to write two functions: 1. `rotate_in_place(array...
def rotate_in_place(array, k): """ Rotate the array to the right by k steps in-place using the array-reversing technique. """ n = len(array) k = k % n # In case k is larger than n reverse(array, 0, n - 1) reverse(array, 0, k - 1) reverse(array, k, n - 1) def reverse(array, start, end):...
from solution import rotate_in_place, rotate_with_slicing def test_rotate_in_place(): array = [1, 2, 3, 4, 5, 6, 7] k = 3 rotate_in_place(array, k) assert array == [5, 6, 7, 1, 2, 3, 4] def test_rotate_in_place_with_more_steps(): array = [1, 2, 3, 4, 5, 6, 7] k = 10 # Equivalent to rotating 3...
[ { "docstring": "Rotate the array to the right by k steps in-place using the array-reversing technique.", "function_declaration": "def rotate_in_place(array, k):", "function_name": "rotate_in_place", "parameter_list": "(array, k)" }, { "docstring": null, "function_declaration": "def rever...
[ 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 rotate_in_place(array: list[int], k: int) -> None:\n \"\"\"\n Rotate the array in-place using reversing technique.\n \"\"\"\n n = len(array)\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036007", "row_id": 36007, "seed_ids": "[283]" }
0.61209
Data_Structure_36007
I
[ "rotate_in_place", "reverse", "rotate_with_slicing" ]
3
[ [ "rotate_in_place", "reverse" ] ]
1
[]
false
[]
false
pytest
true
[]
true
760233b2ebcb6bd7ec6e0c7386e5f5c6b883ebac
04170a5e3d3a462a7ef7e736b88d5db90ee27c6a
v1.0
instruct
Data_Structure
Data_Structure_36008_I
### Prime Numbers within a Specified Range #### Scenario You're designing a feature for a cryptographic application that requires frequent checking for prime numbers within large ranges. For optimal performance, you need to implement a solution efficiently finding all prime numbers within a given range `[m, n]`. ####...
from typing import List def is_prime(num: int) -> bool: """ Helper function to check if a number is prime. """ if num <= 1: return False if num <= 3: return True if num % 2 == 0 or num % 3 == 0: return False i = 5 while i * i <= num: if num % i == 0 or nu...
from solution import find_primes_in_range def test_find_primes_in_range_basic(): assert find_primes_in_range(1, 10) == [2, 3, 5, 7] assert find_primes_in_range(10, 20) == [11, 13, 17, 19] assert find_primes_in_range(1, 1) == [] assert find_primes_in_range(20, 20) == [] def test_find_primes_in_range_la...
[ { "docstring": "Helper function to check if a number is prime.", "function_declaration": "def is_prime(num):", "function_name": "is_prime", "parameter_list": "(num)" }, { "docstring": "Returns a list of all prime numbers in the range [m, n].", "function_declaration": "def find_primes_in_...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(num: int) -> bool:\n \"\"\"\n Helper function to check if a number is prime.\n \"\"\"\n if num <= 1:\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036008", "row_id": 36008, "seed_ids": "[143]" }
0.605967
Data_Structure_36008
I
[ "is_prime", "find_primes_in_range" ]
2
[ [ "find_primes_in_range", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
78a8d7ed95f86f4f074591151d9061b1622f26c4
dfedd7e8e629c5ba9af9a7837549b79edf4ffbab
v1.0
instruct
Data_Structure
Data_Structure_36011_I
### Question: Implement LSD Radix Sort **Context**: You are given a list of non-negative integers that represents a sequence of priorities in a task management system. Your task is to sort this list in ascending order using the LSD (Least Significant Digit) variant of Radix Sort. The list can be very large, so the alg...
def counting_sort(arr, exp, simulation): n = len(arr) output = [0] * n # the output array elements that will have sorted arr count = [0] * 10 # initialize count array as 0 # store count of occurrences in count[] for i in range(n): index = arr[i] // exp count[index % 10] += 1 ...
from solution import radix_sort def test_radix_sort_standard_case(): assert radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_radix_sort_empty_list(): assert radix_sort([]) == [] def test_radix_sort_single_element(): assert radix_sort([5]) == [5] def test_radix_...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp, simulation):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", "function_name": "radix_sort...
[ 1, 1, 0 ]
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, simulation):\n n = len(arr)\n output = [0] * n # the output array elements that will have sorted arr\n count = [0] * 10 ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036011", "row_id": 36011, "seed_ids": "[15]" }
0.596185
Data_Structure_36011
I
[ "counting_sort", "radix_sort" ]
2
[ [ "radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3d4ff8855570eb4a84e62f040d177edd5b0d3ca1
a8aaa59ee9a08ec85f673c354c475f1443fc559b
v1.0
instruct
Data_Structure
Data_Structure_36020_I
#### Context: You have been tasked with simulating the random behavior of a user navigating through different pages on a website. The user's navigation pattern can be modeled using a Markov Chain where each page represents a state, and browsing behavior defines transition probabilities from one page to another. #### P...
import random def __choose_state(transitions): """ Choose the next state based on the given transition probabilities. Args: - transitions (dict): A dictionary of states and their corresponding probabilities. Returns: - next_state (str): The chosen next state. """ states = list(tra...
from solution import simulate_user_navigation, __choose_state # Example chain for tests chain = { 'Home': {'About': 0.1, 'Products': 0.6, 'Home': 0.3}, 'About': {'Home': 0.8, 'Products': 0.2}, 'Products': {'Home': 0.6, 'About': 0.1, 'Products': 0.3} } def test_choose_state(): transitions = {'Home': 0....
[ { "docstring": "Choose the next state based on the given transition probabilities.\n\nArgs:\n- transitions (dict): A dictionary of states and their corresponding probabilities.\n\nReturns:\n- next_state (str): The chosen next state.", "function_declaration": "def __choose_state(transitions):", "function...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef __choose_state(transition_dict):\n \"\"\"\n Chooses the next state based on the transition probabilities in `transition_dict`.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036020", "row_id": 36020, "seed_ids": "[232]" }
0.524305
Data_Structure_36020
I
[ "__choose_state", "simulate_user_navigation" ]
2
[ [ "simulate_user_navigation", "__choose_state" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb8d0797b785743a0d4ae16d8ecee9aa31c94f59
d8e8e666e2f39788a79df44acf924f044924dbd5
v1.0
instruct
Data_Structure
Data_Structure_36022_I
In this assignment, you are required to implement a secure communication setup using the Diffie-Hellman Key Exchange algorithm. Given a large prime number \( p \) and its primitive root \( a \), Alice and Bob need to securely exchange secret keys over an unsecured channel. The algorithm includes the following steps: 1...
import random from sympy import isprime, primerange def prime_check(num): """ Check if the given number is a prime number. """ return isprime(num) def find_primitive_root(n): """ Find primitive roots of 'n'. """ def gcd(a, b): while b: a, b = b, a % b return...
from solution import prime_check, find_primitive_root, alice_private_key, bob_private_key, alice_public_key, bob_public_key, alice_shared_key, bob_shared_key, diffie_hellman_key_exchange def test_prime_check(): assert prime_check(23) == True assert prime_check(24) == False def test_find_primitive_root(): ...
[ { "docstring": "Check if the given number is a prime number.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Find primitive roots of 'n'.", "function_declaration": "def find_primitive_root(n):", "function...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef prime_check(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": "", "prompt_id": "00036022", "row_id": 36022, "seed_ids": "[146]" }
0.405456
Data_Structure_36022
I
[ "prime_check", "find_primitive_root", "alice_private_key", "bob_private_key", "alice_public_key", "bob_public_key", "alice_shared_key", "bob_shared_key", "diffie_hellman_key_exchange" ]
9
[ [ "diffie_hellman_key_exchange", "alice_private_key" ], [ "diffie_hellman_key_exchange", "alice_public_key" ], [ "diffie_hellman_key_exchange", "alice_shared_key" ], [ "diffie_hellman_key_exchange", "bob_private_key" ], [ "diffie_hellman_key_exchange", "bob_pu...
8
[]
false
[]
false
pytest
true
[ "sympy" ]
false
8e31af291f1fca72843ccdc628bc1a6cb88ed872
7b97eb10cda89d26c08db5f6653eb066a3c38ce7
v1.0
instruct
Data_Structure
Data_Structure_36026_I
Extended Base Conversion You are working on a software that needs to frequently convert numbers between various bases. You are provided with two fundamental functions for base conversion – `int_to_base` and `base_to_int`. Now, you need to extend these functionalities to handle some additional features. **Task**: Impl...
def int_to_base(num, base): """Converts an integer to a given base and returns the string representation.""" if num == 0: return "0" digits = [] is_negative = False if num < 0: is_negative = True num = -num while num > 0: digits.append(int(num % base)) ...
def test_extended_base_conversion(): assert extended_base_conversion("-1A", 16, 8) == '-32' assert extended_base_conversion("101", 2, 10) == '5' assert extended_base_conversion("Z", 36, 10) == '35' assert extended_base_conversion("35", 10, 36) == 'Z' assert extended_base_conversion("0", 10, 2) == '0...
[ { "docstring": "Converts an integer to a given base and returns the string representation.", "function_declaration": "def int_to_base(num, base):", "function_name": "int_to_base", "parameter_list": "(num, base)" }, { "docstring": "Converts a string representation of a number in a given base ...
[ 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 int_to_base(num, base):\n \"\"\"Convert an integer to its string representation in a given base.\"\"\"\n if num == 0:\n return \"0\"\n dig...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036026", "row_id": 36026, "seed_ids": "[164]" }
0.695262
Data_Structure_36026
I
[ "int_to_base", "base_to_int", "extended_base_conversion" ]
3
[ [ "extended_base_conversion", "base_to_int" ], [ "extended_base_conversion", "int_to_base" ] ]
2
[]
false
[]
false
pytest
false
[]
true
c7a257ca84032b17ad2869a7316f5a3ba2fa8b32
7b7bc0ea6cfa19784ba8ec468fcd3d32f8383280
v1.0
instruct
Data_Structure
Data_Structure_36107_I
### Advanced Coding Assessment: Diffie-Hellman Key Exchange Simulation **Objective**: Implement an advanced Diffie-Hellman key exchange algorithm that securely allows two parties to exchange keys over an insecure channel and enhance it in a way that optimizes the computation of primitive roots. **Scenario**: You are ...
import math from random import randint def prime_check(num): """Return True if num is a prime number.""" if num <= 1: return False if num == 2 or num == 3: return True if num % 2 == 0 or num % 3 == 0: return False j = 5 while j * j <= num: if num % j == 0 or num ...
import pytest from solution import prime_check, optimized_find_primitive_root, secure_diffie_hellman_key_exchange def test_prime_check(): assert prime_check(7) == True assert prime_check(10) == False assert prime_check(2) == True assert prime_check(1) == False assert prime_check(15) == False def t...
[ { "docstring": "Return True if num is a prime number.", "function_declaration": "def prime_check(num):", "function_name": "prime_check", "parameter_list": "(num)" }, { "docstring": "Return the order of a modulo p.", "function_declaration": "def order(a, p):", "function_name": "order"...
[ 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 random import randint\n\ndef prime_check(num):\n \"\"\"Return True if num is a prime number.\"\"\"\n if num <= 1:\n return Fals...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036107", "row_id": 36107, "seed_ids": "[146]" }
0.497212
Data_Structure_36107
I
[ "prime_check", "order", "euler_totient", "find_primitive_roots", "alice_private_key", "alice_public_key", "bob_private_key", "bob_public_key", "alice_shared_key", "bob_shared_key", "optimized_find_primitive_root", "secure_diffie_hellman_key_exchange" ]
12
[ [ "find_primitive_roots", "euler_totient" ], [ "find_primitive_roots", "order" ], [ "optimized_find_primitive_root", "euler_totient" ], [ "secure_diffie_hellman_key_exchange", "alice_private_key" ], [ "secure_diffie_hellman_key_exchange", "alice_public_key" ...
11
[]
false
[]
false
pytest
true
[]
true
14a3d4a20b0114f271f836e6f96f4d776867716f
3be7277440a020ef7e4473c330347b67bb254416
v1.0
instruct
Data_Structure
Data_Structure_36153_I
### Question: Implement a Bogo Sort #### Context Bogo Sort is a very inefficient sorting algorithm that repeatedly shuffles an array until it is sorted. Though not useful for actual sorting needs, it serves as a good exercise in understanding sorting algorithms and complexity. #### Task Your task is to implement a fu...
import random def is_sorted(arr): """ Check if the given list is sorted in ascending order. """ for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr): """ Perform a Bogo Sort on the given list of integers. Shuffle the list...
from solution import bogo_sort def test_bogo_sort_single_element(): assert bogo_sort([5]) == [5] def test_bogo_sort_already_sorted(): assert bogo_sort([1, 2, 3]) == [1, 2, 3] def test_bogo_sort_reverse_order(): assert bogo_sort([3, 2, 1]) == [1, 2, 3] def test_bogo_sort_unsorted(): assert bogo_sort(...
[ { "docstring": "Check if the given list is sorted in ascending order.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Perform a Bogo Sort on the given list of integers.\nShuffle the list randomly 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\n\ndef bogo_sort(arr):\n \"\"\"\n Sorts a list of integers using the Bogo Sort algorithm.\n The function repeatedly shuffles the list u...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036153", "row_id": 36153, "seed_ids": "[16]" }
0.546455
Data_Structure_36153
I
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3a9eb25ef36623be3d2ebde789ef393f29a9ef5a
b080a5afb79c021ca3795c94c7d8693b6c86c1aa
v1.0
instruct
Data_Structure
Data_Structure_36194_I
### Transitive Closure Matrix You are given a directed graph with `V` vertices numbered from 0 to V-1. The graph is represented using an adjacency matrix, where `graph[i][j]` is 1 if there is a direct edge from vertex `i` to vertex `j`, and 0 otherwise. You need to find the transitive closure of the graph using Depth ...
from typing import List def dfs(graph: List[List[int]], reach: List[List[int]], v: int, source: int): """ Helper function to perform DFS from source vertex. """ for i in range(len(graph)): if graph[source][i] and not reach[v][i]: reach[v][i] = 1 dfs(graph, reach, v, i) ...
from solution import transitive_closure def test_transitive_closure_example(): graph = [ [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1] ] expected_result = [ [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1] ] assert trans...
[ { "docstring": "Helper function to perform DFS from source vertex.", "function_declaration": "def dfs(graph, reach, v, source):", "function_name": "dfs", "parameter_list": "(graph, reach, v, source)" }, { "docstring": null, "function_declaration": "def transitive_closure(V, graph):", ...
[ 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 transitive_closure(V, graph):\n # Initialize the transitive closure matrix the same as the original graph matrix\n reach = [[graph[i][j] for j in ra...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036194", "row_id": 36194, "seed_ids": "[228]" }
0.6709
Data_Structure_36194
I
[ "dfs", "transitive_closure" ]
2
[ [ "transitive_closure", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
64b2272872aa7199526e42141b531e9dea6000b2
60aa8add7e8e173834fdada56e7a42c16ac6b327
v1.0
instruct
Data_Structure
Data_Structure_36264_I
#### Task Implement an insertion sort algorithm for a list of integers and use a binary search function to determine the correct position for each element during the insertion process. This will help improve the efficiency of your insertion sort. #### Scenario You are given a list of grades for a class, but they are n...
def binary_search(array, val): """ Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. :param array: List[int] :param val: int :return: int """ low, high = 0, len(array) - 1 while ...
from solution import binary_search, insertion_sort_with_binary_search def test_binary_search(): assert binary_search([1, 2, 3, 4, 5], 3) == 2 assert binary_search([1, 2, 3, 4, 5], 0) == 0 assert binary_search([1, 2, 3, 4, 5], 6) == 5 assert binary_search([1, 2, 3, 4, 5], 4) == 3 assert binary_searc...
[ { "docstring": "Given a sorted array and a target value, return the index if the target is\nfound. If not, return the index where it would be if it were inserted in order.\n\n:param array: List[int]\n:param val: int\n:return: int", "function_declaration": "def binary_search(array, val):", "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 binary_search(array, val):\n \"\"\"\n Given a sorted array and a target value, return the index if the target is \n found. If not, return the ind...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036264", "row_id": 36264, "seed_ids": "[199]" }
0.640035
Data_Structure_36264
I
[ "binary_search", "insertion_sort_with_binary_search" ]
2
[ [ "insertion_sort_with_binary_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
711cfc3c4313b219b30c4e04707ada357a975443
ac511a57569988ff2dfbc3953e739aa7c999d3a9
v1.0
instruct
Data_Structure
Data_Structure_36307_I
### Heap Sort Enhancement and Application You are part of a team developing educational tools for algorithm visualization. Your task is to create a new feature that extends the functionality of the provided Heap Sort implementations, and then build an advanced usage case that simulates real-world scenarios. ### Part ...
from typing import List def find_median(arr: List[int]) -> float: if not arr: raise ValueError("The array must not be empty") arr.sort() n = len(arr) if n % 2 == 1: return float(arr[n // 2]) else: return (arr[(n // 2) - 1] + arr[n // 2]) / 2.0 def max_heapify(arr,...
from solution import find_median, max_heap_sort, min_heap_sort def test_find_median_odd_length(): assert find_median([7, 1, 3, 5]) == 4.0 def test_find_median_even_length(): assert find_median([1, 2, 3, 4, 5]) == 3.0 def test_find_median_single_element(): assert find_median([5]) == 5.0 def test_find_med...
[ { "docstring": null, "function_declaration": "def find_median(arr):", "function_name": "find_median", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, step_by_step):", "function_name": "max_heapify", "parameter_list": "(arr, n,...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom typing import List\n\ndef find_median(arr: List[int]) -> float:\n \"\"\"\n Finds the median of an unsorted list of integers.\n \"\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036307", "row_id": 36307, "seed_ids": "[8]" }
0.651254
Data_Structure_36307
I
[ "find_median", "max_heapify", "max_heap_sort", "min_heapify", "min_heap_sort" ]
5
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
384568ba7b4c7ed517275d0af3c67a4eb9ce7e64
49c3914edd77ab7501989248e6304d2e7c1a155c
v1.0
instruct
Data_Structure
Data_Structure_36315_I
### Maximum Flow Problem: Custom Implementation #### Problem Statement You are tasked with designing and implementing a custom function for finding the maximum flow in a directed graph using the Ford-Fulkerson algorithm with DFS. Your function needs to handle large input sizes efficiently and correctly manage edge cas...
from typing import List def dfs(residual_capacity, source, sink, parent): visited = [False] * len(residual_capacity) stack = [source] visited[source] = True while stack: u = stack.pop() for v, capacity in enumerate(residual_capacity[u]): if not visited[v] and capacity > 0: ...
from solution import custom_ford_fulkerson def test_small_graph(): 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 custom_ford_fulke...
[ { "docstring": null, "function_declaration": "def dfs(residual_capacity, source, sink, parent):", "function_name": "dfs", "parameter_list": "(residual_capacity, source, sink, parent)" }, { "docstring": "Computes the maximum flow from source to sink in a directed graph using the Ford-Fulkerso...
[ 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 custom_ford_fulkerson(capacity: List[List[int]], source: int, sink: int) -> int:\n def dfs(flow: int, current: int, visited:...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036315", "row_id": 36315, "seed_ids": "[240]" }
0.571141
Data_Structure_36315
I
[ "dfs", "custom_ford_fulkerson" ]
2
[ [ "custom_ford_fulkerson", "dfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
064ddaf840ec098b19cb76f1143c2ee010e08868
78d5b42d7bbeab01704d2270997e3dffa202c668
v1.0
instruct
Data_Structure
Data_Structure_36332_I
### Bucket Sort with Flexible Bucket Management **Scenario**: You are provided with an array of floating-point numbers representing scores ranging from `[0.0, 1.0)` for a programming competition. Your task is to sort the scores efficiently using Bucket Sort. To enhance flexibility and efficiency, you will allow dynami...
from typing import List, Optional import math def insertion_sort(arr: List[float]) -> List[float]: for i in range(1, len(arr)): j = i - 1 key = arr[i] while arr[j] > key and j >= 0: arr[j+1] = arr[j] j = j - 1 arr[j + 1] = key return arr def dynamic_buck...
from solution import dynamic_bucket_sort def test_dynamic_bucket_sort_even_distribution(): assert dynamic_bucket_sort([0.78, 0.17, 0.39, 0.26, 0.72, 0.94, 0.21, 0.12, 0.23, 0.68]) == [0.12, 0.17, 0.21, 0.23, 0.26, 0.39, 0.68, 0.72, 0.78, 0.94] def test_dynamic_bucket_sort_single_element(): assert dynamic_buck...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def dynamic_bucket_sort(arr, num_buckets=None):", "function_name": "dynamic_bucket_sort", "parame...
[ 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, Optional\nimport math\n\ndef insertion_sort(arr: List[float]) -> List[float]:\n \"\"\"\n Sorts a list using the insertion sort ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036332", "row_id": 36332, "seed_ids": "[26]" }
0.517768
Data_Structure_36332
I
[ "insertion_sort", "dynamic_bucket_sort" ]
2
[ [ "dynamic_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
abe8cd5d78e6c05245d4e7f48cef6f2ee5d91157
9ab7ff76745554a2e9c0663ace75756de8ff6717
v1.0
instruct
Data_Structure
Data_Structure_36343_I
You are tasked with implementing the Bucket Sort algorithm to sort an array of floating-point numbers within a range from 0 to 1 (inclusive). Your implementation should also address possible optimizations and edge cases. ### Requirements 1. Implement `bucket_sort(arr: List[float]) -> List[float]` function to sort an ...
from typing import List def insertion_sort(arr: List[float]) -> None: """ A simple insertion sort implementation used for sorting individual buckets. """ for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] ...
from solution import bucket_sort def test_bucket_sort_empty(): assert bucket_sort([]) == [] def test_bucket_sort_single_element(): assert bucket_sort([0.4]) == [0.4] def test_bucket_sort_already_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_rev...
[ { "docstring": "A simple insertion sort implementation used for sorting individual buckets.", "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": "Perform bucket sort on an array of floating-point numbers in the r...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(bucket: List[float]) -> List[float]:\n \"\"\"\n Helper function to sort individual buckets using insertion...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036343", "row_id": 36343, "seed_ids": "[26]" }
0.552812
Data_Structure_36343
I
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ef6ae5723395ca3a6863b3092a198db012073916
f91a353d522771ce3ce715fd42cc794663a50dee
v1.0
instruct
Data_Structure
Data_Structure_36370_I
### Merge Sort Implementation You are tasked with implementing the Merge Sort algorithm. Merge Sort is a classic sorting algorithm that follows the divide-and-conquer strategy to sort an array. Your goal is to write a function `merge_sort` that sorts an array of integers in non-decreasing order. #### Expected Input a...
def merge_sort(arr): """ Sorts the input array using Merge Sort. Parameters: arr (list of int): The array to sort. Returns: list of int: The sorted array. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(a...
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_two_elements(): assert merge_sort([2, 1]) == [1, 2] def test_merge_sort_sorted(): assert merge_sort([1, 2, 3, 4, 5]) == [1,...
[ { "docstring": "Sorts the input array using Merge Sort.\n\nParameters:\narr (list of int): The array to sort.\n\nReturns:\nlist of int: The sorted array.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two 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": "def merge_sort(arr):\n \"\"\"\n Sorts the input array using Merge Sort.\n \n Parameters:\n arr (list of int): The array to sort.\n \n Ret...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036370", "row_id": 36370, "seed_ids": "[12]" }
0.737662
Data_Structure_36370
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b967d07fe3206ef75812292285c8d1fcef0eb5c5
796a401f2c81414244a1eae46ce837206bdf6d3e
v1.0
instruct
Data_Structure
Data_Structure_36392_I
You are provided with a data storage structure and algorithm designed for efficiently handling sparse vectors. Sparse vectors mainly contain zero values, and only a few elements are non-zero. Your task is to improve upon and extend the existing implementation. You will need to: 1. Implement a function to convert spars...
def vector_to_index_value_list(vector): """ Converts a vector to a list of index-value pairs, omitting zero values. Parameters: vector (list[float]): The input sparse vector. Returns: list[tuple[int, float]]: A list of (index, value) pairs. """ return [(i, value) for i, value i...
import pytest from solution import vector_to_index_value_list, dot_product, handle_zero_vectors def test_vector_to_index_value_list(): assert vector_to_index_value_list([1.0, 0.0, 3.0]) == [(0, 1.0), (2, 3.0)] assert vector_to_index_value_list([0.0, 0.0, 0.0]) == [] assert vector_to_index_value_list([]) ==...
[ { "docstring": "Converts a vector to a list of index-value pairs, omitting zero values.\n\nParameters:\nvector (list[float]): The input sparse vector.\n\nReturns:\nlist[tuple[int, float]]: A list of (index, value) pairs.", "function_declaration": "def vector_to_index_value_list(vector):", "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 vector_to_index_value_list(vector):\n \"\"\"\n Converts a vector to a list of index-value pairs, omitting zero values.\n \n Parameters:\n v...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036392", "row_id": 36392, "seed_ids": "[341]" }
0.41514
Data_Structure_36392
I
[ "vector_to_index_value_list", "dot_product", "handle_zero_vectors" ]
3
[ [ "handle_zero_vectors", "vector_to_index_value_list" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a62a8fff853aad54143731520c8ab82a56b285d0
8c0201f7815c0f3d3c62be6b69400eccc344356e
v1.0
instruct
Data_Structure
Data_Structure_36436_I
### Question: Construct and Verify Full Binary Tree from Traversal Arrays You are given arrays representing preorder and postorder traversal of a Full Binary Tree (a tree where every node has either 0 or 2 children). Your task is to construct the binary tree from these traversal arrays and validate it by producing its...
class Node: def __init__(self, key): self.left = None self.right = None self.val = key def build_tree_util(pre, post, preIndex, l, h, size, postIndexMap): # Base case if preIndex[0] >= size or l > h: return None # The first node in preorder traversal is the root. So tak...
from solution import construct_tree def test_construct_tree_simple(): pre = [1, 2, 4, 5, 3, 6, 7] post = [4, 5, 2, 6, 7, 3, 1] size = len(pre) assert construct_tree(pre, post, size) == [4, 2, 5, 1, 6, 3, 7] def test_construct_tree_empty(): pre = [] post = [] size = len(pre) assert cons...
[]
[ 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 construct_tree(pre, post, size):\n \"\"\"\n Constructs the Full Binary Tree and returns its inorder traversal.\n Parameters:\n pre (list) ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036436", "row_id": 36436, "seed_ids": "[300]" }
0.582482
Data_Structure_36436
I
[ "build_tree_util", "build_tree", "inorder_traversal", "construct_tree" ]
4
[ [ "build_tree", "build_tree_util" ], [ "construct_tree", "build_tree" ], [ "construct_tree", "inorder_traversal" ] ]
3
[]
false
[ "Node" ]
true
pytest
true
[]
true
5a974f05f6dbaba766eb30d08a2902ec379f3fa5
1b8e0c141becd6dc729d031dd1eee0e63f9730db
v1.0
instruct
Data_Structure
Data_Structure_36527_I
### Stooge Sort Enhancement and Analysis #### Problem Statement You are provided with the Stooge Sort algorithm. Although it is known for its inefficiency, your task is to write an enhanced version of Stooge Sort that includes: 1. **Optimization for small arrays**: If the length of the sub-array is 3 or less, use a m...
def insertion_sort(arr, l, h): for i in range(l+1, h+1): key = arr[i] j = i-1 while j >= l and arr[j] > key: arr[j+1] = arr[j] j -= 1 arr[j+1] = key def optimized_stoogesort(arr, l, h): if l >= h: return if arr[l] > arr[h]: arr[l]...
from solution import optimized_stoogesort def test_optimized_stoogesort_integers(): arr = [5, 2, 8, 3, 1] optimized_stoogesort(arr, 0, len(arr)-1) assert arr == [1, 2, 3, 5, 8] def test_optimized_stoogesort_sorted_integers(): arr = [1, 2, 3, 4, 5] optimized_stoogesort(arr, 0, len(arr)-1) asser...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, l, h):", "function_name": "insertion_sort", "parameter_list": "(arr, l, h)" }, { "docstring": null, "function_declaration": "def optimized_stoogesort(arr, l, h):", "function_name": "optimized_stoogesort", "para...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_stoogesort(arr, l, h):\n \"\"\"\n Enhanced Stooge Sort with optimizations for small arrays and edge case handling.\n \n :param arr: ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036527", "row_id": 36527, "seed_ids": "[10]" }
0.570245
Data_Structure_36527
I
[ "insertion_sort", "optimized_stoogesort" ]
2
[ [ "optimized_stoogesort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9fb935c8c2bc9cea380a8b3a9cd5d324c54aceb1
b603b365a8f48b222ce481ea25ac081053f9dbc0
v1.0
instruct
Data_Structure
Data_Structure_36537_I
#### Scenario: You are working on a navigation system that helps users find the nearest restaurants around them. To build this feature, you need to write a function that finds the k closest restaurants (represented as points) to a given user location (origin). #### Function Specifications: Implement a function `k_clos...
import heapq def distance(point, origin=(0, 0)): return (point[0] - origin[0])**2 + (point[1] - origin[1])**2 def k_closest_restaurants(restaurants, k, origin=(0, 0)): """ Finds the k closest restaurants to the given origin. :param restaurants: List of tuples, each representing the coordinates (x...
from solution import k_closest_restaurants def test_k_closest_basic(): restaurants = [(1, 2), (2, 3), (3, 4), (1, 1)] k = 2 origin = (0, 0) result = k_closest_restaurants(restaurants, k, origin) assert set(result) == set([(1, 2), (1, 1)]) # order doesn't matter def test_k_equals_restaurant_count(...
[ { "docstring": null, "function_declaration": "def distance(point, origin=(0, 0)):", "function_name": "distance", "parameter_list": "(point, origin=(0, 0))" }, { "docstring": "Finds the k closest restaurants to the given origin.\n\n:param restaurants: List of tuples, each representing the coo...
[ 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 heapq\n\ndef distance(point, origin=(0, 0)):\n return (point[0] - origin[0])**2 + (point[1] - origin[1])**2\n\ndef k_closest_restaurants(restaurants...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036537", "row_id": 36537, "seed_ids": "[266]" }
0.665109
Data_Structure_36537
I
[ "distance", "k_closest_restaurants" ]
2
[ [ "k_closest_restaurants", "distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f14c4ac56ac8c0d5a266e0926281baca39ee9e9d
ec41f69a55d8732bc4ba38a09f7222084aa54c22
v1.0
instruct
Data_Structure
Data_Structure_36540_I
### Problem: Efficient Range Sum Query with Fenwick Tree You have been provided with an integer array `arr` which contains `n` elements. Your task is to implement an efficient solution to perform the following operations: 1. **Prefix Sum Query**: Return the sum of the first `i` elements of the array. 2. **Point Update...
def construct_bit_tree(arr): """ Constructs the Fenwick Tree for given array `arr` and returns it. Parameters: arr (List[int]): The input array of integers. Returns: List[int]: The constructed Fenwick Tree. """ n = len(arr) bit_tree = [0] * (n + 1) for i in range(n...
def test_construct_and_query(): arr = [1, 7, 3, 0, 7, 8, 3, 2, 6, 2, 6, 8, 4, 9] bit_tree = construct_bit_tree(arr) assert prefix_sum(bit_tree, 5) == sum(arr[:6]) # Should return sum of first 6 elements def test_update(): arr = [1, 7, 3, 0, 7, 8, 3, 2, 6, 2, 6, 8, 4, 9] bit_tree = construct_bit_tr...
[ { "docstring": "Constructs the Fenwick Tree for given array `arr` and returns it.\n\nParameters:\narr (List[int]): The input array of integers.\n\nReturns:\nList[int]: The constructed Fenwick Tree.", "function_declaration": "def construct_bit_tree(arr):", "function_name": "construct_bit_tree", "para...
[ 0, 0, 0, 0, 1, 0, 1, 1, 0, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def construct_bit_tree(arr):\n \"\"\"\n Constructs the Fenwick Tree for given array `arr` and returns it.\n \"\"\"\n n = len(arr)\n bit_tree = ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00036540", "row_id": 36540, "seed_ids": "[305]" }
0.491418
Data_Structure_36540
I
[ "construct_bit_tree", "prefix_sum", "update_bit_tree" ]
3
[ [ "construct_bit_tree", "update_bit_tree" ] ]
1
[]
false
[]
false
pytest
false
[]
true
b60f9663da3fd186718d05e29f4884ec90b0c855
a7add58dc54bb43bb7cdda8a1a5d706c1aab1aa2
v1.0
instruct
Data_Structure
Data_Structure_36561_I
### Question **Order Finding Algorithm** You are given a positive integer \( n \) and another integer \( a \) such that \( \text{gcd}(a, n) = 1 \). Your task is to implement a function to find the smallest positive integer \( k \) (known as the order of \( a \) modulo \( n \)) such that \( a^k \equiv 1 \ (\text{mod} ...
import math def gcd(a, b): while b: a, b = b, a % b return a def find_order(a: int, n: int) -> int: """ Finds the smallest positive integer k such that a^k % n == 1. If gcd(a, n) != 1, return -1. """ if gcd(a, n) != 1: return -1 k = 1 power = a % n while power ...
from solution import find_order def test_find_order(): assert find_order(2, 5) == 4 # 2^4 % 5 == 1 assert find_order(3, 7) == 6 # 3^6 % 7 == 1 assert find_order(2, 4) == -1 # gcd(2, 4) != 1 assert find_order(10, 1) == -1 # 10 > 1 is out of constraints assert find_order(5, 9) == 6 # 5^6 % 9 == ...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": "Finds the smallest positive integer k such that a^k % n == 1.\nIf gcd(a, n) != 1, return -1.", "function_declaration": "def find_order(a, n):", "functi...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_order(a: int, n: int) -> int:\n \"\"\"\n Finds the smallest positive integer k such that a^k ≡ 1 (mod n).\n If no such k exists, returns -1....
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00036561", "row_id": 36561, "seed_ids": "[150]" }
0.602385
Data_Structure_36561
I
[ "gcd", "find_order" ]
2
[ [ "find_order", "gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f1c0efa170a15d4155b89fb2aaea7a2908304637
f5eb4dbaabc104c96dbf6c7228e4c84c4b76be4c
v1.0
instruct
Data_Structure
Data_Structure_36578_I
Implement Bitonic Sorting for Non-Power of Two Arrays #### Background: You are given an enhancement to the traditional Bitonic Sort algorithm which can handle arrays whose sizes are not powers of two. The objective is to pad the array to the next power of two, perform Bitonic Sort, and then return only the sorted elem...
def next_power_of_two(x): return 1 if x == 0 else 2**(x - 1).bit_length() def bitonic_sort(arr, up): def compare_and_swap(arr, i, j, up): if (arr[i] > arr[j]) == up: arr[i], arr[j] = arr[j], arr[i] def bitonic_merge(arr, low, cnt, up): if cnt > 1: mid = cnt // 2 ...
from solution import bitonic_sort_non_power_of_two def test_bitonic_sort_non_power_of_two(): assert bitonic_sort_non_power_of_two([3, 7, 8, 5, 2, 1, 9, 6], False) == [1, 2, 3, 5, 6, 7, 8, 9] assert bitonic_sort_non_power_of_two([3, 7, 8, 5, 2, 1], True) == [8, 7, 5, 3, 2, 1] assert bitonic_sort_non_power_o...
[ { "docstring": null, "function_declaration": "def next_power_of_two(x):", "function_name": "next_power_of_two", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def bitonic_sort(arr, up):", "function_name": "bitonic_sort", "parameter_list": "(arr, up)" }...
[ 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 math\n\ndef bitonic_sort_non_power_of_two(arr, reverse=False):\n def next_power_of_two(x):\n return 1 << (x - 1).bit_length()\n \n def ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036578", "row_id": 36578, "seed_ids": "[17]" }
0.659357
Data_Structure_36578
I
[ "next_power_of_two", "bitonic_sort", "bitonic_sort_non_power_of_two" ]
3
[ [ "bitonic_sort_non_power_of_two", "bitonic_sort" ], [ "bitonic_sort_non_power_of_two", "next_power_of_two" ] ]
2
[]
false
[]
false
pytest
true
[]
true
9e1d4252ce98a0cff4fd10d9dab05a8052236161
33c0bab5d77cc2a1f2fbda5911098b66d316cd24
v1.0
instruct
Data_Structure
Data_Structure_36605_I
#### Context You are working on a project that requires efficient sorting of numerical data which is approximately uniformly distributed. You decide to implement the Bucket Sort algorithm due to its suitability for this data pattern. #### Task Write a function `enhanced_bucket_sort(arr, num_buckets)` that performs a b...
from typing import List def insertion_sort(bucket: List[int]) -> List[int]: """ Simple insertion sort function to sort each individual bucket. """ for i in range(1, len(bucket)): key = bucket[i] j = i - 1 while j >= 0 and key < bucket[j]: bucket[j + 1] = bucket[j] ...
from solution import enhanced_bucket_sort def test_enhanced_bucket_sort_empty(): assert enhanced_bucket_sort([], 5) == [] def test_enhanced_bucket_sort_single_element(): assert enhanced_bucket_sort([5], 5) == [5] def test_enhanced_bucket_sort_multiple_elements(): arr = [42, 32, 33, 52, 37, 47, 51] so...
[ { "docstring": "Simple insertion sort function to sort each individual bucket.", "function_declaration": "def insertion_sort(bucket):", "function_name": "insertion_sort", "parameter_list": "(bucket)" }, { "docstring": "Perform bucket sort on a given list of numbers with specified number of b...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(arr: List[int]) -> List[int]:\n for i in range(1, len(arr)):\n key = arr[i]\n j = i - 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036605", "row_id": 36605, "seed_ids": "[26]" }
0.483884
Data_Structure_36605
I
[ "insertion_sort", "enhanced_bucket_sort" ]
2
[ [ "enhanced_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5621819a0d78108842f915b9e52eddd7d8c6c44a
1a42119b5c3fb347a2c87cb265ddd71e94ec051e
v1.0
instruct
Data_Structure
Data_Structure_36607_I
### Maximum Flow Calculation #### Problem Description You have been provided with the implementation of three different maximum flow algorithms: Ford-Fulkerson using DFS, Edmonds-Karp using BFS, and Dinic's algorithm. To test your understanding, you are required to implement an additional function that determines whic...
def ford_fulkerson(capacity, source, sink): # Use DFS for Ford-Fulkerson n = len(capacity) residual = [row[:] for row in capacity] parent = [-1] * n def dfs_flow(u, flow): if u == sink: return flow for v in range(n): if parent[v] == -1 and residual[u][v] ...
from solution import select_max_flow_algorithm def test_ford_fulkerson(): 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 =...
[ { "docstring": null, "function_declaration": "def ford_fulkerson(capacity, source, sink):", "function_name": "ford_fulkerson", "parameter_list": "(capacity, source, sink)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "e...
[ 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 ford_fulkerson(capacity, source, sink):\n def dfs(flow, capacity, source, sink, visited):\n visited[source] = True\n if source == sink:\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036607", "row_id": 36607, "seed_ids": "[240]" }
0.586043
Data_Structure_36607
I
[ "ford_fulkerson", "edmonds_karp", "dinic", "select_max_flow_algorithm" ]
4
[ [ "select_max_flow_algorithm", "dinic" ], [ "select_max_flow_algorithm", "edmonds_karp" ], [ "select_max_flow_algorithm", "ford_fulkerson" ] ]
3
[]
false
[]
false
pytest
true
[]
true
95d4a7071d87537e2d7ec408080109d1182bd418
210b0cd0a6eb53d20971a07589e62761570bbb34
v1.0
instruct
Data_Structure
Data_Structure_36627_I
### Question: Cholesky Decomposition Verification and Application #### Background: Cholesky decomposition is a method in numerical linear algebra that decomposes a given Hermitian positive-definite matrix \( A \) into the product of a lower triangular matrix \( V \) and its conjugate transpose \( V* \), i.e., \( A = V...
import numpy as np def verify_hermitian_positive_definite(matrix): """ Verify if the given matrix is Hermitian positive-definite. Parameters: matrix (List[List[float]]): A square matrix Returns: bool: True if the matrix is Hermitian positive-definite, False otherwise """ A = n...
from solution import verify_hermitian_positive_definite, cholesky_decomposition def test_verify_hermitian_positive_definite(): assert verify_hermitian_positive_definite([[4, 12, -16], [12, 37, -43], [-16, -43, 98]]) == True assert verify_hermitian_positive_definite([[1, 1], [2, 2]]) == False assert verify_...
[ { "docstring": "Verify if the given matrix is Hermitian positive-definite.\n\nParameters:\nmatrix (List[List[float]]): A square matrix\n\nReturns:\nbool: True if the matrix is Hermitian positive-definite, False otherwise", "function_declaration": "def verify_hermitian_positive_definite(matrix):", "funct...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import numpy as np\nfrom typing import List, Optional\n\ndef verify_hermitian_positive_definite(matrix: List[List[float]]) -> bool:\n \"\"\"\n Verifies ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036627", "row_id": 36627, "seed_ids": "[339]" }
0.477478
Data_Structure_36627
I
[ "verify_hermitian_positive_definite", "cholesky_decomposition" ]
2
[ [ "cholesky_decomposition", "verify_hermitian_positive_definite" ] ]
1
[]
false
[]
false
pytest
true
[ "numpy" ]
false
93d5351a6873a70807ffc35a7284b187e93c76f3
a398b622e3ed6698603621de2197e3b70e00e03f
v1.0
instruct
Data_Structure
Data_Structure_36645_I
### Intersection of Two Linked Lists You are tasked with implementing a function to find the node at which two singly linked lists intersect. Given the following interface and definition for a Node, implement the function `find_intersection(h1, h2)` that returns the intersecting node. If there is no intersection, retu...
class Node: def __init__(self, val=0, next=None): self.val = val self.next = next def get_length(head: Node) -> int: length = 0 current = head while current: length += 1 current = current.next return length def find_intersection(h1: Node, h2: Node) -> Node: if n...
import pytest from solution import Node, find_intersection def test_find_intersection_case1(): a1 = Node(1) b1 = Node(3) c1 = Node(5) d = Node(7) e = Node(9) f = Node(11) a2 = Node(2) b2 = Node(4) c2 = Node(6) a1.next = b1 b1.next = c1 c1.next = d a2.next = b2 ...
[]
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_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: Node...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036645", "row_id": 36645, "seed_ids": "[245]" }
0.564662
Data_Structure_36645
I
[ "get_length", "find_intersection" ]
2
[ [ "find_intersection", "get_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
5d8e1cbc48cb5c6198e3327b931258efbf5aa792
0cf3e3d64e8b820ba09ab924b5796c9788513aa1
v1.0
instruct
Data_Structure
Data_Structure_36664_I
### Rotation of Singly Linked List #### Context: Given a singly linked list, you are tasked with rotating the list to the right by a given number of places `k`. This problem is crucial for understanding the manipulation of linked list structures and optimizing rotational computations. #### Task: Implement a function ...
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def get_length(head): count = 0 while head: count += 1 head = head.next return count def rotate_right(head, k): if not head or not head.next or k == 0: return head # G...
from solution import ListNode, rotate_right def linked_list_to_list(head): """ Helper function to convert linked list to list """ lst = [] while head: lst.append(head.val) head = head.next return lst def list_to_linked_list(lst): """ Helper function to convert list to linked list "...
[]
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef get_length(head):\n count = 0\n whil...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00036664", "row_id": 36664, "seed_ids": "[250]" }
0.613303
Data_Structure_36664
I
[ "get_length", "rotate_right" ]
2
[ [ "rotate_right", "get_length" ] ]
1
[]
false
[ "ListNode" ]
true
pytest
true
[]
true
09e3a24919f9e1544751c1d51568c0648ffc7506
fe993c785cb4d10231c7fcc60426eb4521aeca65
v1.0
instruct
Data_Structure
Data_Structure_36676_I
### RSA Encryption Implementation You are tasked with implementing an RSA encryption and decryption system. This involves writing functions to generate RSA keys, encrypt data with the public key, and decrypt data with the private key. #### Function Implementations * **generate_key(k, seed=None)**: This function shou...
import random from math import gcd def is_prime(n): """ Check if a number is prime using a simple method. Not optimized but works for small n. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if ...
from solution import generate_key, encrypt, decrypt def test_rsa_encryption_decryption(): k = 16 n, e, d = generate_key(k, seed=42) data = 20 encrypted = encrypt(data, e, n) decrypted = decrypt(encrypted, d, n) assert decrypted == data def test_key_generation_with_fixed_seed(): k = 16 ...
[ { "docstring": "Check if a number is prime using a simple method. Not optimized but works for small n. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Generate a prime number with approximately k bits. ", "function_de...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": null, "trial_gpt4o_1": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared1_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime\nfrom sympy.ntheory.generate import randprime\n\ndef gen_prime(bits):\n \"\"\"\n Gener...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036676", "row_id": 36676, "seed_ids": "[154]" }
0.595291
Data_Structure_36676
I
[ "is_prime", "gen_prime", "modinv", "egcd", "generate_key", "encrypt", "decrypt" ]
7
[ [ "gen_prime", "is_prime" ], [ "generate_key", "gen_prime" ], [ "generate_key", "modinv" ], [ "modinv", "egcd" ] ]
4
[]
false
[]
false
pytest
true
[]
true
5c322e8de20f0ee5af5c715c505cc26870ced869
3e9c9d667b9db1e48459a445e43ae80e886522bd
v1.0
instruct
Data_Structure
Data_Structure_36715_I
### Secure Communication Key Exchange In a secure communication scenario, two parties, Alice and Bob, need to establish a shared secret key using the Diffie-Hellman key exchange method. However, this version employs some enhancements to improve the detection of potential problems. You are required to implement the `e...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i) <= n: if (n % i == 0) or (n % (i + 2) == 0): return False i += 6 return True def is_primitive_root(a, p): if p <=...
from solution import enhanced_diffie_hellman_key_exchange def test_valid_keys(): assert enhanced_diffie_hellman_key_exchange(5, 23, True) def test_invalid_prime(): assert not enhanced_diffie_hellman_key_exchange(5, 24, True) def test_invalid_primitive_root(): assert not enhanced_diffie_hellman_key_exchan...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def is_primitive_root(a, p):", "function_name": "is_primitive_root", "parameter_list": "(a, p)" }, { "doc...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef is_prime(n):\n \"\"\"Utility function to check if a number is prime using trial division.\"\"\"\n if n <= 1:\n return False\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036715", "row_id": 36715, "seed_ids": "[146]" }
0.497572
Data_Structure_36715
I
[ "is_prime", "is_primitive_root", "gcd", "enhanced_diffie_hellman_key_exchange" ]
4
[ [ "enhanced_diffie_hellman_key_exchange", "is_prime" ], [ "enhanced_diffie_hellman_key_exchange", "is_primitive_root" ], [ "is_primitive_root", "gcd" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4d4f7b6d7da432ff66dee62fdd7f39dc27f4803d
f5874003b7232932cf739eb54aa0a2cf49399661
v1.0
instruct
Data_Structure
Data_Structure_36775_I
### Maximum Flow in a Flow Network **Context**: You are working as a network engineer responsible for optimizing the data flow in a communication network. The network can be represented as a directed graph where nodes are routers, and edges are data paths with certain capacities. Your goal is to ensure the optimal flo...
from collections import deque from typing import List def bfs(capacity, source, sink, parent): visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for ind, val in enumerate(capacity[u]): if visited[ind] == False...
import pytest from solution import maximum_flow def test_edmonds_karp_small_graph(): 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 algori...
[ { "docstring": null, "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docstring": null, "function_declaration": "def edmonds_karp(capacity, source, sink):", "function_name": "edmonds...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nfrom typing import List\n\ndef bfs_capacity(residual_capacity: List[List[int]], source: int, sink: int, parent: List[int]) -> b...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00036775", "row_id": 36775, "seed_ids": "[240]" }
0.587624
Data_Structure_36775
I
[ "bfs", "edmonds_karp", "maximum_flow" ]
3
[ [ "edmonds_karp", "bfs" ], [ "maximum_flow", "edmonds_karp" ] ]
2
[]
false
[]
false
pytest
true
[]
true
73dfb68cfe8e1642c165cc23db4ced634f4a97db
d2b9b723b156f096065294f2c5bc9b7a391374b4
v1.0
instruct
Data_Structure
Data_Structure_36870_I
### Sorting Adventure: Implementing and Enhancing the Exchange Sort Algorithm One day, you're approached by a friend who is learning about sorting algorithms. They have written a simple sorting algorithm called "Exchange Sort" but are curious about its efficiency and possible improvements. Your task is twofold: 1. Im...
def exchange_sort(arr: list) -> list: """ Sorts the list arr using the Exchange Sort algorithm. :param arr: List of integers to sort. :return: Sorted list of integers. """ # Exchange Sort Implementation n = len(arr) for i in range(n): for j in range(i+1, n): if arr[i...
from solution import exchange_sort, optimized_sort def test_exchange_sort_empty(): assert exchange_sort([]) == [] def test_exchange_sort_single_element(): assert exchange_sort([1]) == [1] def test_exchange_sort_sorted_list(): assert exchange_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_exchange_sor...
[ { "docstring": "Sorts the list arr using the Exchange Sort algorithm.\n\n:param arr: List of integers to sort.\n:return: Sorted list of integers.", "function_declaration": "def exchange_sort(arr):", "function_name": "exchange_sort", "parameter_list": "(arr)" }, { "docstring": "Sorts the list...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def exchange_sort(arr):\n \"\"\"\n Sorts the list arr using the Exchange Sort algorithm.\n \n :param arr: List of integers to sort.\n :return: ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036870", "row_id": 36870, "seed_ids": "[28]" }
0.582877
Data_Structure_36870
I
[ "exchange_sort", "optimized_sort", "merge" ]
3
[ [ "optimized_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
41661475a7413d20df0e9074754f4dfc58dd73c1
40b35b580a441477589db899b42a3a4e4bc2eee1
v1.0
instruct
Data_Structure
Data_Structure_36877_I
### Prime Checking & Advanced Number Theory Functions #### Context You have been approached by a cryptography company to assist in optimizing their number theory functions, specifically focusing on primality testing and related operations. Their current implementation has been found efficient for small to moderate-siz...
def is_prime(n): """ Check if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return Tr...
from solution import is_prime, next_prime def test_is_prime(): assert is_prime(2) assert is_prime(3) assert not is_prime(4) assert is_prime(5) assert not is_prime(9) def test_next_prime_small_numbers(): assert next_prime(10) == 11 assert next_prime(14) == 17 assert next_prime(17) == 19...
[ { "docstring": "Check if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Given an integer n, return the smallest prime number that is greater than n.", "function_declaration": "def next_prime(n):",...
[ 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if an integer n is a prime number.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return T...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00036877", "row_id": 36877, "seed_ids": "[143]" }
0.735359
Data_Structure_36877
I
[ "is_prime", "next_prime" ]
2
[ [ "next_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
31b8a9264052588cf5adefe39fe254319e59fe62
e1df60044d962a400a884b2dfa56e238cff12193
v1.0
instruct
Data_Structure
Data_Structure_36897_I
### Coding Challenge: Optimized Insertion Sort You are tasked with implementing an optimized version of the Insertion Sort algorithm using the provided `search_insert` helper function to find the correct position for each element during sorting. #### Function Specification Define a function `optimized_insertion_sort(...
from bisect import bisect_left from typing import List def search_insert(array: List[int], value: int) -> int: """ Finds the index where the value should be inserted to keep the array sorted. """ return bisect_left(array, value) def optimized_insertion_sort(array: List[int]) -> List[int]: """ ...
from solution import optimized_insertion_sort def test_optimized_insertion_sort_basic(): assert optimized_insertion_sort([4, 2, 9, 1]) == [1, 2, 4, 9] assert optimized_insertion_sort([3, 3, 3]) == [3, 3, 3] assert optimized_insertion_sort([]) == [] assert optimized_insertion_sort([10, -1, 2]) == [-1, 2...
[ { "docstring": "Finds 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)" }, { "docstring": "Sorts an array of integers using an optimized ins...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(array: List[int], value: int) -> int:\n \"\"\"\n Helper function to find the insertion index of value withi...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036897", "row_id": 36897, "seed_ids": "[199]" }
0.60163
Data_Structure_36897
I
[ "search_insert", "optimized_insertion_sort" ]
2
[ [ "optimized_insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c1a730d4765399dc11297122082e068e813d7dc
8496e3ef7c205a0fccacd6feb385c97c4e1aad15
v1.0
instruct
Data_Structure
Data_Structure_36938_I
### Pancake Sort Enhancement You are required to implement an enhanced version of the Pancake Sort algorithm. The goal is to incorporate the following additional functionality: * **Enhanced Performance**: Implement a preliminary step that uses a more efficient sorting method (e.g., QuickSort) for large arrays before a...
def pancake_sort(arr): def flip(sublist, k): return sublist[:k][::-1] + sublist[k:] n = len(arr) for i in range(n, 1, -1): max_idx = arr.index(max(arr[:i])) if max_idx != i - 1: if max_idx != 0: arr = flip(arr, max_idx + 1) arr = flip(arr, i) ...
from solution import enhanced_sort def test_enhanced_sort_small_array_no_threshold(): assert enhanced_sort([3, 1, 2], 3) == [1, 2, 3] def test_enhanced_sort_small_array_with_threshold(): assert enhanced_sort([3, 1, 2], 2) == [1, 2, 3] def test_enhanced_sort_large_array_with_threshold(): assert enhanced_s...
[ { "docstring": null, "function_declaration": "def pancake_sort(arr):", "function_name": "pancake_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def quicksort(arr):", "function_name": "quicksort", "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": "def pancake_sort(arr):\n def flip(sublist, k):\n sublist[:k] = reversed(sublist[:k])\n\n n = len(arr)\n for size in range(n, 1, -1):\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00036938", "row_id": 36938, "seed_ids": "[9]" }
0.71252
Data_Structure_36938
I
[ "pancake_sort", "quicksort", "enhanced_sort" ]
3
[ [ "enhanced_sort", "pancake_sort" ], [ "enhanced_sort", "quicksort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
72bc5b64568b37a931e2d4638a52c69ffbb276f2
7b735f5cfdb3ede9ea04ef31efc4b17da166dd67
v1.0
instruct
Data_Structure
Data_Structure_36970_I
Your task is to implement a function that will secure communication in a simple text-based encryption system. The system encrypts messages using modular arithmetic. To do so, you need to: 1. Compute the inverse of a given number `a` under modulo `m`. 2. Use the Extended Euclidean Algorithm to aid in that computation. ...
from typing import List, Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: old_s, s = 1, 0 old_t, t = 0, 1 old_r, r = a, b while r != 0: quotient = old_r // r old_r, r = r, old_r - quotient * r old_s, s = s, old_s - quotient * s old_t, t = t, old_t - quoti...
from solution import modular_inverse_message, extended_gcd, modular_inverse def test_extended_gcd(): assert extended_gcd(30, 20) == (1, -1, 10) assert extended_gcd(240, 46) == (-9, 47, 2) def test_modular_inverse(): assert modular_inverse(3, 11) == 4 assert modular_inverse(10, 17) == 12 def test_modu...
[ { "docstring": null, "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def modular_inverse(a, m):", "function_name": "modular_inverse", "parameter_list": "(a, m)" }, ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef modular_inverse_message(a: int, m: int, encrypted_message: List[int]) -> Tuple[int, List[int]]:\n # Extended GCD func...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00036970", "row_id": 36970, "seed_ids": "[161]" }
0.519926
Data_Structure_36970
I
[ "extended_gcd", "modular_inverse", "modular_inverse_message" ]
3
[ [ "modular_inverse", "extended_gcd" ], [ "modular_inverse_message", "modular_inverse" ] ]
2
[]
false
[]
false
pytest
true
[]
true
4fb465f899aaa4b8e9812838e5abce7d209964ce
63270858a76280160be41210fd35c70d542e0c98
v1.0
instruct
Data_Structure
Data_Structure_37005_I
You are given a linked list. Write a function to detect if the linked list contains a cycle. If there is a cycle, return the length of the cycle. Otherwise, return 0. Your solution should not use any extra space apart from a few variables. ### Function Signature ```python def cycle_length(head: Optional[Node]) -> int:...
class Node: def __init__(self, val: int = 0, next: 'Node' = None): self.val = val self.next = next def cycle_length(head: Node) -> int: """ Detects if a cycle exists in a linked list and returns the length of the cycle. If there is no cycle, returns 0. """ if not head: r...
from solution import Node, cycle_length def test_cycle_length_no_cycle(): head = Node(1) head.next = Node(2) head.next.next = Node(3) assert cycle_length(head) == 0 def test_cycle_length_single_node_no_cycle(): head = Node(1) assert cycle_length(head) == 0 def test_cycle_length_sing...
[]
[ 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": "class Node:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\n\ndef cycle_length(head: Node) -> int:\n \"\"\"\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037005", "row_id": 37005, "seed_ids": "[258]" }
0.574347
Data_Structure_37005
I
[ "cycle_length", "calculate_cycle_length" ]
2
[ [ "cycle_length", "calculate_cycle_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
a681e85b89304658d9a964e09f3cb8ade385d7f1
5981766b4e401dfdeaad2e818774225eae9c2402
v1.0
instruct
Data_Structure
Data_Structure_37115_I
### RSA Encryption and Decryption Given the implementation of the RSA key generation algorithm in the provided code snippet, your task is to implement a secure messaging system using RSA encryption and decryption. **Context**: You are developing a basic encryption service where users can encrypt and decrypt messages ...
def rsa_encrypt(data: int, e: int, n: int) -> int: """ Encrypts the given data using RSA encryption algorithm. :param data: The integer data to encrypt. :param e: The public exponent. :param n: The modulus. :return: The encrypted integer. """ if data < 0 or data >= n: raise Valu...
import pytest from solution import rsa_encrypt, rsa_decrypt, secure_message def test_rsa_encrypt_decrypt_single_value(): n, e, d = 3233, 17, 2753 original_value = 65 encrypted_value = rsa_encrypt(original_value, e, n) decrypted_value = rsa_decrypt(encrypted_value, d, n) assert encrypted_value == 27...
[ { "docstring": "Encrypts the given data using RSA encryption algorithm.\n\n:param data: The integer data to encrypt.\n:param e: The public exponent.\n:param n: The modulus.\n:return: The encrypted integer.", "function_declaration": "def rsa_encrypt(data, e, n):", "function_name": "rsa_encrypt", "par...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def rsa_encrypt(data: int, e: int, n: int) -> int:\n \"\"\"\n Encrypts data using RSA encryption.\n\n :param data: int, the data to be encrypted\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037115", "row_id": 37115, "seed_ids": "[154]" }
0.628548
Data_Structure_37115
I
[ "rsa_encrypt", "rsa_decrypt", "secure_message" ]
3
[ [ "secure_message", "rsa_decrypt" ], [ "secure_message", "rsa_encrypt" ] ]
2
[]
false
[]
false
pytest
true
[]
true
97e3bdae227c785507b86c19c980b405e57b8502
ae2df2d93c1a1e4e0a73cd820aac14393d8de913
v1.0
instruct
Data_Structure
Data_Structure_37126_I
### Question: Implement an Extended Bitonic Sort with Error Handling and Iterative Approach #### Context: You have been given the task of sorting a dataset that needs to be frequently updated and sorted on a parallel processing system. For initial sorting, an efficient algorithm like Bitonic Sort is ideal, especially ...
def is_power_of_two(n): """ Check if a number is a power of two. """ return (n & (n - 1) == 0) and n != 0 def bitonic_compare_and_swap(arr, i, j, direction): """ Compares and swaps elements according to the bitonic sort rule. """ if (direction == (arr[i] > arr[j])): arr[i], arr[...
from solution import extended_bitonic_sort def test_power_of_two_length_ascending(): arr = [3, 7, 2, 8, 1, 5, 4, 6] assert extended_bitonic_sort(arr) == [1, 2, 3, 4, 5, 6, 7, 8] def test_power_of_two_length_descending(): arr = [3, 7, 2, 8, 1, 5, 4, 6] assert extended_bitonic_sort(arr, reverse=True) ==...
[ { "docstring": "Check if a number is a power of two.", "function_declaration": "def is_power_of_two(n):", "function_name": "is_power_of_two", "parameter_list": "(n)" }, { "docstring": "Compares and swaps elements according to the bitonic sort rule.", "function_declaration": "def bitonic_...
[ 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 extended_bitonic_sort(arr, reverse=False):\n \"\"\"\n Sorts the array using bitonic sort with iterative merge.\n\n :param arr: List[int] - the ar...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037126", "row_id": 37126, "seed_ids": "[17]" }
0.548294
Data_Structure_37126
I
[ "is_power_of_two", "bitonic_compare_and_swap", "bitonic_merge", "bitonic_sort_recursive", "extended_bitonic_sort" ]
5
[ [ "bitonic_merge", "bitonic_compare_and_swap" ], [ "bitonic_sort_recursive", "bitonic_merge" ], [ "extended_bitonic_sort", "bitonic_sort_recursive" ], [ "extended_bitonic_sort", "is_power_of_two" ] ]
4
[]
false
[]
false
pytest
true
[]
true
67442b9b47985c9da98208ec62a3682803beef07
be8ea8af15a60bbc98f0b1a946858fc68b9f9507
v1.0
instruct
Data_Structure
Data_Structure_37197_I
**Diffie-Hellman Key Exchange Implementation** Alice and Bob want to establish a shared secret key using the Diffie-Hellman key exchange protocol. Given a large prime number `p` and a number `a` which is a primitive root of `p`, they want to perform the key exchange securely. You are to implement the core functions r...
import random from math import gcd from sympy import isprime, totient, primerange def prime_check(num): return isprime(num) def find_order(a, n): if gcd(a, n) != 1: return -1 order = 1 current = a % n while current != 1: current = (current * a) % n order += 1 return ord...
import pytest from solution import ( prime_check, find_order, 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(): asser...
[ { "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...
[ 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 math import gcd\nfrom sympy import isprime, totient, primerange\n\ndef prime_check(num):\n return isprime(num)\n\ndef find_order(a, n):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037197", "row_id": 37197, "seed_ids": "[146]" }
0.501289
Data_Structure_37197
I
[ "prime_check", "find_order", "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" ]
11
[ [ "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...
11
[]
false
[]
false
pytest
true
[ "sympy" ]
false
57d997676b34d2cfdfc5e888f6c0cc1c5b31b84d
7c027ce95c25478817a9b3aef1b327fa3f4c8c2d
v1.0
instruct
Data_Structure
Data_Structure_37218_I
### Bitonic Sort Implementation #### Context: You have a large dataset with a size that is guaranteed to be a power of two. This dataset can be sorted effectively using the bitonic sort algorithm, which divides and merges the array using the bitonic sequences for sorting. However, you need to enhance this algorithm fo...
from typing import List def bitonic_merge(arr: List[int], low: int, cnt: int, direction: bool): if cnt > 1: k = cnt // 2 for i in range(low, low + k): if (direction and arr[i] > arr[i + k]) or (not direction and arr[i] < arr[i + k]): arr[i], arr[i + k] = arr[i + k], arr[...
def test_bitonic_sort_ascending(): assert bitonic_sort([3, 7, 4, 8, 6, 2, 1, 5], reverse=False) == [1, 2, 3, 4, 5, 6, 7, 8] def test_bitonic_sort_descending(): assert bitonic_sort([3, 7, 4, 8, 6, 2, 1, 5], reverse=True) == [8, 7, 6, 5, 4, 3, 2, 1] def test_bitonic_sort_edge_case_single_element(): assert b...
[ { "docstring": null, "function_declaration": "def bitonic_merge(arr, low, cnt, direction):", "function_name": "bitonic_merge", "parameter_list": "(arr, low, cnt, direction)" }, { "docstring": null, "function_declaration": "def bitonic_sort_rec(arr, low, cnt, direction):", "function_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": "from typing import List\n\ndef bitonic_compare_and_swap(arr, i, j, ascending):\n if (ascending and arr[i] > arr[j]) or (not ascending and arr[i] < arr[j]):...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037218", "row_id": 37218, "seed_ids": "[17]" }
0.629456
Data_Structure_37218
I
[ "bitonic_merge", "bitonic_sort_rec", "bitonic_sort" ]
3
[ [ "bitonic_sort", "bitonic_sort_rec" ], [ "bitonic_sort_rec", "bitonic_merge" ] ]
2
[]
false
[]
false
pytest
false
[]
true
ecb8f301b79437b3a9deb1924e360d63aaeae553
876e636b5cc170b4991e47f80ae1617f0557f1e2
v1.0
instruct
Data_Structure
Data_Structure_37227_I
### Question: As a software developer, you are tasked with implementing a custom utility that performs multiple numerical computations. Specifically, your utility should include functions for calculating the GCD, LCM, and the number of trailing zeros of binary representations of integers. To assess your understanding o...
def compute_gcd(a, b): """ Returns the greatest common divisor of a and b using the Euclidean algorithm. """ a, b = abs(a), abs(b) while b: a, b = b, a % b return a def compute_lcm(a, b): """ Returns the least common multiple of a and b. """ a, b = abs(a), abs(b) ret...
from solution import compute_gcd, compute_lcm, count_trailing_zeros, compute_gcd_bit def test_compute_gcd(): assert compute_gcd(14, 21) == 7 assert compute_gcd(100, 10) == 10 assert compute_gcd(-14, 21) == 7 assert compute_gcd(0, 5) == 5 assert compute_gcd(5, 0) == 5 def test_compute_lcm(): as...
[ { "docstring": "Returns the greatest common divisor of a and b using the Euclidean algorithm.", "function_declaration": "def compute_gcd(a, b):", "function_name": "compute_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple of a and b.", "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 compute_gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b using the Euclidean algorithm.\n \"\"\"\n a, b = abs(a), abs(b)\n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037227", "row_id": 37227, "seed_ids": "[166]" }
0.580433
Data_Structure_37227
I
[ "compute_gcd", "compute_lcm", "count_trailing_zeros", "compute_gcd_bit" ]
4
[ [ "compute_lcm", "compute_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f8b96b25a7ec3e26a4169a9bf191c5c1d523bebd
878d4c47ab38d50d744fe5c77035f91a34287db2
v1.0
instruct
Data_Structure
Data_Structure_37311_I
Implement a Hybrid Quicksort #### Objective Implement a hybrid Quicksort which improves the standard Quicksort by incorporating Insertion Sort for small partitions and selecting a median-of-three pivot to avoid worst-case performance. #### Problem Statement Write a function `hybrid_quick_sort(arr)` that sorts an arra...
def insertion_sort(arr, left, right): """ Performs insertion sort on the subarray of arr from index left to 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 + ...
from solution import hybrid_quick_sort def test_hybrid_quick_sort_normal_case(): assert hybrid_quick_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10] def test_hybrid_quick_sort_empty_list(): assert hybrid_quick_sort([]) == [] def test_hybrid_quick_sort_single_element(): assert hybrid_quick_sort([1]...
[ { "docstring": "Performs insertion sort on the subarray of arr from index left to right.", "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": "Returns the index of the median of the firs...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insertion_sort(arr, left, right):\n \"\"\"\n Performs insertion sort on the subarray of arr from index left to right.\n \"\"\"\n for i in rang...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00037311", "row_id": 37311, "seed_ids": "[25]" }
0.583574
Data_Structure_37311
I
[ "insertion_sort", "median_of_three", "quick_sort", "hybrid_quick_sort" ]
4
[ [ "hybrid_quick_sort", "quick_sort" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "median_of_three" ] ]
3
[]
false
[]
false
pytest
true
[]
true
8e3c7d8cac830d57e9574b61296f89f74888c298
886f673d76340405b09a63e0e8e3a7f5c40eb92b
v1.0
instruct
Data_Structure
Data_Structure_37340_I
### Merge Sort Implementation Challenge **Context**: A software company is building an application to handle large datasets efficiently. One crucial feature is to ensure data is sorted rapidly, regardless of the input's initial order. Merge Sort is selected for its predictable performance characteristics. You have bee...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in ascending order using the merge sort algorithm. """ if len(arr) <= 1: # Base case: arrays with 0 or 1 element are already sorted return arr # Find the middle point to divide the...
from solution import merge_sort def test_merge_sort_unsorted_array(): assert merge_sort([4, 1, 3, 9, 7]) == [1, 3, 4, 7, 9] def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_single_element_array(): assert merge_sort([1]) == [1] def test_merge_sort_already_sorted_array():...
[ { "docstring": "Sorts an array of integers in ascending order using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into a single sorted list.", "function_decla...
[ 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 \"\"\"\n Sort the array in ascending order using the merge sort algorithm.\n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037340", "row_id": 37340, "seed_ids": "[12]" }
0.65977
Data_Structure_37340
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cd9d49fdbc2f9ef6c24cae2b7f05f54bfefc32a4
5b504e35ac5c261c20ab63469f9462d04a2e954b
v1.0
instruct
Data_Structure
Data_Structure_37430_I
You are tasked with implementing a specialized version of the radix sort algorithm that deals with positive and negative integers. Your solution should handle input arrays containing both types of integers, correctly ordering them such that all negative numbers appear before the positive numbers, with both groups inter...
from typing import List def counting_sort(arr: List[int], exp: int, simulation: bool = False) -> List[int]: n = len(arr) output = [0] * n # output array that will have the sorted elements count = [0] * 10 # count array to store count of occurrences of each digit # Count occurrences of each digit ...
from solution import advanced_radix_sort def test_basic(): arr = [3, -1, 2] assert advanced_radix_sort(arr) == [-1, 2, 3] def test_mixed(): arr = [170, -45, 75, -90, 802, 24, 2, 66] assert advanced_radix_sort(arr) == [-90, -45, 2, 24, 66, 75, 170, 802] def test_all_negative(): arr = [-5, -1, -3, ...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp, simulation=False):", "function_name": "counting_sort", "parameter_list": "(arr, exp, simulation=False)" }, { "docstring": null, "function_declaration": "def radix_sort(arr, simulation=False):", "function_name":...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort(arr, exp, simulation=False):\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n \n if simulati...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00037430", "row_id": 37430, "seed_ids": "[15]" }
0.663527
Data_Structure_37430
I
[ "counting_sort", "radix_sort", "advanced_radix_sort" ]
3
[ [ "advanced_radix_sort", "radix_sort" ], [ "radix_sort", "counting_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
09613c8f4594a6f42b73e3e601fe23f64dbeda32
3a8a6f78702ddad212d0c6a911679c1e718b3a96
v1.0
instruct
Data_Structure
Data_Structure_37439_I
### Coding Task: Implement Optimized Quick Sort with Improved Pivot Selection #### Scenario You are tasked to implement an optimized version of the Quick Sort algorithm. Your implementation should address potential performance bottlenecks related to pivot selection and small arrays. #### Requirements 1. Implement th...
def optimized_quick_sort(arr): """ Sorts an array using the optimized quick sort algorithm. Arguments: arr : list of integers -- the array to be sorted. Returns: list of integers -- the sorted array. """ if len(arr) <= 1: return arr _quick_sort(arr, 0, len(arr) - 1)...
from solution import optimized_quick_sort def test_optimized_quick_sort_empty(): assert optimized_quick_sort([]) == [] def test_optimized_quick_sort_single_element(): assert optimized_quick_sort([1]) == [1] def test_optimized_quick_sort_sorted(): assert optimized_quick_sort([1, 2, 3, 4, 5]) == [1, 2, 3, ...
[ { "docstring": "Sorts an array using the optimized quick sort algorithm.\n\nArguments:\narr : list of integers -- the array to be sorted.\n\nReturns:\nlist of integers -- the sorted array.", "function_declaration": "def optimized_quick_sort(arr):", "function_name": "optimized_quick_sort", "parameter...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_quick_sort(arr):\n \"\"\"\n Sorts an array using the optimized quick sort algorithm.\n \n Arguments:\n arr : list of integers -- ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037439", "row_id": 37439, "seed_ids": "[25]" }
0.552045
Data_Structure_37439
I
[ "optimized_quick_sort", "_quick_sort", "median_of_three", "partition", "insertion_sort" ]
5
[ [ "_quick_sort", "insertion_sort" ], [ "_quick_sort", "median_of_three" ], [ "_quick_sort", "partition" ], [ "optimized_quick_sort", "_quick_sort" ] ]
4
[]
false
[]
false
pytest
true
[]
true
9445be873bd782644ba1b08f1bfe3aa05e750ad1
5ed426347fe25a548a0309d5f83e89104d14c735
v1.0
instruct
Data_Structure
Data_Structure_37527_I
**Probable Prime Finder** You are tasked with developing a function that identifies whether a number is a probable prime using the Rabin-Miller primality test. The function should call the `is_prime` function outlined above but needs to include several additional features to handle real-world inputs properly. ### Fun...
import random def is_prime(n: int, k: int) -> bool: """ This helper function checks if n is a probable prime using the Miller-Rabin test. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0: return False # Find r and d such that n-1 = d * 2^r, with d od...
from solution import probable_prime_checker def test_probable_prime_checker_basic(): assert probable_prime_checker(11, 5) == True assert probable_prime_checker(4, 5) == False assert probable_prime_checker(0, 5) == False assert probable_prime_checker(17, 3) == True def test_probable_prime_checker_edge_...
[ { "docstring": "This helper function checks if n is a probable prime using the Miller-Rabin test.", "function_declaration": "def is_prime(n, k):", "function_name": "is_prime", "parameter_list": "(n, k)" }, { "docstring": "Determines if n is a probable prime using the Miller-Rabin primality 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": "import random\n\ndef is_prime(n, k):\n if n <= 1:\n return False\n if n == 2 or n == 3:\n return True\n if n % 2 == 0:\n return ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037527", "row_id": 37527, "seed_ids": "[136]" }
0.770812
Data_Structure_37527
I
[ "is_prime", "probable_prime_checker" ]
2
[ [ "probable_prime_checker", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3472e4f14fba3df5b57b724705a99ee34bfcf9a4
9c1cb3ee6dde541cdd4a9e74c9e2036b08c5541d
v1.0
instruct
Data_Structure
Data_Structure_37609_I
## Coding Assessment Question ### Objective Write a function to compute the greatest common divisor (GCD) of two non-negative integers using the Euclidean algorithm, another function for the least common multiple (LCM), a function to count trailing zeros in an integer's binary representation, and finally a function to...
def compute_gcd(a: int, b: int) -> int: """ Computes the greatest common divisor of a and b using Euclid's algorithm. """ while b: a, b = b, a % b return a def compute_lcm(a: int, b: int) -> int: """ Computes the least common multiple of a and b. """ if a == 0 or b == 0: ...
import pytest from solution import compute_gcd, compute_lcm, count_trailing_zeros, compute_gcd_bitwise def test_compute_gcd(): assert compute_gcd(48, 18) == 6 assert compute_gcd(101, 103) == 1 assert compute_gcd(0, 0) == 0 assert compute_gcd(0, 10) == 10 assert compute_gcd(50, 0) == 50 def test_co...
[ { "docstring": "Computes the greatest common divisor of a and b using Euclid's algorithm.", "function_declaration": "def compute_gcd(a, b):", "function_name": "compute_gcd", "parameter_list": "(a, b)" }, { "docstring": "Computes the least common multiple of a and b.", "function_declarati...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def compute_gcd(a: int, b: int) -> int:\n \"\"\"\n Returns the greatest common divisor (GCD) of two non-negative integers using the Euclidean algorithm....
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037609", "row_id": 37609, "seed_ids": "[166]" }
0.672612
Data_Structure_37609
I
[ "compute_gcd", "compute_lcm", "count_trailing_zeros", "compute_gcd_bitwise" ]
4
[ [ "compute_lcm", "compute_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
07b41c664393570f014969951fdb2f2501258789
a074ce5f0e98b290be15c6e41c33a22ab1e2ea2a
v1.0
instruct
Data_Structure
Data_Structure_37611_I
Cosine Similarity Calculation #### Description: You are required to implement a function `cosine_similarity` that calculates the cosine similarity between two given 1D lists (vectors) of floating-point numbers. The vectors must have the same length, and each vector represents coordinates in a multi-dimensional space. ...
import math def _l2_distance(vec): """ Calculate L2 distance (norm) of a vector. :type vec: list :rtype: float """ norm = 0.0 for element in vec: norm += element * element return math.sqrt(norm) def cosine_similarity(vec1, vec2): """ Calculate cosine similarity bet...
from solution import cosine_similarity def test_cosine_similarity_basic(): assert math.isclose(cosine_similarity([1, 0], [0, 1]), 0.0) def test_cosine_similarity_same_vector(): assert math.isclose(cosine_similarity([1, 2, 3], [1, 2, 3]), 1.0) def test_cosine_similarity_different_lengths(): try: ...
[ { "docstring": "Calculate L2 distance (norm) of a vector.\n\n:type vec: list\n:rtype: float", "function_declaration": "def _l2_distance(vec):", "function_name": "_l2_distance", "parameter_list": "(vec)" }, { "docstring": "Calculate cosine similarity between two vectors.\n\n:type vec1: list o...
[ 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 math\n\ndef _l2_distance(vec):\n \"\"\"\n Calculate L2 distance (norm) of a vector.\n \n :type vec: list\n :rtype: float\n \"\"\"\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037611", "row_id": 37611, "seed_ids": "[149]" }
0.563761
Data_Structure_37611
I
[ "_l2_distance", "cosine_similarity" ]
2
[ [ "cosine_similarity", "_l2_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
29c09a0104f5feb6b7c4b2f1a3f86b5e91a40e03
61c7c310cdad5b954a80fbd58326b6ea24c45e73
v1.0
instruct
Data_Structure
Data_Structure_37717_I
### Word Square Generator **Scenario**: Imagine you are working on a popular word puzzle game where players need to form word squares. A word square is an arrangement of words in a square grid such that each row and column reads the same word. You are tasked with implementing a function that generates all possible wor...
from typing import List, Dict, DefaultDict from collections import defaultdict def build_prefix_dict(words: List[str]) -> Dict[str, List[str]]: prefix_dict = defaultdict(list) for word in words: for i in range(len(word) + 1): prefix = word[:i] prefix_dict[prefix].append(word) ...
from solution import generate_word_squares def test_generate_word_squares_example(): words = ["area", "lead", "wall", "lady", "ball"] expected_output = [ ["wall", "area", "lead", "lady"], ["ball", "area", "lead", "lady"] ] assert generate_word_squares(words) == expected_output def test...
[ { "docstring": null, "function_declaration": "def build_prefix_dict(words):", "function_name": "build_prefix_dict", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def backtrack(step, word_square, length, prefix_dict, results):", "function_name": "backtra...
[ 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 collections import defaultdict\nfrom typing import List\n\ndef generate_word_squares(words: List[str]) -> List[List[str]]:\n def build_prefix_dict(wor...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00037717", "row_id": 37717, "seed_ids": "[87]" }
0.596143
Data_Structure_37717
I
[ "build_prefix_dict", "backtrack", "generate_word_squares" ]
3
[ [ "generate_word_squares", "backtrack" ], [ "generate_word_squares", "build_prefix_dict" ] ]
2
[]
false
[]
false
pytest
true
[]
true
1b5a8c2ad17ef9820166bccb32f0f28c949f4022
3ad1bedc912ed3efd29c47a241069a93c3e0c41c
v1.0
instruct
Data_Structure
Data_Structure_37726_I
### Programming Exercise #### Scenario You have been hired by a software company to work on their text editing tool's "find" functionality. The current implementation is too slow for large documents, and they have decided to use the Knuth-Morris-Pratt string matching algorithm to improve performance. #### Task Imple...
from typing import List def compute_lps(pattern: str) -> List[int]: """ Compute the longest prefix which is also suffix array (LPS array) for the pattern. """ lps = [0] * len(pattern) length = 0 # length of the previous longest prefix suffix i = 1 while i < len(pattern): if pa...
from solution import knuth_morris_pratt def test_knuth_morris_pratt(): assert knuth_morris_pratt('hello there hero!', 'he') == [0, 7, 12] assert knuth_morris_pratt('abcd', 'e') == [] assert knuth_morris_pratt('abababab', 'ab') == [0, 2, 4, 6] assert knuth_morris_pratt('aaaaa', 'aa') == [0, 1, 2, 3] ...
[ { "docstring": "Compute the longest prefix which is also suffix array (LPS array) for the pattern.", "function_declaration": "def compute_lps(pattern):", "function_name": "compute_lps", "parameter_list": "(pattern)" }, { "docstring": "Find all occurrences of the pattern in the given text usi...
[ 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 knuth_morris_pratt(text: str, pattern: str) -> List[int]:\n if not pattern:\n return []\n\n def compute_lps(patter...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037726", "row_id": 37726, "seed_ids": "[93]" }
0.578701
Data_Structure_37726
I
[ "compute_lps", "knuth_morris_pratt" ]
2
[ [ "knuth_morris_pratt", "compute_lps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
45fc635c96c3048686e3068a8554dd36b50005dd
d0e03b8640ccded592dab126fd289e97fe867c9d
v1.0
instruct
Data_Structure
Data_Structure_37748_I
You are required to implement a function `invert_matrix(matrix: List[List[int]]) -> List[List[int]]` that inverts a given square matrix. Follow these steps and constraints carefully to complete the task. ### Input: - A 2D list, `matrix`, containing integers with dimensions n x n (1 ≤ n ≤ 10), representing the square ...
from typing import List def determinant(matrix: List[List[float]]) -> float: n = len(matrix) if n == 1: return matrix[0][0] if n == 2: return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0] det = 0 for col in range(n): submatrix = [row[:col] + row[col+1:]...
def test_invert_valid_matrix_2x2(): matrix = [ [4, 7], [2, 6] ] expected = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) assert result == expected def test_invert_valid_matrix_3x3(): matrix = [ [1, 2, 3], [0, 1, 4], [5, 6...
[ { "docstring": null, "function_declaration": "def determinant(matrix):", "function_name": "determinant", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def adjugate(matrix):", "function_name": "adjugate", "parameter_list": "(matrix)" }, { "d...
[ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Union\n\ndef invert_matrix(matrix: List[List[Union[int, float]]]) -> List[List[float]]:\n # Check if input is a matrix\n if not...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00037748", "row_id": 37748, "seed_ids": "[347]" }
0.600756
Data_Structure_37748
I
[ "determinant", "adjugate", "invert_matrix" ]
3
[ [ "adjugate", "determinant" ], [ "invert_matrix", "adjugate" ], [ "invert_matrix", "determinant" ] ]
3
[]
false
[]
false
pytest
false
[]
true
5455a19fe5e27fa79717985c4351ace0e01c614d
1b912261a8f51c58e0f9e97cf9c09c786a0f21bb
v1.0
instruct
Data_Structure
Data_Structure_37757_I
### Coding Challenge: Efficient CRT Solver with Pairwise Coprime Check **Scenario**: In a digital security exercise, you need to solve a series of simultaneous congruences using the Chinese Remainder Theorem (CRT). The system is secure only when the moduli of the congruences are pairwise coprime. Your task is to imple...
from typing import List def gcd(a, b): while b: a, b = b, a % b return a def are_pairwise_coprime(nums: List[int]) -> bool: n = len(nums) for i in range(n): for j in range(i + 1, n): if gcd(nums[i], nums[j]) != 1: return False return True def extended_g...
import pytest from solution import efficient_solve_chinese_remainder, gcd, are_pairwise_coprime def test_gcd(): assert gcd(48, 18) == 6 assert gcd(101, 103) == 1 assert gcd(20, 8) == 4 def test_are_pairwise_coprime(): assert are_pairwise_coprime([3, 5, 7]) == True assert are_pairwise_coprime([4, 5...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def are_pairwise_coprime(nums):", "function_name": "are_pairwise_coprime", "parameter_list": "(nums)" }, { "d...
[ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom math import gcd\n\ndef pairwise_coprime(nums: List[int]) -> bool:\n for i in range(len(nums)):\n for j in range(i + 1,...
trial_gpt4o_6
{ "original_instruction": "", "prompt_id": "00037757", "row_id": 37757, "seed_ids": "[158]" }
0.614407
Data_Structure_37757
I
[ "gcd", "are_pairwise_coprime", "extended_gcd", "efficient_solve_chinese_remainder" ]
4
[ [ "are_pairwise_coprime", "gcd" ], [ "efficient_solve_chinese_remainder", "are_pairwise_coprime" ], [ "efficient_solve_chinese_remainder", "extended_gcd" ] ]
3
[]
false
[]
false
pytest
true
[]
true
a854c825a084d3676c617d6b7a2fc315f566ca58
e33f368d2b94223162ecefa57cef217720d54342
v1.0
instruct
Data_Structure
Data_Structure_37764_I
### Function Implementation: Subtree Checker **Context**: Consider a scenario where you are working with hierarchical data representations using binary trees. With given two binary trees s and t, you need to verify if t is a subtree of s. A subtree of s is defined as a tree consisting of a node in s and all of its des...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def is_subtree(big, small): if not small: return True if not big: return False if is_same_tree(big, small): return True return is_subtree(big.left, small) or i...
from solution import TreeNode, is_subtree def test_same_tree_structure1(): 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 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": "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": "", "prompt_id": "00037764", "row_id": 37764, "seed_ids": "[288]" }
0.629062
Data_Structure_37764
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
7f8a6042a4c0d9323f4b9388351357ff762a716d
e76602e57ec972160907b822e2b66294f7cc4bf0
v1.0
instruct
Data_Structure
Data_Structure_37784_I
You are tasked to sort a list of integers using the merge sort algorithm. But in this challenge, you will enhance the standard implementation by handling arrays with fewer than a threshold length using insertion sort. This hybrid sorting approach can lead to improved performance for certain inputs. ### Function Signat...
from typing import List def insertion_sort(arr: List[int]) -> List[int]: for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr def merge(left: List[int], right: List[int]...
import pytest from solution import hybrid_sort def test_hybrid_sort_small_array(): assert hybrid_sort([4, 1, 7, 0, 3], 2) == [0, 1, 3, 4, 7] assert hybrid_sort([10, 3, 5, 1, 9], 1) == [1, 3, 5, 9, 10] def test_hybrid_sort_large_array(): assert hybrid_sort([38, 27, 43, 3, 9, 82, 10], 4) == [3, 9, 10, 27, 3...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(arr: List[int]) -> List[int]:\n for i in range(1, len(arr)):\n key = arr[i]\n j = i - 1\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037784", "row_id": 37784, "seed_ids": "[12]" }
0.626334
Data_Structure_37784
I
[ "insertion_sort", "merge", "hybrid_sort" ]
3
[ [ "hybrid_sort", "insertion_sort" ], [ "hybrid_sort", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d9f651d5d1f6a0e4179f4ebde6853050879f1129
70c4ff2c228982e656563b2cbc7f44eb70c5cd26
v1.0
instruct
Data_Structure
Data_Structure_37806_I
**String Manipulation**: Write a function `reverse_string` that takes a single argument `s` (a string) and returns the string reversed. ### Requirements 1. Implement the function using at least three different methods: recursive, iterative, and a built-in Python function. 2. Ensure your reverse_string function can han...
def reverse_string_recursive(s): """ Reverse the string `s` using a recursive approach. Time complexity: O(n) Space complexity: O(n) due to the recursive call stack """ if len(s) == 0: return "" else: return s[-1] + reverse_string_recursive(s[:-1]) def reverse_string_iterati...
def test_reverse_string_recursive(): assert reverse_string_recursive("") == "" assert reverse_string_recursive("a") == "a" assert reverse_string_recursive("ab") == "ba" assert reverse_string_recursive("hello") == "olleh" assert reverse_string_recursive("1234567890") == "0987654321" def test_rev...
[ { "docstring": "Reverse the string `s` using a recursive approach.\nTime complexity: O(n)\nSpace complexity: O(n) due to the recursive call stack", "function_declaration": "def reverse_string_recursive(s):", "function_name": "reverse_string_recursive", "parameter_list": "(s)" }, { "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": "def reverse_string_recursive(s):\n \"\"\"\n Returns the reverse of the string s using a recursive approach.\n \"\"\"\n if len(s) == 0:\n re...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00037806", "row_id": 37806, "seed_ids": "[61]" }
0.754706
Data_Structure_37806
I
[ "reverse_string_recursive", "reverse_string_iterative", "reverse_string_builtin", "reverse_string" ]
4
[ [ "reverse_string", "reverse_string_builtin" ], [ "reverse_string", "reverse_string_iterative" ], [ "reverse_string", "reverse_string_recursive" ] ]
3
[]
false
[]
false
pytest
false
[]
true
36fef957ea91c9d817b0d38ad5f74e02cd36e161
81d543ceb30d429a2591f033004dcfe56bab39d7