Ankita Saini has Published 277 Articles

Swift Program to Check if two Dictionaries are equal

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:59:28

In Swift, a dictionary is an unordered collection in which data is stored in the form of key-value pairs, where keys are the unique identifiers. So to check the equality of two dictionaries we first need to check if the size of both the dictionaries is equal or not. If ... Read More

Swift Program to check a string starts with a specified substring

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:56:17

Swift provides an hasPrefix() function to check if a string starts with a specified substring. The hasPrefix() function returns a boolean value which indicates whether the specified substring matches the starting string characters of the input string. The hasPrefix() function is case sensitive, which means according to this function “a”, ... Read More

Swift Program to check a string end with a specified substring

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:54:35

Swift provides an hasSuffix() function to check a string end with a specified substring. The hasSuffix() function returns a boolean value which indicates whether the specified substring matches the ending characters of the input string. The hasSuffix() function is case sensitive that means according to this function “t”, and “T” ... Read More

Swift Program to Add Elements to a Dictionary

Ankita Saini

Ankita Saini

Updated on 09-May-2023 09:49:31

In Swift, a dictionary is an unordered collection in which data is stored in the form of key-value pairs. To add elements to a dictionary we can use any of the following methods − Using Bracket notation Using updateValue() method Method 1: Using Brackets Notation We can key-value ... Read More

Swift Program to Split a set into Two Halves

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:52:21

In Swift, a set is used to create an unordered collection of unique elements. To split a set into two halves we use a approach in which we first determine the midpoint of the given set using integer division method and then loop through the set and insert element ... Read More

Swift Program to sort an array in descending order using selection sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:48:16

Selection sort algorithm in swift is a sorting algorithm, in which it select smallest or largest element from the given unsorted array and place that element at the beginning of the unsorted array. This process continue till the last unsorted element. So now we sort an array in descending order ... Read More

Swift Program to sort an array in descending order using bubble sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:46:23

Bubble sort algorithm in swift, is the easiest search algorithm. This algorithm sorts the elements by repeatedly swapping adjacent elements if they are not present at the right place. So now we sort an array in descending order using bubble sort. For example − Array - [4, 7, 1, 8] ... Read More

Swift Program to sort an array in ascending order using quick sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:44:58

Quick sort algorithm in swift is a sorting algorithm which works on divide and conquer approach. In this sort, we first divide the array into subarrays by selecting a pivot element. Here the division takes place in such a way, in which the smallest elements placed at the left side ... Read More

Swift Program to sort an array in ascending order using selection sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 10:41:00

Selection sort algorithm in swift is a sorting algorithm, in which it select smallest or largest element from the given unsorted array and place that element at the beginning of the unsorted array. This process continue till the last unsorted element. So now we sort an array in ascending order ... Read More

Swift Program to sort an array in ascending order using bubble sort

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:48:25

In swift, Bubble sort algorithm is the easiest search algorithm. This algorithm sorts the elements by repeatedly swapping adjacent elements if they are not present at the right place. So now we sort an array in ascending order using bubble sort. For example − Array - [4, 7, 1, 8] ... Read More

Advertisements