Professional Documents
Culture Documents
ASSIGNMENT UNIT- 1
COURSE: B. TECH
BRANCH: ECE
Answer: Abstract Data Type (ADT) is a theoretical concept that represents a data type by its behavior
rather than its implementation. It defines a set of operations that can be performed on the data along with
the behavior of these operations. The actual implementation details are hidden, providing an abstraction
layer that allows programmers to focus on using the data structure rather than worrying about its internal
representation.
Characteristics of ADT:
i. Encapsulation: ADT encapsulates data and operations into a single unit.
ii. Data Hiding: The internal representation of data is hidden from the user.
iii. Interface: ADT provides a set of operations that can be performed on the data, defining its behavior.
iv. Flexibility: ADTs can be implemented in various ways, providing flexibility in choosing the most
suitable implementation based on requirements.
Short note:
Nodes are organized in levels, with the top node called the root and the bottom nodes called leaves.
Trees are used to represent hierarchical relationships, such as file systems, organization charts, and family
trees.
A binary search tree is a specific type of tree where each node has at most two children.
The left child of a node contains a value less than the node's value, while the right child contains a value
greater than the node's value.
BSTs are commonly used for searching, insertion, and deletion operations due to their efficient structure.
Time Complexity: Time complexity measures the amount of time an algorithm takes to complete as a
function of the input size. It indicates how the runtime of an algorithm grows with increasing input size.
Space Complexity: Space complexity measures the amount of memory space an algorithm requires to
execute as a function of the input size. It indicates how the memory usage of an algorithm grows with
increasing input size.
Answer: 1D Array:
A 1D array is a linear data structure that stores elements in a single row or column.
2D Array:
A 2D array is a collection of multiple 1D arrays arranged in rows and columns to form a grid-like structure.
It is accessed using two indices, one for the row and another for the column.
Primitive data types are basic data types predefined by the programming language.
They are directly supported by the language and typically have fixed sizes.
Non-primitive data types are derived from primitive data types or other non-primitive types.
They are also called reference types as they store references to memory locations where data is stored.
Differences:
Storage: Primitive data types store actual values, whereas non-primitive data types store references to
objects.
Size: Primitive data types have fixed sizes determined by the language, while non-primitive data types can
vary in size depending on the data they hold.
Mutability: Primitive data types are immutable (cannot be changed), whereas non-primitive data types can
be mutable.
Examples: Primitive data types include integers, floats, etc., while non-primitive data types include arrays,
classes, etc.
Answer: Recursion is a programming technique where a function calls itself in order to solve a problem.
It involves breaking down a problem into smaller subproblems, solving each subproblem recursively,
and combining their results to solve the original problem.
Example:
def factorial(n):
if n == 0:
return 1
else:
return n * factorial (n - 1)
Num = 5
In this example, the factorial () function calls itself with a smaller value (n - 1) until the base case (n == 0) is
reached. Each recursive call calculates the factorial of a smaller number, and the results are combined to find
the factorial of the original number.
array = [1, 2, 3, 4, 5]
new_element = 10
position = 2
Output:
Answer: Linear data structures are arrangements of data elements in which each element is connected to its
previous and next element in a linear order. The main types of linear data structures are arrays, linked lists,
stacks, and queues.
Arrays: Arrays are a collection of elements of the same data type arranged in contiguous memory locations.
Example: int array [] = {1, 2, 3, 4, 5};
Linked Lists: Linked lists are a collection of nodes where each node contains data and a reference (or
pointer) to the next node in the sequence. Example: 1 -> 2 -> 3 -> 4 -> 5
Stacks: Stacks are a collection of elements with Last-In-First-Out (LIFO) order. Elements are added and
removed from the same end, typically called the top of the stack. Example: function call stack.
Queues: Queues are a collection of elements with First-In-First-Out (FIFO) order. Elements are added to the
rear and removed from the front. Example: waiting line in a cafeteria.
array = [1, 2, 3, 4, 5]
position = 2
delete_element (array, position)
print ("Updated Array:", array)
Output:
Updated Array: [1, 2, 4, 5]