Lecture9 - Algorithms in Systems Engineering ISE 172...

Info icon This preview shows pages 1–10. Sign up to view the full content.

Algorithms in Systems Engineering ISE 172 Lecture 9 Dr. Ted Ralphs
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

ISE 172 Lecture 9 1 References for Today’s Lecture Required reading Chapter 5 References CLRS Section 11.1, Chapter 12 D.E. Knuth, The Art of Computer Programming, Volume 3: Sorting and Searching (Third Edition), 1998. R. Sedgewick, Algorithms in C++ (Third Edition), 1998.
Image of page 2
ISE 172 Lecture 9 2 Symbol Tables and Dictionaries We have now discussed in detail the ADT for a list and have seen two implementations, as well as other data structures built on lists. We now consider a different kind of list data structure that supports different kinds of operations. A symbol table is a data structure for storing a list of items, each with a key and satellite data . This data structure supports the following basic operations. Construct a symbol table. Search for an item (or items) having a specified key. Insert an item. Remove a specified item. Count the number of items. Print the list of items. Symbol tables are also called dictionaries because of the obvious comparison with looking up entries in a dictionary. Note that the keys may not have an ordering.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

ISE 172 Lecture 9 3 Additional Operations on Symbol Tables If the items can be ordered, e.g., by lt and eq , we may support the following additional operations. Sort the items (print them in sorted order). Return the maximum or minimum item. Select the k th item. Return the successor or predecessor of a given item. We may also want to be able to join two symbol tables into one. These operations may or may not be supported in various implementations.
Image of page 4
ISE 172 Lecture 9 4 Applications of Symbol Tables What are some applications of symbol tables?
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

ISE 172 Lecture 9 5 Dictionary ADT class Dictionary: def __init__() def __getitem__(key) def __setitem__(key, value) def __delitem__(key) def __contains__(key) def __len__() def get() def keys() def values() def items() def sort()
Image of page 6
ISE 172 Lecture 9 6 Implementation Consider a list of items whose keys are small positive integers. Assuming no duplicate keys, we can implement such a symbol table using an unordered list. class Dictionary: def __init__(self, maxKey): self.list = [None for i in range(maxKey)] self.maxKey = maxKey def append(self, key, value): self.list[key] = value def remove(key): self.list[key] = None def __contains__(key) if self.list[key] = None: return False else: return True
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

ISE 172 Lecture 9 7 Implementation (cont.) def __getitem__(self, key): for i in self.list: if i != None: key -= 1 if key == 0: return self.list[i] def sort(self): pass def __len__(self): count = 0 for i in self.list if i != None: count += 1 return count
Image of page 8
ISE 172 Lecture 9 8 Arbitrary Keys Note that with arrays, most operations are constant time.
Image of page 9

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern