Assignment: Programming Methodology and Data Structure
Course: BSc (1st Year)
Subject: Programming Methodology and Data Structures
Submission Date: [Your Deadline]
Introduction
This assignment aims to enhance your understanding of Programming Methodology and Data
Structures.
It includes both theoretical and practical questions covering fundamental concepts such as
programming paradigms,
data structures, recursion, and sorting algorithms. The goal is to reinforce knowledge through
conceptual understanding
and hands-on coding exercises.
Section A: Theory Questions
1. What are the different programming paradigms?
Programming paradigms define how a programming language structures its computation.
Common paradigms include Procedural, Object-Oriented, Functional, and Logic Programming.
Each has unique principles and is suitable for specific tasks.
2. What are the key principles of structured programming?
Structured programming emphasizes clarity and organization using control structures:
Sequence, Selection, and Iteration. It avoids 'goto' statements and promotes modularity.
3. Explain the difference between linear and non-linear data structures.
Linear structures store data sequentially (e.g., Arrays, Linked Lists), while non-linear structures
organize data hierarchically (e.g., Trees, Graphs).
4. Discuss the advantages and disadvantages of arrays vs. linked lists.
Arrays offer fast access but fixed size, whereas linked lists allow dynamic resizing but have
higher memory overhead.
5. What is time complexity? Explain Big-O notation with examples.
Time complexity measures algorithm efficiency. Big-O notation describes the worst-case
performance, such as O(n) for linear search and O(log n) for binary search.
6. Compare and contrast different searching algorithms.
Linear search scans elements one by one (O(n)), while binary search divides the array in half
each time (O(log n)).
7. What is recursion? Explain with an example.
Recursion occurs when a function calls itself. Example: Factorial(n) = n * Factorial(n-1).
8. Compare recursion and iteration.
Recursion is easier to read but may cause stack overflow. Iteration is more memory-efficient
but sometimes less intuitive.
Section B: Practical Coding Problems
1. Write a program to perform basic array operations (insert, delete, display).
2. Implement a stack using an array or linked list with push, pop, peek, and isEmpty
operations.
3. Create a singly linked list and perform insert and delete operations.
4. Implement Bubble Sort and Insertion Sort to sort an array of integers.
Code Implementation
1. Array Operations (Python)
def insert(arr, pos, val):
arr.insert(pos, val)
return arr
def delete(arr, pos):
arr.pop(pos)
return arr
arr = [1, 2, 3, 4, 5]
arr = insert(arr, 2, 99)
arr = delete(arr, 4)
print(arr) # Output: [1, 2, 99, 3, 5]
2. Stack Implementation (Python)
class Stack:
def __init__(self):
self.stack = []
def push(self, val):
self.stack.append(val)
def pop(self):
return self.stack.pop() if self.stack else "Stack is empty"
def peek(self):
return self.stack[-1] if self.stack else "Stack is empty"
stack = Stack()
stack.push(10)
stack.push(20)
print(stack.pop()) # Output: 20
print(stack.peek()) # Output: 10
3. Sorting Algorithms (Python)
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n-i-1):
if arr[j] > arr[j+1]:
arr[j], arr[j+1] = arr[j+1], arr[j]
return arr
arr = [5, 3, 8, 1, 2]
print(bubble_sort(arr)) # Output: [1, 2, 3, 5, 8]
Conclusion
This assignment provided an in-depth understanding of fundamental programming concepts
and data structures. The theoretical questions covered programming paradigms, data
structures, and algorithms,
while the coding exercises focused on implementing arrays, stacks, linked lists, and sorting
algorithms.
By completing this assignment, students will gain confidence in problem-solving and coding
efficiency.
These concepts are essential for further studies in computer science and software
development.