Data Structures - For my Ninth Grader – Part 2
Data Structures - For my Ninth Grader – Part 1
Data Structures - For my Ninth Grader – Part 1
Set: Let’s keep
all of the members of from49ers (http://www.49ers.com/team/roster.html) in a
room. No two members are
identical, everyone is unique and they have reason to be in room ( after all
they are on 49ers roster). In the room each member can do whatever each wish;
each member can exist without any specific order. You have a Set.
Set is a data structure that can store certain values,
without any particular order, and no repeated values.
One can do following operations on a set:
- Add a specific item to the set >>> add (item)
- Remove a specific item from the set >>> remove (item)
- Find out if specific item is in set >>> IsElementOf (item)
- Find out if list is set >>> isEmpty()
- Find out number of items in the set >>> size()
- How many number of items a set can hold >>> capacity()
- Get an arbitrary element from a set >>> pop()
- Delete all elements from a set >>> clear()
Map: Lets’ write
each telephone number in ordered fashion in notebook for city of Sunnyvale (http://sunnyvale.ca.gov). In front
of each telephone number write name of owner and address. Each telephone number
is unique. If someone knows a telephone number, he can find that who owns this
telephone number. In this case Telephone number is Key and telephone owner name
and address is value. It is also possible that a person can own multiple
telephone numbers in that case his name will appear at multiple places in your
notebook. This note book represents a map.
A map is an ordered data structure in which collections of
unique key and collections of values are stored where each key is associated
with one value. The operation of finding the value is called lookup.
One can do following operations on a map:
- Add a specific item with specific key to a map >>> add (key, value)
- Remove an item associated with a specific key from a map >>> remove (key)
- Find out the item associated with a key in a map >>> lookup (key)
- Replace the value in one of the (key,value) pairs that are already in the collection >>> reassign(key, value)
- Delete all elements from a map >>> clear()
Map is an ordered data structure. This means that elements are
maintained in sequence, the ordering determined by key values
No comments:
Post a Comment