0% found this document useful (0 votes)
12 views26 pages

Lecture 1.Pptx 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views26 pages

Lecture 1.Pptx 3

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

NEHRU ARTS AND SCIENCE COLLEGE

COIMBATORE -641 105

DEPARTMENT OF INFORMATION TECHNOLOGY


Course: Data Structures

Facilitator : Dr.S.Saraswathi
Symbol Table
Introduction
• Symbol table is an important data structure created and
maintained by compilers in order to store information about the
occurrence of various entities such as variable names, function
names, objects, classes, interfaces, etc.

• Symbol table is used by both the analysis and the synthesis


parts of a compiler.
A symbol table may serve the following purposes depending upon
the language in hand:

• To store the names of all entities in a structured form at one


place.

• To verify if a variable has been declared.

• To implement type checking, by verifying assignments and


expressions in the source code are semantically correct.

• To determine the scope of a name (scope resolution).


• A symbol table is simply a table which can be either linear or a hash
table. It maintains an entry for each name in the following format:

<symbol name, type, attribute>


• For example, if a symbol table has to store information about the following
variable declaration:

static int interest;


• then it should store the entry such as:

<interest, int, static>


• The attribute clause contains the entries related to the name.
Implementation

A symbol table can be implemented in one of the following


ways:

• Linear (sorted or unsorted) list

• Binary Search Tree

• Hash table
Operations

• insert(): insert the symbols into the table.

• lookup(): operation is used to search a name in the symbol


table

• Delete(): to remove the symbol from the table.


Advantages of Symbol Table
1. The efficiency of a program can be increased by using symbol tables, which give quick
and simple access to crucial data such as variable and function names, data kinds, and
memory locations.

2. better coding structure Symbol tables can be used to organize and simplify code, making
it simpler to comprehend, discover, and correct problems.

3. Faster code execution: By offering quick access to information like memory addresses,
symbol tables can be utilized to optimize code execution by lowering the number of
memory accesses required during execution.
1. Symbol tables can be used to increase the portability of code by offering a standardized
method of storing and retrieving data, which can make it simpler to migrate code between
other systems or programming languages.

2. Improved code reuse: By offering a standardized method of storing and accessing


information, symbol tables can be utilized to increase the reuse of code across multiple
projects.

3. Symbol tables can be used to facilitate easy access to and examination of a program’s
state during execution, enhancing debugging by making it simpler to identify and correct
mistakes.
Disadvantages of Symbol Table
1. Increased memory consumption: Systems with low memory resources may suffer from symbol tables’ high
memory requirements.

2. Increased processing time: The creation and processing of symbol tables can take a long time, which can be
problematic in systems with constrained processing power.

3. Complexity: Developers who are not familiar with compiler design may find symbol tables difficult to construct
and maintain.

4. Limited scalability: Symbol tables may not be appropriate for large-scale projects or applications that require o
the management of enormous amounts of data due to their limited scalability.

5. Upkeep: Maintaining and updating symbol tables on a regular basis can be time- and resource-consuming.

6. Limited functionality: It’s possible that symbol tables don’t offer all the features a developer needs, and therefore
more tools or libraries will be needed to round out their capabilities.
Static and Dynamic Data Structure
Aspect Static Data Structure Dynamic Data Structure

Memory allocation Memory is allocated at compile-time Memory is allocated at run-time

Size Size is fixed and cannot be modified Size can be modified during runtime

Memory utilization Memory utilization may be inefficient Memory utilization is efficient as memory can be reused

Access time may be slower due to indexing and pointer


Access Access time is faster as it is fixed
usage

Examples Arrays, Stacks, Queues, Trees (with fixed size) Lists, Trees (with variable size), Hash tables
Advantage of Static data structure :
• Fast access time
• Predictable memory usage
• Ease of implementation and optimization
• Efficient memory management
• Simplified code
• Reduced overhead
Advantage Of Dynamic Data Structure
:
• Flexibility
• Reduced memory waste
• Improved performance for some operations
• Simplified code
• Scalability
Static Tree Table
Huffman Algorithm

• Huffman algorithm is a method for building an extended binary tree


with a minimum weighted path length...
• In 1951, David Huffman found the “most efficient method of
representing numbers, letters, and other symbols”
• (i) Data can be encoded efficiently using Huffman Codes.
• (ii) It is a widely used and beneficial technique for
compressing data.
• (iii) Huffman's greedy algorithm uses a table of the
frequencies of occurrences of each character to build up an
optimal way of representing each character as a binary
string.
• Suppose we have 105 characters in a data file. Normal Storage: 8 bits
per character (ASCII) - 8 x 105 bits in a file.
• But we want to compress the file and save it compactly. Suppose only
six characters appear in the file:
Fixed length Code
• Each letter represented by an equal number of bits. With a fixed length code, at least 3
bits per character:
•a 000

•b 001

•c 010
For a file with 105 characters, we need 3 x 105 bits.
•d 011

•e 100

•f 101
A variable-length code
• It can do considerably better than a fixed-length code, by
giving many characters short code words and infrequent
character long codewords.
• a 0
• b 101
• c 100
• d 111
• e 1101
• f 1100
• Number of bits = (45 x 1 + 13 x 3 + 12 x 3 + 16 x 3 + 9 x 4 + 5 x 4) x 1000
• = 2.24 x 105bits
Algorithm of Huffman Code

Huffman (C)
1. n=|C|
2. Q ← C
3. for i=1 to n-1
4. do
5. z= allocate-Node ()
6. x= left[z]=Extract-Min(Q)
7. y= right[z] =Extract-Min(Q)
8. f [z]=f[x]+f[y]
9. Insert (Q, z)
10. return Extract-Min (Q)
Find an optimal Huffman Code for the following set of
frequencies: a: 50 b: 25 c: 15 d: 40 e: 75
Again for i=2
Similarly, we apply the same process we get
Thank you

You might also like