Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Show the MAP M after each of a series of following operations on an initially em

ID: 3830419 • Letter: S

Question

Show the MAP M after each of a series of following operations on an initially empty map storing integer keys and single-character values. (The map is assumed to be an unsorted map). put (k, V): If M does not have an entry with key equal to k, then adds entry (k, V) to M and returns null; else, replaces with V the existing value of the entry with key equal to k and returns the old value. remove (k): Removes from M the entry with key equal to k, and returns its value; if M has no such entry, then returns null. get (k): Returns the value V associated with key k, if such an entry exists; otherwise returns null.

Explanation / Answer

Put(5,A) ->           5,A

Put(7,B) ->           5,A

                              7,B

Put(2,C) ->           5,A

                              7,B

                              2,C

Put(8,D) ->           5,A

                              7,B

                              2,C

                              8,D

Put(2,E) ->           5,A

                              7,B

2,E         //since 2 is already there, replace the existing value with the new value

                              8,D

Get(4)                   null         //since map does not contain 4 as a key, so it will return null. Values in map remains same

Remove(5)          7,B

2,E

                              8,D

Remove(2)          7,B

                              8,D

Get(2)                   null

Remove(2)          null         // since map does not contain 2 as a key

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote