Saturday, 28 February 2015

Week 7- Summary of Abstract Data Types

There are 4 ADT's I have learned so far. I learned 2 of them in CSC108 and the other 2 in CSC148. The ADT's I learned so far are lists, stacks, queues and dictionaries.
1. Lists are sequences of items and they can be added, removed, modified, and accessed by position. Lists are mutable. This means that you can modify a list. You can access a list by putting its index in brackets. Empty list is shown as '[]'. You can add a object to a list by using 'append' method which is pre-defined. Len operation helps you to find the length of a list.
2. Stacks are specialized lists where we only have access to most recently added item. They have methods such as pop and push. Pop removes and returns the last item on a stack and push adds an item to the last index of the stack. They also have indexes such as lists.
3.Queues are also specialized lists where we have access to most recently added item and the first item. They have methods such as enqueue and dequeue. The first item gets in and the first item gets out. Enqueue adds the first item to a list and dequeue removes the first item that you put in a queue.
4.Dictionaries are mutable and another container types that can store python objects. Empty dictionary is represented as "{}". Dictionaries have keys and values. You can access the keys and values by a for loop. The general form a dictionary is "{key: value}". You can have one key and multiples values but you can't have multiple keys. Keys have to be immutable.

No comments:

Post a Comment