Your tasks Implement the methods marked with ??? in frequencies.scala. (as shown in below) (Programming Style Restrictions) (In addition to computing frequencies, we also practice functional programming style in this exercise. Therefore, you are not allowed to use var declarations, Arrays, scala.collection.mutable or java.util data types in this exercise. The val declarations are allowed and even recommended to break down longer sequences of method applications into smaller and more readable parts.) package frequencies: /* * NOTE: this is an exercise on functional programming style. * Therefore, you are NOT allowed to use mutable data structures or vars. */ /** * Given a sequence seq of items of type T, * returns a map that associates each item in the sequence to the number times it * occurs in the sequence. * The resulting map should be undefined for all the items that do not appear in the sequence. * Hint: study the methods of scala.collection.Seq and scala.collection.Map; * For instance, groupBy and map may be useful. */ def frequencies[T](seq: Seq[T]): Map[T, Int] = ??? end frequencies /** * Given a sequence seq of items of type T, * returns a map that associates, to each positive integer i, the set of items * that occur i times in the sequence. * If no item occurs i times in the sequence, then the map must be undefined for that i. */ def freqToItems[T](seq: Seq[T]): Map[Int, Set[T]] = ??? end freqToItems /** * Given a sequence seq of items of type T, * returns the set of all items that occur most frequently in the sequence. * If the sequence is empty, then (and only then) the resulting set should be empty. */ def mostFrequent[T](seq: Seq[T]): Set[T] = ??? end mostFrequent
Your tasks Implement the methods marked with ??? in frequencies.scala. (as shown in below) (Programming Style Restrictions) (In addition to computing frequencies, we also practice functional programming style in this exercise. Therefore, you are not allowed to use var declarations, Arrays, scala.collection.mutable or java.util data types in this exercise. The val declarations are allowed and even recommended to break down longer sequences of method applications into smaller and more readable parts.) package frequencies: /* * NOTE: this is an exercise on functional programming style. * Therefore, you are NOT allowed to use mutable data structures or vars. */ /** * Given a sequence seq of items of type T, * returns a map that associates each item in the sequence to the number times it * occurs in the sequence. * The resulting map should be undefined for all the items that do not appear in the sequence. * Hint: study the methods of scala.collection.Seq and scala.collection.Map; * For instance, groupBy and map may be useful. */ def frequencies[T](seq: Seq[T]): Map[T, Int] = ??? end frequencies /** * Given a sequence seq of items of type T, * returns a map that associates, to each positive integer i, the set of items * that occur i times in the sequence. * If no item occurs i times in the sequence, then the map must be undefined for that i. */ def freqToItems[T](seq: Seq[T]): Map[Int, Set[T]] = ??? end freqToItems /** * Given a sequence seq of items of type T, * returns the set of all items that occur most frequently in the sequence. * If the sequence is empty, then (and only then) the resulting set should be empty. */ def mostFrequent[T](seq: Seq[T]): Set[T] = ??? end mostFrequent
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
Your tasks
- Implement the methods marked with ??? in frequencies.scala. (as shown in below)
(Programming Style Restrictions)
(In addition to computing frequencies, we also practice functional programming style in this exercise. Therefore, you are not allowed to use var declarations, Arrays, scala.collection.mutable or java.util data types in this exercise. The val declarations are allowed and even recommended to break down longer sequences of method applications into smaller and more readable parts.)
package frequencies:
/*
* NOTE: this is an exercise on functional programming style.
* Therefore, you are NOT allowed to use mutable data structures or vars.
*/
/**
* Given a sequence seq of items of type T,
* returns a map that associates each item in the sequence to the number times it
* occurs in the sequence.
* The resulting map should be undefined for all the items that do not appear in the sequence.
* Hint: study the methods of scala.collection.Seq and scala.collection.Map;
* For instance, groupBy and map may be useful.
*/
def frequencies[T](seq: Seq[T]): Map[T, Int] =
???
end frequencies
/**
* Given a sequence seq of items of type T,
* returns a map that associates, to each positive integer i, the set of items
* that occur i times in the sequence.
* If no item occurs i times in the sequence, then the map must be undefined for that i.
*/
def freqToItems[T](seq: Seq[T]): Map[Int, Set[T]] =
???
end freqToItems
/**
* Given a sequence seq of items of type T,
* returns the set of all items that occur most frequently in the sequence.
* If the sequence is empty, then (and only then) the resulting set should be empty.
*/
def mostFrequent[T](seq: Seq[T]): Set[T] =
???
end mostFrequent
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education