This tutorial is a part of the Data Structures and Algorithms class:
- How data looks like (print it out!)
- How to insert/delete/access/search data
- How fast to insert/delete/access/search data
String data structure:
- is one of the most popular data structures.
- is usually used to store text or any kind of information as text.
- built-in in Javascript.
⬆️ String data structure: on RAM and on code
How data looks like (print it out!)
lecture-3/string-data-structure.js
// initialize
let str = 'Today is a good day to learn Data Structures!'
// print out, see how data looks like
console.log(str) // Today is a good day to learn Data Structures!
$ node string-data-structure.js
Today is a good day to learn Data Structures!
How to insert/delete/access/search data
lecture-3/string-data-structure.js
// insert
str = str + ' So'
console.log(str) // Today is a good day to learn Data Structures! So
console.log(str.concat(' start learning!')) // Today is a good day to learn Data Structures! So start learning!
// access
console.log(str[29]) // D
console.log(str.substring(29, 44)); // Data Structures
// search
console.log(str.includes('good day')) // true
$ node string-data-structure.js
Today is a good day to learn Data Structures! So
Today is a good day to learn Data Structures! So start learning!
D
Data Structures
true
How fast to insert/delete/access/search data
Data Structure | Insert | Delete | Access | Search |
---|---|---|---|---|
String | O(n): concat | O(n): replace | O(1) with index, substring |
O(n): includes |
⬆️ Time complexity (worst case) per operation
Real life interview questions
- Do you know how your data looks like?
- What kind of information can string data structure store in real life applications?
- How do you insert/delete/access/search with string data structure?
- What is the Time Complexity of string data structure on insert/delete/access/search operation?
- Solve Leetcode #17: Letter Combinations of a Phone Number