Programming Exercises

Exercise 1: Find Maximum Element in a List

Write a Python function that uses linear search to find the maximum element in a list.

 

Exercise 2: Find Duplicates in a List

Write a Python function that uses searching algorithms to find duplicate elements in a list and returns a list of duplicates.

 

Exercise 3: Search for a Key in a Dictionary

Write a Python function that takes a dictionary and a key as input and checks if the key exists using linear search.

 

Exercise 4: Check if a String is a Palindrome

Implement a Python function that uses two pointers to check if a given string is a palindrome by comparing characters from the start and end of the string.

 

Exercise 5: Search for a Word in a Text File

Implement a Python program that reads a text file and searches for a specific word, counting how many times it appears.

 

Exercise 6: Phone Book Search

Implement a simple phone book application using Python dictionaries. Write functions to add contacts, search for a contact by name, and delete contacts. Utilize linear search for searching contacts by name.

 

Exercise 7: Application of Searching Algorithms

Given a list of integers, implement a function find_pair_sum(arr, target_sum) that uses any of the searching algorithms to find a pair of numbers in the list that sum up to the target_sum. Return the indices of the pair if found, otherwise return None.