Algorithms Interview Questions

Similar documents
Algorithm classification

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

LECTURE 3 ALGORITHM DESIGN PARADIGMS

Algorithm Design Paradigms

CSCE 321/3201 Analysis and Design of Algorithms. Prof. Amr Goneid. Fall 2016

CS301 - Data Structures Glossary By

CAD Algorithms. Categorizing Algorithms

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS

CS 445: Data Structures Final Examination: Study Guide

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: CS6402- Design & Analysis of Algorithm Year/Sem : II/IV UNIT-I INTRODUCTION

SORTING AND SELECTION

About this exam review

Comparison Sorts. Chapter 9.4, 12.1, 12.2

Anany Levitin 3RD EDITION. Arup Kumar Bhattacharjee. mmmmm Analysis of Algorithms. Soumen Mukherjee. Introduction to TllG DCSISFI &

QuickSort

Backtracking is a refinement of the brute force approach, which systematically searches for a

SORTING, SETS, AND SELECTION

Merge Sort fi fi fi 4 9. Merge Sort Goodrich, Tamassia

Quick-Sort. Quick-sort is a randomized sorting algorithm based on the divide-and-conquer paradigm:

Part I Basic Concepts 1

Hiroki Yasuga, Elisabeth Kolp, Andreas Lang. 25th September 2014, Scientific Programming

Topic Analysis PART-A

having any value between and. For array element, the plot will have a dot at the intersection of and, subject to scaling constraints.

Lecture 19 Sorting Goodrich, Tamassia

Merge Sort Goodrich, Tamassia Merge Sort 1

COMP Data Structures

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

Tribhuvan University Institute of Science and Technology Computer Science and Information Technology (CSC. 154) Section A Attempt any Two questions:

Lecture 3, Review of Algorithms. What is Algorithm?

Sorting and Selection

Greedy Algorithms. CLRS Chapters Introduction to greedy algorithms. Design of data-compression (Huffman) codes

CPE702 Algorithm Analysis and Design Week 7 Algorithm Design Patterns

CS61BL. Lecture 5: Graphs Sorting

Quick-Sort fi fi fi 7 9. Quick-Sort Goodrich, Tamassia

CS6402 DESIGN AND ANALYSIS OF ALGORITHMS QUESTION BANK UNIT I

Advanced Algorithms and Data Structures

Greedy Algorithms CHAPTER 16

Algorithms. MIS, KUAS, 2007 Ding

SAMPLE OF THE STUDY MATERIAL PART OF CHAPTER 6. Sorting Algorithms

Sorting. Hsuan-Tien Lin. June 9, Dept. of CSIE, NTU. H.-T. Lin (NTU CSIE) Sorting 06/09, / 13

Algorithms. Algorithms ALGORITHM DESIGN

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

Faster Sorting Methods

Sorting is a problem for which we can prove a non-trivial lower bound.

Practical Session 10 - Huffman code, Sort properties, QuickSort algorithm, Selection

Programming II (CS300)

Pseudo code of algorithms are to be read by.

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Topic Notes: Brute-Force Algorithms

Chapter 4: Sorting. Spring 2014 Sorting Fun 1

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

Sorting. Data structures and Algorithms

Data Structures and Algorithm Analysis in C++

Analysis of Algorithms. Unit 4 - Analysis of well known Algorithms

DESIGN AND ANALYSIS OF ALGORITHMS

CS-6402 DESIGN AND ANALYSIS OF ALGORITHMS

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.

Sorting Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

AP Computer Science 4325

Question 7.11 Show how heapsort processes the input:

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

CLASS: II YEAR / IV SEMESTER CSE CS 6402-DESIGN AND ANALYSIS OF ALGORITHM UNIT I INTRODUCTION

Sorting Algorithms. + Analysis of the Sorting Algorithms

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Sorting Goodrich, Tamassia Sorting 1

Programming II (CS300)

T(n) = expected time of algorithm over all inputs of size n. half the elements in A[1.. j 1] are less than A[ j ], and half the elements are greater.

12 Abstract Data Types

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting)

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

Sorting. Outline. Sorting with a priority queue Selection-sort Insertion-sort Heap Sort Quick Sort

Quick-Sort. Quick-Sort 1

Advanced Algorithms and Data Structures

Data Structures, Algorithms & Data Science Platforms

Introduction to Computers and Programming. Today

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Sorting. Sorting. Stable Sorting. In-place Sort. Bubble Sort. Bubble Sort. Selection (Tournament) Heapsort (Smoothsort) Mergesort Quicksort Bogosort

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

COT 5407: Introduction. to Algorithms. Giri NARASIMHAN. 1/29/19 CAP 5510 / CGS 5166

CSE 373 Final Exam 3/14/06 Sample Solution

DATA STRUCTURE AND ALGORITHM USING PYTHON

CSCI2100B Data Structures Heaps

DATA STRUCTURES AND ALGORITHMS

Index. Anagrams, 212 Arrays.sort in O(nlogn) time, 202

Lecture 7 Quicksort : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Sorting. Divide-and-Conquer 1

MCS-375: Algorithms: Analysis and Design Handout #G2 San Skulrattanakulchai Gustavus Adolphus College Oct 21, Huffman Codes

Sorting. CSE 143 Java. Insert for a Sorted List. Insertion Sort. Insertion Sort As A Card Game Operation. CSE143 Au

We ve done. Now. Next

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

6. Algorithm Design Techniques

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42

Introduction. e.g., the item could be an entire block of information about a student, while the search key might be only the student's name

Searching, Sorting. part 1

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order.

Transcription:

Algorithms Interview Questions 1. Define the concept of an algorithm. An algorithm is any well-defined computational procedure that takes some value (or set of values) as input and produces some value (or set of values) as output. In short, it can be seen as a sequence of computational steps that transform the input into the output. 2.What are the arguments present in pattern matching algorithms? These are the following arguments which are present in pattern matching Algorithms. 1) Subject, 2) Pattern 3) Cursor 4) MATCH_STR 5) REPLACE_STR 6) REPLACE_FLAG 3. Explain the function SUB in algorithmic notation? In the algorithmic notation rather than using special marker symbols, generally people use the cursor position plus a substring length to isolate a substring. The name of the function is SUB. SUB returns a value the sub string of SUBJECT that is specified by the parameters i and j and an assumed value of j. 4. In Algorithmic context how would you define book keeping operations? Usually when a user wants to estimate time he isolates the specific function and brands it as active operation. The other operations in the algorithm, the assignments, the manipulations of the index and the accessing of a value in the vector, occur no more often than the addition of vector values. These operations are collectively called as book keeping operations. 5. Define and describe an iterative process with general steps of flow Page 1 of 7

chart? There are four parts in the iterative process they are Initialization: -The decision parameter is used to determine when to exit from the loop. Decision: -The decision parameter is used to determine whether to remain in the loop or not. Computation: - The required computation is performed in this part. Update: - The decision parameter is updated and a transfer to the next iteration results. 6. State recursion and its different types? Recursion is the name given to the technique of defining a set or a process in terms of itself. There are essentially two types of recursion. The first type concerns recursively defined function and the second type of recursion is the recursive use of a procedure. 7. Define and state the importance of sub algorithm in computation and its relation ship with main algorithm? A sub algorithm is an independent component of an algorithm and for this reason is defined separately from the main algorithm. The purpose of a sub algorithm is to perform some computation when required, under control of the main algorithm. This computation may be performed on zero or more parameters passed by the calling routine. 8. Name any three skills which are very important in order to work with generating functions. The three most important skills which are used extensively while working with generating functions are 1)Manipulate summation expressions and their indices. 2)Solve algebraic equations and manipulate algebraic expressions, including partial function decompositions. 3)Identify sequences with their generating functions Page 2 of 7

9. What is the general strategy for Markov Algorithm? The general strategy in a Markov Algorithm is to take as input a string x and, through a number of steps in the algorithm, transform x to an output string y. this transformation process is generally performed in computers for text editing or program compilation. 10. Define string in an algorithmic notation and an example to support it? In the algorithmic notation, a string is expressed as any sequence of characters enclosed in single quote marks. 11. How to find median of a BST? Find the no. of elements on the left side. If it is n-1 the root is the median. If it is more than n-1, then it has already been found in the left subtree. Else it should be in the right subtree 12. What is Diffie-Hellman? It is a method by which a key can be securely shared by two users without any actual exchange. 13. What is the goal of the shortest distance algorithm? The goal is completely fill the distance array so that for each vertex v, the value of distance[v] is the weight of the shortest path from start to v. 14. Explain the depth of recursion? This is another recursion procedure which is the number of times the procedure is called recursively in the process of enlarging a given argument or arguments. Usually this quantity is not obvious except in the case of extremely simple recursive functions, such as FACTORIAL (N), for which the depth is N. 15. Explain about the algorithm ORD_WORDS? Page 3 of 7

This algorithm constructs the vectors TITLE, KEYWORD and T_INDEX. 16. Which are the sorting algorithms categories? Sorting algorithms can be divided into five categories: a) insertion sorts b) exchange sorts c) selection sorts d) merge sorts e) distribution sorts 17.Define a brute-force algorithm. Give a short example. A brute force algorithm is a type of algorithm that proceeds in a simple and obvious way, but requires a huge number of steps to complete. As an example, if you want to find out the factors of a given number N, using this sort of algorithm will require to get one by one all the possible number combinations. 18. What is a greedy algorithm? Give examples of problems solved using greedy algorithms. A greedy algorithm is any algorithm that makes the local optimal choice at each stage with the hope of finding the global optimum. A classical problem which can be solved using a greedy strategy is the traveling salesman problem. Another problems that can be solved using greedy algorithms are the graph coloring problem and all the NPcomplete problems. 19. What is a backtracking algorithm? Provide several examples. It is an algorithm that considers systematically all possible outcomes for each decision. Examples of backtracking algorithms are the eight queens problem or generating permutations of a given sequence. 20. What is the difference between a backtracking algorithm and a bruteforce one? Page 4 of 7

Due to the fact that a backtracking algorithm takes all the possible outcomes for a decision, it is similar from this point of view with the brute force algorithm. The difference consists in the fact that sometimes a backtracking algorithm can detect that an exhaustive search is unnecessary and, therefore, it can perform much better. 21. Describe divide and conquer paradigm. When a problem is solved using a divide and conquer algorithm, it is subdivided into one or more subproblems which are all similar to the original problem in such a way that each of the subproblems can be solved independently. In the end, the solutions to the subproblems are combined in order to obtain the solution to the original problem. 22. Describe on short an insertion sorting algorithm. An algorithm that sorts by insertion takes the initial, unsorted sequence and computes a series of sorted sequences using the following rules: a) the first sequence in the series is the empty sequence b) given a sequence S(i) in the series, for 0<=i<n, the next sequence in the series, S(i+1), is obtained by inserting the (i+1)th element of the unsorted sequence S(i+1) into the correct position in S(i). 23. Which are the advantages provided by insertion sort? Insertion sort provides several advantages: a) simple implementation b) efficient for small data sets c) adaptive - efficient for data sets that are already substantially sorted: the time complexity is O(n + d), where d is the number of inversions d) more efficient in practice than most other simple quadratic, i.e. O(n2) algorithms such as selection sort or bubble sort; the best case (nearly sorted input) is O(n) e) stable - does not change the relative order of elements with equal keys f) in-place - only requires a constant amount O( 1) of additional memory space g) online - can sort a list as it receives it 24. Shortly describe the quicksort algorithm. Page 5 of 7

In quicksort, the steps performed are the following: a) pick an element, called a pivot, from the list b) reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way) c) recursively sort the sub-list of lesser elements and the sub-list of greater elements 25. What is the difference between selection and insertion sorting? In insertion sorting elements are added to the sorted sequence in an arbitrary order. In selection sorting, the elements are added to the sorted sequence in order so they are always added at one end. 26. What is merge sorting? Merging is the sorting algorithm which combines two or more sorted sequences into a single sorted sequence. It is a divide and conquer algorithm, an O(n log n) comparison-based sorting algorithm. Most implementations produce a stable sort, meaning that the implementation preserves the input order of equal elements in the sorted output. 27. Which are the main steps of a merge sorting algorithm? Sorting by merging is a recursive, divide-and-conquer strategy. The basic steps to perform are the following: a) divide the sequence into two sequences of length b) recursively sort each of the two subsequences c) merge the sorted subsequences to obtain the final result 28. Provide a short description of binary search algorithm. Binary search algorithm always chooses the middle of the remaining search space, discarding one half or the other, again depending on the comparison between the key value found at the estimated position and the key value sought. The remaining search space is reduced to the part before or after the estimated position. Page 6 of 7

29. What is the linear search algorithm? Linear search is a method for finding a particular value in a list which consists of checking every one of its elements, one at a time and in sequence, until the desired one is found. It is the simplest search algorithm, a special case of brute-force search. Its worst case cost is proportional to the number of elements in the list; and so is its expected cost, if all list elements are equally likely to be searched for. Therefore, if the list has more than a few elements, other methods (such as binary search or hashing) may be much more efficient. 30. What is best-first search algorithm? It is a search algorithm that considers the estimated best partial solution next. This is typically implemented with priority queues. 31. What is Huffman coding? In computer science and information theory, Huffman coding is an entropy encoding algorithm used for lossless data compression. The term refers to the use of a variablelength code table for encoding a source symbol (such as a character in a file) where the variable-length code table has been derived in a particular way based on the estimated probability of occurrence for each possible value of the source symbol. Page 7 of 7