EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Top Interview Question Algorithm Interview Questions
Secondary Sidebar
Top Interview Question Tutorial
  • Interview Questions
    • Apache PIG Interview Questions
    • Elasticsearch Interview Questions
    • Data Engineer Interview Questions
    • Algorithm Interview Questions
    • OBIEE Interview Question
    • SSIS Interview Questions
    • Cognos Interview Questions
    • MapReduce Interview Questions
    • NoSQL Interview Questions
    • SharePoint Interview Questions
    • Sqoop Interview Questions
    • Business Intelligence Interview Questions
    • Mainframe Interview Questions
    • Rail Interview Questions
    • SSRS Interview Questions
    • Data Modeling Interview Questions
    • J2EE Interview Questions
    • Minitab Interview Questions
    • Statistics Interview Questions
    • MS SQL Interview Questions
    • Ab Initio Interview Questions
    • Spark Interview Questions
    • WordPress Interview Questions
    • OS Interview Questions
    • Drupal Interview Questions
    • OOP Interview Questions
    • Mulesoft Interview Questions
    • Typescript Interview Questions
    • Redux Interview Questions
    • Pig Interview Questions
    • ES6 Interview Questions
    • Multithreading Interview Questions
    • Go Interview Questions
    • APEX Interview Questions
    • Teradata Interview Questions
    • Groovy Interview Questions
    • ExtJS Interview Questions
    • E-Commerce Interview Questions
    • Appium Interview Questions
    • SOA Interview Questions
    • ITIL Interview Questions
    • Digital Electronics Interview Questions
    • IT Interview Questions
    • WinForms Interview Questions
    • IT Security Interview Questions
    • WCF Interview Questions
    • Microprocessor Interview Questions
    • Apache Interview Questions
    • MicroStrategy Interview Questions
    • Virtualization Interview Questions
    • UI Developer Interview Questions
    • Electrical Engineering Interview Questions
    • RMAN Interview Questions
    • SVN Interview Questions
    • Talend interview questions
    • SAP ABAP Interview Questions
    • Inheritance Interview Questions
    • Threading Interview Questions
    • Quality Control Interview Questions
    • Embedded System Interview Questions
    • OpenStack Interview Questions
    • Objective C Interview Questions
    • QA Interview Question
    • PLC Interview Questions
    • SDET Interview Questions
    • JCL Interview Questions
    • SOAP Interview Questions
    • IELTS Interview Questions
    • SoapUI Interview Questions
    • Front end Developer Interview Questions
    • DB2 Interview Questions
    • VSAM Interview Question
    • MVC Interview Questions
    • WPF Interview Questions
    • Java Collections Interview Questions
    • UI Designer Interview Questions
    • NLP Interview Questions
    • TFS Interview Questions
    • Active Directory Interview Questions
    • Xamarin Interview Questions
    • Intrusion Prevention System Interview Questions
    • COBOL Interview Questions
    • Control System Interview Questions
    • Blue Prism Interview Questions
    • Scenario Interview Questions
    • Unit testing interview questions
    • Linked List Interview Questions
    • Mainframe testing interview questions
    • Selenium Interview Questions
    • Binary Tree Interview Questions
    • Cloud Security Interview Questions
    • Functional Testing Interview Questions
    • Civil Engineering Questions for Interview
    • DHCP interview questions
    • Spring Batch Interview Questions
    • Perl interview questions
    • ESL interview questions
    • OBIEE Interview Questions
    • DynamoDB interview questions
    • Automation Anywhere Interview Questions
    • Scrum Interview Questions
    • Security Testing Interview Questions
    • Struts Interview Questions
    • Databricks Interview Questions
    • Electronics Engineering Interview Questions
    • Java concurrency interview questions
    • RxJava Interview Questions
    • ServiceNow Interview Question
    • XML Interview Questions
    • Entity Framework Interview Questions
    • Terraform Interview Questions
    • LINQ Interview Questions
    • MVVM Interview Questions
    • OSPF Interview Questions
    • Server interview questions
    • Appdynamics Interview Questions
    • Webpack Interview Questions
    • Data Architect Interview Questions
    • GitHub Interview Questions
    • Data Analyst Technical Interview Questions
    • GitHub JavaScript Interview Questions
    • Bitbucket Interview Questions
    • OOPs Java Interview Questions
    • DNS Interview Question
    • MPLS Interview Questions
    • Django Interview Question

Related Courses

Programming Languages Course

C programming Course

Selenium Training Certification

Algorithm Interview Questions

By Priya PedamkarPriya Pedamkar

Algorithm Interview Questions

Introduction to Algorithm Interview Questions and Answers

Preparing for a job interview in Algorithm. I am sure you want to know the most common 2023 Algorithm Interview Questions and Answers that will help you crack the Algorithm Interview with ease. Below is the list of top Algorithm Interview Questions and answers at your rescue.

Below is the list of 2023 Algorithm Interview Questions and answers, which can be asked during an Interview for fresher and experience.  These top interview questions are divided into two parts are as follows:

Part 1 – Algorithm Interview Questions and Answers (Basic)

This first part covers basic Interview Questions and Answers.

1. Write an algorithm to reverse a string. For example, if my string is “vahbunA”, then my result will be “Anubhav”.

Answer:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • Step 1: Start
  • Step 2: Take two-variable I and j.
  • Step 3: j is positioned on the last character (Technically, we can do this by length(string)-1)
  • Step 4: I is positioned on the first Character (we can do this by the string[0])
  • Step 5: String[i] is interchanged String[j]
  • Step 6: Increment I by 1
  • Step 7: Increment J by 1
  • Step 8: If ‘I’ > ‘j’, then go to step 3
  • Step 9: Stop

2. Write an algorithm to insert a node in the linked list, assuming the linked list is sorted already?

Answer:

Case 1: If the linked list is empty, then make the node as head and return it.

Code:

New_node-> Next = head;
head = New_node

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,697 ratings)

Case 2: Insert node in the middle

Code:

While (P!= insert_position)
{
P= p->Next;
}
Store_next= P->Next;
P->Next = New_Node;
New_Node->Next = Store_next;

Case 3: Insert a node at the end

Code:

While (P->next!= null)
{
P= P->Next;
}
P->Next = New_Node;
New_Node->Next = null;

3.Write an algorithm for bubble sort?

Answer: We are going to implement the bubble sort algorithm through C language.

Step 1: Repeat Step 2 and step 3

for I = 1 to 10

Step 2:

Set j = 1

Step 3: Repeat

while j <= n (Where n is number of elements in the array)
{ If a[i] < a[j] Then interchange a[i] and a[j] [End of if] }
Set j = j + 1
[End of inner loop] [End of step 1 outer loop]

Step 4:

Exit

4.Write an algorithm for Heapsort?

Answer:

  • Step 1: Since the tree satisfies the max-Heap property, then the largest item is stored at the root node.
  • Step 2: Remove the root element and put at the end of the array (nth position) put the last item of the tree (heap) at the vacant place.
  • Step 3: Reduce the heap’s size by 1 and heap the root element again so that we have the highest element at the root.
  • Step 4: The process is repeated until all the items on the list is sorted.

Part 2 – Algorithm Interview Questions and Answers (Advanced)

Let us now have a look at the advanced Interview Questions.

5. Write an algorithm for the Fibonacci search?

Answer:

Step 1: A is

sorted_int_array;

Step 2: take one variable c

Step 3:

Fib2 = 1, Fib1 = 1 and fib = 2

Step 4:

While fib < n do (where n is number of element in list)

Step 5: Assign the variable.

Fib2 = Fib1
Fib1 = Fib
Fib = Fib1 + Fib2
End while

Step 6: Assign the value to a temporary variable

I = 0, offset = 0;

Step 7:

While Fib > 1 do
I = min (offset + Fib2, n)
If c < A[i] then
Fib = Fib2
Fib1 = Fib1 – Fib2
Fib2 = Fib – Fib1
Else if c > A[i] then
Fib = Fib1;
Fib1 = Fib2;
Fib2 = Fib – Fib1;
Offset = I;
Else
Return true
End if
End while
Return false

6. Write an algorithm of push and pop operation in the stack?

Answer:

For Push Operation
Procedure Add( Item, Stack, N, Top)
(Insert ‘Item’ into the ‘stack’ of maximum size ‘n’, top is the number of elements currently in ‘Stack’)

Step 1: Check Stack is overflow?

If (Top >= N)
Stack is overflow
Exit

Step 2: If the stack does not overflow, increment the loop

Top = Top + 1

Step 3: Insert the element.

Stack [Top] = Item

Step 4:

Exit

For POP Operation:

Step 1: Check Stack is underflow means empty.

If (Top <= 0)
Stack is empty
Exit

Step 2: If the stack is not underflow, then deleting the element

Item = stack[top]

Step 3: decrementing the top value

Top = Top – 1

Step 4:

Exit

7. Write an algorithm for insert and delete operation in Queue?

Answer:

For insertion operation
Procedure add(queue, F, R, N, item)
(This will insert ‘item’ in the ‘queue’ after ‘R’(rare) where ‘n’ is the array size.)

Step 1: Check Queue is overflow means the queue is full.

If (R >= N)
Queue is full
Exit

Step 2: If the Queue is not overflowed, then increment the loop

R = R + 1

Step 3: Insert an element into the queue

Queue[R] = item

Step 4: Setting the ‘F’(Front) Pointer

If ( F = 0)
F = 1
Exit

For Deletion operation in Queue
Procedure delete(queue, F, R, item)
(Delete ‘item’ from the ‘stack’, ‘F’ is the Front-end pointer and ‘R’ is the rare end pointer.

Step 1: Check Queue is underflow means empty.

If ( R < = 0)
Queue is empty
Exit

Step 2: Deleting an element from the queue

Item = queue [F]

Step 3: Incrementing the value of F

F = F+1

Step 4: Checking the empty queue

If (F > R)
Then F = R = 0
Exit

8. Write an algorithm to find the minimum depth of a binary tree?

Answer:

Let “node” be the pointer to the root node of a subtree.

  • Step 1: If the node is equal to Null, return 0
  • Step 2: If the node is a leaf node, return 1.
  • Step 3: Recursively, find the minimum depth of the left and right sub-tree, let it be left Min Depth and right min depth, respectively.
  • Step 4: To get the tree’s minimum height rooted at the node, we will take a minimum of left min depth and right min depth and 1 for the root node.

Program:

Procedure minDepth ( Node )

Step 1:

if ( root = null)
Return 0

Step 2:

if (root -> Left = Null and root -> right = Null )
Return 1

Step 3:

if (root -> left is not null)
Return minDepth (root -> right ) + 1;

Step 4:

If (root -> Right is not null )
Return minDepth ( root -> left) + 1;

Step 5:

return min(minDepth (root -> left), minDepth (root -> right)) + 1

Recommended Articles

This has been a comprehensive guide to the Algorithm Interview Questions and answers so that the candidate can crackdown these Algorithm Interview Questions easily. You may also look at the following articles to learn more –

  1. Big Data interview questions
  2. Elasticsearch Interview Questions
  3. COBOL Interview Questions
  4. Apache PIG Interview Questions
Popular Course in this category
All in One Software Development Bundle (600+ Courses, 50+ projects)
  600+ Online Courses |  3000+ Hours |  Verifiable Certificates |  Lifetime Access
4.6
Price

View Course

Related Courses

Programming Languages Training (41 Courses, 13+ Projects, 4 Quizzes)4.9
C Programming Training (3 Courses, 5 Project)4.8
Selenium Automation Testing Training (11 Courses, 4+ Projects, 4 Quizzes)4.7
3 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more