Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7920515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:14:50+00:00 2026-06-03T16:14:50+00:00

I am trying to rebuild this algorithm: http://courses.csail.mit.edu/6.006/fall10/lectures/lec02.pdf (Page 14 Algorithm II) (found this

  • 0

I am trying to rebuild this algorithm:
http://courses.csail.mit.edu/6.006/fall10/lectures/lec02.pdf
(Page 14 “Algorithm II”)
(found this with google, unfortunatly i am not at MIT 🙂 and this is not homework)

Which is:

•Pick middle column (j=m/2)
•Find global maximum a=A[i,m/2]in that column
    (and quit if m=1)
•Compare a to b=A[i,m/2-1]and c=A[i,m/2+1]
•If b>a   then recurse on left columns
•Else, if c>a   then recurse on right columns
•Else a is a 2D peak!  

What i have is this:

trimmed is a vector which holds my frequencies of size (blockSizeSmall-minBlockSize).

So its a 2D Matrix with trimmed.size() columns and (blockSizeSmall-minBlockSize) rows.

For simpliciticy i save the peaks in 2 int vectors vector<int> peaksrow and peakscolumn.

Whats wrong there ?
I dont get what

"Find global maximum a=A[i,m/2]in that column (and quit if m=1)"

should result in.

    public void findPeaks() {
        for (int column = trimmed.size() / 2; column < trimmed.size();) {
            int globalmax = 0;
            for (int row = 0; row < (blockSizeSmall - minBlockSize); row++) {
                if (trimmed.elementAt(column).reducedFreqs[row] > globalmax) {
                    globalmax = row; 
                    //find globalmax in row
                }
            }
            if (globalmax == 0) {
                break; //<- ???
            } else {
                if (column - 1 >= 0 && column + 1 < trimmed.size()) {
                //stay in bounds
                    if (trimmed.elementAt(column - 1).reducedFreqs[globalmax] > globalmax) {
                        column--; 
                        //if element at left side is > globalmax, recurse on column--;

                    } else if (trimmed.elementAt(column + 1).reducedFreqs[globalmax] > globalmax) {
                        column++; 
                        //if element at right side is > globalmax, recurse on column++;

                    } else { 
                        //if globalmax is higher than right or left element i have a peak
                        peaksrown.add(globalmax);
                        peakscolumnn.add(column);
                        Log.e(TAG, "" + peaksrown.size());
                    }
                }else{
                //what to do when out of bounds ?? break ??
                //if i break here, how can i be sure the algorithm 
                //went to both sides(column=0 and column=max) ??
                //just tried with break here, still infinit loop
                }
            }
        }
    }

It just loops endless.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:14:52+00:00Added an answer on June 3, 2026 at 4:14 pm

    You don’t seem to understand the concept of recursion so I would advise you look it up. Here’s an algorithm in C# for reference, not tested beyond the one example in the paper but it should work. I ignored the “and quit if m=1” part as I don’t think that’s needed. Note how the function Peak() calls itself from within itself, but with changed parameters.

        static void Peak(int[,] map, int left, int right)
        {
            // calculate middle column
            int column = (right + left) / 2;
    
    
            // get max row in column
            int arow = 0;
            for (int row = 0; row < map.GetLength(0); row++)
                if (map[row, column] > map[arow, column])
                    arow = row;
    
            int a = map[arow, column];
    
            // get left value
            int b = 0;
            if (column - 1 >= left) b = map[arow, column - 1];
            // get right value
            int c = 0;
            if (column + 1 <= right) c = map[arow, column + 1];
    
            // if left is higher, recurse left
            if (b > a) Peak(map, left, column - 1);
            // else if right is higher, recurse right
            else if (c > a) Peak(map, column + 1, right);
            // else, peak
            else Console.WriteLine("Peak: " + arow + " " + column + " " + a);
        }
    
        static void Main(string[] args)
        {
            int[,] map = { {12, 8, 5},
                           {11, 3, 6 },
                           {10, 9, 2 },
                           { 8, 4, 1 } };
            Peak(map, 0, 2);
            Console.ReadLine();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rebuild this with pure css. And I've got this far.
I am trying to rebuild my page to go from old-school recordset paging, to
I was trying to rebuild my kernel after modifying some source files and noticed
I'm trying to rebuild someone's old C++ project using Dev-C++ (version 4.9.9.2) and the
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I'm trying to rebuild an object encoded with Json but i'm not getting any
I'm trying to debug an ASP.NET web application in this environment: Windows Server Standard
I am trying to integrate OpenFeint 2.12.5 into my app. I already read this
I'm trying to rebuild a web server in a virtual pc. Installed required software
I used this guide to rebuild the boost library in VC++6 under windows XP.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.