# Technical Interview Questions for Freshers (With Answers)

> Technical interview questions for freshers with clear answers on DSA, OOP, operating systems, computer networks and short coding problems.

Canonical: https://devsunite.com/guides/technical-interview-questions-for-freshers
Last updated: 2026-11-02

Last updated: 2026-11-02

These technical interview questions for freshers cover the computer science basics that come up again and again in campus and off-campus rounds: data structures, OOP, operating systems, networks and short coding problems. Each answer is short enough to say out loud in an interview, and precise enough to survive a follow-up question.

Read the answer, then try explaining it in your own words without looking. If you can do that, and write the small code snippets from memory, you are ready for most fresher technical rounds.

## What a fresher technical round covers

Most fresher technical rounds mix a few areas. The exact balance depends on the company, but expect questions from most of these:

- **Data structures and algorithms (DSA):** complexity, arrays, linked lists, stacks, queues, hashing, trees, graphs, searching and sorting.
- **Object-oriented programming (OOP):** the four pillars, overloading vs overriding, interfaces and abstract classes.
- **DBMS and SQL:** keys, normalization, joins and transactions. See the [SQL interview questions for freshers](https://devsunite.com/guides/sql-interview-questions-for-freshers).
- **Operating systems:** processes, threads, scheduling, memory management and synchronization.
- **Computer networks:** OSI and TCP/IP models, TCP vs UDP, DNS and HTTP(S).
- **Your own projects:** what you built, why you chose that stack, and what you would change. Know every line on your resume.

> Interviewers usually go one level deeper than your first answer. Practice saying each answer out loud with an [AI mock interview](https://devsunite.com/mock-interview) so the follow-ups do not catch you off guard.

## Data structures and algorithms interview questions

DSA is the core of most technical rounds. For structured practice, work through the [DSA sheets](https://devsunite.com/resources/dsa-sheets) and the [DSA patterns](https://devsunite.com/resources/dsa-patterns).

### 1. What is Big O notation?

Big O describes an upper bound on how an algorithm's running time or memory grows as the input size `n` grows, ignoring constant factors and lower-order terms. In interviews it usually means the worst case.

- `O(1)`: constant, such as array access by index.
- `O(log n)`: halving the input each step, such as binary search.
- `O(n)`: one pass over the input.
- `O(n log n)`: efficient comparison sorts like merge sort.
- `O(n^2)`: nested loops over the input, such as bubble sort.

### 2. What is the difference between an array and a linked list?

| Aspect | Array | Linked list |
| --- | --- | --- |
| Memory | Contiguous block | Nodes scattered in memory, linked by pointers |
| Access by index | O(1) | O(n), you must walk from the head |
| Insert or delete at front | O(n), elements shift | O(1) |
| Insert or delete in middle | O(n) | O(1) once you hold the node, O(n) to find it |
| Extra memory | None per element | One pointer per node (two for doubly linked) |
| Cache behaviour | Cache friendly | Poor locality |

### 3. What is the difference between a stack and a queue?

A **stack** is LIFO (last in, first out): you push and pop from the same end. A **queue** is FIFO (first in, first out): you enqueue at the back and dequeue from the front. Both support their core operations in `O(1)`.

- Stack uses: function call stack, undo, balanced bracket checking, DFS.
- Queue uses: BFS, task scheduling, buffering requests.

### 4. How does hashing work, and what is a collision?

A hash table runs a key through a hash function to get an index into an array of buckets, which gives average `O(1)` insert, lookup and delete. A **collision** happens when two different keys map to the same bucket.

- **Chaining:** each bucket holds a list (or tree) of entries. Java's `HashMap` does this and converts long chains to balanced trees.
- **Open addressing:** on a collision, probe for another empty slot (linear probing, quadratic probing, double hashing). Python's `dict` uses open addressing.

The worst case is `O(n)` when many keys collide, which is why a good hash function and resizing at a load factor threshold matter.

### 5. How does binary search work, and what is its complexity?

Binary search works on a **sorted** array. Compare the target with the middle element, then discard the half that cannot contain it. It runs in `O(log n)` time and `O(1)` extra space when written iteratively.

```python
def binary_search(arr, target):
    lo, hi = 0, len(arr) - 1
    while lo <= hi:
        mid = lo + (hi - lo) // 2
        if arr[mid] == target:
            return mid
        if arr[mid] < target:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1
```

### 6. What is a stable sorting algorithm?

A sort is **stable** if elements with equal keys keep their original relative order. This matters when you sort by one field after another, for example by name and then by department.

- Stable: merge sort, insertion sort, bubble sort, counting sort. Python's `sorted()` (Timsort) and Java's `Collections.sort()` for objects are stable.
- Not stable in typical implementations: quick sort, heap sort, selection sort.

### 7. What are the time complexities of common sorting algorithms?

| Algorithm | Best | Average | Worst | Extra space |
| --- | --- | --- | --- | --- |
| Bubble sort | O(n) | O(n^2) | O(n^2) | O(1) |
| Insertion sort | O(n) | O(n^2) | O(n^2) | O(1) |
| Merge sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Quick sort | O(n log n) | O(n log n) | O(n^2) | O(log n) stack |
| Heap sort | O(n log n) | O(n log n) | O(n log n) | O(1) |

Bubble sort reaches `O(n)` only with the early-exit check that stops when a pass makes no swaps.

### 8. What is the difference between BFS and DFS?

| Aspect | BFS | DFS |
| --- | --- | --- |
| Order | Level by level | Goes as deep as possible, then backtracks |
| Data structure | Queue | Stack (or recursion) |
| Shortest path | Finds it in an unweighted graph | Does not guarantee it |
| Typical uses | Shortest path, nearest neighbour, level order traversal | Cycle detection, topological sort, connected components |

Both run in `O(V + E)` time on an adjacency list, where `V` is vertices and `E` is edges.

## OOP interview questions for freshers

OOP questions test whether you can explain design ideas, not just recite definitions. The [OOP notes](https://devsunite.com/resources/core-subjects/oop) go deeper on each topic.

### 9. What are the four pillars of OOP?

- **Encapsulation:** bundle data with the methods that use it and hide internal state behind a public interface (private fields, public methods).
- **Abstraction:** expose what an object does and hide how it does it, using interfaces and abstract classes.
- **Inheritance:** a class reuses and extends another class's fields and methods (an is-a relationship). See [types of inheritance](https://devsunite.com/resources/core-subjects/oop/types-of-inheritance).
- **Polymorphism:** one interface, many forms. The same call behaves differently depending on the actual object. See [polymorphism](https://devsunite.com/resources/core-subjects/oop/overview-of-polymorphism).

### 10. What is the difference between method overloading and method overriding?

| Aspect | Overloading | Overriding |
| --- | --- | --- |
| What it is | Same method name, different parameter lists, in the same class | Subclass redefines a method with the same signature as the parent |
| Resolved at | Compile time (static polymorphism) | Runtime (dynamic polymorphism) |
| Return type | Can differ, but return type alone cannot distinguish overloads | Same, or a subtype (covariant return in Java) |
| Inheritance needed | No | Yes |

Python does not support overloading by signature: a second `def` with the same name replaces the first. More on [function overloading](https://devsunite.com/resources/core-subjects/oop/function-overloading) and [method overriding](https://devsunite.com/resources/core-subjects/oop/method-overriding).

### 11. What is the difference between an abstract class and an interface?

In Java (8 and later), both can have abstract and concrete methods, so the practical differences are these:

- A class can **extend only one** abstract class but **implement many** interfaces.
- An abstract class can have constructors and instance fields with any access level. Interface fields are always `public static final` constants.
- Interfaces can have `default`, `static` and (since Java 9) `private` methods, but no instance state.
- Use an abstract class for shared state and code among closely related classes, and an interface for a capability that unrelated classes can share (like `Comparable`).

In C++ the equivalent is a class with pure virtual functions. See [abstract classes and pure virtual functions](https://devsunite.com/resources/core-subjects/oop/abstract-classes-and-pure-virtual-functions).

### 12. What is composition, and why is it often preferred over inheritance?

**Composition** means a class holds instances of other classes and delegates work to them (a has-a relationship), for example a `Car` that has an `Engine`. Inheritance is an is-a relationship.

Composition is often preferred because it keeps classes loosely coupled, lets you swap parts at runtime, and avoids fragile deep hierarchies where a change in a base class breaks subclasses. See [composition vs aggregation vs inheritance](https://devsunite.com/resources/core-subjects/oop/composition-vs-aggregation-vs-inheritance).

### 13. What is the difference between a class and an object?

A **class** is a blueprint that defines fields and methods. An **object** is a concrete instance of that class created at runtime, with its own copy of the instance fields. One class can have many objects.

### 14. What are the SOLID principles?

- **S**ingle responsibility: a class should have one reason to change.
- **O**pen/closed: open for extension, closed for modification.
- **L**iskov substitution: a subclass must be usable wherever its parent is expected without breaking behaviour.
- **I**nterface segregation: prefer small, focused interfaces over one large one.
- **D**ependency inversion: depend on abstractions, not concrete classes.

Freshers are rarely asked to apply all five in depth, but naming them with one example each is a strong signal. More in [SOLID principles](https://devsunite.com/resources/core-subjects/oop/solid-principles).

## Operating system interview questions

OS questions focus on processes, memory and synchronization. The [operating systems notes](https://devsunite.com/resources/core-subjects/operating-systems) cover each topic in detail.

### 15. What is the difference between a process and a thread?

| Aspect | Process | Thread |
| --- | --- | --- |
| Definition | A program in execution with its own address space | A unit of execution inside a process |
| Memory | Separate address space per process | Shares code, heap and open files with other threads of the same process; has its own stack and registers |
| Creation and switching cost | Higher | Lower |
| Communication | Needs IPC (pipes, sockets, shared memory) | Can share data directly, so needs synchronization |
| Failure isolation | A crash usually affects only that process | A crashing thread can bring down the whole process |

See [process vs program vs threads](https://devsunite.com/resources/core-subjects/operating-systems/process-vs-program-vs-threads).

### 16. What is a deadlock, and what are the four necessary conditions?

A **deadlock** is a state where a set of processes are each waiting for a resource held by another process in the same set, so none can proceed. All four Coffman conditions must hold at the same time:

1. **Mutual exclusion:** at least one resource is non-shareable.
2. **Hold and wait:** a process holds one resource while waiting for another.
3. **No preemption:** a resource cannot be forcibly taken away.
4. **Circular wait:** a cycle of processes, each waiting on the next.

Breaking any one condition prevents deadlock, for example by always acquiring locks in a fixed order to break circular wait. See [deadlock prevention](https://devsunite.com/resources/core-subjects/operating-systems/deadlock-prevention) and the [Banker's algorithm](https://devsunite.com/resources/core-subjects/operating-systems/bankers-algorithm) for avoidance.

### 17. What is paging, and what is virtual memory?

**Paging** splits a process's logical address space into fixed-size **pages** and physical memory into frames of the same size. A page table maps pages to frames, so a process does not need contiguous physical memory, which removes external fragmentation.

**Virtual memory** lets a process use an address space larger than physical RAM by keeping only the needed pages in memory and the rest on disk. Accessing a page that is not in memory causes a **page fault**, and the OS loads it (demand paging), evicting another page if needed using a page replacement algorithm such as LRU.

More on [paging](https://devsunite.com/resources/core-subjects/operating-systems/paging-in-os), [virtual memory and demand paging](https://devsunite.com/resources/core-subjects/operating-systems/virtual-memory-and-demand-paging) and [page replacement algorithms](https://devsunite.com/resources/core-subjects/operating-systems/page-replacement-algorithms).

### 18. What are the common CPU scheduling algorithms?

- **FCFS (first come, first served):** non-preemptive, simple, but short jobs can wait behind a long one (convoy effect).
- **SJF (shortest job first):** gives the minimum average waiting time for a given set of jobs, but needs burst times in advance and can starve long jobs. Its preemptive form is SRTF.
- **Priority scheduling:** runs the highest-priority job first; low-priority jobs can starve, which aging fixes.
- **Round robin:** each process gets a fixed time quantum in turn; good response time for time-sharing systems.
- **Multilevel feedback queue:** processes move between queues based on their behaviour, favouring short and interactive jobs.

See [process scheduling](https://devsunite.com/resources/core-subjects/operating-systems/process-scheduling) and [round robin scheduling](https://devsunite.com/resources/core-subjects/operating-systems/round-robin-scheduling).

### 19. What is the difference between a mutex and a semaphore?

- A **mutex** is a lock with ownership: only the thread that locked it should unlock it. It allows exactly one thread into a critical section.
- A **semaphore** is an integer counter with atomic `wait` (P) and `signal` (V) operations. A **counting semaphore** allows up to N threads at once, for example to limit access to a pool of N connections. A **binary semaphore** (0 or 1) behaves like a lock but has no ownership, so any thread can signal it.

Use a mutex for mutual exclusion and a semaphore for signalling or limiting concurrent access. See [semaphores](https://devsunite.com/resources/core-subjects/operating-systems/semaphores) and the [critical section problem](https://devsunite.com/resources/core-subjects/operating-systems/critical-section-problem).

### 20. What is a context switch?

A **context switch** is when the CPU stops running one process or thread and starts another. The OS saves the current state (registers, program counter, and so on) into its process control block and loads the saved state of the next one.

It is pure overhead, since no useful work runs during the switch, which is why very small time quanta in round robin hurt throughput. See [context switching](https://devsunite.com/resources/core-subjects/operating-systems/context-switching).

## Computer networks: computer science interview questions

Networking questions for freshers rarely go beyond the core models and protocols. The [computer networks notes](https://devsunite.com/resources/core-subjects/computer-networks) cover them in more depth.

### 21. What is the difference between the OSI model and the TCP/IP model?

The **OSI model** is a 7-layer reference model: Physical, Data Link, Network, Transport, Session, Presentation, Application. The **TCP/IP model** is the model the internet actually uses, usually described with 4 layers: Link (network access), Internet, Transport, Application.

TCP/IP folds OSI's Session, Presentation and Application layers into one Application layer, and OSI's Physical and Data Link layers into the Link layer. Some textbooks describe a 5-layer version that keeps Physical and Data Link separate. See the [OSI model](https://devsunite.com/resources/core-subjects/computer-networks/osi-model) and the [TCP/IP model](https://devsunite.com/resources/core-subjects/computer-networks/tcp-ip-model).

### 22. What is the difference between TCP and UDP?

| Aspect | TCP | UDP |
| --- | --- | --- |
| Connection | Connection-oriented (three-way handshake: SYN, SYN-ACK, ACK) | Connectionless |
| Reliability | Guaranteed delivery with acknowledgements and retransmission | No delivery guarantee |
| Ordering | Delivers bytes in order | No ordering |
| Flow and congestion control | Yes | No |
| Header size | 20 bytes minimum | 8 bytes |
| Typical uses | Web (HTTP/1.1, HTTP/2), email, file transfer, SSH | DNS queries, video calls, online games, QUIC (HTTP/3) |

### 23. What happens when you type a URL into the browser and press Enter?

1. The browser parses the URL (scheme, host, path) and checks its caches.
2. **DNS resolution:** the hostname is resolved to an IP address via the browser, OS and resolver caches, then recursive lookups through root, TLD and authoritative name servers if needed.
3. The browser opens a **TCP connection** to the server (port 443 for HTTPS) with a three-way handshake. HTTP/3 uses QUIC over UDP instead.
4. For HTTPS, a **TLS handshake** verifies the server's certificate and agrees on session keys.
5. The browser sends an **HTTP request** (for example `GET /path`) with headers and cookies.
6. The server processes it and returns an **HTTP response** with a status code, headers and body (usually HTML).
7. The browser parses the HTML, builds the DOM and CSSOM, fetches CSS, JavaScript and images, runs scripts, and renders the page.

Interviewers often pick one step and drill into it, so know DNS and TLS well. See [how the internet works](https://devsunite.com/resources/core-subjects/computer-networks/how-the-internet-works).

### 24. What is the difference between HTTP and HTTPS?

**HTTPS** is HTTP sent over **TLS**. TLS encrypts the traffic, protects it from tampering, and authenticates the server with a certificate signed by a trusted certificate authority. Plain HTTP sends everything in clear text.

HTTP uses port 80 by default and HTTPS uses port 443. TLS uses asymmetric cryptography during the handshake to agree on keys, then fast symmetric encryption for the data. See [HTTP vs HTTPS](https://devsunite.com/resources/core-subjects/computer-networks/http-vs-https).

### 25. What is DNS and how does it work?

**DNS (Domain Name System)** translates human-readable names like `example.com` into IP addresses. It is a distributed, hierarchical system: root servers point to TLD servers (`.com`, `.in`), which point to the domain's authoritative name servers.

A recursive resolver (usually your ISP's or a public one) does the lookup on your behalf and caches answers for their TTL. DNS mostly runs over UDP port 53 and falls back to TCP for large responses and zone transfers. Common record types: `A` (IPv4), `AAAA` (IPv6), `CNAME` (alias), `MX` (mail). See [DNS](https://devsunite.com/resources/core-subjects/computer-networks/dns).

### 26. What is the difference between an IP address and a MAC address?

An **IP address** is a logical address at the network layer used to route packets across networks, and it can change when a device moves. A **MAC address** is a 48-bit hardware address at the data link layer used to deliver frames within the same local network. **ARP** maps an IPv4 address to a MAC address on a local network. See [ARP](https://devsunite.com/resources/core-subjects/computer-networks/arp-protocol).

## Coding interview questions for freshers with short solutions

These classic problems show up in online assessments and live coding rounds. Solutions are in Python 3; state the time and space complexity every time you finish one.

### 27. How do you reverse a string?

In Python, slicing with a step of -1 is the idiomatic answer. If the interviewer asks you to do it without built-ins, use two pointers. Both are `O(n)` time.

```python
def reverse_string(s: str) -> str:
    return s[::-1]

def reverse_two_pointers(s: str) -> str:
    chars = list(s)  # strings are immutable in Python
    i, j = 0, len(chars) - 1
    while i < j:
        chars[i], chars[j] = chars[j], chars[i]
        i += 1
        j -= 1
    return "".join(chars)
```

In Java, `new StringBuilder(s).reverse().toString()` does the same.

### 28. How do you check if a string is a palindrome?

Compare characters from both ends moving inward. This version ignores case and non-alphanumeric characters, which is the common interview variant. `O(n)` time, `O(1)` extra space.

```python
def is_palindrome(s: str) -> bool:
    i, j = 0, len(s) - 1
    while i < j:
        if not s[i].isalnum():
            i += 1
        elif not s[j].isalnum():
            j -= 1
        elif s[i].lower() != s[j].lower():
            return False
        else:
            i += 1
            j -= 1
    return True
```

### 29. How do you solve Two Sum with a hash map?

Given an array and a target, return the indices of two numbers that add up to the target. Store each number's index in a dictionary and check whether the complement has been seen. `O(n)` time and `O(n)` space, versus `O(n^2)` for the brute force.

```python
def two_sum(nums: list[int], target: int) -> list[int]:
    seen = {}  # value -> index
    for i, x in enumerate(nums):
        if target - x in seen:
            return [seen[target - x], i]
        seen[x] = i
    return []
```

### 30. How do you detect a cycle in a linked list?

Use **Floyd's cycle detection** (slow and fast pointers). The slow pointer moves one step and the fast pointer moves two. If there is a cycle they eventually meet; if fast reaches the end, there is none. `O(n)` time, `O(1)` space.

```python
def has_cycle(head) -> bool:
    slow = fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
        if slow is fast:
            return True
    return False
```

A common follow-up: to find where the cycle starts, reset one pointer to the head after they meet and move both one step at a time; they meet at the cycle start.

### 31. How do you find the missing number in an array of 0 to n?

The array holds `n` distinct numbers from the range `0` to `n` with one missing. The expected sum is `n * (n + 1) / 2`; subtract the actual sum. `O(n)` time, `O(1)` space.

```python
def missing_number(nums: list[int]) -> int:
    n = len(nums)
    return n * (n + 1) // 2 - sum(nums)

def missing_number_xor(nums: list[int]) -> int:
    result = len(nums)
    for i, x in enumerate(nums):
        result ^= i ^ x
    return result
```

Python integers do not overflow, but in Java the sum can overflow `int` for large `n`. The XOR version avoids that, which is a good point to mention.

### 32. How do you reverse a linked list?

Walk the list once and flip each `next` pointer to point at the previous node. `O(n)` time, `O(1)` space.

```python
def reverse_list(head):
    prev = None
    curr = head
    while curr:
        nxt = curr.next
        curr.next = prev
        prev = curr
        curr = nxt
    return prev
```

## Frequently asked questions

### Where can I practice technical interview questions for freshers with answers?

Start with the question groups on this page, then practice the same topics out loud in an AI mock interview. For coding, work through a DSA sheet topic by topic rather than solving random problems.

### Which subjects are asked in a fresher technical interview?

Most rounds cover data structures and algorithms, OOP, DBMS and SQL, operating systems, computer networks and your own projects. The weight of each varies by company and role.

### Which programming language should I use in a technical interview?

Use the language you are most fluent in, as long as the company allows it. Java, Python and C++ are accepted almost everywhere for coding rounds.

### How many coding problems should a fresher practice before interviews?

There is no fixed number. Covering the common patterns, such as two pointers, sliding window, hashing, recursion, BFS and DFS, matters more than the raw count of problems solved.

### What should I do if I do not know the answer to a technical question?

Say so honestly, then reason out loud from what you do know. Interviewers usually value a clear thought process and a willingness to say I am not sure over a confident wrong answer.

## Related

- [Core CS subjects](https://devsunite.com/resources/core-subjects)
- [DSA sheets](https://devsunite.com/resources/dsa-sheets)
- [DSA patterns](https://devsunite.com/resources/dsa-patterns)
- [AI mock interview](https://devsunite.com/mock-interview)
- [Java interview questions for freshers](https://devsunite.com/guides/java-interview-questions-for-freshers)
- [Python interview questions for freshers](https://devsunite.com/guides/python-interview-questions-for-freshers)
- [SQL interview questions for freshers](https://devsunite.com/guides/sql-interview-questions-for-freshers)
- [FAANG interview questions](https://devsunite.com/resources/faang-interview-questions)
- [All career guides](https://devsunite.com/guides)
