Upgrade to remove ads
CS21B General Programming Interview
Terms in this set (38)
How much time does it take to retrieve an element if stored in:
HashMap, Binary tree and Linked list?
-HashMap it takes O(1) time
-Binary tree it takes O(logN) where N is a number of nodes in the tree.
-Linked list it takes O(n) time where n is a number of element in the list.
What is the difference between Overriding and Overloading?
Overriding is done at runtime
Overloading is done at compile time.
What is the difference between forking a process and spawning a thread?
When you fork a process, the new process will run the same code as the parent process but in different memory space.
When you spawn a new thread in the existing process it just creates another independent path of execution but it shares the same memory space.
What is a critical section?
Is a part of the code which is really important
What is the difference between value type and reference type?
A value type points to a value
A reference type points to an object.
What is heap and stack in a process?
The stack is used to store primitive values and reference type to object but the actual object is always created in the heap.
What is a strongly typed language?
A strongly typed language has different data types such as int, float, String, char, boolean.
Python and Perl are weakly typed.
Can you describe the difference between valid and well formed XML?
A well formed XML is the one which has root element and all tags are closed properly, attributes are defined properly.
A valid XML can be validated against a schema
What is the difference between a DOM and SAX parser?
-DOM parser is an in memory parser so it loads whole XML file in memory and create a DOM tree to parse.
SAX parser is an event based parser so it parses XML docuent based on the event received such as opening tag or closing tag.
What is the relationship between threads and processes?
A process can have multiple threads but a thread always belongs to a single process.
What is immutable class?
A class is said to be immutable if its state cannot be changed once created. For example a String is immutable.
*Why would you ever want to create a mock object?
A mock object is very useful to test an individual unit in your Software, in fact, stub and mocks a are a powerful tool for creating automated unit tests. Suppose you write a program to display currency conversion rates but you don't have a URL to connect to, now if you want to test your code, you can use mock objects. In Java world, there are a lot of frameworks which can create powerful mock objects for you e.g. Mockito and PowerMock.
What is SQL injection?
SQL injection is a security vulnerability which allows intruder to steal data from the system. Any system which takes input from user and creates SQL query without validating/sanitazing that input is vulnerable. The intrude injects SQL code instead of data to retrieve more information.
What is the difference between an inner join and a left join in SQL?
Inner join= only matching records from both tables are selected.
Left join=All records from the left table are selected in addition to the matching records from both tables.
What does MVC stand for?
View- what user sees such as webpage
Model-is the actual objects/data such as User, Employee, Order
Controller-Is used for the routing request to correct processor.
What is the difference between a class and an object?
A class is a blueprint on which objects are created. You cannot create an object without first having a class to represent its structure.
What is loose coupling?
Loose coupling is a desirable quality in software which allows one part of software to modify without affecting another part of the software.
Ex. Changing the user interface does not affect the back end.
What is the difference between composition aggregation and association?
Association means two objects are related to each other but can exist without each other.
Composition is a form of association where one object is composed of multple object but they only exist together. (think of the human body)
Aggregation is a collection of object (city is an aggregation of citizens)
What is the difference between an interface and an abstract class?
An interface is the purest form of abstraction with nothing concrete in place while an abstract class is a combination of some abstraction and concrete things.
What is unit testing?
Unit testing is a way to test individual unit for their functionality instead of testing the whole application.
What are 3 different types of testing that might be performed on an application before it goes live?
Unit testing, integration, and smoke testing.
Unit testing is used to test individual units to verify whether they are working as expected.
Integration testing is done to verify whether the individual tested module can work together or not.
Smoke testing is a way to test whether the most common functionality of software is working properly
What is the difference between iteration and recursion?
Iteration uses a loop to perform the same step again and again.
Recursion calls the function itself to do the repetitive task.
Recursion can cause stackoverflow so iteration can be preferred
How do you get the last digit of an integer?
By using the number % 10.
For instance 567%10 returns 7.
Test driven development
Test driven is a programming method where tests are written before writing any function code.
What is the Liskov substitution principle?
What is the difference between binary tree and binary search tree?
A binary search tree is an ordered binary tree, where the values of all nodes in the left tree are less than or equal to the root while all the nodes in the right subtree is greater than or equal to root.
What is an example of a recursive algorithm?
Recursive algorithms can be used in binary trees and linked lists.
Some example algorithms are reversing a linked list, tree traversal and quick sort algorithms.
What is the time complexity of an algorithm?
The time complexity specifies the ratio of time to the input. It shows how much time an algorithm will take to complete for a given number of input.
What are differences between a linked list and an array?
Arrays store its elements in a contiguous location while a linked list stores its data anywhere in memory. This gives linked list the ability to expand itself.
What is a way to resolve a collision on a hash table?
-Linear probing-if the bucket is already occupied then function checks next bucket until it finds an empty one.
-chaining- multiple elements are stored in the same bucket location
What is a regular expression?
A regular expression is a way to perform pattern matching in text data. You can use REGEX to check if an email is valid; You can also check is a string is a number or not.
What is a stateless system?
A stateless system is a system which does not maintain any internal state. Such system will produce the same output for same input at any point of time.
Write a SQL query to find the second highest salary in the employee table.
SELECT MAX(Salary) FROM employee WHERE salary NOT IN (SELECT MAX(Salary) FROM employee)
Can you describe the difference between correlated and non correlated subquery?
In a correlated subquery, inner query depends upon the outter query and executes for each row in the outer query. While non correlated subquery doesn't depend upon the outer query and can be executed independently. An example of correlated subquery is finding the nth highest salary in employee table.
How do you find if a number is a power of two without using arithmetic operator?
Whenever you cannot use arithmetic it is about using bitwise operators.
return x & (x-1) == 0;
the above converts the right most but to zero if its on.
How do you find a running Java process on UNIX?
You can find a combination of ps and grep command to find any process running on UNIX.
-ps -ef | grep "MyJavaApp"
ps -e will list every process from all users
ps -f will give you full details including PID.
How do you find large files in UNIX?
you can find large files by using the find command because it provides an option to search files based on size.
find . - type f -size +1g -print
What is a shell script?
A shell script is a set of shell commands with some programming contructs such as an if or for loop. such as a scriot to daily cleanup logfiles.
YOU MIGHT ALSO LIKE...
Python Program Overview
Revature Interview questions
Programming Terms 1-5
OTHER SETS BY THIS CREATOR