Author |
Topic: Right angle Triangle Problem (Read 3247 times) |
|
sumtatt
Newbie
Gender:
Posts: 23
|
|
Right angle Triangle Problem
« on: Jan 10th, 2012, 5:44am » |
Quote Modify
|
There is array of some number of integers, find the combination of all number which make the right angle triangle. i.e int a[9] = (1,2,3,4,5,6,7,8,10); Answer should be (3,4,5) (6,8,10) Kindly provide the link if it has already asked.
|
« Last Edit: Jan 10th, 2012, 8:12pm by sumtatt » |
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: Rectangle Triangle Problem
« Reply #1 on: Jan 10th, 2012, 6:49am » |
Quote Modify
|
I don't understand what you mean by "make the rectangle triangle. Also, in your output there is a 5, which is not in the input. Is that normal?
|
|
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: Rectangle Triangle Problem
« Reply #3 on: Jan 10th, 2012, 9:46am » |
Quote Modify
|
Makes sense. One method would be to take every pair in the set as the first 2 numbers and do a binary search for the third. Another method would be to generate all triples up to the maximum number in the set and check each triple if it's in the set. The first method would be best if the numbers are few and very large. The second if the numbers are many and relatively small.
|
« Last Edit: Jan 10th, 2012, 9:49am by Grimbal » |
IP Logged |
|
|
|
sumtatt
Newbie
Gender:
Posts: 23
|
|
Re: Rectangle Triangle Problem
« Reply #4 on: Jan 10th, 2012, 11:29am » |
Quote Modify
|
Thanks! What will be the complexity for the same. Can you write the algorithm please?
|
|
IP Logged |
|
|
|
sumtatt
Newbie
Gender:
Posts: 23
|
|
Re: Rectangle Triangle Problem
« Reply #5 on: Jan 10th, 2012, 11:32am » |
Quote Modify
|
Sorry Grimbal.. I have corrected the question. I think i have lost my mind when i was writing. My apologies.
|
|
IP Logged |
|
|
|
|