Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Easy/Linear Search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// C++ Code

// Function to search for an element using linear search
// Takes an array and the element to find as parameters
void linearSearch(int arr[], int size, int element) {
for (int idx = 0; idx < size; idx++) {
if (arr[idx] == element) {
std::cout << "The element " << element << " found at index " << idx << " in the given array" << std::endl;
return; // No need to continue searching if the element is found
}
}
std::cout << "The element " << element << " not found in the given array" << std::endl;
}

// Test drive code
int main() {
int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int size = sizeof(arr) / sizeof(arr[0]); // Calculate the size of the array
int target = 10;
linearSearch(arr, size, target);
return 0;
}
23 changes: 23 additions & 0 deletions Easy/Linear Search.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Java Code

public class LinearSearch {

// Function to search for an element using linear search
// Takes an array and the element to find as parameters
static void linearSearch(int[] array, int element) {
for (int idx = 0; idx < array.length; idx++) {
if (array[idx] == element) {
System.out.printf("The element %d found at index %d in the given array%n", element, idx);
return; // No need to continue searching if the element is found
}
}
System.out.printf("The element %d not found in the given array%n", element);
}

// Test drive code
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int target = 10;
linearSearch(arr, target);
}
}
16 changes: 16 additions & 0 deletions Easy/Linear Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Python Code

# Function to search for an element using linear search
# Takes an array and the element to find as parameters
def linear_search(array, element):
for idx, val in enumerate(array): # Using enumerate for a more Pythonic way to iterate with index
if val == element:
print(f"The element {element} found at index {idx} in the given array")
return # No need to continue searching if the element is found
else:
print(f"The element {element} not found in the given array")

# Test drive code
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 10
linear_search(arr, target)
173 changes: 173 additions & 0 deletions Easy/README.md (ToLowerCase).md (ToLowerCase).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# TO LowerCase

# Introduction
The toLowerCase() function is a fundamental text-processing tool available in many programming languages. Its primary role is to convert all characters in a string to lowercase, ensuring uniformity and enabling case-insensitive operations within the text. This function serves as a building block in various software development tasks, offering consistency and ease of manipulation when handling textual data.
The toLowerCase() function is a method available in many programming languages that converts all characters in a string to lowercase. It's a fundamental operation when dealing with text data processing.
# Exploration:
This function provides a consistent and standardized way to convert text to lowercase, enabling uniformity and easing comparisons within strings.
# Overview of ToLowerCase
The toLowerCase() function, available in programming languages like JavaScript, Java, Python, and many others, is a method used to convert all the characters within a string to their lowercase equivalents. Its primary purpose is to ensure uniformity in textual data by standardizing the case of all letters to lowercase, facilitating case-insensitive operations.

This function is especially useful when dealing with user inputs, comparisons, or any scenario where case differences should not affect the outcome. For instance, when validating email addresses or usernames, converting all characters to lowercase enables easier and more accurate checks without worrying about case variations.

The toLowerCase() function does not alter the original string; instead, it returns a new string with all alphabetic characters converted to lowercase. It is a simple yet powerful tool for maintaining consistency in text processing and comparison operations.


# PYTHON Code


```python
def toLowerCase(s: str) -> str:
# Initialize an empty string to store the converted characters
lowercase = ""

# Loop through each character in the input string
for char in s:
# Check if the character is uppercase
if 'A' <= char <= 'Z':
# Convert the uppercase character to lowercase using ASCII manipulation
lowercase += chr(ord(char) + 32)
else:
# If the character is not uppercase, keep it unchanged
lowercase += char

# Return the converted string with lowercase characters
return lowercase

# Test the function
string = "UpperCase"
print(toLowerCase(string))

```

### Output
![Alt text](../Screenshorts/TLCPY.png)

# Explanation:

- The toLowerCase() function takes a string s as input and returns the string with all characters converted to lowercase.
- It initializes an empty string lowercase to store the converted characters.
- It iterates through each character in the input string using a for loop.
- For each character, it checks if it is an uppercase letter by comparing it with ASCII values. The comparison 'A' <= char <= 'Z' ensures it's an uppercase letter.
- If the character is uppercase, it converts it to lowercase using ASCII manipulation. The ord() function gets the ASCII value of the character, adds 32 to it (the difference between uppercase and lowercase ASCII values), and then chr() converts the new ASCII value back to a character.
- If the character is not uppercase, it appends it unchanged to the lowercase string.
- Finally, it returns the lowercase string containing the original string with all characters converted to lowercase.


# JAVA Code

```java
public class Main {

// Function to convert a string to lowercase
// Returns the lowercase version of the input string

public static String toLowerCase(String s) {
StringBuilder result = new StringBuilder();

// Iterate through each character in the input string
for (char c : s.toCharArray()) {
// Check if the character is an uppercase letter
if (c >= 'A' && c <= 'Z') {
// Convert uppercase to lowercase using ASCII values
result.append((char) (c + 32));
} else {
// Keep non-uppercase characters unchanged
result.append(c);
}
}

return result.toString();
}

public static void main(String[] args) {
// Example string
String inputString = "UpperCase";

// Convert the string to lowercase and print the result
System.out.println("Original: " + inputString);
System.out.println("Lowercase: " + toLowerCase(inputString));
}
}
```

### Output
![Alt text](../Screenshorts/TLCJAVA.png)

# Explanation:

- The toLowerCase() method takes a string s as input and returns the string with all characters converted to lowercase.
- It initializes a StringBuilder named result to store the converted characters.
- It iterates through each character in the input string using a for-each loop (for (char c : s.toCharArray())).
- For each character, it checks if it is an uppercase letter by comparing it with ASCII values (c >= 'A' && c <= 'Z').
- If the character is uppercase, it converts it to lowercase using ASCII values. It adds 32 to the character's ASCII value to perform this conversion (result.append((char) (c + 32));).
- If the character is not an uppercase letter, it appends it unchanged to the result StringBuilder.
- Finally, it returns the string representation of the result StringBuilder using result.toString().

# C++ code

```c++

#include <iostream>

// Function to convert a string to lowercase
// Returns the lowercase version of the input string

std::string toLowerCase(const std::string& s) {
// Initialize an empty string to store the lowercase result
std::string result = "";

// Iterate through each character in the input string
for (char i : s) {
// Check if the character is an uppercase letter
if (i >= 'A' && i <= 'Z') {
// Convert uppercase to lowercase using ASCII values and append to the result
result += static_cast<char>(i + 32);
} else {
// Keep non-uppercase characters unchanged and append to the result
result += i;
}
}

// Return the final lowercase result
return result;
}

int main() {
// Example string
std::string inputString = "UpperCase";

// Print the original string
std::cout << "Original: " << inputString << std::endl;

// Convert the string to lowercase using the function and print the result
std::cout << "Lowercase: " << toLowerCase(inputString) << std::endl;

return 0;
}
```

### Output
![Alt text](../Screenshorts/TLCC++.png)

# Explanation:

- The toLowerCase function takes a constant reference to a string s as input and returns the string with all characters converted to lowercase.
- It initializes an empty string result to store the converted characters.
- It iterates through each character in the input string using a range-based for loop (for (char i : s)).
- For each character, it checks if it is an uppercase letter by comparing it with ASCII values (i >= 'A' && i <= 'Z').
- If the character is uppercase, it converts it to lowercase using ASCII values. It adds 32 to the character's ASCII value to perform this conversion (result += static_cast<char>(i + 32)).
- If the character is not an uppercase letter, it appends it unchanged to the result string.
- Finally, it returns the result string, which contains the input string with all characters converted to lowercase.


# Scheduling Problems:
While seemingly unrelated, the toLowerCase() function's uniformity can be analogous to scheduling problems. It ensures consistency, akin to scheduling entities in time slots without conflicts.

# Real-time Applications:
The toLowerCase() function is utilized in various real-world scenarios, such as:
- Data Processing: Cleaning and standardizing textual data for analysis.
- Web Development: Sanitizing inputs for uniformity and consistency in web applications.
- Comparisons: Enabling case-insensitive comparisons in search operations or string matching algorithms.
# Summary:
The toLowerCase() function, available across multiple programming languages, is a fundamental tool for standardizing and manipulating text data. Its role spans from ensuring uniformity in text to aiding in comparisons and analysis, making it a crucial component in various software development tasks.
36 changes: 36 additions & 0 deletions Easy/ToLower Case.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>

// Function to convert a string to lowercase
// Returns the lowercase version of the input string
std::string toLowerCase(const std::string& s) {
// Initialize an empty string to store the lowercase result
std::string result = "";

// Iterate through each character in the input string
for (char i : s) {
// Check if the character is an uppercase letter
if (i >= 'A' && i <= 'Z') {
// Convert uppercase to lowercase using ASCII values and append to the result
result += static_cast<char>(i + 32);
} else {
// Keep non-uppercase characters unchanged and append to the result
result += i;
}
}

// Return the final lowercase result
return result;
}

int main() {
// Example string
std::string inputString = "UpperCase";

// Print the original string
std::cout << "Original: " << inputString << std::endl;

// Convert the string to lowercase using the function and print the result
std::cout << "Lowercase: " << toLowerCase(inputString) << std::endl;

return 0;
}
31 changes: 31 additions & 0 deletions Easy/ToLower Case.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public class Main {

// Function to convert a string to lowercase
// Returns the lowercase version of the input string
public static String toLowerCase(String s) {
StringBuilder result = new StringBuilder();

// Iterate through each character in the input string
for (char c : s.toCharArray()) {
// Check if the character is an uppercase letter
if (c >= 'A' && c <= 'Z') {
// Convert uppercase to lowercase using ASCII values
result.append((char) (c + 32));
} else {
// Keep non-uppercase characters unchanged
result.append(c);
}
}

return result.toString();
}

public static void main(String[] args) {
// Example string
String inputString = "UpperCase";

// Convert the string to lowercase and print the result
System.out.println("Original: " + inputString);
System.out.println("Lowercase: " + toLowerCase(inputString));
}
}
22 changes: 22 additions & 0 deletions Easy/ToLower Case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

def multi_string_search(text, patterns):
result = []

for pattern in patterns:
# Use the built-in find method to check if the pattern is present in the text
if text.find(pattern) != -1:
result.append(pattern)

return result


if __name__ == "__main__":
# Sample text and patterns
text = "This is a sample text for multi-string search."
patterns = ["sample", "search", "notfound"]

# Perform multi-string search
result = multi_string_search(text, patterns)

# Print the found patterns
print("Found patterns:", *result)
Loading