Narendra Kumar has Published 191 Articles

Merge Sort for Linked Lists using C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:21:00

296 Views

Problem statementGiven a linked list. Sort it using merge sort algorithmList: 10->20->8-17->5->13->4 Sorted list: 4->5->8->10->13->17->20Algorithm1. If head is NULL or list contains only one element then return list 2. Create two lists by dividing original list into 2 parts 3. Sort first and second part of list 4. Merge both ... Read More

Merge two binary Max Heaps using C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:18:19

293 Views

Problem statementGiven two binary max heaps as arrays, merge the into single max heap.Heap1[] = {20, 17, 15, 10} Heap2[] = {19, 13, 7} Result[] = {20, 19, 15, 13, 17, 7, 10}Algorithm1.Create an array to store result 2. Copy both given arrays one by one to result array 3. ... Read More

Merge two sorted arrays using C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:14:58

3K+ Views

Problem statementGiven 2 sorted arrays list. Write a function to merge given two sorted arrays into oneArr1[] = {10, 15, 17, 20} Arr2[] = {5, 9, 13, 19} Result[] = {5, 9, 10, 13, 15, 17, 19, 20}Algorithm1. Traverse both array    1.1. If arr1[i] < arr2[j]       ... Read More

Merge two sorted linked lists using C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:12:11

3K+ Views

Problem statementGiven 2 sorted singly linked list. Write a function to merge given two sorted linked listsList1: 10->15->17->20 List2: 5->9->13->19 Result: 5->9->10->13->15->17->19->20Algorithm1. Traverse both lists    1.1. If list1->data < list2->data       1.1.1 Add list1->data to new list and increment list1 pointer    1.2 If list2->data < list1->data ... Read More

Merging elements of two different arrays alternatively in third array in C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:09:34

842 Views

Problem statementGiven two arrays, we need to combine two arrays in such a way that the combined array has alternate elements of the first and second array. If one of the arrays has an extra element, then these elements should be appended at the end of the combined array.arr1[] = ... Read More

Merging two unsorted arrays in sorted order in C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 06:03:10

457 Views

Problem statementWrite a function that takes two unsorted arrays and merges them into a new array in sorted order.arr1[] = {10, 5, 7, 2} arr2[] = {4, 17, 9, 3} result[] = {2, 3, 4, 5, 7, 9, 10, 17}Algorithm1. Merge two unsorted array into new array 2. Sort newly ... Read More

Mid-Square hashing in C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 05:56:52

3K+ Views

Problem statementThe mid-square method is a method of generating pseudorandom numbers. This method was invented by John von Neumann and was described at a conference in 1949In this technique, an initial seed value is taken and it is squared.Some digits from the middle are extracted and these extracted digits form ... Read More

Mersenne Prime Number in C++.

Narendra Kumar

Narendra Kumar

Updated on 31-Oct-2019 05:54:02

661 Views

DescriptionIn mathematics, a Mersenne prime is a prime number that is one less than a power of two. That is, it is a prime number of the form Mn = 2n − 1 for some integer n.Write a C++ program to print all Mersenne Primes smaller than an input positive ... Read More

Minimize the total number of teddies to be distributed in C++

Narendra Kumar

Narendra Kumar

Updated on 22-Oct-2019 12:23:51

128 Views

Problem statementGiven N number of students and an array which represent the mark obtained by students. School has dicided to give them teddy as a price. Hoever, school wants to save money, so they to minimize the total number of teddies to be distrubuted by imposing following constrain −All students ... Read More

Minimize the sum of squares of sum of N/2 paired formed by N numbers in C++

Narendra Kumar

Narendra Kumar

Updated on 22-Oct-2019 12:16:10

133 Views

Problem statementGiven an array of n elements. The task is to create n/2 pairs in such a way that sum of squares of n/2 pairs is minimal.ExampleIf given array is −arr[] = {5, 10, 7, 4} then minimum sum of squares is 340 if we create pairs as (4, 10) ... Read More

Advertisements