Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the first video lecture of this week's module, I illustrated a simple way to use hash tables to implement sets ( similar to java.util.HashSet

In the first video lecture of this week's module, I illustrated a simple way to use hash tables to implement sets (similar to java.util.HashSet in Java) and maps (similar to dictionary in Python) in C programming language (The source codes are given under the video on Canvas).
Consider the following programming challenge:
Assuming that a single word (containing to whitespace) is given to a C program as its only command-line argument, the program must print "can become a palindrome" if reordering the letters of the given word produces a palindrome. Otherwise, if no permutation of the given word is a palindrome, the program prints "cannot become a palindrome". Palindrome is a word that reads the same both forward and backward.
For example, letters of string "mississippi" can make the following palindrome: "iipssmsspii", but letters of string "madams" cannot make any palindrome.
1. Try solving this challenge using a hash map whose keys are letters occurred in the given word and values specify the number of occurrences of letters in the word. For example, given the word "mississippi", the map looks like this: "m: 1, i: 4, s: 4, p: 2". After this map is made, count the number of letters with odd occurrences. If more than one letter has appeared odd number of times in the given word, the word cannot become a palindrome; otherwise, it can.
2. Propose another way to solve this challenge using a hash set instead of hash map (both hash set and hash map can solve this challenge with O(n) amortized time complexity where n is the length of given word).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions