STRING

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

TutorialsDSAData ScienceWeb TechCourses

DSA Data Structures Array String Linked List Stack Queue Tree Binary Tree Binary Sea

String in Data Structure


Last Updated : 01 Apr, 2024
In data structures, a string is a sequence of characters used to
represent text. Strings are commonly used for storing and
manipulating textual data in computer programs. They can be
manipulated using various operations like concatenation, substring
extraction, and comparison.

String in Data Structure

Table of Content
What is a String?
String Data Type
String Operations
Applications of String
Basics of Strings
String in different language
Basic Operations of String
Binary String
Substring & Subsequence
Pattern Searching

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 1/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Problems on Palindrome String


Easy Problems on String
Medium Problems on String
Hard Problems on String
What is a String?
String is considered a data type in general and is typically represented
as arrays of bytes (or words) that store a sequence of characters.
String is defined as an array of characters. The difference between a
character array and a string is the string is terminated with a special
character ‘\0’. Some examples of strings are: “geeks” , “for”, “geeks”,
“GeeksforGeeks”, “Geeks for Geeks”, “123Geeks”, “@123 Geeks”.

String Data Type:


In most programming languages, strings are treated as a distinct data
type. This means that strings have their own set of operations and
properties. They can be declared and manipulated using specific
string-related functions and methods.

Note: In some languages, strings are implemented as arrays of


characters, making them a derived data type.

String Operations:
Strings support a wide range of operations, including concatenation,
substring extraction, length calculation, and more. These operations
allow developers to manipulate and process string data efficiently.

Below are fundamental operations commonly performed on strings in


programming.

Concatenation: Combining two strings to create a new string.


Length: Determining the number of characters in a string.
Access: Accessing individual characters in a string by index.
Substring: Extracting a portion of a string.
Comparison: Comparing two strings to check for equality or order.
Search: Finding the position of a specific substring within a string.
Modification: Changing or replacing characters within a string.

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 2/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Applications of String:
Text Processing: Strings are extensively used for text processing
tasks such as searching, manipulating, and analyzing textual data.
Data Representation: Strings are fundamental for representing and
manipulating data in formats like JSON, XML, and CSV.
Encryption and Hashing: Strings are commonly used in encryption
and hashing algorithms to secure sensitive data and ensure data
integrity.
Database Operations: Strings are essential for working with
databases, including storing and querying text-based data.
Web Development: Strings are utilized in web development for
constructing URLs, handling form data, processing input from web
forms, and generating dynamic content.

Basics of Strings:
Introduction to Strings – Data Structure and Algorithm Tutorials
Applications, Advantages and Disadvantages of String
Storage for Strings in C

String in different language:


Strings in C
String Class in C++
String Class in Java
Python String
C# | String
JavaScript String
PHP | Strings

Basic Operations of String:


Searching For Characters and Substring in a String
Program to reverse a string (Iterative and Recursive)
Left Rotation and Right Rotation of a String
Sort string of characters
Print the frequency of each character in Alphabetical order

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 3/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Swap characters in a String


C program to find the length of a string
How to insert characters in a string at a certain position?
Program to check if two strings are same or not
Concatenating Two Strings
Remove all occurrences of a character in a string

Binary String:
Change if all bits can be made same by single flip
Number of flips to make binary string alternate
Binary representation of next number
Min flips of continuous characters to make all characters same in a
string
Generate all binary strings without consecutive 1’s
Find i’th Index character in a binary string obtained after n iterations
Generate n-bit Gray Codes

Substring & Subsequence:


Program to print all substrings of a given string
Print all subsequences of a string
Count Distinct Subsequences
Count distinct occurrences as a subsequence
Longest Common Subsequence
Shortest Superstring Problem
Printing Shortest Common Supersequence
Shortest Common Supersequence
Longest Repeating Subsequence
Longest Palindromic Subsequence
Longest Palindromic Substring using Dynamic Programming

Pattern Searching:
Naive algorithm for Pattern Searching
KMP Algorithm for Pattern Searching
Z algorithm
Search a Word in a 2D Grid of characters
https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 4/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Wildcard Pattern Matching


Aho-Corasick Algorithm
Find all strings that match specific pattern in a dictionary
Check if string follows order of characters defined by a pattern or
not

Problems on Palindrome String:


C Program to Check if a Given String is Palindrome
Check if a given string is a rotation of a palindrome
Check if characters of a given string can be rearranged to form a
palindrome
Online algorithm for checking palindrome in a stream
Print all palindromic partitions of a string
Minimum characters to be added at front to make string palindrome
Make largest palindrome by changing at most K-digits
Minimum number of deletions to make a string palindrome
Minimum insertions to form a palindrome with permutations
allowed

Easy Problems on String:


Count strings with consecutive 1’s
Generate all binary strings from given pattern
Add n binary strings
Divide large number represented as string
Program to find Smallest and Largest Word in a String
Count number of equal pairs in a string
Camel case of a given sentence
Second most repeated word in a sequence
Print all possible strings that can be made by placing spaces
Check if all levels of two trees are anagrams or not

Medium Problems on String:


K’th Non-repeating Character
Queries for characters in a repeated string
URLify a given string (Replace spaces is %20)
https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 5/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Count of total anagram substrings


Count number of binary strings without consecutive 1’s
Lexicographically next string
Check if given string can be split into four distinct strings
Word Break Problem
Check for balanced parentheses in an expression | O(1) space
Length of Longest Balanced Subsequence
Minimum Swaps for Bracket Balancing
Convert a sentence into its equivalent mobile numeric keypad
sequence
Burrows – Wheeler Data Transform Algorithm
Form minimum number from given sequence
Print shortest path to print a string on screen
Mirror characters of a string

Hard Problems on String:


Multiply Large Numbers represented as Strings
Count ways to increase LCS length of two strings by one
Minimum rotations required to get the same string
Find if an array of strings can be chained to form a circle
Given a sorted dictionary of an alien language, find order of
characters
Remove minimum number of characters so that two strings become
anagram
Minimum Number of Manipulations required to make two Strings
Anagram Without Deletion of Character
Palindrome Substring Queries
Powet Set in Lexicographic order
Minimum Word Break
Minimum number of bracket reversals needed to make an
expression balanced
Word Wrap problem ( Space optimized solution )
Decode a string recursively encoded as count followed by substring

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 6/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Imagine you're in a tech interview, and you get a tough question. Stay
calm and confident with Tech Interview 101 - From DSA to System
Design. This course is perfect for computer science enthusiasts. You'll
learn all about data structures, algorithms, and system design with
hands-on practice. Get the skills you need to succeed in any interview.
Ready to land your dream job? Sign up today!

H hare…

Next Article
Introduction to Strings - Data
Structure and Algorithm Tutorials

Similar Reads

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 7/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks

Static Data Structure vs Dynamic Data Structure


Data structure is a way of storing and organizing data efficiently such
that the required operations on them can be performed be efficient wit…
4 min read

Is array a Data Type or Data Structure?


What is Data Type? In computer programming, a data type is a
classification of data that determines the type of values that can be…
8 min read

Data Structure Alignment : How data is arranged and accessed in…


Data structure alignment is the way data is arranged and accessed in
computer memory. Data alignment and Data structure padding are two…
4 min read

Difference between data type and data structure


Data Type A data type is the most basic and the most common
classification of data. It is this through which the compiler gets to know…
4 min read

Efficiently check if a string has all unique characters without using…


Implement an space efficient algorithm to determine if a string (of
characters from 'a' to 'z') has all unique characters or not. Use additiona…
9 min read

View More Articles

Article Tags : DSA Strings

Practice Tags : Strings

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 8/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks
201305

Company Languages
About Us Python
Legal Java
In Media C++
Contact Us PHP
Advertise with us GoLang
GFG Corporate Solution SQL
Placement Training Program R Language
GeeksforGeeks Community Android Tutorial
Tutorials Archive

DSA Data Science & ML


Data Structures Data Science With Python
Algorithms Data Science For Beginner
DSA for Beginners Machine Learning Tutorial
Basic DSA Problems ML Maths
DSA Roadmap Data Visualisation Tutorial
Top 100 DSA Interview Problems Pandas Tutorial
DSA Roadmap by Sandeep Jain NumPy Tutorial
All Cheat Sheets NLP Tutorial
Deep Learning Tutorial

Web Technologies Python Tutorial


HTML Python Programming Examples
CSS Python Projects
JavaScript Python Tkinter
TypeScript Web Scraping
ReactJS OpenCV Tutorial
NextJS Python Interview Question
Bootstrap Django
Web Design

Computer Science DevOps


Operating Systems Git
Computer Network Linux
Database Management System AWS
Software Engineering Docker
Digital Logic Design Kubernetes
Engineering Maths Azure

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 9/10
6/29/24, 6:36 PM String in Data Structure - GeeksforGeeks
Software Development GCP
Software Testing DevOps Roadmap

System Design Inteview Preparation


High Level Design Competitive Programming
Low Level Design Top DS or Algo for CP
UML Diagrams Company-Wise Recruitment Process
Interview Guide Company-Wise Preparation
Design Patterns Aptitude Preparation
OOAD Puzzles
System Design Bootcamp
Interview Questions

School Subjects GeeksforGeeks Videos


Mathematics DSA
Physics Python
Chemistry Java
Biology C++
Social Science Web Development
English Grammar Data Science
Commerce CS Subjects
World GK

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/string-data-structure/?ref=lbp 10/10

You might also like