Merge Sort on Linked List in Kotlin
To implement merge sort on a linked list, you can follow these steps: The linked list before sorting : 3 2 1 4 Output : 1 2 3 4
To implement merge sort on a linked list, you can follow these steps: The linked list before sorting : 3 2 1 4 Output : 1 2 3 4
To remove a duplicate from an unsorted linked list, you can follow these steps: The output of the program will be: 1 2 3 4, which is the linked list with duplicates removed.
To check if a string is a palindrome or not, we need to compare the original string with its reversed form. If both strings are the same, the original string is a palindrome. Here’s an example Kotlin code to check if a string is a palindrome: In this code, the isPalindrome function takes a String … Read more
In Kotlin, you can reverse a string by converting it to a StringBuilder object and using the reverse() method. Here’s an example code to reverse a string: In this code, the reverseString function takes a String parameter str and returns a new string with the characters of str reversed. The function creates a StringBuilder object … Read more
To rotate a matrix by 90 degrees, we need to swap the elements in the matrix in a specific pattern. Here’s a step-by-step algorithm to rotate a matrix by 90 degrees clockwise: This will give us the matrix rotated by 90 degrees clockwise. Here’s an example Kotlin code to implement this algorithm: In this code, … Read more
The greedy algorithm to find the minimum number of coins required to make a given amount of change involves selecting the largest denomination coin that is less than or equal to the remaining amount of change and subtracting it from the remaining amount, until the remaining amount becomes zero. Here is the step-by-step process for … Read more
The activity selection problem is a classic optimization problem that involves selecting the maximum number of mutually compatible activities from a given set of activities, where each activity has a start time and an end time. The goal is to select the maximum number of activities such that no two selected activities overlap. To solve … Read more
The job sequencing problem is a classic optimization problem in computer science, operations research, and related fields. It involves scheduling a set of jobs to be processed on a single machine or multiple machines, subject to various constraints and objectives. In the basic version of the problem, each job has a processing time, a deadline, … Read more
Boundary traversal of a binary tree involves visiting the boundary nodes of the tree in a clockwise direction, starting from the root node. The boundary nodes of a tree include the root node, the left boundary, the leaf nodes, and the right boundary. Here’s an example of a binary tree : The boundary traversal of … Read more
Diagonal traversal of a binary tree is a way to visit all the nodes of a binary tree in a diagonal order. In diagonal traversal, we first visit the left child of the root node, then all the nodes on the diagonal starting from the left child of the root, and then we move to … Read more