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

  • Home
  • SEARCH
  • 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 8868943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:22:17+00:00 2026-06-14T17:22:17+00:00

I mean on a specific level, NOT up to that specific level. Could someone

  • 0

I mean on a specific level, NOT up to that specific level. Could someone please check my modified BFS algorithm? (most of which is taken from Wikipedia)

Queue levelorder(root, levelRequested){
      int currentLevel = 0;
      q = empty queue
      q.enqueue(root)
      while not q.empty do{
           if(currentLevel==levelRequested)
                 return q;
           node := q.dequeue()
           visit(node)
           if(node.left!=null || node.right!=null){
                 currentLevel++;
                 if node.left ≠ null
                       q.enqueue(node.left)
                 if node.right ≠ null
                       q.enqueue(node.right)
           }
      }
}
  • 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-14T17:22:19+00:00Added an answer on June 14, 2026 at 5:22 pm

    I think a recursive solution would be much more concise:

    /*
     * node - node being visited
     * clevel - current level
     * rlevel - requested level
     * result - result queue
     */
    drill (node, clevel, rlevel, result) {
      if (clevel == rlevel) {
        result.enqueue (node);
      else {
        if (node.left != null)
          drill (node.left, clevel + 1, rlevel, result);
        if (node.right != null)
          drill (node.right, clevel + 1, rlevel, result);
      }
    }
    

    Initial invocation would look like: drill (root, 0, n, rqueue);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I mean things like: FK1 -> 1FK2 -> 2PK Please, note that 1FK2 is
I would just like to clarify that by 'design', I mean software design, not
I have a specific requirement of having a toggling table. By toggling I mean
I mean something like that: class parentClass { public function method() { echo $this->prop;
Currently, I'm making a program that intercept keystrokes from a specific keyboard (filtered using
DotNetNuke is a large ASP.NET CMS which is mostly pre-compiled, as are most of
The specific query that led me to try and unpick this process was: Will
This page states that string::iterator and string::const_iterator are compiler specific iterator types. Does this
Is there a specific data structure that a deque in the C++ STL is
I have problem with the third level of a drop down menu, which 'over-passes'

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.