Saddle point in a matrix - GeeksforGeeks

文章推薦指數: 80 %
投票人數:10人

Given a matrix of n x n size, the task is to find the saddle point of the matrix. A saddle point is an element of the matrix such that it is ... Skiptocontent CoursesForWorkingProfessionalsLIVEDSALiveClassesSystemDesignJavaBackendDevelopmentFullStackLIVEExploreMoreSelf-PacedDSA-SelfPacedSDETheoryAllDevelopmentCoursesExploreMoreForStudentsLIVECompetitiveProgrammingGATELiveCourse2023DataScienceExploreMoreSelf-PacedDSA-SelfPacedCIPJAVA/Python/C++ExploreMoreSchoolCoursesSchoolGuidePythonProgrammingLearnToMakeAppsExploremoreAllCoursesTutorialsAlgorithmsAnalysisofAlgorithmsAsymptoticAnalysisWorst,AverageandBestCasesAsymptoticNotationsLittleoandlittleomeganotationsLowerandUpperBoundTheoryAnalysisofLoopsSolvingRecurrencesAmortizedAnalysisWhatdoes'SpaceComplexity'mean?Pseudo-polynomialAlgorithmsPolynomialTimeApproximationSchemeATimeComplexityQuestionSearchingAlgorithmsSortingAlgorithmsGraphAlgorithmsPatternSearchingGeometricAlgorithmsMathematicalBitwiseAlgorithmsRandomizedAlgorithmsGreedyAlgorithmsDynamicProgrammingDivideandConquerBacktrackingBranchandBoundAllAlgorithmsDataStructuresArraysLinkedListStackQueueBinaryTreeBinarySearchTreeHeapHashingGraphAdvancedDataStructureMatrixStringsAllDataStructuresInterviewCornerCompanyPreparationTopTopicsPracticeCompanyQuestionsInterviewExperiencesExperiencedInterviewsInternshipInterviewsCompetititveProgrammingDesignPatternsSystemDesignTutorialMultipleChoiceQuizzesLanguagesCC++JavaPythonC#JavaScriptjQuerySQLPHPScalaPerlGoLanguageHTMLCSSKotlinML&DataScienceMachineLearningDataScienceCSSubjectsMathematicsOperatingSystemDBMSComputerNetworksComputerOrganizationandArchitectureTheoryofComputationCompilerDesignDigitalLogicSoftwareEngineeringGATEGATEComputerScienceNotesLastMinuteNotesGATECSSolvedPapersGATECSOriginalPapersandOfficialKeysGATE2021DatesGATECS2021SyllabusImportantTopicsforGATECSWebTechnologiesHTMLCSSJavaScriptAngularJSReactJSNodeJSBootstrapjQueryPHPSoftwareDesignsSoftwareDesignPatternsSystemDesignTutorialSchoolLearningSchoolProgrammingMathematicsNumberSystemAlgebraTrigonometryStatisticsProbabilityGeometryMensurationCalculusMathsNotes(Class8-12)Class8NotesClass9NotesClass10NotesClass11NotesClass12NotesNCERTSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionRDSharmaSolutionsClass8MathsSolutionClass9MathsSolutionClass10MathsSolutionClass11MathsSolutionClass12MathsSolutionPhysicsNotes(Class8-11)Class8NotesClass9NotesClass10NotesClass11NotesChemistryNotesClass8NotesClass9NotesClass10NotesCSExams/PSUsISROISROCSOriginalPapersandOfficialKeysISROCSSolvedPapersISROCSSyllabusforScientist/EngineerExamUGCNETUGCNETCSNotesPaperIIUGCNETCSNotesPaperIIIUGCNETCSSolvedPapersStudentCampusAmbassadorProgramSchoolAmbassadorProgramProjectGeekoftheMonthCampusGeekoftheMonthPlacementCourseCompetititveProgrammingTestimonialsStudentChapterGeekontheTopInternshipCareersJobsApplyforJobsPostaJobHirewithUsKnowaboutJobathonJobathonPracticeAllDSAProblemsProblemoftheDayInterviewSeries:WeeklyContestsBi-WizardCoding:SchoolContestsContestsandEventsPracticeSDESheetCuratedDSAListsTop50ArrayProblemsTop50StringProblemsTop50TreeProblemsTop50GraphProblemsTop50DPProblems ComewritearticlesforusandgetfeaturedLearnandcodewiththebestindustryexpertsGetaccesstoad-freecontent,doubtassistanceandmore!ComeandfindyourdreamjobwithusGeeksDigestQuizzesGeeksCampusGblogArticlesIDECampusMantriHomeSavedVideosCoursesGBlogPuzzlesWhat'sNew? ChangeLanguage ArrayMatrixStringsHashingLinkedListStackQueueBinaryTreeBinarySearchTreeHeapGraphSearchingSortingDivide&ConquerMathematicalGeometricBitwiseGreedyBacktrackingBranchandBoundDynamicProgrammingPatternSearchingRandomized RelatedArticles ▲RelatedArticlesProgramtofindlargestelementinanarrayMatrixChainMultiplication|DP-8PrintagivenmatrixinspiralformRatinaMaze|Backtracking-2Findthenumberofislands|Set1(UsingDFS)Sudoku|Backtracking-7Inplacerotatesquarematrixby90degrees|Set1CountallpossiblepathsfromtoplefttobottomrightofamXnmatrixProgramtomultiplytwomatricesMinCostPath|DP-6SearchinarowwiseandcolumnwisesortedmatrixMaximumsizesquaresub-matrixwithall1sRotateamatrixby90degreeinclockwisedirectionwithoutusinganyextraspaceDivideandConquer|Set5(Strassen'sMatrixMultiplication)TheCelebrityProblemGoldMineProblemMaximumsizerectanglebinarysub-matrixwithall1sPrintingallsolutionsinN-QueenProblemPythonprogramtomultiplytwomatricesProgramtofindtransposeofamatrixSparseMatrixanditsrepresentations|Set1(UsingArraysandLinkedLists)MagicSquare|ODDOrderMinimumtimerequiredtorotallorangesSearchaWordina2DGridofcharactersShortestpathinaBinaryMazeRotateMatrixElementsProgramtoprinttheDiagonalsofaMatrixReal-timeapplicationofDataStructuresFindtherowwithmaximumnumberof1sMultiplicationoftwoMatricesinSinglelineusingNumpyinPythonProgramtofindlargestelementinanarrayMatrixChainMultiplication|DP-8PrintagivenmatrixinspiralformRatinaMaze|Backtracking-2Findthenumberofislands|Set1(UsingDFS)Sudoku|Backtracking-7Inplacerotatesquarematrixby90degrees|Set1CountallpossiblepathsfromtoplefttobottomrightofamXnmatrixProgramtomultiplytwomatricesMinCostPath|DP-6SearchinarowwiseandcolumnwisesortedmatrixMaximumsizesquaresub-matrixwithall1sRotateamatrixby90degreeinclockwisedirectionwithoutusinganyextraspaceDivideandConquer|Set5(Strassen'sMatrixMultiplication)TheCelebrityProblemGoldMineProblemMaximumsizerectanglebinarysub-matrixwithall1sPrintingallsolutionsinN-QueenProblemPythonprogramtomultiplytwomatricesProgramtofindtransposeofamatrixSparseMatrixanditsrepresentations|Set1(UsingArraysandLinkedLists)MagicSquare|ODDOrderMinimumtimerequiredtorotallorangesSearchaWordina2DGridofcharactersShortestpathinaBinaryMazeRotateMatrixElementsProgramtoprinttheDiagonalsofaMatrixReal-timeapplicationofDataStructuresFindtherowwithmaximumnumberof1sMultiplicationoftwoMatricesinSinglelineusingNumpyinPythonSaddlepointinamatrixViewDiscussion ImproveArticle SaveArticle LikeArticle DifficultyLevel: MediumLastUpdated: 05Jul,2022Givenamatrixofnxnsize,thetaskistofindthesaddlepointofthematrix.Asaddlepointisanelementofthematrixsuchthatitistheminimumelementinitsrowandmaximuminitscolumn. Examples: Input:Mat[3][3]={{1,2,3}, {4,5,6}, {7,8,9}} Output:7 7isminimuminitsrowandmaximuminitscolumn. Input:Mat[3][3]={{1,2,3}, {4,5,6}, {10,18,4}} Output:NosaddlepointRecommended:Pleasetryyourapproachon{IDE}first,beforemovingontothesolution.AsimplesolutionistotraverseallmatrixelementsonebyoneandcheckiftheelementisSaddlePointornot.Anefficientsolutionisbasedonthebelowsteps. Traverseallrowsonebyoneanddothefollowingforeveryrowi.  Findtheminimumelementofthecurrentrowandstorethecolumnindexoftheminimumelement.Checkiftherowminimumelementisalsomaximuminitscolumn.Weusethestoredcolumnindexhere.Ifyes,thensaddlepointelsecontinuestilltheendofthematrix.Belowistheimplementationoftheabovesteps.  C++//C++programtoillustrateSaddlepoint#includeusingnamespacestd; constintMAX=100; //FunctiontofindsaddlepointboolfindSaddlePoint(intmat[MAX][MAX],intn){    //Processallrowsonebyone    for(inti=0;imat[i][j])            {                min_row=mat[i][j];                col_ind=j;            }        }         //Checkiftheminimumelementofrowisalso        //themaximumelementofcolumnornot        intk;        for(k=0;k#include #defineMAX100 //FunctiontofindsaddlepointboolfindSaddlePoint(intmat[MAX][MAX],intn){    //Processallrowsonebyone    for(inti=0;imat[i][j])            {                min_row=mat[i][j];                col_ind=j;            }        }         //Checkiftheminimumelementofrowisalso        //themaximumelementofcolumnornot        intk;        for(k=0;kmat[i][j])                {                    min_row=mat[i][j];                    col_ind=j;                }            }                  //Checkiftheminimumelementofrowisalso            //themaximumelementofcolumnornot            intk;            for(k=0;kmat[i][j]):                min_row=mat[i][j];                col_ind=j;         #Checkiftheminimumelement        #ofrowisalsothemaximum        #elementofcolumnornot        k=0;        forkinrange(n):             #Notethatcol_indisfixed            if(min_rowmat[i,j])                {                    min_row=mat[i,j];                    col_ind=j;                }            }                 //Checkiftheminimumelement            //ofrowisalsothemaximum            //elementofcolumnornot            intk;            for(k=0;k$mat[$i][$j])            {                $min_row=$mat[$i][$j];                $col_ind=$j;            }        }         //Checkiftheminimumelementof        //rowisalsothemaximumelement        //ofcolumnornot        $k;        for($k=0;$kJavascriptOutputValueofSaddlePoint7Exercise: CantherebemorethanoneSaddlePointsinaMatrix?ThisarticleiscontributedbySahilChhabra(KILLER).IfyoulikeGeeksforGeeksandwouldliketocontribute,youcanalsowriteanarticleusingwrite.geeksforgeeks.orgormailyourarticletoreview-team@geeksforgeeks.org.SeeyourarticleappearingontheGeeksforGeeksmainpageandhelpotherGeeks.MyPersonalNotes arrow_drop_upSave LikePreviousGFact22|(2^x+1andPrime)Next GCD,LCMandDistributivePropertyRecommendedArticlesPage:19,Apr2115,Jan2127,Sep2103,Feb2221,Aug1730,May1804,Oct1830,Jun2127,Jun1927,Jun1904,Jul1929,Sep2120,Nov1930,Apr2013,Jul2009,Aug2006,Oct2016,Oct2011,Nov2005,Nov2013,Jan2124,Dec2103,Feb2124,Jun21ArticleContributedBy:GeeksforGeeksVotefordifficultyCurrentdifficulty: MediumEasy Normal Medium Hard ExpertImprovedBy:KRVvt_m29AjayKumarrag2127kothavvsaakashhardikkoriinternArticleTags:MatrixPracticeTags:MatrixReportIssueWritingcodeincomment? Pleaseuseide.geeksforgeeks.org, generatelinkandsharethelinkhere. LoadCommentsWhat'sNewViewDetailsViewDetailsViewDetailsImproveyourCodingSkillswithPracticeTryIt! Weusecookiestoensureyouhavethebestbrowsingexperienceonourwebsite.Byusingoursite,you acknowledgethatyouhavereadandunderstoodour CookiePolicy& PrivacyPolicy GotIt! StartYourCodingJourneyNow!Login Register



請為這篇文章評分?