Zusammenfassung der Ressource
Data Structures - Abstract Data Types
- The Queue
Anmerkungen:
- Queue is recursive data structure
Items are added at the back of the queue
- FIFO
Queue preserves order.
- We can only access the data from one place.
- Process the information in the same order they were received.
- size
- O(1)
- peek
Anmerkungen:
- Return the last item, which is front most item in the Queue.
- return self.items[-1]
- O(1)
Anmerkungen:
- if self.items:
return self.items[-1]
- is_empty
Anmerkungen:
- return self.items == []
- Returns a boolean value representing if the Queue is empty
- O(1)
- enqueue
Anmerkungen:
- -- insert the item at the 0th position
- O(n)
Anmerkungen:
- The runtime is O(n) or linear time because inserting into the 0th index of the list enforces all the items to be pushed.
- dequeue
Anmerkungen:
- Returns and removes the front most item from the Queue
- self.items.pop()
- O(1)
- Stack
Anmerkungen:
- push
- O(1)
- pop
- O(1)
- peek
Anmerkungen:
- Show us the next value which can be popped
- O(1)
Anmerkungen:
- Indexing in the list is constant time
- size
Anmerkungen:
- Just use the length method of the list
- O(1)
Anmerkungen:
- The method runs in constant time
- is_empty
- O(1)
- Deque
Anmerkungen:
- Can add items to both ends.
- mutable and needs ordered collection of data structures. Can be implemented using list.
- limited access datatype
- If the string is palindrome. deque data structures is best.
- add_front
Anmerkungen:
- Inserting the items to the 0th position
- O(N)
- add_rear
Anmerkungen:
- Just append the item. Constant runt time as the items are added to the end.
- O(1)
- remove_front
Anmerkungen:
- Just use Lists builtin pop method and pass 0
- O(N)
- remove_rear
- O(1)
Anmerkungen:
- Just use the lists pop method without any argument
- peek_front
Anmerkungen:
- Return the item at list index 0th position.
- O(1)
- size
Anmerkungen:
- Return the length of self.items
- O(1)
- O(1)
Anmerkungen:
- Just use the length fuction
- is_empty
- O(1)
- peek_rear
Anmerkungen:
- return the item at -1 index for getting the last item from the list
- O(1)