give you the data like this, how will you check and count how many duplicate cla
ID: 3820106 • Letter: G
Question
give you the data like this, how will you check and count how many duplicate class? using associative array!! thank you.
1236 MATH-142 Spring 2016 Spring 2016 8104 MATH-142 Fall 2015 8240 MATH-121 Fall 2015 8296 MATH-192 Spring 2005 1022 MATH-110 Summer 2005 1050 MATH-110 Summer 2010 1176 MATH-075 1176 Summe r 2008 MATH-075 Summer 2009 1176 MATH-075 Summer 2007 1176 MATH-075 Spring 2005 2273 MATH-080K Spring 2008 8025 MATH-114 Fall 2006 8066 MATH-080C Spring 2010 8111 MATH-075SP Spring 2010 8114 MATH-110SP Spring 2010 8116 MATH-120SP Spring 2009 8171 MATH-110 Spring 2008 8171 MATH-110 Spring 2007 8172 MATH-075 Spring 2006 8172 MATH-075 Spring 2005 8210 MATH-080K Spring 2010 8221 MATH-050 Spring 2010 8222 MATH-051 Spring 2010 8223 MATH-052 Fall 2006 8235 MATH-075 Fall 2008 8235 MATH-075 Fall 2007 8235 MATH-075 Fall 2009 8235 MATH-075 Fall 2010 8513 MATH-075SP Fall 2010 8514 MATH-110SP Fall 2010 8515 MATH-120SP Fall 2010 8531 MATH-050 Fall 2010 8532 MATH-051 Fall 2010 8537 MATH-052 Summer 2016 9025 MATH-114. Summer 2015 9025 MATH-114. Fall 2007 9078 MATH-120 Fall 2013 9091 MATH-142 Fall 2014 9091 MATH-142 Spring 2006 9123 MATH-080C Spring 2007 9123 MATH-080C Fall 2015 9273 MATH-120Explanation / Answer
Let me talk in generic terms. An associative array a collection of (key, value) pairs, such that each possible key appears at most once in the collection, i.e. suppose in a class of students, we may say registration number is the key and student name along with his/her marks is the value set since registration number is unique field.
Suppose we have a tabular data as you have provided containing 4 columns(fields). Among those we need to select the key fields (may be composite i.e. containing multiple fields). Remaining required fields may be considered as value field.
Different implementation of associative array include hash table, binary search tree, or sequential. Among these only by using binary search tree and sequential storage we can access data one after another in much efficient way. And using sequential storage we may face problems during insertion and searching of data (You should know the search technique used in BST vs Linear List). So it is better to use BST implementation.
Solution:
Create a TreeSet<Class, count>
For every tuple of our data set
If class is found in TreeSet
Then we increase the count (count indicating duplicates)
Else
We insert <class, count = 0>
After we are done with insertions, we start traversing the tree (in any order you like) and you shall have all the classes and their duplicate counts.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.