0% found this document useful (0 votes)
22 views

DSA_Assignment_Answers

The document provides an overview of various data structures, including linear and non-linear types, and their characteristics such as time and space complexity. It explains concepts like stacks, queues, trees, and hashing, along with their applications and algorithms like binary search and recursion. Additionally, it discusses memory allocation in linked lists and the differences between divide and conquer and greedy algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

DSA_Assignment_Answers

The document provides an overview of various data structures, including linear and non-linear types, and their characteristics such as time and space complexity. It explains concepts like stacks, queues, trees, and hashing, along with their applications and algorithms like binary search and recursion. Additionally, it discusses memory allocation in linked lists and the differences between divide and conquer and greedy algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DSA Assignment Answers

1. A data structure is a way of organizing and storing data to perform operations efficiently.

Examples of linear data structures: Array, Linked List. Examples of non-linear data structures: Tree,

Graph.

2. An array stores elements in contiguous memory and has a fixed size, whereas a linked list

consists of nodes that contain data and a pointer to the next node, allowing dynamic memory

allocation.

3. Time complexity indicates how the runtime of an algorithm increases with input size. In linear

search, the worst-case time complexity is O(n), where n is the number of elements in the array.

4. In stacks, overflow occurs when we try to push an element into a full stack. Underflow occurs

when we try to pop an element from an empty stack, both leading to errors.

5. Space complexity is the amount of memory used by an algorithm during its execution. For

example, an algorithm that sorts an array without extra space has O(1) space complexity.

6. A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. Real-life

applications include undo operations in editors and backtracking in mazes or puzzles.

7. The height of a tree is the number of edges on the longest path from the root to a leaf. A BST with

7 nodes in a balanced form has a height of 2.

8. A queue is a linear structure that follows FIFO order, while a circular queue connects the last

position back to the first, utilizing memory more efficiently and avoiding unused space.

9. The postfix expression of (A + B) * (C - D / E) is: AB+CDE/-*. This form eliminates the need for

parentheses and follows operand-operator order for evaluation.

10. Hashing is a technique for mapping data to a fixed-size table using a hash function. Collision

occurs when two keys map to the same index in the hash table.

11. A circular queue connects the end of the queue back to the front, allowing efficient use of

memory by reusing freed spaces, which is not possible in a simple linear queue.
12. A binary tree is a hierarchical structure where each node has at most two children. A full binary

tree has all nodes with 0 or 2 children, while a complete one is filled level-wise.

13. Dynamic memory allocation in linked lists allows memory to be allocated at runtime using

pointers. Each node is created as needed using functions like malloc() in C.

14. The recursive formula for Fibonacci is: fib(n) = fib(n-1) + fib(n-2), with base cases fib(0)=0,

fib(1)=1. So, fib(5) = 5.

15. Binary search is an efficient algorithm for finding an element in a sorted array. It requires that the

array must be sorted before applying the search.

16. To insert a node at the beginning of a singly linked list: create a new node, point its next to the

current head, and update the head to the new node.

17. Divide and conquer splits the problem into subproblems (e.g., merge sort), while greedy

algorithms make local optimal choices (e.g., Kruskal's algorithm). Both solve problems but use

different strategies.

18. Recursion is a technique where a function calls itself to solve smaller instances of the problem.

Example for factorial: factorial(n) = n * factorial(n-1), with factorial(0) = 1.

19. Push pseudocode: if top == size-1 then overflow else top++, stack[top] = item. Pop pseudocode:

if top == -1 then underflow else item = stack[top], top--.

20. A priority queue assigns priority to elements. The highest priority is dequeued first, unlike a

normal queue that follows FIFO regardless of priority.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy