0% found this document useful (0 votes)
6 views38 pages

Unit 1 (Into To The Data Structure and Algorithm)

The document outlines a course on Data Structures and Algorithms using C, detailing objectives, prerequisites, and course content divided into units covering algorithms, linear and non-linear data structures, sorting and searching algorithms. It includes assessments, reference books, and explanations of key concepts such as pseudocode and flowcharts. The course aims to enhance logical ability and the appropriate selection of data structures and algorithms for various applications.

Uploaded by

tuyisengeeric034
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views38 pages

Unit 1 (Into To The Data Structure and Algorithm)

The document outlines a course on Data Structures and Algorithms using C, detailing objectives, prerequisites, and course content divided into units covering algorithms, linear and non-linear data structures, sorting and searching algorithms. It includes assessments, reference books, and explanations of key concepts such as pseudocode and flowcharts. The course aims to enhance logical ability and the appropriate selection of data structures and algorithms for various applications.

Uploaded by

tuyisengeeric034
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 38

Course: Data Structure and Algorithm

With C

Lecturer: Shimirwa Aline Valerie


Email: [email protected]
Tel: 0784931189
Objectives and prerequisite
This course should enable you to :
 Demonstrate major algorithms and data structures.
 Choose the appropriate data structure and algorithm design method for a specified application.
 To improve the logical ability.
Prerequisite:
 You should be familiar with C language and concepts of mathematics.
Content
 UNIT 1(Introduction To Algorithms And Data Structures)
 Algorithms: Definition, Properties, Performance Analysis, Space Complexity, Time Complexity,
Asymptotic Notations. Data structures: Introduction, Data Structures types, DS Operations.
 UNIT 2(Linear Data Structures)
 Arrays, Stacks: Introduction, Stack Operations, Applications: Infix to Postfix Conversion, Evaluation
of Postfix Expression. Queues: Introduction, Operations on queues, Circular queues, Priority queues.
Linked lists: Introduction, Singly linked lists, Circular linked lists, Doubly linked lists, Multiply linked
lists, Applications: Polynomial Representation. Implementation of Stack and Queue using linked list.
 UNIT 3(Non-linear Data Structure)
 Trees: Basic terminology, Binary Trees, Binary Tree Representation, Graphs: Terminology, Sequential
and linked Representations of graphs, Graph Traversal : Depth First Search and Breadth First Search,
Spanning Trees, Spanning Trees: Prims and Kruskal algorithm
Content
 UNIT 4(Sorting and Searching Algorithm)
 Sorting: Introduction, Selection sort, Bubble sort, Insertion sort, Merge sort, Quick sort, Heap Sort.
Searching: Introduction, Linear search, Binary search, Hash table methods, Hashing Functions.
Books for Reference
1. Richard F. Gilberg& Behrouz A. Forouzan, Data Structures, Pseudo code Approach with C,
2ndEdition, Cengage Learning India Edition, 2007
2. Sartaj Sahni, Ellis Horowitz, Fundamentals of at Structures in C, 2nd Edition,
Orientblackswan, 2010.
3. Jean Paul Trembley and Paul G. Sorenson, “An Introduction to Data Structures with
applications”, McGraw Hill.
Assessments

 Quizzes +Assignments = 30%


 CAT = 30%
 Final Exam = 40%
1.1 Introduction to the Properties of algorithm
Algorithm Unambiguous : Algorithm should be clear and
unambiguous. Each of its steps (or phases), and
 An algorithm: is a Step By Step process to solve a their inputs/outputs should be clear and must lead
problem. Algorithm contains finite number of steps that to only one meaning.
leads to the solution of the problem. An algorithm can
be implemented in more than one programming
Input: An algorithm should have well- defined
language. inputs.
Categories of the algorithms Output: An algorithm should have 1 or more
well-defined outputs, and should match the desired
From the data structure point of view, following are some output.
important categories of algorithms :
Finiteness: Algorithms must terminate after a
 Search : Algorithm to search an item in a data structure.
finite number of steps.
 Sort: Algorithm to sort items in a certain order.
Feasibility: Should be feasible with the available
 Insert : Algorithm to insert item in a data structure. resources.
 Update: Algorithm to update an existing item in a data Independent: An algorithm should have step-by-
structure. step directions, which should be independent of
 Delete: Algorithm to delete an existing item from a data any programming code.
structure.
A variable is a location in the computer memory
which is given a specific name and can hold a
1.2 Variables and assignment single value at time.
 Before writing an algorithm for a problem, one When running an algorithm, we will need to
should find out what is/are the input(s) to the store data, or even results. For this, we use
algorithm and what is/are expected output(s) after variables. For each variable is given a name which
running the algorithm. must begin with a letter, but make contain digits or
an underscore.
 Now let us take some exercises to develop an
algorithm for some simple problems. While writing A variable can be compared to a box or a
algorithms we will use following symbol for container that is given a label and the box can hold
different operations: one content at a time.
Variables are given values either directly by the
user through input statements or by assignment
statements. Examples:
 i←0 is an assignment expression meaning “assign
the value 0 to variable i”.
 n←i means “assign the value equivalent to that in
variable i to variable n”.
 j←j+1 means “add 1 to the value in j”.
Pseudocode is a generic way of describing an
algorithm without use of any specific programming
1.3 Pseudocode language syntax.
 As its name suggests, pseudocode cannot be
 Pseudocode is a notation system for writing
executed on a real computer, but it models and
algorithms. The pseudocode notation specifies resembles real programming code, and is written at
operations that a machine can perform in as human- roughly the same level of detail.
friendly (e.g., easy to read) way as possible, while
avoiding ambiguity. Computer science textbooks often use pseudocode in
their examples so that all programmers can understand
 Pseudocode (which means fake code, because it is them, even if they do not all know the same
not really programming code) specifies the steps programming languages. Since.
required to accomplish the task. Pseudocode style varies from author to author, there
 Pseudocode is a type of structured English that is is usually an accompanying introduction explaining
used to specify an algorithm and it cannot be the syntax used.
compiled nor executed, and there are no real In the algorithm design, the steps of the algorithm are
formatting or syntax rules. written in free English text and, although brevity is
 Pseudocode is one of the tools that can be used to desired, they may be as long as needed to describe the
particular operation.
write a preliminary plan that can be developed into a
computer program. The steps of an algorithm are said to be written in
pseudocode.
For example, suppose you are required to design an algorithm
for finding the average of six numbers, and the sum of the
numbers is given. The pseudocode will be as follows:
1.3 Pseudocode cont…
 We write algorithms in a step-by-step manner. There
are different ways we can use while writing the
algorithms such as:
1.3.1 Sequence structure
Comments begin with // and go to the end of the line.
 The first way of writing algorithms is called the Comment statements are not executed by the computer. They
are only reminders to ourselves.
sequence structure. This structure is the most
elementary structure. The back arrow ← is used to assign a value to a variable. For
example: i←1. Such a statement is called an assignment
 The sequence structure is a case where the steps in statement. You should think of assignment as the movement of
data into the storage location named by the variable.
an algorithm are constructed in such a way that, no
condition step is required. Mathematical expressions are allowed on the right of an
assignment. For example: z←x*y+1
 The sequence structure is the logical equivalent of a We may read a value from an input device. For example, the
straight line. Each step is carried out in order of their statement: READ n will get a data value from the input device
position and is only done once. and store it in the variable n.
We may write a value to an output device. For example, the
 It always starts with ‘START’, then the steps are
statement: WRITE x will copy the value of x to the output
listed out and ends in ‘END’. device.
Binary selection pseudocode
1.3 Pseudocode cont…
1.3.2 Selection
 There are many occasions where a program is
required to take alternative actions. For example,
there are occasions where we need to take action
according to the user choice. All computer
languages provide a means of selection.
Here are all logical operators which can be
 It decides a particular answer from a set of variable used in the pseudocode:
answers and carries out the steps that proceeds it.
There are two types of selection control structures:
1.3.2.1 Binary selection
 Binary selection is where there are two possible
choices to choose. Usually it is in the form of “IF …
ELSE … ENDIF” statement and our pseudocode is
no exception to this.
 If the condition is met (true) then one path is taken,
otherwise (false) the other path is taken.
Case selection pseudocode
1.3 Pseudocode cont…
1.3.2.2 Case selection (also called multiple selection)
 Case selection is where there is more than one
possible choices to choose when trying to solve the
problem. Only one process can be carried out.
 Case selection uses “CASEWHERE ... ENDCASE”.
 The condition is checked and if the first choice is
true then it is carried out. If the first choice is false,
then the second will be checked. If it’s true then it is
carried out. If no choice is found to be true then the
“OTHERWISE” choice will be carried out.
Pre-test repetition pseudocode

1.3 Pseudocode cont…


 1.3.3 Repetition
 A sequence of steps which are repeated a number of
times is called repetition.
 For a repeating process to end, a decision must be 1.3.3.2 Post-test repetitions
made. The decision is usually called a test. The Post-test repetitions (sometimes called un-
position of this test divides repetition structures into guarded loops because no check is made before
two types: Pre-test and Post-test repetitions. the algorithm begins the loop structure) will
1.3.3.1 Pre-test repetitions perform the test after the main part of the loop (the
body) has been performed at least once. Post-test
 Pre-test repetitions (sometimes called guarded loops loops end when the condition is true but the loop
because the loop is only operated when the always do the loop at least once, even if the end
condition is met) will perform the test before any condition is originally true. Post-test loops uses
part of the loop occurs. “REPEAT … UNTIL”. Post-test repetition
pseudocode:
 If the condition is “False” the first time, the
processes will never carry out. Pre-test loops end
when the condition is “False”. Pre-test repetitions
uses “WHILE … ENDWHILE”.
1.3.4 Some examples of
Example2: algorithm for Converting
pseudocodes temperature Fahrenheit to Celsius.

Example 1: algorithm for finding the area of a circle


of radius r.
1.3.4 Some examples of
Example 4: algorithm for calculating the
pseudocodes cont.… average from 5 exam scores.

Example 3: Algorithm for finding the greater


number between two numbers.

Exercise: Create another algorithm for calculating the


product of three numbers.
You can see a flow chart as a blueprint of a
1.4 Flowchart design you have made for solving a problem. For
example suppose you are going for a picnic with
 The flowchart is a diagram which visually presents your friends then you plan for the activities you
the flow of data through processing systems. This will do there. If you have a plan of activities then
means by seeing a flow chart one can know the you know clearly when you will do what activity.
operations performed and the sequence of these
operations in a system. Similarly when you have a problem to solve
using computer or in other word you need to write
 Algorithms are nothing but sequence of steps for a computer program for a problem then it will be
solving problems. So a flow chart can be used for good to draw a flowchart prior to writing a
representing an algorithm. computer program. Flowchart is drawn according
 A flowchart, will describe the operations (and in to defined rules.
what sequence) are required to solve a given
problem.
1.4.1 Flowchart Symbols
 below are basic symbols commonly used in
flowcharting :
 Terminal,
 Process,
 Input/Output,
 Decision,
 Connector ,
 Flow lines
 Predefined Process.
 This is not a complete list of all the possible
flowcharting symbols, it is the ones used most often.
1.4.2 General rules for
flowcharting 6. Subroutines and Interrupt programs have their
own and independent flowcharts.
1. All boxes of the flowchart are connected with Arrows
(not lines). 7. All flow charts start with a Terminal or
Predefined Process (for interrupt programs or
2. Flowchart symbols have an entry point on the top of the subroutines) symbol.
symbol with no other entry points. The exit point for all
flowchart symbols is on the bottom except for the 8. All flowcharts end with a terminal or a
decision symbol. contentious loop.
3. The decision symbol has two exit points; these can be on
the sides or the bottom and one side.
4. Generally, a flowchart will flow from top to bottom.
However, an upward flow can be shown as long as it
does not exceed 3 symbols.
5. Connectors are used to connect breaks in the flowchart.
Examples are:
 From one page to another page.
 From the bottom of the page to the top of the
same page.
 An upward flow of more than 3 symbols.
1.4.3 Advantages and
disadvantages of flowchart 1.4.3.2 Disadvantages
1.4.3.1 Advantages Complex logic: Sometimes, the program logic is
quite complicated. In that case, flowchart
 Communication: flowcharts are better way of becomes complex and clumsy.
communicating the logic of a system to all concerned.
Alterations and Modifications: If alterations are
 Effective analysis: With the help of flow chart, problem
can be analyzed in more effective way. required the flow chart may require redrawing
completely.
 Proper documentation: Program flow charts serve as a
good program documentation, which is needed for various Reproduction: As the flow chart symbols cannot
purposes. be typed, reproduction of flow chart becomes a
problem.
 Efficient coding: The flow charts act as a guide or
blueprint during the systems analysis and program
development phase.
 Proper debugging: The flow chart helps in debugging
process.
 Efficient program Maintenance: The maintenance of
operating program becomes easy with the help of flow
chart. It helps the programmer to put efforts more
efficiently on that part.
1.4.4 Some examples of
flowcharts
Example 1: flowchart that shows the process of finding the
area of a circle of radius r.
1.4.4 Some examples of
flowcharts cont…
Example 2: flowchart that shows the process of Converting
temperature Fahrenheit to Celsius.
1.4.4 Some examples of
flowcharts cont…
Example 3: flowchart that shows the algorithm for finding the
greater number between two numbers.
1.5 Exercises
Exercise 1: Write algorithm and flowchart for swapping
contents of two variables.
Algorithm:
1. Start
2. Read value of A
3. Read value of B
4. C A
5. A B
6. B C
7. Print A
8. Print B
9. End
1.5 Exercises Exercise 2: Write an algorithm to find the
summation of numbers from 0 to 15.
Exercise 1: Write algorithm and flowchart for swapping
contents of two variables. Exercise 3: Write an algorithm to sum the odd
numbers between 10 and 200.
Algorithm:
1. Start
2. Read value of A
3. Read value of B
4. C A
5. A B
6. B C
7. Print A
8. Print B
9. End
1.6 Advantages and
disadvantages of Algorithms Algorithms can be designed as modular
components that can be reused across different
Algorithms offer several advantages in various fields and projects or parts of a program. This reusability
applications. Here are some of the key advantages of algorithms: saves time and effort by eliminating the need to
 Efficiency: Algorithms are designed to solve problems efficiently reinvent solutions for similar problems. By
by optimizing the use of computational resources. They help in encapsulating algorithms as functions or libraries,
reducing time and space complexities, making processes faster and programmers can leverage existing code, enhancing
more efficient. productivity and maintainability..
 Automation: Algorithms facilitate automation by providing step- Algorithms serve as a common language among
by-step instructions for performing specific tasks. They can programmers, facilitating collaboration and
automate repetitive and mundane processes, freeing up human
resources for more complex and creative work. communication. They provide a standard way to
express solutions to problems, making it easier for
 Optimization: Many algorithms focus on optimization problems, programmers to understand, discuss, and
aiming to find the best solution among a set of possible collaborate on code. Algorithms promote effective
alternatives. They can optimize resource allocation, scheduling,
logistics, and other operations, leading to cost reduction, improved communication, enabling programmers to exchange
efficiency, and better utilization of resources. ideas, share code, and work together towards a
common goal.
 Problem Solving: Algorithms are powerful tools for problem-
solving. They provide systematic approaches to address complex Overall, algorithms provide structured and
problems and guide the development of solutions. By breaking systematic approaches to problem-solving, enabling
down problems into smaller, manageable steps, algorithms enable efficiency, scalability, accuracy, automation,
effective problem-solving strategies.
optimization, and innovation across various
domains.
1.6 Advantages and Disadvantages of
Algorithms cont…. Lack of Flexibility: Once an algorithm is
implemented, modifying or adapting it to
1.6.2 Disadvantages accommodate new requirements or changing
constraints can be difficult. Certain algorithms
 Implementation Complexity: Implementing complex may lack the flexibility to easily incorporate new
algorithms can be challenging and time-consuming. features, handle different input formats, or adjust
Algorithms often require precise coding techniques, careful
handling of data structures, and thorough testing to ensure
to evolving business needs. Lack of flexibility
correctness. The complexity of implementation can can limit the adaptability and long-term viability
increase the chances of introducing bugs and errors, of an algorithm.
making maintenance and debugging more difficult.
 Algorithm Selection: Choosing the right algorithm for a
specific problem can be non-trivial. There are often
multiple algorithms available to solve a problem, each with
its own strengths, weaknesses, and trade-offs. Selecting an
inappropriate algorithm can result in suboptimal
performance, increased resource usage, or even incorrect
results. It requires careful analysis and understanding of
the problem domain to make informed algorithmic choices.
Performance analysis of an Time Complexity: is the amount of time
required for an algorithm to complete its
Algorithm execution. An algorithm is said to be efficient if it
takes the minimum (reasonable) amount of time
 Suppose X is an algorithm and n is the size of input to complete its execution.
data, the time and space used by the algorithm X are
the two main factors, which decide the efficiency of Space Complexity: is the amount of space
X. occupied by an algorithm. An algorithm is said to
 Time Factor: Time is measured by counting the be efficient if it occupies less space and required
number of key operations steps taken to perform a the minimum amount of time to complete its
task. For example number of comparisons in the execution.
sorting algorithm.
 Space Factor: Space is measured by counting the
maximum memory space required by the algorithm.
 The complexity of an algorithm X(n) gives the
running time and the storage space required by the
algorithm in terms of n as the size of input data.
Asymptotic Analysis Of An
Algorithm Usually, the time required by an algorithm falls
under three types:
 Asymptotic analysis refers to computing the running  Best Case: Minimum time required for
time of any operation in mathematical units of program execution.
computation.  Average Case: Average time required for
 “The running time to perform any operation depends on program execution.
the size of the input”. Let's understand this statement  Worst Case: Maximum time required for
through a simple example: Suppose we have an array of program execution.
five elements, and we want to add a new element at the
beginning of the array. To achieve this, we need to shift Using asymptotic analysis, we can very well
each element towards right, and suppose each element conclude the best case, average case, and worst
takes one unit of time. There are five elements, so five case scenario of an algorithm.
units of time would be taken. Suppose there are 1000
elements in an array, then it takes 1000 units of time to
shift. This example concludes that time complexity
depends upon the input size.
 If the input size is n, then f(n) is a function of n that
denotes the time complexity.
Asymptotic Notations what are the most operations/steps that could
happen for an input of size n? Following is a list of
 Following are the commonly used asymptotic notations some common asymptotic notations:
to calculate the running time complexity of an algorithm:  O(1) means that it takes a constant time to run
 Ο Notation an algorithm, regardless of the size of the
 Ω Notation input.
 θ Notation  O(n) means that the run time increases at the
same pace as the input.
Big Oh Notation, Ο  O(n²) means that the calculation runs in
 The notation Ο(n) is the formal way to express the upper quadratic time, which is the squared size of
bound of an algorithm’s running time. It measures the the input data.
worst case time complexity or the longest amount of time  O(log n) means that the running time grows
an algorithm can possibly take to complete. in proportion to the logarithm of the input
size, meaning that the run time barely
 “running time” when using Big-O notation does not
increases as you exponentially increase the
directly equate to time we know (e.g., seconds, input.
milliseconds, microseconds, etc.). Instead, we can think
of time as the number of operations or steps it takes to
complete a problem of size n. In other words, Big-O
notation is a way to track how quickly the runtime grows
relative to the size of the input.
Asymptotic Notations Theta Notation, θ

Omega Notation, Ω The notation θ(n) is the formal way to express both
the lower bound and the upper bound of an
The notation Ω(n) is the formal way to express the lower algorithm’s running time.
bound of an algorithm’s running time. It measures the best
case time complexity or the best amount of time an
algorithm can possibly take to complete.
Algorithm Design Techniques 3. Dynamic Programming: Dynamic Programming is a
 An algorithm is designed to achieve optimum solution for a given bottom-up approach. We solve all possible small problems
and then combine them to obtain solutions for bigger
problem. The following is a list of several popular algorithm design problems. Dynamic programing approach follows five
approaches: different steps to find the optimal solution for the
1. Divide and Conquer Approach: It is a top-down approach. The problem:
algorithms which follow the divide & conquer techniques involve  It breaks down the problem into a subproblem to
three steps: find the optimal solution.
 Divide the original problem into a set of subproblems.  After breaking down the problem, it finds the
 Solve every subproblem individually, recursively. optimal solution out of these subproblems.
 Combine the solution of the subproblems (top level)  Stores the result of the subproblems is known as
into a solution of the whole original problem. memorization.
 Reuse the result so that it cannot be recomputed for
2. Greedy Technique: Greedy method is used to solve the the same subproblems.
optimization problem. An optimization problem is one in which  Finally, it computes the result of the complex
we are given a set of input values, which are required either to be
maximized or minimized (known as objective), i.e. some program.
constraints or conditions.
 Greedy Algorithm always makes the choice (greedy
criteria) looks best at the moment, to optimize a given
objective.
 The greedy algorithm doesn't always guarantee the
optimal solution however it generally produces a solution
that is very close in value to the optimal.
Data Structure
 A data structure is a particular way of organizing data in a computer so that it can be used
effectively. The idea is to reduce the space and time complexities of different tasks.
 A data structure is not only used for organizing the data. It is also used for processing,
retrieving, and storing data. Some examples of Data Structures are arrays, Linked List, Stack,
Queue, trees, etc.
 Data Structures are the main part of many computer science algorithms as they enable the
programmers to handle the data in an efficient way. It plays a vital role in enhancing the
performance of a software or a program as the main function of the software is to store and
retrieve the user's data as fast as possible.
Need for Data Structures  Multiple requests: If thousands of users are
 As applications are getting complexed and amount of searching the data simultaneously on a web server,
then there are the chances that a very large server can
data is increasing day by day, there may rise the be failed during that process.
following problems:
 Processor speed: To handle very large amount of in order to solve the above problems, data
data, high speed processing is required, but as the structures are used. Data is organized to form a
data is growing day by day to the billions of files per data structure in such a way that all items are not
entity, processor may fail to deal with that much required to be searched and required data can be
amount of data. searched instantly.
 Data Search: Consider an inventory size of 106
items in a store, If our application needs to search
for a particular item, it needs to traverse 106 items
every time, this results in slowing down the search
process.
Advantages of data structures
 Efficiency: Efficiency of a program depends upon the choice of data structures. For example:
suppose, we have some data and we need to perform the search for a particular record. In that
case, if we organize our data in an array, we will have to search sequentially element by
element. hence, using array may not be very efficient here. There are better data structures
which can make the search process efficient like ordered array, binary search tree or hash
tables.
 Reusability: Data structures are reusable, i.e. once we have implemented a particular data
structure, we can use it at any other place. Implementation of data structures can be compiled
into libraries which can be used by users.
 Abstraction: Data structure is specified by the ADT which provides a level of abstraction. The
client of the program uses the data structure through interface only, without getting into the
implementation details.
Types of Data Structure
 Primitive Data structures are directly supported by the
language i.e.,.; any operation is directly performed in
these data items. Example: integer, Character, Real
numbers etc.
 Linear Data Structures: A data structure is called
linear if all of its elements are arranged in the linear
order. In linear data structures, the elements are stored in
non-hierarchical way where each element has the
successors and predecessors except the first and last
element. Example: Array, Linked list, stack, Queue, etc.
 Non Linear Data Structures: These data structures do
not form a sequence( i.e. each item or element is
connected with two or more other items in a non-linear
arrangement). The data elements are not arranged in
sequential structure. Example: Tree, Graph
Data Structure Operations
4) Searching: The process of finding the
1) Traversing: Every data structure contains the set of data location of an element within the data structure is
elements. Traversing the data structure means visiting each called Searching. There are two algorithms to
element of the data structure in order to perform some perform searching, Linear Search and Binary
specific operation like searching or sorting. Search. We will discuss each one of them later.
2) Insertion: Insertion can be defined as the process of 5) Sorting: The process of arranging the data
adding the elements to the data structure at any location. structure in a specific order is known as Sorting.
3) Deletion : The process of removing an element from the There are many algorithms that can be used to
data structure is called Deletion. We can delete an element perform sorting, for example, insertion sort,
from the data structure at any random location. If we try to selection sort, bubble sort, etc.
delete an element from an empty data structure 6) Merging: When two lists List A and List B of
then underflow occurs. size M and N respectively, of similar type of
elements, joined to produce the third list, List C
of size (M+N), then this process is called
merging
Memory Allocations in Data
Structures
C provides the following dynamic allocation
 Memory allocation is the process of setting aside
and de-allocation functions :
sections of memory to be used to store variables, and
instances of structures and classes. There are two types  malloc( )
of memory allocations possible in C:  calloc( )
1. Compile-time or Static allocation: memory is  free( )
allocated by the compiler. Exact size of memory must
be known at compile time.  realloc( )
2. Run-time or Dynamic allocation (using pointers):
Dynamic memory allocation is when an executing
program requests that the operating system give it a
block of main memory. The program then uses this
memory for some purpose.
Exercises
1. Write an algorithm to find the largest among three different numbers entered by user
2. Write an algorithm to find sum of elements in the array.
3. What is an algorithm?
4. What is data structure ?
5. List and define the types of data structures.

You might also like