session: "5101-design-analysis-of-algo/2026-08-22 0000 DAA 22 Aug"
title: "DAA 22 Aug"
date: "2026-08-22 00:00"
duration: "1h 33m"
language: "en"
model: "deepseek-ai/DeepSeek-V4.1-Flash-1017"
parts: 3
transcript_chars: 62161
generated: "2026-11-23T23:24:27+05:30"
DAA 22 Aug
Overview
This class lays the foundations for Design & Analysis of Algorithms: it surveys the taxonomy of data structures (primitive/non-primitive, linear/non-linear, tree vs. graph, stack/queue), the four core operations (traversal, search, insertion, deletion), and the formal definition and correctness of an algorithm. It motivates algorithm design through a Patna-to-Delhi journey-planning example and real-world problems (DNA string matching, network flow, e-commerce, shortest route). The second half introduces factors affecting algorithm performance (time/space/computational complexity, approximation, failure probability, robustness, scalability, parallelization), the algorithmic paradigms (brute force, backtracking, greedy, dynamic programming, divide and conquer, branch and bound, NP completeness, randomized algorithms), and the mathematical tools of monotonicity and floor/ceiling. It fits at the very start of the course, before asymptotic analysis (promised for the next two to three lectures) and the individual sorting algorithms.
Learning outcomes
- Classify data structures as primitive/non-primitive, linear/non-linear, and distinguish a tree from a graph by the presence of a closed loop.
- State the formal definition of an algorithm and the condition for correctness (halts in finite time and outputs the correct solution for every problem instance).
- List the four core operations on data structures and explain why faster operations make an organization more suitable.
- Identify the factors in algorithm design illustrated by the journey example (resource constraints, waypoints, subjectivity) and explain what makes an algorithm generic.
- Name the factors in choosing among sorting algorithms and the factors affecting algorithm performance (time, space, computational complexity, approximation, failure probability, robustness, scalability, parallelization).
- Match each algorithmic paradigm (brute force, backtracking, greedy, dynamic programming, divide and conquer) to its definition and example problems.
- Distinguish divide and conquer (top-down) from dynamic programming (bottom-up, storing results).
- Define monotonically increasing/decreasing and strictly increasing/decreasing functions and explain why monotonically increasing functions matter for complexity.
- Compute floor and ceiling of positive and negative real numbers and apply the stated floor/ceiling properties.
Core concepts
Tree data structures
Trees play a pivotal role because access time can be reduced to order of log of n. They are the hierarchical (non-linear) structure whose efficiency motivates much of the course; tree and graph will probably be covered in detail after some classes.
Taxonomy of data structures
Two types: primitive (integer, float, double, long double, string, "anything") and non-primitive, which splits into linear and non-linear. This taxonomy frames the whole first part of the course — DSA first goes toward different data structures, which is why it is difficult to jump directly into algorithms without them.
Linear data structures
The axis of the elements follows a sequential pattern: the first element is attached to the next, the next to the third, and so on; there is sequential access from one side to the other.
- Array: location is fixed — declaring an array of size 100 reserves 100 locations, and data is stored sequentially. An array could be 1D, 2D, 3D, 4D as per requirement.
- Linked list: offers dynamic nature; at runtime the size can be increased or decreased as required (otherwise it is static). A node stores a value/information/data plus a link or address to the next node; access proceeds first node, then next, then next. A specific pointer points towards the first node; the last node always holds an address that points to null (null means there is no further value).
Non-linear / hierarchical organization
The entire structure forms a hierarchy; this arrangement is witnessed in tree and graph. Single difference between tree and graph: formation of a boundary or a closed loop. If present, it is a graph; otherwise it is a tree. So a tree is a subset of graph with the condition that there is no closed boundary or loop.
Stack and queue (derived data structures)
Also known as derived data structures, having specific properties — LIFO (last in first out) for stack and FIFO (first in first out) for queue.
Core operations in algorithm study
The four things algorithms will be discussed on:
1. Traversal — e.g., if there are 100 students in a class and you are asked to traverse them, a person goes to all the students (say they write their name or roll number) and comes back; i.e., visiting all the nodes exactly once.
2. Search — visiting the node but checking whether it is equal to a certain key; if the key is found, the search stops.
3. Insertion.
4. Deletion.
If these four operations are faster, that organization or logical arrangement is more suitable. This criterion connects the data-structure half of the class to the algorithm half.
Motivation: journey-planning example (Patna to Delhi)
By flight there is one path (Patna airport to Delhi airport, then from IGI to a specific target location); by train there are a number of possibilities (number of trains, classes and categories depending on costing); by car there are a number of possibilities — flights and trains have a pre-specified path and schedule, but the car journey is more interesting. The factors extracted from this example are the design factors for algorithms:
- Resource constraint — primarily time and money (in time and money there will of course be petrol; using expressways may use more or less petrol). Example: choosing not to use toll roads (Purwanchal expressway, Lucknow–Agra expressway, Agra–Delhi Noida expressway) and instead using state highways — in cost of toll you get lesser time.
- Numerous waypoints — a waypoint is an intermediate stoppage or intermediate location we wish to visit (e.g., Varanasi, Prayagraj, Kanpur); some people have favorite hotels or buses they will surely visit, which also counts as a waypoint.
- Subjectivity / human biasness — e.g., wanting to eat from some particular place, wanting to stay in a comfortable hotel, wanting to visit a specific place such as a temple or workshop; or a person who will not drive at night or will not drive in the morning.
Genericity of an algorithm
The algorithm is generic and works well even for a partial set of input — it works for a subset of input. Given only source and destination, it produces a relevant output; given source, destination and resource (lesser time), it produces output; given source, destination, resource and waypoint (e.g., stay in Varanasi for a night), it also produces output. Contrast with burger making: burger making is feasible only with a fixed set of input; an algorithm's input could be variable. Sorting example: an algorithm that sorts works whether we provide 100 numbers, 10 numbers, 20 numbers, or 10,000 numbers.
Formal definition and correctness
Formal definition: "an algorithm is any well-defined computational procedure that takes some input value or set of values as input and produce some value or set of value as an output in finite amount of time." Also described as a sequence of computational steps that transform the input into output. (The finite-amount-of-time aspect will be discussed when covering P and NP problems.) In general terms, an algorithm can be a computer program or even a hardware design (the slide says this can be skipped).
Correctness: an algorithm for a computational problem is correct if for every problem instance provided as input, it halts (finishes its computation in finite time) and outputs the correct solution. "Problem instance" means a portion, a part, or even the entire thing. If only source is provided, the algorithm should ask for the destination (that kind of arrangement has to be made). Sorting works for two numbers, three numbers, a thousand numbers.
Sorting and searching dominate
Throughout the algorithm discussion, sorting and searching algorithms will dominate; e.g., given a sequence of n numbers, getting a sorted order is a sorting problem.
Choosing among sorting algorithms
Which algorithm is best for a given application depends on a number of factors. Examples named: insertion sort, merge sort, quick sort, counting sort, bucket sort. If you only know insertion sort, you use it for all sorting; knowing merge sort, you think it is a little bit faster than insertion sort and can be used when the size of input is very high (merge sort will definitely increase the computational requirement); with quicksort, it may produce the answer in a similar time as merge sort but maybe faster in some instances. Factors in selecting an algorithm:
1. Number of items to be sorted — what is n; if n is very small, any algorithm can be used; if n is large, choose accordingly.
2. Extent to which the items are already sorted — e.g., 1, 3, 5, 9, 7, 21, 25 has only one element misplaced; or 2, 1, 3, 4, 9, 6, 8, 10 where elements are more towards their actual position.
3. Possible restriction on the item value — the item should not go beyond this or beyond that.
4. The architecture of the computer, kind of storage device used.
Students need not bother about these factors at this stage; after seeing around 7–8 sorting algorithms, these questions will be automatically solved (the first three will definitely be solved; the instructor is not sure about 4 and 5).
Real-world problems solved by algorithms
- DNA / string matching: determining the sequence of 3 billion chemical bases (chemical base pairs) that make up human DNA; DNA matching is used in crime investigation (culprit's DNA matching on-site evidence). Manually matching 3 billion chemical bases is very difficult; string matching checks whether a pattern is available in another string. String matching algorithms identify how one string s1 and another string s2 match or whether there is similarity; if similarity is more than 95 percent, we declare the same DNA. String matching will be covered in detail.
- Network flow analysis: the internet enables people around the world to quickly access and retrieve large amounts of information; how data flows, what type of network speed, what bottleneck can be held — from network flow analysis algorithms. Example: a network operator says your network speed is good but you do not get the same speed at home — possibly access points are not capable enough to accommodate that level of speed. At IIT Patna, the OFC link was 10 Gbps but at some point the access switches supported only 1 Gbps, so there was a bottleneck; those were eliminated.
- E-commerce: negotiation and other activities are one set of algorithms; inventory management is another set.
- Shortest route path: traveling salesman problem, also called minimum spanning tree — to be covered in detail.
Factors affecting algorithm performance
- Input size is the pivotal factor. An algorithm does not take a fixed time on all platforms/architectures, but "in more or less way it will be behaving likewise." Two i7 machines running the same algorithm may differ in speed (one pre-loaded with multiple programs, one newer), so the claim is general, not exact.
- Time complexity: the clock time the algorithm will take; analyzed theoretically. Faster algorithms (lower time complexity) are preferred — analogy: just as internet speeds moved from kbs to gbs and users shift to the faster provider, the algorithm with lower time complexity "will win." Time complexity plays a pivotal role in determining the complexity of an algorithm or selection of an algorithm.
- Space complexity: was very popular when memory was a constraint; now laptops have more than 8 GB RAM and SSDs, so space complexity is not a complicating factor for general algorithms (which need only few kbs or mbs). It becomes relevant for AI/ML-based algorithms. In this course, space complexity will be discussed but time complexity will be more prominent.
- Computational complexity: combines time and space complexity — striking a balance between time and space. Primarily refers to time complexity (the clock time for execution), though theoretically we stabilize orders like n square and log n.
- Approximation: making a balance between precision and computational efficiency. Example: int vs. float — float has higher precision but requires 32 bits of memory, int requires 8 bits; computation is reduced with 8 bits and increases with 32 bits. Compromising precision gives faster speed (in terms of time and space).
- Failure probability: the chances the algorithm will fail — e.g., an algorithm for moving from Patna to Delhi must handle a road closure that was not considered; what are the alternatives.
- Robustness and error handling: how the algorithm tackles/handles errors if a failure happens.
- Scalability: if the algorithm is correct for 10 inputs, is it correct for 10,000 inputs? During scalability analysis, asymptotic analysis is used — how the algorithm behaves when input n tends toward infinity.
- Parallelization and concurrency: possibility of running the program in parallel or concurrently. An octa-core processor has cores 1–8, but sequential coding always uses only core 1 while other cores remain idle; this aspect addresses engaging other cores.
- Note on scope: these aspects (failure probability, robustness, scalability, parallelization) are not part of the algorithm itself; apart from approximation, they belong to a subject called advanced algorithm, which works on top of the algorithms subject.
Algorithmic paradigms (algorithmic designing techniques)
How an algorithm is designed. Each paradigm is an umbrella containing multiple algorithms.
- Brute force: simplest designing technique — systematically exploring all possible solutions until a correct one is found. Example: searching for a misplaced laptop in bedroom, dining, washroom, kitchen, outside, garden — covering all aspects until found (e.g., in the dining hall). No intelligence applied; time complexity is definitely higher.
- Backtracking: systematically exploring all possible solutions in a structured manner; when a step is not reaching toward a solution, backtrack (go back, make changes, then come back to another path). Example: Sudoku. Problems: N-Queen problem, subset sum problem.
- Greedy: choosing the local optima/local minima at a stage without bothering about the global minima — doing what is correct at this instance. Analogy: cheating in an exam to clear it, without bothering whether it leads to some loss. Problem: knapsack problem.
- Dynamic programming: divide a complex problem into simpler overlapping sub-problems and store the results of sub-problems to solve a large problem. Algorithms: matrix chain multiplication, assembly line scheduling.
- Divide and conquer: breaking a complex problem into smaller, manageable sub-problems, each solved independently, then combined to get the result. Algorithms: merge sort, quick sort, binary search, maximum subarray. Historical aside: the concept is driven from the partition of Bengal (Lord Curzon).
- Branch and bound: listed as a paradigm to be explored later.
- NP completeness: not an algorithmic paradigm. Concerns problems not solvable in finite time; covers P type, NP type, NP complete, and NP hard problems.
- Randomized algorithms: leveraging randomness in a fundamental concept, incorporating a degree of unpredictability. Example: randomized quicksort. Advanced topic, covered if time allows.
Divide and conquer vs. dynamic programming
- Divide and conquer (top-down): "Top to down means that we will divide, divide, divide, divide the problem in very small then combine combine and get the result."
- Dynamic programming (bottom-up): "primarily a bottom-up approach we will solve a sub problem store the result and then go to the last problem then we will solve again it then store the result and go ahead."
- Effect of storing results: "this storing will reduce the computational complexity so that that's why dynamic programming are treated as the fastest algorithm paradigm but on the cost of memory."
- Key distinction: "the fine difference is we are storing the previous result or not storing the previous result strategy is top to bottom in divide and conquer and in dynamic program it is bottom to up." In both, the mechanism is to divide the problem into sub-problems; dynamic programming uses the result of the previous step to get the output of the next step; in divide and conquer this is not the policy. Also, divide and conquer is primarily a top-to-down approach.
Types of functions and monotonicity
Types of functions: functions are mathematical objects; there are many types, e.g., continuous functions and discrete-type functions. When determining the computational complexity of an algorithm, "we will definitely get continuous functions" (to be shown later: how an algorithm is converted into a form of a function, or a continuous function).
Monotonicity: similar type of behavior repeating again and again / retained throughout — if a function is increasing it keeps increasing; if decreasing it keeps decreasing. Applicable at low and high input sizes, with no condition that the property changes or reduces after some time.
- Monotonically increasing: m ≤ n implies f(m) ≤ f(n).
- Monotonically decreasing: m < n implies f(m) > f(n) (as stated in the lecture).
- Strictly increasing / strictly decreasing: the equality signs are missing — at no point of time are m equal to n or f(m) equal to f(n); strictness ensures the comparison cannot be made.
- Why studied: when determining computational complexity, we identify monotonically increasing functions, because with increasing input size no known algorithm decreases its computational complexity — it can reduce the pace of increase but will always increase. Stabilizing monotonically increasing functions makes determining an algorithm's computational complexity easy.
- No algorithm reduces its computational complexity as input increases: "none of the algorithm on this earth that will reduce its computational complexity when input increases." Computational complexity increases when input size increases, so monotonically increasing functions are what we see "in all the aspects, all the problems." A monotonically decreasing function also exists mathematically, but the focus is on monotonically increasing behavior. We cannot nullify complexity, only reduce/minimize it: "we cannot nullify it we will reduce it."
Combining sub-algorithms: when several algorithms/sub-problems are involved, "individually their results are calculated and while combining we will use" them. If one sub-problem is more complicated, the time complexity depends on the execution of that sub-problem, and "while combining we have to wait when all three are ready then we will combine."
Floor and ceiling
- Floor: for any real number x, the greatest integer less than or equal to x, denoted floor of x. Floor means taking the integer just less than the value (in the negative series, go in the reverse direction).
- Ceiling: the least integer greater than or equal to x, denoted ceiling of x. Ceiling means the integer just greater than the value — the least/smallest such integer (not just any greater integer like 5, 6, 7 for 3.14).
Formulas and maths
- Access time in tree data structures: order of $\log n$ — $n$ is the number of elements; used to justify why trees are pivotal.
- DNA similarity threshold: if similarity is more than $95\%$, we declare the same DNA