1/49
Introductory flashcards covering the basics of algorithms, pseudocode, and algorithm analysis methods (RAM model and Operation Count) as presented in the SLIIT Data Structures and Algorithms lecture.
How is an 'Algorithm' defined in the lecture?
It is any well defined computational procedure that takes some value or set of values as input and produce some value or set of values as output.
According to the example on Page 3, what is the first step in the sorting algorithm provided?
Get the smallest value from the input.
What is the third step of the algorithm example logic on Page 3?
Repeat steps 1 and 2 for remaining input until there is no item in the input.
List the five properties of an algorithm mentioned on Page 4.
Be correct, be unambiguous, give the correct solution for all cases, be simple, and it must terminate.
What are five applications of algorithms listed on Page 5?
Data retrieval, network routing, sorting, searching, and shortest paths in a graph.
How does the transcript define 'Pseudocode'?
A method of writing down an algorithm that is easy to read and understand, more expressive, and similar to other programming languages.
Does pseudocode concern itself with the techniques of software engineering?
No, it does not concern with the technique of software engineering.
In pseudocode conventions, what symbol is used to indicate a comment line?
//
In pseudocode conventions, what symbol is used to indicate assignment?
=
How are array elements accessed according to pseudocode conventions?
By specifying the array name followed by the index in the square bracket.
What notation is used in pseudocode to indicate a range of values within an array?
The notation ".." (e.g., A[1..i]).
According to the transcript, what does the index notation A[1..i] indicate?
The sub array of A consisting of elements A[1],A[2],..,A[i].
What is the primary idea behind the 'Analysis of Algorithms'?
To predict the resource usage.
What three resources are typically predicted during algorithm analysis?
Memory, Logic Gates, and Computational Time.
What are the two reasons provided for needing an analysis of algorithms?
To compare and to predict the growth of run time.
How is the 'Best case' running time defined?
Minimum number of steps taken on any instance of size n.
How is the 'Worst case' running time defined?
Maximum number of steps taken on any instance of size n.
How is the 'Average case' running time defined?
An average number of steps taken on any instance of size n.
What are the four analysis methods mentioned on Page 12?
Operation Count Methods, Step Count Method(RAM Model), Exact Analysis, and Asymptotic Notations.
What is the focus of the 'Operation count' method for time complexity analysis?
Selecting one or more operations (such as add, multiply, and compare) and considering the time spent on those chosen operations, but not all.
What is the core assumption of the Step Count (RAM Model) regarding processors?
It assumes a generic one processor where instructions are executed one after another with no concurrent operations.
In the RAM Model, how many steps does an operation like +, −, or = take?
1 step.
In the RAM Model, how many steps does each memory access take?
1 step.
In the RAM Model, how is 'Running Time' calculated?
Running Time=Sum of the steps.
In RAM Model Example 1, how many steps are assigned to the code segment: n=100, n=n+100, and Print n?
1 step, 2 steps, and 1 step, totaling 4 steps.
What is the total step count formula for Example 2 involving a loop to calculate sum?
Steps=6n+3
In the RAM analysis of a loop 'for i=1 to n', how many assignments and comparisons are attributed to the loop control?
n+1 assignments and n+1 comparisons.
In RAM analysis, how many steps are counted for the operation 'sum=sum+A[i]'?
n additions, n assignments, and n memory accesses.
Using the RAM model, how many steps are needed to display numbers from 1 to 10?
42 steps.
In Question 01, how many steps are calculated for the instruction 'While i <= 10'?
11 steps.
In Question 01, how many steps are calculated for 'i=i+1'?
10+10=20 steps.
Using the RAM model, how many steps are needed to display numbers from 10 to 20?
46 steps.
What is the hint given for calculating the steps for 'While i <= 20' when starting at i=10?
20−10+2=12 steps.
In Question 02, how many steps are counted for 'print i' when displaying numbers from 10 to 20?
11 steps.
Using the RAM model, how many steps are needed to display even numbers from 10 to 20?
63 steps.
In Question 03, what is the total step count for the loop 'for i=10 to 20'?
12+12+11=35 steps.
In Question 03, how many steps is 'if i \text{ % } 2 \text{ == } 0' worth?
2×11=22 steps.
In Question 03, how many steps are counted for 'print i' when displaying even numbers from 10 to 20?
6 steps.
What is a major problem with the RAM model regarding different architectures?
The number of steps differs with different architecture.
Provide the example given in the transcript of an instruction that is one step in a CISC processor but potentially more in others.
sum=sum+A[i]
Besides architectural differences, what is another problem with the RAM model?
It is difficult to count the exact number of steps in the algorithm.
What specific algorithm is mentioned as being efficient for sorting a small number of elements?
Insertion sort.
What does Page 7 list as common Pseudocode Conventions?
English, Indentation, Separate line for each instruction, Looping and conditional constructs, // for comments, and = for assignment.
What is the step count for the initialization 'i=1' in the RAM model analysis of Question 01?
1 step.
In the RAM model analysis for Question 02, 'i=i+1' results in 22 steps. How is this broken down?
11 additions and 11 assignments.
In the summary, what are the five main areas covered in the lecture?
What is an algorithm, Properties of an algorithm, Design methods, Pseudocode, and Analysis (Operation count & Step count, RAM model).
How many steps are counted for 'sum=0' in the loop example analysis on Page 15?
1 assignment (total 1 step).
How many steps are assigned to 'i=1' in the 'for 1 to n' loop analysis on Page 15?
1 assignment (total 1 step).
According to Page 15, how many steps does 'sum=sum+A[i]' represent in terms of memory accesses?
n memory accesses.
Are instructions executed concurrently in the RAM model?
No, instructions are executed one after another, with no concurrent operations.