0 purchases
vazifa
Search Algorithms in Dart #
This project demonstrates various search algorithms implemented in Dart, including binary search and jump search. The project also includes functionality to measure the time taken for searching operations using Dart's Stopwatch class.
Features #
Binary Search: Efficient algorithm for finding an element in a sorted list.
Jump Search: Searches for an element in a sorted list by jumping ahead by a fixed number of steps.
Performance Measurement: Uses Stopwatch to measure the time taken by search algorithms.
Getting Started #
Prerequisites #
Dart SDK
Installing #
Clone the repository:
git clone https://github.com/yourusername/search-algorithms-dart.git
copied to clipboard
Navigate to the project directory:
cd search-algorithms-dart
copied to clipboard
Usage #
Binary Search:
import 'binary_search.dart';
void main() {
List<int> sortedList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
int itemToFind = 7;
// Start the stopwatch
Stopwatch stopwatch = Stopwatch()..start();
int index = binarySearch(sortedList, itemToFind, 0, sortedList.length - 1);
// Stop the stopwatch
stopwatch.stop();
if (index != -1) {
print("Item found at index: $index");
} else {
print("Item not found.");
}
print("Time taken for search: ${stopwatch.elapsedMicroseconds} microseconds");
}
copied to clipboard
Jump Search:
import 'jump_search.dart';
void main() {
List<int> sortedList = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19];
int itemToFind = 13;
// Start the stopwatch
Stopwatch stopwatch = Stopwatch()..start();
int index = jumpSearch(sortedList, itemToFind);
// Stop the stopwatch
stopwatch.stop();
if (index != -1) {
print("Item found at index: $index");
} else {
print("Item not found.");
}
print("Time taken for search: ${stopwatch.elapsedMicroseconds} microseconds");
}
copied to clipboard
Running the Tests #
To run tests, use the following command:
dart test
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.