Interview Questions

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Showcase Inheritance with the help of a program?

The class Cat inherits the property color from the class Animal by extending the parent class (Animal). This way a class Cat can have more parent classes if it wishes to inherit their properties

Binary Search Tree

A binary search tree is used to store data in a manner that it can be retrieved very efficiently. The left sub-tree contains nodes whose keys are less than the node's key value. The right sub-tree contains nodes whose keys are greater than or equal to the node's key value

What is a Binary Tree?

A binary tree is an extension of the linked list structure where each node has at most two children. A binary tree has two nodes at all times, a left node and a right node.

Polymorphism

A concept that allows a task to be performed in different ways. In Java, we use method overloading and method overriding to achieve polymorphism.

Abstraction

A concept that hides the internal details of an application and only shows the functionality. In Java, we use abstract class and interface to achieve abstraction.

Inheritance

A concept that refers to an object gaining all the properties and behaviors of a parent object. It provides code reusability.

Encapsulation

A concept that refers to the wrapping of code and data together into a single unit.

What is a Data Structure

A data structure is a storage format that defines the way data is stored, organized, and manipulated. Some popular data structures are Arrays, Trees, and Graphs.

What is a Deque?

A deque is a double-ended queue. This is a structure in which elements can be inserted or removed from either end.

How do you find the factorial of an integer?

A factorial is a function that multiplies a number by every number below it. For example, 5!= 5*4*3*2*1=120. Recursive function multiples the numbers until it reaches 1.

What is a Graph?

A graph is a particular type of data structure that contains a set of ordered pairs. The ordered pairs in a graph are also known as edges or arcs and are most commonly used to connect nodes where the data can be stored and retrieved

Class

A logical entity that defines the blueprint from which an object can be created or instantiated

What is a Queue?

A queue refers to a linear data structure that performs operations in a FIFO order. In a queue, the least recently added elements are removed first as opposed to a stack.

Object

A real-world entity having a particular state and behavior. We can define it as an instance of a class.

What is a Stack

A stack refers to a linear data structure performing operations in a LIFO (Last In First Out) order. In a stack, elements can only be accessed, starting from the topmost to the bottom element.

How do you determine if a string is a palindrome?

A string is a palindrome when it stays the same on reversing the order of characters in that string. It can be achieved by reversing the original string first and then checking if the reversed string is equal to the original string.

What is an Array?

An array is commonly referred to as a collection of items stored at contiguous memory locations. Items stored are of the same type. It organizes data so that a related set of values can be easily sorted or searched.

What are Dynamic Data Structures?

Dynamic data structures have the feature where they expand and contract as a program runs. It provides a very flexible method of data manipulation because adjusts based on the size of the data to be manipulated.

Doubly Linked Lists

Doubly linked lists are categorized as a special type of linked list in which traversal across the data elements can be done in both directions. This is made possible by the presence of two links in every node, one that links to the node next to it and another that connects to the node before it.

how do you get the matching elements in an integer array?

Declare an array. Nest a couple of loops to compare the numbers with other numbers in the array. Print the matching elements if found.

How would you swap two numbers without using a third variable?

Declare two variables and initialize them with values. Make b the sum of both numbers. Then subtract the sum (b) from a, so a is now swapped. Lastly, subtract a from the sum (b), so b is also swapped.

How would you implement Binary Search?

Binary search divides the array into half in every iteration step until it finds the element. It works on the sorted arrays since it compares the values of adjacent elements and then calculates the mid number. If the value of low becomes greater than high at any point, it means the element is not present in the list.

How do you reverse a linked list?

Declare a linked list. Add elements to that linked list. Apply the descending iterator method to the linked list. This reverses the order of elements in the linked list.

How do you reverse a string?

Declare a string. Take out the length of that string. Loop through the characters of the string. Add the characters in reverse order in the new string.

How would you implement the bubble sort algorithm

Declare an array. Nest a couple of loops to compare the numbers in the array. The array will be sorted in ascending order by replacing the elements if found in any other order

What is FIFO?

FIFO stands for First In First Out. It is a way of accessing, storing and retrieving data. The data that was stored first is extracted first

What is LIFO

LIFO is an abbreviation for Last In First Out It is a way of accessing, storing and retrieving data. It extracts the data that was stored last first.

What is a Linked List?

Like an array, a linked list refers to a linear data structure in which the elements are not necessarily stored in a contiguous manner. It is basically a sequence of nodes, each node points towards the next node forming a chain-like structure

Differentiate between Linear and Non-Linear Data Structure?

Linear Data Structure: It is a structure in which data elements are adjacent to each other - Linked lists, Arrays, Queues, and Stacks Non-Linear Data Structure: It is a structure in which each data element can connect to over two adjacent data elements - graphs and lists

How would you find the second largest number in an array

Loop through the array. If the value of i is greater than the highest, store the value of i in highest, and store the value of highest in the second-highest variable.

How do you calculate the number of Vowels and consonants in a String?

Loop through the string. Increase the vowel variable by one whenever the character is found to be a vowel, using the if condition. Otherwise, increment the consonant variable. Print the values of both the vowel and the consonant count.

How do you reverse an array?

Loop till the half-length of the array. Replace the numbers corresponding to the indexes from the starting and the end.

What is OOPs Concepts?

OOPs stands for Object-Oriented Programming System, a paradigm that provides concepts such as objects, classes, and inheritance.

What are the concepts introduced in OOPs?

Object, Class, Inheritance, Polymorphism, Abstraction, Encapsulation

Explain overloading and overriding with the help of a program?

Overloading: When a class has two or more methods with the same name, they are called overloaded methods. Overriding: When a superclass method is also implemented in the child class, it's a case of overriding.

What is Recursion?

Recursion refers to a function calling itself based on a terminating condition. It uses LIFO and therefore makes use of the stack data structure.

Stack vs Array

Stack: Stack follows a Last In First Out (LIFO) pattern. What this means is that data access necessarily follows a particular sequence where the last data to be stored is the first one that will be extracted. Array: On the other hand, Arrays do not follow a specific order, but instead can be accessed or called by referring to the indexed element within the array.

Print a fibonacci series using recursion?

The Fibonacci numbers are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ........ We can calculate them using the mathematical formula used in the Fibonacci recursive function. public static int fibonacci(int n) {

How does Variable Declaration Affect Memory?

The amount of memory that is to be reserved or allocated depends on the data type being stored in that variable. For example, if a variable is declared to be "integer type", 32 bits of memory storage will then be reserved for that particular variable.

What sorting algorithm is the best?

There are many types of sorting algorithms: bubble sort, quick sort, balloon sort, merge sort, radix sort, and more. No algorithm can be considered as the best or fastest because they have designed each for a specific type of data structure where it performs the best

Find the number of occurences of a character in a String?

To find the number of occurrences, loop through the string and search for that character at every iteration; whenever it is found, it will update the count.

How to find out if two given strings are anagrams or not

Two strings are anagrams if they contain a similar group of characters in a varied sequence. Declare a boolean variable that tells at the end of the two strings are anagrams or not. First, check if the length of both strings is the same, if not, they cannot be anagrams. Convert both the strings to character arrays and then sort them. Check if the sorted arrays are equal. If they are equal, print anagrams, otherwise not anagrams.

How do you sum all the elements in an array?

Use for loop to iterate through the array and keep adding the elements in that array.

How do you check if the given number is prime?

Use if statements to check for each condition separately:If the number is 0 or 1, it cannot be prime.If the number is 2, it is prime number.If the number is indivisible by other numbers, it is prime.

How do you remove all occurrences of a given character from the input string?

Use the built-in string method "replace" to replace a character with any other character, including symbols and white spaces.

How would you implement the insertion sort algorithm

We assume the first element in the array to be sorted. The second element is stored separately in the key. This sorts the first two elements. You can then take the third element and do a comparison with the ones on the left of it. This process will go on until a point where we sort the array.


संबंधित स्टडी सेट्स

Types of Tissues Found in the Body

View Set

Real Estate Investment Trusts (REIT)

View Set

section 7 unit 1: A Brief History of Agency

View Set

Information Systems Management - C724 (Set 1)

View Set

Geometry - (Points, Lines, Planes, Rays, Segments)

View Set