Articles for author: Niyati Thakkar

Josephus problem

Problem Statement There is n number of people standing in a circle. Numbering starts from 1 to n and is in the fixed clockwise direction. In each step, we are supposed to eliminate a person which is at the $k^{th}$ position from the current position such that only one man remains at the end who ...

Uniform-Cost Search Algorithm

The Uniform Cost Search Algorithm is a search algorithm to find the minimum cumulative cost of the path from the source node to the destination node. It is an uninformed algorithm i.e. it doesn’t have prior information about the path or nodes and that is why it is a brute-force approach. What is the Uniform ...

N-ary Trees

An N-ary tree or Generic Tree is a tree that can have at most N children. If we replace N with 2 then we get a binary tree. In other words, an n-ary tree node can have between 0 to N child nodes. N-ary trees are used in various use cases but moreover, these are useful where we are required to represent hierarchical data with multiple branching points at ...

How to Move All Zeroes to End of Array?

Given an array of random numbers and zeros, arrange the array such that all the numbers restoring their order are moved in front and move all zeros to end of array. There are so many ways to solve this problem. We can make use of additional arrays, pointers, partitions, etc. Example to Understand Let us ...

How to Reverse a Stack Using Recursion?

Given a stack, write a program to reverse the order of the elements inside the stack using recursion. The element at the top should be moved to the bottom and so on. This program must use only standard stack operations – push(item), pop(), top(), size(), and isEmpty(). Example: Input: $23, 56, 82, 90$ Output: $90, ...