Skip to main content

C# Assignment - HashTable, Dictionary Lab and HashSet

C# Data structure assignment - HashTable, Dictionary Lab and HashSet




Question 1

In this lab, we will create a very simple HashTable

a. Create a console application
b. Create a new Hash table.
c. Add the following key value pair to the hash table
Josh", "Joshua Whitetail"
"Sam", "Samantha Bernie"
"Eli", "Elizabeth Spiegel"
"Will", "William Johnson"
"Don", "Donald Regan"
d. Use foreach, to print the key and value to console window.


Question 2

 

Write a console application that does the following:
a. The main method should  take a String array (use the one given  below), and store the array's elements into a HashSet to eliminate duplicates, and finally output the number of unique strings in the array and print the strings to the console.
String [] sampleStrings = {"that", "that", "is", "is", "that", "that", "is", "not", "is", "not", "is", "that", "it", "it", "is"};
Output:
Number of Unique Strings: 4
that, is, not, it

b. Add new code to the above application to create a Dictionary that holds the number of occurrences of each unique string in the array, and finally output the unique strings and the number of occurrences of that string to the console.
that  - 5 occurrences
is  - 6 occurrences  and so on....


Question 3
Zimmermann Telegram is a popular german secret communication that was decoded by British Intelligence during World War I. Google to learn more about Zimmermann Telegram.  Zimmermann Telegram used Code book cipher. In this exercise we will create a simple codebook cipher to encrypt and decrypt text messages. The code book cipher will use the following code book extracted cryptology notes by Christensen (2005). This code book has codes for popular words and codes for 26l alphabets to spell the words that are not included in the codebook.

a 141 about 592 all 653 an 589 and 793 are 238 as 462 at 643 b 383 be 279 been 502 but 884 by 197 c 169 call 399 can 375 come 105 could 820 d 974 day 944 did 307 do 816 down 406 e 286 each 208 f 998 find 628 first 034 for 825 from 342 g 117 get 067 go 982 h 148 had 086 has 513 have 282 he 306 her 647 him 093 his 844 how 609 i 550 I 582 if 231 in 725 into 359 is 408 it 128 its 481 j 450 k 284 l 102 like 701 long 938 look 521 m 559 made 644 make 622 many 948 may 954 more 930 my 381 n 964 no 428 not 810 now 975 number 665 o 334 of 461 oil 756 on 482 one 337 or 867 other 831 out 652 p 712 part 019 people 091 q 456 r 856 s 692 said 346 see 861 she 045 so 432 some 664 t 821 than 339 that 607 the 260 their 249 them 273 then 724 there 870 these 066 they 063 this 155 time 881 to 488 two 152 u 092 up 096 use 254 v 715 w 364 was 367 water 892 way 590 we 360 were 011 what 330 when 305 which 204 who 213 will 841 with 469 word 519 would 415 write 116 x 094 y 572 you 703 your 657 z 595

Write a program that create and populates a dictionary with the code book given above. Then use that dictionary to encrypt or decrypt messages.  The main method and the output expected is shown below:

static void Main(string[] args)
        {
            CodeBookCipher cipher = new CodeBookCipher();
            Console.WriteLine(cipher.encrypt("This is a test message"));
            Console.WriteLine(cipher.decrypt("155 408 141 821 286 692 821 559 286 692 692 141 117 286"));
            Console.ReadLine();

        }


 155 408 141 821 286 692 821 559 286 692 692 141 117 286
 this is a t e s t m e s s a g e



Question 4
  1. What is the motivation to use HashTable or Dictionary over other collections such as List or ArrayList?
  2. When do you use a HashSet?




Reference

Christensen, C (2005), Cryptology notes on Codes and Nomenclators 

Hashtable and Dictionary Collection Types - https://msdn.microsoft.com/enus/library/4yh14awz(v=vs.110).aspx

Comments

Popular posts from this blog

A Comprehensive Evaluation of the Internal Consulting Process: Steps and Considerations

Introduction Internal consulting has emerged as a critical function within organizations, offering in-house expertise to solve complex business problems and drive change. It closely mirrors external consulting in methodology but is differentiated by the consultant's intimate knowledge of the organization and a vested interest in its long-term success. This article aims to evaluate the key steps involved in the internal consulting process, offering insights into each phase's significance and challenges. Steps in the Internal Consulting Process The internal consulting process can generally be segmented into five distinct stages: Initial Assessment, Data Collection and Analysis, Solution Development, Implementation, and Evaluation. Below is an evaluation of each step: Step 1: Initial Assessment Objective: To understand the problem or opportunity area and define the scope of the project. Significance: A well-defined scope ensures that the consulting project stays focused and manage...

The Evolving Landscape of Consulting Practice: Changes and Implications

Introduction Consulting is a field that thrives on its ability to adapt to market demands and emerging trends. As businesses evolve due to technological advancements, shifts in consumer behavior, and fluctuations in global markets, consulting practices must keep pace. This article explores some of the significant changes currently transforming the consulting industry and discusses their implications for both consultants and clients. Technological Disruption Data Analytics and Artificial Intelligence Consulting firms are increasingly integrating data analytics and artificial intelligence into their service offerings. These technologies allow consultants to offer data-driven insights that can significantly enhance strategic decision-making. This evolution means consultants now need skills in data interpretation and analysis, alongside their traditional expertise in business strategy. Virtual Consulting Platforms The advent of digital platforms enables consulting services to be offered re...

The Skillset of Internal Consultants: A Comparative Analysis

Introduction In the organizational landscape, the role of internal consultants has gained prominence due to the increasing complexity of business problems and the need for specialized in-house expertise. While many skills required for internal consulting overlap with those of external consultants, there are distinct abilities that set them apart. This article aims to compare and contrast these skill sets to provide a clearer understanding of what makes an effective internal consultant. Skills Common to Both Internal and External Consultants Problem-Solving Both types of consultants need to excel at identifying issues and creating viable solutions. Critical thinking and analytical skills are paramount for dissecting complex situations and recommending actionable strategies. Communication Excellent communication skills are a must for any consultant. Whether it’s making a presentation to stakeholders, writing a report, or simply discussing ideas with a team, effective communication is key...