STRING

A STRING is a sequence of characters, such as letters, numbers, symbols, and spaces. It is a fundamental data type used to represent text in programming.

A string is a sequence of characters. It is used to store and manipulate text.

Key Properties of Strings: Characters inside quotes: "hello" or 'a'
Immutable in many languages (like C++ std::string and Python)
Indexed: You can access characters by position (starting at index 0)

TECHNICAL DEFINITION - An STRING stores multiple values under a single name. All values must be of the same type (like all numbers or all letters). Each item has an index (starting from 0).

INITIALIZATION - int arr[size] = {comma separated values};

REAL LIFE EXAMPLE OF STRING

REAL LIFE EXAMPLE - fruits = [name of fruits separated by commas];

FEATURES OF STRING

FEATURES OF ARRAYS - Same data type, Fixed size, Indexed access, Fast access, Efficient memory usage, Easy to loop through, Supports sorting and searching, Temporary storage in RAM, Can be multidimensional, Supported in most programming languages.

OPERATIONS IN AN STRING

INSERTION IN STRING

1. AT BEGINNING - Insert a character at the start of the STRING. All characters shift right by one. i.e., at index 0.

TIME COMPLEXITY - O(n)

2. AT MIDDLE/GIVEN POSITION - Insert a character at a specified position in the STRING. All characters after it shift right. i.e., index = position.

TIME COMPLEXITY - O(n)

3. AT END - Add a character at the end of the STRING. No shifting needed.

TIME COMPLEXITY - O(1)

DELETION IN STRING

1. FROM BEGINNING - Remove the first character from the STRING. All characters shift left by one.

TIME COMPLEXITY - O(n)

2. FROM MIDDLE/GIVEN POSITION - Remove a character from a specific index in the STRING. Remaining characters shift left.

TIME COMPLEXITY - O(n)

3. FROM END - Remove the last character from the STRING.

TIME COMPLEXITY - O(1)

SEARCHING IN STRING

Check if a particular character or substring exists within the STRING. This is done by scanning from index 0 to end.

TIME COMPLEXITY - O(n)

SORTING IN STRING

Sort the characters of the STRING alphabetically or in reverse order.

TIME COMPLEXITY - O(n²) (using basic sorting like bubble sort)


                

                

                

            

STRING COMPLEXITIES IN A GO...

COMPLEXITIES - PREVIEW UNAVAILABLE
HOME TOP OF THE PAGE