0% found this document useful (0 votes)
2 views6 pages

CC Worksheet Exp1

The document outlines two experiments in a Computer Science & Engineering course. Experiment 1.1 involves designing a Java program to increment a large integer represented as an array, while Experiment 1.2 focuses on finding unique quadruplets in an array that sum to a target value. Each experiment includes aims, pseudo code, implementation, input/output examples, and complexity analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

CC Worksheet Exp1

The document outlines two experiments in a Computer Science & Engineering course. Experiment 1.1 involves designing a Java program to increment a large integer represented as an array, while Experiment 1.2 focuses on finding unique quadruplets in an array that sum to a target value. Each experiment includes aims, pseudo code, implementation, input/output examples, and complexity analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.1
Student Name: Tasneem Reza UID:24BET10004
Branch: BE-IT Section/Group: 24BET_IOT_BD-704 (B)
Semester: 05 Date of Performance: 13/07/2026
Subject Name: COMPETITIVE CODING-II Subject Code: 24ITP-305

1. Aim: To design and implement a Java program to increment a large integer


represented as an array of digits by one and return the resulting array. (Easy)
[Link]
2. Pseudo code/Logic:

START

Read the number of digits (n).

Create an array of size n.

Input all the digits into the array.

Start checking the digits from the last position.

If the current digit is less than 9,


Increase it by 1.
Print the updated array.
Stop.

Otherwise,
Change the current digit to 0.
Move to the previous digit.

If all the digits become 0,


Create a new array with one extra position.
Put 1 in the first position.
Print the new array.

STOP
3. Implementation/Code:
class Solution {
public int[] plusOne(int[] digits) {
for (int i = [Link] - 1; i >= 0; i--) {
if (digits[i] < 9) {
digits[i]++;
return digits;
}
digits[i] = 0;
}

int[] result = new int[[Link] + 1];


result[0] = 1;
return result;
}
}

4. Output
5. Input
6. digits =
7. [1,2,3]
8. Output
9. [1,2,4]
10. Expected
11. [1,2,4]
5. Time & Space Complexity:
a. Time complexity: O(n)
Where n is the number of digits in the array, as in the worst case all digits are
traversed once.

b. Space complexity: O(1)


The algorithm modifies the input array in place. In the special case where all digits
are 9, a new array of size n + 1 is created, resulting in O(n) total space for the
output array.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment 1.2

1. Aim: To design and implement a Java program to find all unique quadruplets
in an array whose sum is equal to a given target value. (Medium)
[Link]
2. Pseudo code/Logic:

START

Read the size of the array (n).

Input all the array elements.

Input the target value.

Sort the array in ascending order.

Repeat for each first element.


Skip duplicate values.

Repeat for each second element.


Skip duplicate values.

Set two pointers:


left = next element
right = last element

While left is less than right


Calculate the sum of four elements.

If sum equals target


Store the quadruplet.
Skip duplicate values.
Move both pointers.

Else if sum is less than target


Move left pointer forward.

Else
Move right pointer backward.

Display all unique quadruplets.

STOP
3. Implementation/Code:
import [Link].*;

class Solution {
public List<List<Integer>> fourSum(int[] nums, int target) {

List<List<Integer>> ans = new ArrayList<>();


int n = [Link];

[Link](nums);

for (int i = 0; i < n; i++) {

if (i > 0 && nums[i] == nums[i - 1])


continue;

for (int j = i + 1; j < n; j++) {

if (j > i + 1 && nums[j] == nums[j - 1])


continue;

long target2 = (long) target - (long) nums[i] - nums[j];

int left = j + 1;
int right = n - 1;

while (left < right) {

long sum = (long) nums[left] + nums[right];

if (sum < target2) {


left++;
} else if (sum > target2) {
right--;
} else {

[Link]([Link](nums[i], nums[j], nums[left], nums[right]));

while (left < right && nums[left] == nums[left + 1])


left++;

while (left < right && nums[right] == nums[right - 1])


right--;
left++;
right--;
}
}
}
}

return ans;
}
}
4. Input/Output:
Input
nums =
[1,0,-1,0,-2,2]
target =
0
Output
[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]
Expected
[[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]

5. Time/Space Complexity:
a. Time complexity: O(n³)
b. Space complexity: O(1)

You might also like