General Programming Questions
Conceptual Questions:
1. What is a data structure?
A data structure is a storage format that defines the way data is stored, organized and manipulated
Examples:
Array
Trees
Graphs
2. What is an Array?
An array is a collection of items stored at contiguous memory locations
Items stored are the same type
3. What is a Linked List?
A linked list, like an array, is linear data structured in which the elements are not necessary stored in a contiguous manner
It is basically a sequence of nodes, each node points towards the next node forming a chain-like structure
4. What is a Stack?
Stack is a linear data structure that performs 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
5. What is LIFO?
LIFO stands for Last in First Out
It is a way of accessing, storing and retrieving data
6. What is a Queue?
A Queue is a linear data structure that performs operations in a FIFO (First in first Out) order
7. What is FIFO?
FIFO stands for First In First Out
It's a way of accessing, storing and retrieving data
The data that was stored first is extracted first
8. What are binary trees?
Binary trees are an extension of the linked list structured
Binary tree has two nodes at all times, a left node and a right node
9. What is Recursion?
Recursion refers to a function calling itself based on a terminating condition
It uses LIFO and therefor makes use of the stack data structure
10. What is the OOPs concept?
Stands for Object Oriented Programming System which is a paradigm that provides concepts such as objects, classes, inheritance, among others
11. What are the concepts introduced in OOPs?
The concepts introduce in OOPs are:
Object: A real-world entity having a particular state and behavior. It can be defined as an instance of a class
Class: A logical entity that defines the blueprint from which an object can be created or instantiated
Inheritance: A concept that refers to an object acquiring all the properties and behavior of a parent object. It provides code re-usability
Polymorphism: A concept that allows a task to be performed in different ways. In Java, we use method overloading and method overriding to achive 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 achive abstraction
Encapsulation: A concept that refers t the wrapping of code and data together into a single unit
12. Explain Binary Search Tree?
A binary search tree stores data in such a way that it can be retrieved very efficiently
The left subtree contains nodes whose keys are less or equal than the node's key value
The right subtree contains nodes whose keys are greater than the node's key value
13. Explain Doubly Linked Lists?
Doubly linked lists are a special type of linked list in which traversal across the data elements can be done in both directions
This is made possible by having two links in every node, one that links to the next node and another that connects to the previous node
14. What is a Graph?
A graph is one type of data structure that contains a set of ordered pairs
These ordered pairs are also referred to as edges or arcs and are used to connect nodes where data can be stored and retrieved
15. Differentiate between linear and non-linear data structure?
16. What is a deque?
Is a double-ended queue
This is a structure in which elements can be inserted or removed from either end:
17. What is the difference between Stack and Array?
18. What sorting algorithm is the best?
There are many types of sorting algorithms:
quick sort
bubble sort
balloon sort
radix sort
merge sort
etc...
No algorithm can be considered as the best or fastest because each is designed for a specific type of data structure where it performs the best
19. How does variable declaration affect memory?
The amount of memory to be allocated or reserved depends on the data type being stored in that variable
Example: A variable is declared to be INTEGER type then 32 bits of memory storage will be reserved for that variable.
20. What are dynamic data structures?
Dynamic data structures are structures that expand and contract as a program runs
It provides a flexible means of manipulating data because it can adjust according to the size of the data
Programming Interview Questions:
1. How do you reserve a string in Java?
2. How do you determine if a string is palidrome?
Reverse the string and compare it to the original string. If they are equal then it is palidrome
3. Find the number of occurances of a character in a string?
Java:
Define a count as INT
Define search word
for loop through each character
in loop if character = search character then count = count + 1
print count
Python:
4. Find if the given two strings are anagrams or not?
Two strings are anagrams if they contain a similar group of characters in a carried sequence
Python:
5. How do you calculate the number of vowels and consonants in a String?
Python:
6. How do you get the matching elements in an integer array?
Java:
Define an INT array
Nest couple of loops where you compare the numbers against all other numbers
if condition to print if it does find 2 numbers matching
7. Code the Bubble Sort algorithm?
Java:
Declare array
Nest couple of loops to compare the numbers
Then sort the array will be sorted in the ascending order if found in any other order
Python:
8. Code the Insertion Sort algorithm?
Python:
9. How to reverse an array?
Python:
Using List Slicing to Reverse an Array in Python:
Output:
Using reverse() Method
Output:
10. Swap two numbers without using a third variable
11. Print a Fibonacci series using recurison?
12. How do you find the factorial of a number?
13. Reverse a linked list?
14. How do you implement Binary Search?
15. Find the second largest number in an array?
16. How do you remove all occurances of a given character from the input string?
17. Showcase Inheritance with the help of a program?
18. 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
19. Check if the given number is prime?
20. Sum up all elements in an array
Last updated