Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Soukaina Fali Boubrahimi CSc 2720- Data Structures: Lab 7 Given an array of unique positive integers, write a function findSurns that takes the array input
Soukaina Fali Boubrahimi CSc 2720- Data Structures: Lab 7 Given an array of unique positive integers, write a function findSurns that takes the array input and 1. Creates a hashtable called "hashT and inserts all the elements of the input array in the hashtable. 2. Finds pairs of clements in the hashtable whose sum is anather element (sum) in the hashtable and print the pairs in the console. 3. Returns anather hashtable names "sums af those sum elements For example: Input: [1,5,4,6,7,9 output: t6,5,7,91 Explanation: 6-1+5; 5-147-16;9-54 Class Tenplate irport java.util.HashSet public class FindSun t public static void nain(String args [] arr 1, 5, 4, 6, 7, 9 ) HashSet t HashSetInteger suns = new HashSet(); findsus (it[ clanants) // Initialize hashtable HashSotcIntogar> hashtable-now HashSatcIntegor) To add "newiten" to hashtable To check if "it exist in hashtable hashtableadd(newTtem) hashtable.contains(iten); return sums
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started