package com.thealgorithms.stacks; import java.util.Stack; /** * Solves the celebrity problem using a stack-based algorithm. * *
Celebrity is someone known by everyone but doesn't know anyone else. *
Applications: Graph theory and social network analysis.
*
* @author Hardvan
*/
public final class CelebrityFinder {
private CelebrityFinder() {
}
/**
* Finds the celebrity in the given party matrix using a stack-based algorithm.
*
* @param party A 2D matrix where party[i][j] is 1 if i knows j, otherwise 0.
* @return The index of the celebrity, or -1 if there is no celebrity.
*/
public static int findCelebrity(int[][] party) {
// Push all people onto the stack
Stack