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

Problem Set-1

The document outlines Problem Set 1 for a Data Structure and Algorithm training course, consisting of six problems focusing on basic problem-solving skills. Each problem includes specific tasks such as identifying Pythagorean triples, calculating sums of powers, analyzing triangular matrices, finding the second largest number in a sequence, summing adjacent pairs, and generating an inverted right-angle triangle pattern. Test cases are provided for each problem to illustrate expected inputs and outputs.

Uploaded by

Akhilesh Bhadana
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 views4 pages

Problem Set-1

The document outlines Problem Set 1 for a Data Structure and Algorithm training course, consisting of six problems focusing on basic problem-solving skills. Each problem includes specific tasks such as identifying Pythagorean triples, calculating sums of powers, analyzing triangular matrices, finding the second largest number in a sequence, summing adjacent pairs, and generating an inverted right-angle triangle pattern. Test cases are provided for each problem to illustrate expected inputs and outputs.

Uploaded by

Akhilesh Bhadana
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

Problem Set 1: Basic problem solving Data structure and Algorithm Training

Data Structure and Algorithms

Problem Set 1: Basic problem solving

Date of issue: Due Date:

Problem 1) Pythagorean triple: Three numbers form a Pythagorean triple if the sum of
squares of two numbers is equal to the square of the third.

For example, 3, 5 and 4 form a Pythagorean triple, since 3*3 + 4*4 = 25 = 5*5

You are given three integers, a, b, and c. They need not be given in increasing order. If they
form a Pythagorean triple, then print "yes", otherwise, print "no". Please note that the output
message is in small letters.

Input Output

Test Case 1 3 yes


5
4

Test Case 2 5 no
8
2

Problem 2) Sum of powers of number: In this program, you are given an input N, which is a
positive integer less than or equal to 40. Write a program to find the sums of fourth powers of
the first N numbers.

Ex Input: n=2 (1^4+ 2^4)

Output: 17

Input Output

Test Case 1 2 17

Test Case 2 1 1

Page | 1
Problem Set 1: Basic problem solving Data structure and Algorithm Training

Problem 3) Triangular matrix: In this assignment, you will be given an NxN matrix. You have
to determine whether the matrix is a triangular matrix.

The diagonal of the matrix M of size NxN is the set of entries M(0,0), M(1,1), M(2,2), ..., M(N,N).

A matrix is upper triangular if every entry below the diagonal is 0. For example,
111
001
002
is an upper triangular matrix. (The diagonal itself, and the entries above and below the
diagonals can be zeroes or non-zero integers.)

A matrix is lower triangular if every entry above the diagonal is 0. For example,
200
310
422
is a lower triangular matrix.

Input Output

Test Case 1 2 Yes


1 1
0 1

Test Case 2 3 Yes


1 0 0
0 1 0
1 1 2

Test Case 3 3 No
1 0 1
0 1 0
1 1 2

Page | 2
Problem Set 1: Basic problem solving Data structure and Algorithm Training

Problem 4) Find the second largest: You are given a sequence of integers as input,
terminated by a -1. (That is, the input integers may be positive, negative or 0. A -1 in the input
signals the end of the input.)

-1 is not considered as part of the input.

Find the second largest number in the input. You may not use arrays.

Input Output

Test Case 1 -840 -288 -261 -337 -335 488 -1 -261

Test Case 2 -840 -335 -1 -840

Problem 5) Sum of adjacent pairs: You are given a sequence of numbers, ending with
a -1. You can assume that are at least two numbers before the ending -1.
Let us call the sequence x0 x1 ... xn -1.
You have to output the sequence of sums of adjacent pairs of numbers, as follows:
x0+x1 x1+x2 ... xn-1+xn
Note that the sums are separated by spaces. Kindly do not use arrays in the code.
Input Output

Test Case 1 4 5 6 7 -1 9 11 13

Test Case 2 3 4 5 -1 7 9

Test Case 3 1 2 -1 3

Page | 3
Problem Set 1: Basic problem solving Data structure and Algorithm Training

Problem 6) Inverted right angle: Write a program to do the following:-

a) Take height h as the input


b) Based on the height, print h lines in output such that they form a pattern in the shape of
an "inverted" right angled triangle
c) Each line should form an Arithmetic Progression with the starting element = row_number
and common difference = 1. Take modulo 10 for numbers greater than 9

Input Output

Test Case 1 5 12345


2345
345
45
5

Test Case 2 14 12345678901234


2345678901234
345678901234
45678901234
5678901234
678901234
78901234
8901234
901234
01234
1234
234
34
4

Page | 4

You might also like