Junior — Middle
What types of data structures can be used to implement data indexing?
sobes.tech AI
Answer from AI
The following data structures are often used for data indexing in programming:
- Hash tables (Hash maps) — provide fast access by key, usually with amortized time O(1).
- Trees (e.g., binary search trees, B-trees) — allow storing data in sorted order and performing efficient search, insertion, and deletion.
- Trie (prefix tree) — used for string indexing and prefix search.
- Skip list — a probabilistic data structure that provides logarithmic time for search and insertion.
Example of using a hash table in Go:
package main
import "fmt"
func main() {
index := make(map[string]int)
index["apple"] = 1
index["banana"] = 2
fmt.Println(index["apple"]) // Output: 1
}