0% found this document useful (0 votes)
2 views3 pages

Here Are 50 Placement Questions On Data Types

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Here Are 50 Placement Questions On Data Types

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Here are 50 placement questions on Data Types, Class & Object (OOP), Stacks, and Linked

Lists with clear questions and concise answers for engineering interviews:

Data Types (10 Questions)

1. Q: What are the primitive data types in Python?


A: int, float, bool, str, complex.
2. Q: What is the difference between mutable and immutable data types?
A: Mutable types (like list, dict) can be changed after creation; immutable types (like int,
str, tuple) cannot.
3. Q: How is memory allocated for variables in Python?
A: Python uses dynamic typing; memory is allocated on the heap for objects and
references on the stack.
4. Q: What is typecasting? Give an example.
A: Converting one data type to another. Example: int('10') converts string '10' to
integer 10.
5. Q: What is the difference between a list and a tuple?
A: Lists are mutable; tuples are immutable.
6. Q: Explain the Boolean data type in Python.
A: Boolean represents True or False values, used for conditional checks.
7. Q: What are composite data types?
A: Data types made of multiple elements, e.g., list, tuple, set, dict.
8. Q: How do you declare a variable and assign a value in Python?
A: variable_name = value (e.g., x = 5).
9. Q: What is the difference between a string and a character in Python?
A: Python doesn’t have a separate character type; characters are strings of length 1.
10. Q: What happens when you try to add an integer and a string in Python?
A: It raises a TypeError since different data types cannot be added directly.

Class and Object (OOP) (15 Questions)

11. Q: What is a class in Python?


A: A blueprint for creating objects with attributes and methods.
12. Q: What is an object?
A: An instance of a class.
13. Q: Explain the difference between instance variables and class variables.
A: Instance variables belong to objects; class variables belong to the class shared by all
objects.
14. Q: What is inheritance?
A: A mechanism where a new class derives properties and behavior from an existing
class.
15. Q: What is polymorphism?
A: The ability of different classes to respond to the same function call in different ways.
16. Q: What is encapsulation?
A: Wrapping data and methods that operate on data within a class and restricting access.
17. Q: How do you create a constructor in Python?
A: Using the __init__ method.
18. Q: What is method overriding?
A: Redefining a method in the child class that exists in the parent class.
19. Q: What are class methods and static methods?
A: Class methods receive the class as the first parameter (@classmethod), static methods
don’t receive any implicit first argument (@staticmethod).
20. Q: Explain the difference between composition and inheritance.
A: Inheritance is "is-a" relationship; composition is "has-a" relationship.
21. Q: What is the difference between self and cls?
A: self refers to the instance; cls refers to the class.
22. Q: How do you make a class attribute private?
A: Prefix it with double underscore __.
23. Q: What is multiple inheritance?
A: A class can inherit from more than one base class.
24. Q: Explain the super() function.
A: It allows calling the parent class methods in a child class.
25. Q: What is abstraction in OOP?
A: Hiding complex implementation details and showing only the necessary parts.

Stacks (10 Questions)

26. Q: What is a stack?


A: A linear data structure following Last-In-First-Out (LIFO).
27. Q: What are the basic operations of a stack?
A: Push, Pop, Peek (or Top), isEmpty.
28. Q: How can you implement a stack in Python?
A: Using a list with append() for push and pop() for pop operations.
29. Q: What is stack overflow?
A: Trying to push an element into a full stack.
30. Q: What is stack underflow?
A: Trying to pop an element from an empty stack.
31. Q: How is a stack used in function calls?
A: The call stack stores return addresses, parameters, and local variables for function
calls.
32. Q: What is the difference between stack and queue?
A: Stack is LIFO, queue is FIFO.
33. Q: How to check if parentheses in an expression are balanced using stack?
A: Push opening brackets and pop when matching closing bracket appears; if stack is
empty at end, parentheses are balanced.
34. Q: Can you implement a stack using a linked list?
A: Yes, by inserting and deleting nodes at the head of the list.
35. Q: What is a real-world application of stacks?
A: Undo functionality in text editors.

Linked Lists (15 Questions)

36. Q: What is a linked list?


A: A linear data structure where elements (nodes) are linked using pointers.
37. Q: Differentiate between singly and doubly linked lists.
A: Singly linked list nodes point to the next node; doubly linked lists nodes point to both
next and previous nodes.
38. Q: What are the advantages of linked lists over arrays?
A: Dynamic size, ease of insertion/deletion without shifting elements.
39. Q: How do you traverse a linked list?
A: Start from the head node and follow next pointers until null.
40. Q: How to insert a node at the beginning of a linked list?
A: Create a new node and set its next pointer to current head, then update head to new
node.
41. Q: How to delete a node from a linked list?
A: Change the next pointer of the previous node to the node after the one to delete.
42. Q: What is a circular linked list?
A: The last node points back to the head, forming a circle.
43. Q: How do you detect a cycle in a linked list?
A: Use Floyd’s cycle detection algorithm with two pointers moving at different speeds.
44. Q: What is a sentinel node in linked lists?
A: A dummy node used to simplify boundary conditions.
45. Q: How do you reverse a singly linked list?
A: Iteratively change the next pointer of each node to its previous node.
46. Q: How can linked lists be used to implement stacks?
A: Push and pop operations happen at the head node.
47. Q: What is the time complexity of insertion in a linked list?
A: O(1) if inserting at the head or tail (with tail pointer); O(n) otherwise.
48. Q: How do you merge two sorted linked lists?
A: Compare nodes from both lists and build a new sorted list.
49. Q: Explain the difference between shallow copy and deep copy in linked lists.
A: Shallow copy copies references; deep copy duplicates nodes and structure.
50. Q: How is memory managed in linked lists?
A: Nodes are dynamically allocated and deallocated during insertion and deletion.

You might also like