L06 - ContiguousMemoryStructures.pdf - Contiguous Data...

This preview shows page 1 - 10 out of 30 pages.

Contiguous Data Structures
ObjectivesReview of CS 171 data structuresTuplesListsDictionariesIntroduce Queues and StacksUnderstand Contiguous MemoryReadingPhillips: Chapter 624/29/2019
Data Structures34/29/2019
Linear Data StructuresLinear structures can be thought of as having two ends.Sometimes these ends are referred to as:The “left” and the “right” The “front” and the “rear” The “top” and the “bottom” What distinguishes one linear structure from another is the way in which items are added and removed44/29/2019
Basic Python Data StructuresIn CS171 you learned about different ways to have collections of objects.In particular tuples, lists, sets, and dictionaries.5DefinitionMutableElement accessCreationTupleOrdered sequence of valuesNoIndexed by integer numbersmyTuple = ()ListOrdered sequence of valuesYesIndexed by integer numbersmyList = []DictionaryUnordered set of key:valuepairs. YesMembers are accessed by keys (immutable objects)myDict = {}SetsUnordered collection with no duplicate elementsYesYou can loop through the set items using a for loop, or ask if a specified value is present in a set, by using the in keyword.mySet = set()4/29/2019
More Data StructuresTuples, Lists, Sets, and Dictionaries are great “general use” data structuresHowever, for certain applications and algorithms a different data structure may be appropriateAlthough it may be built upon one of these aforementioned data structuresChoosing the right data structure can help inIncreasing performanceIncreasing ease of useOne data structure that is built on top of lists are queues64/29/2019
QueuesThe word queue is related to the English word for a line.If we’re at the supermarket, we’d hope that the first person in line, is the first person served.And once he/she is served, they are removed from the front of the line.If anyone new shows up, they’re added to the end of the line.Therefore a queue is also referred to as a FIFOdata structureFirst In – First Out74/29/2019
QueuesHopefully we can think of a lot of good computer-science applications for Queues:Storing (and servicing) messages received on a networkStoring (and servicing) requests to use the CPUEtc.So if we were to design a queue data structure, we would want it to efficiently allow for:Adding things to the endRemoving things from the front.These operations are typically called enqueueand dequeue, respectivelyHowever in Python they’re referred to as putand get, respectively84/29/2019
Queues in PythonPython provides for us the Queueclass.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture