0% found this document useful (0 votes)
3 views

Algorithm_Exercises

Algo

Uploaded by

safaamoudjari38
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Algorithm_Exercises

Algo

Uploaded by

safaamoudjari38
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Algorithm Exercises

Exercise 1: Swapping

Write an algorithm to swap the highest-weight and lowest-weight digits of an integer.

Exercise 2: Digit Frequency Counter

Count the frequency of each digit (0-9) in a given integer using minimal resources.

Exercise 3: Exponential Approximation

Compute the approximation of e^n using a fixed number of terms t.

Exercise 4: Palindrome Checker

Write an algorithm to check if a given number or string is a palindrome.

Exercise 5: Prime Number Checker

Determine if a given number is prime.

Exercise 6: Factorial Calculator

Calculate the factorial of a given number.

Exercise 7: Fibonacci Sequence

Generate the first n numbers in the Fibonacci sequence.

Exercise 8: Binary to Decimal

Convert a binary number to its decimal equivalent.

Exercise 9: Decimal to Binary

Convert a decimal number to its binary equivalent.

Exercise 10: Greatest Common Divisor (GCD)

Find the GCD of two integers using the Euclidean algorithm.

Exercise 11: Least Common Multiple (LCM)

Page 1
Algorithm Exercises

Find the LCM of two integers.

Exercise 12: Sorting Algorithm

Implement a simple sorting algorithm (e.g., bubble sort) to sort a list of integers.

Exercise 13: Reverse Array

Write an algorithm to reverse an array.

Exercise 14: Matrix Addition

Add two matrices of the same dimensions.

Exercise 15: Matrix Multiplication

Multiply two matrices.

Exercise 16: String Reversal

Reverse a given string.

Exercise 17: Anagram Checker

Check if two strings are anagrams of each other.

Exercise 18: Word Frequency Counter

Count the frequency of each word in a string.

Exercise 19: Character Frequency Counter

Count the frequency of each character in a string.

Exercise 20: Linear Search

Implement a linear search algorithm to find an element in an array.

Exercise 21: Binary Search

Implement a binary search algorithm to find an element in a sorted array.

Page 2
Algorithm Exercises

Exercise 22: Find Maximum

Find the maximum value in an array.

Exercise 23: Find Minimum

Find the minimum value in an array.

Exercise 24: Average of Numbers

Calculate the average of a list of numbers.

Exercise 25: Sum of Digits

Calculate the sum of the digits of an integer.

Exercise 26: Armstrong Number Checker

Check if a given number is an Armstrong number.

Exercise 27: Perfect Number Checker

Check if a given number is a perfect number.

Exercise 28: Sum of First N Numbers

Calculate the sum of the first n natural numbers.

Exercise 29: Leap Year Checker

Determine if a given year is a leap year.

Exercise 30: Quadratic Roots

Find the roots of a quadratic equation.

Exercise 31: Circle Area

Calculate the area of a circle given its radius.

Exercise 32: Rectangle Perimeter

Page 3
Algorithm Exercises

Calculate the perimeter of a rectangle given its length and width.

Exercise 33: Triangle Area

Calculate the area of a triangle given its base and height.

Exercise 34: Decimal Precision

Round a decimal number to a given precision.

Exercise 35: Factorial Trailing Zeros

Find the number of trailing zeros in a factorial.

Exercise 36: Harmonic Series Sum

Calculate the sum of the first n terms of the harmonic series.

Exercise 37: Power Calculator

Compute x raised to the power y using minimal resources.

Exercise 38: Digit Product

Calculate the product of the digits of an integer.

Exercise 39: Merge Arrays

Merge two sorted arrays into one sorted array.

Exercise 40: Remove Duplicates

Remove duplicate elements from an array.

Page 4

You might also like