Ankita Saini has Published 319 Articles

Swift Program to Recursively Linearly Search an Element in an Array

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:36:11

266 Views

In Swift, linear search is the most easiest search algorithm. It is also known as sequential search because it check all the elements of the given array or sequence one by one. If the target element is found, then return the index of that array otherwise return element not found. ... Read More

Swift Program to read and print two-dimensional array

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 09:34:42

826 Views

Just like other programming languages Swift also supported two- dimensional array. A two dimensional array is known as an array of array that store same type of data in a tabular format. Or we can say 2-D array is an array which represent homogeneous data in rows and columns. ... Read More

Swift Program to Print a Set

Ankita Saini

Ankita Saini

Updated on 24-Apr-2023 08:59:33

533 Views

In Swift, a set is used to define a collection of unique elements, means a set doesn’t contains duplicate elements. In a set, the elements are not arranged in a particular order. To print a set we can use for-in loop, forEach() function, as well as the name of the ... Read More

Swift Program to Merge Two Sets

Ankita Saini

Ankita Saini

Updated on 21-Apr-2023 13:48:12

2K+ Views

Merging two sets means combining all the elements of a set into another set without any duplicates. In Swift, we can either use formUnion() function or for-in loop to merge the elements of two sets. Lets discuss both the methods in detail along with examples. Method 1: Using formUnion() Function ... Read More

Swift Program to Initializing a Set

Ankita Saini

Ankita Saini

Updated on 21-Apr-2023 13:47:07

171 Views

In Swift, a set is used to define a collection of unique elements, means a set doesn’t contains duplicate elements. In a set, the elements are not arranged in a particular order. Initialising a set means to store some information in the set. It can be done at the time ... Read More

Swift Program to Iterate Over an Set

Ankita Saini

Ankita Saini

Updated on 21-Apr-2023 13:45:20

1K+ Views

In Swift, a set is used to define a unordered collection of unique elements. To iterate over an set swift provide inbuilt forEach() function as well as for-in loop. Lets discuss both the methods in detail along with examples. Method 1: Using for-in Loop To iterate over an set we ... Read More

Swift Program to Implement Linear Search Algorithm

Ankita Saini

Ankita Saini

Updated on 21-Apr-2023 11:38:05

607 Views

In Swift, the Linear search algorithm is the easiest search algorithm. In a linear search algorithm, searching starts from index 0 and checks all the elements of the given array/sequence one by one until the desired element is found. If the desired element is found, then return the index of ... Read More

Swift Program to Implement Bubble Sort Algorithm

Ankita Saini

Ankita Saini

Updated on 21-Apr-2023 11:32:18

544 Views

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. This algorithm works well only for small set of elements, it is not suitable for larger number of elements because its ... Read More

Swift Program to Implement Binary Search Algorithm

Ankita Saini

Ankita Saini

Updated on 13-Apr-2023 11:43:30

1K+ Views

In swift, Binary search algorithm is used to search element from the sorted array. It repeatedly divides the search interval into half and then search the specified element. In the binary search algorithm, the input array must be in sorted order to reduce the time complexity. Algorithm Step 1 ... Read More

Swift Program to Convert Set into Array

Ankita Saini

Ankita Saini

Updated on 06-Apr-2023 08:38:24

1K+ Views

In Swift, a set is used to define an unordered collection of unique elements whereas an array is used to define an ordered collection with may or may not be unique elements. To convert a set into an array Swift provides an inbuilt initializer named as Array(). Syntax Array(MySet) ... Read More

Advertisements