Algorithm-symbol table, algorithm symbol

Source: Internet
Author: User

Algorithm-symbol table, algorithm symbol

Definition:A symbol table is a data structure that stores key-value pairs. It supports two types of operations: insert (put), storing a new set of key-value pairs into a table; search (get ), obtain the corresponding value based on the given key.

1. Ordered symbol table

2. Cost Model

Search cost model:When learning the implementation of the symbol table, we will count the number of comparisons (equivalence tests or comparison of keys ). When the inner loop is not compared (very small), we will count the number of visits to the array.

 3. Use Cases for symbol tables

/*** Symbol table use case */public class FrequencyCounter {public static void main (String [] args) {int minlen = Integer. parseInt (args [0]); // minimum key length ST <String, Integer> st = new ST <String, Integer> (); // construct the symbol table and calculate the frequency while (! StdIn. isEmpty () {String word = StdIn. readString (); // ignore the shorter word if (word. length () <minlen) {continue;} if (! St. contains (word) {st. put (word, 1);} else {st. put (word, st. get (word) + 1) ;}/// find the most frequently occurring word String max = ""; st. put (max, 0); for (String word: st. keys () {if (st. get (word)> st. get (max) {max = word ;}} StdOut. println (max + "" + st. get (max ));}}

 

Source code download]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.