CS112_25_Slides-symbolTables

CS112_25_Slides-symbolTables - Symbol Tables Yinglin Wang...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112 Fundamentals of Programming Abstractions Symbol Tables Yinglin Wang CS Dept., SJTU CS112 Fundamentals of Programming Abstractions Main points of this lecture Familiar with the concept of a symbol table and the design of its interface The technique of hashing and how it applies to symbol tables
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions What’ s a symbol table? A symbol table is conceptually similar to a dictionary. A symbol tables stores associations between pairs of items. A symbol tables provides a mapping between an identifying tag called a key and an value associated with the key CS112 Fundamentals of Programming Abstractions Symbol Tables In the example shown here, each variable name has an associated value. An interpreter might use such a table as it executes a program. When it needs to know the value of a variable, it looks the variable up in the symbol table.
Background image of page 2
CS112 Fundamentals of Programming Abstractions Examples of Symbol Tables Here is another example that stores the job for each person. Engineer Dan Officer Joan Teacher Sam Engineer Joe Job Person CS112 Fundamentals of Programming Abstractions Interface Design of Symbol Tables The terminology that we will use is that the symbol table associates a value with a key . There are two fundamental operations: Enter lets us add a key/value pair to the table. If the key is already present, we simply change the value to the new one. No key is ever present more than once. There are no such restrictions on values –they can be repeated. Lookup retrieves the value associated with a specified key. The reverse is not possible: there is no function that retrieves the key associated with a value (among other things, several keys might have the same value).
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS112 Fundamentals of Programming Abstractions Implementation of Symbol Tables One way to implement a symbol table would be with parallel arrays. The trouble with this approach is that the best performance we can expect is (if we keep the arrays ordered) O(N) for Enter and O(log N) for Lookup . CS112 Fundamentals of Programming Abstractions Bucket Implementation of Symbol Tables We will take another approach. We will divide the key/value pairs among a number of "buckets". Then to find a value, we only have to search through the bucket where its key resides.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

CS112_25_Slides-symbolTables - Symbol Tables Yinglin Wang...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online