SlideShare a Scribd company logo
1 of 69
Download to read offline
Linked List Vs Array
1. An array is the data structure that contains a collection
of similar type data elements whereas the Linked list is
considered as data structure contains a collection of
unordered linked elements known as nodes.
2. Accessing an element in an array is fast using Index,
Random access is not allowed in linked List. We have to
access elements sequentially starting from the first
node.
3. Operations like insertion and deletion in arrays
consume a lot of time. On the other hand, the
performance of these operations in Linked lists is fast.
5. Arrays are of fixed size. In contrast, Linked lists are
dynamic and flexible and can expand and contract its size.
6. In an array, memory is assigned during compile time while
in a Linked list it is allocated during execution or runtime.
memory utilization is inefficient in the array. Conversely,
memory utilization is efficient in the linked list.
7. Elements are stored consecutively in arrays whereas it is
stored randomly in Linked lists.
8. The requirement of memory is less due to actual data
being stored within the index in the array. As against, there is
a need for more memory in Linked Lists due to storage of
additional next and previous referencing elements.
• A linked list is represented by a pointer to the
first node of the linked list. The first node is
called head. If the linked list is empty, then
value of head is NULL.
• Each node in a list consists of at least two
parts:
1) data
2) Pointer (Or Reference) to the next node
In C language, a linked list can be
implemented using structure and pointers.
Declaring a Linked list :
// A linked list node
struct Node
{
int data;
struct Node *next;
};
• Each element in a linked list is stored in the form
of a node..
Types Of Linked Lists
1. Singly Linked List
2. Doubly Linked List
3. Circular Linked List
Self-referential Pointers
o/p: 5 10 15
• They are passed to main() function.
• They are parameters/arguments supplied to the
program when it is invoked.
• They are used to control program from outside
instead of hard coding those values inside the
code.
• Command-line arguments are given after the name
of the program in command-line shell of Operating
Systems.
• To pass command line arguments, we typically
define main() with two arguments : first argument
is the number of command line arguments and
second is list of command-line arguments.
• argc (ARGument Count) is int and stores number
of command-line arguments passed by the user
including the name of the program. So if we pass
a value to a program, value of argc would be 2
(one for program name and one for argument).
• The value of argc should be positive always.
• argv(ARGument Vector) is array of character
pointers listing all the arguments.
• argv[0] holds the name of the program , after
that till argv[argc-1] every element is command -
line arguments.
• argv[argc] is a NULL pointer.
Working with File
• fopen() is used to open a file.
• fopen() returns a pointer to structure FILE which
is a predefined structure in "stdio.h" header file.
• Opening a file means we bring the file contents
from disk to RAM to perform operations on it.
• If the file is successfully opened then fopen()
returns a pointer to the file and if it is unable to
open the file then it returns NULL.
• The file to be opened must be present in the
directory in which the executable file of this
program is present.
• fgetc() read a character from the file, and fputc()
write a character into the file.
File Opening Modes
Return
NULL
Return
NULL
• fclose() function closes the file.
Writing data in File
Append data in File
To copy content of one file into another
Reading and printing data
Reading and printing integer
o/p: This is C Programming Language
Dynamic memory Allocation
malloc()
calloc()
realloc()
free()
Stdlib.h
Memory
Allocation
Static Memory
Allocation
Dynamic
Memory
Allocation
Size must be defined
before loading and
executing the program
Memory is only
allocation at the time of
execution.
Dynamic memory allocation:
functions
• malloc():
– memory allocation
– create memory block of given size.
– By default value will be garbage value in allocated
block.
– Most application in allocating size for structures.
– E.g: malloc(4)
• calloc():
– calculated allocation
– used to allocate the continuous memory on element
by element by basis.
– It is useful to create array type structure.
– By default value will zero(0) in allocated block.
– E.g: calloc(3,2)
• realloc():
– re-allocation.
– used to increase/decrease the size of the block while
preserving the address and content of the beginning
of the block.
– E.g: realloc(ptr,4)
• free(): used to release (de-allocate)memory.
– Free(address of pointer which points to the allocated
block)
It will print M1 as it found its match at first place.
It will print hello as it doesn’t found its match.
Time Complexity
67
Asymptotic Notation
• O notation: Upper Bound:
– f(n)=O(g(n)) implies: f(n) “≤” c.g(n)
•  notation: Lower Bound:
– f(n)=  (g(n)) implies: f(n) “≥” c. g(n)
•  notation: Average Bound:
– f(n)=  (g(n)) implies: c1.g(n) ≤ f(n) ≤ c2.g(n)
68
Example
• Associate a "cost" with each statement.
• Find the "total cost“ by finding the total number of
times each statement is executed.
Algorithm 1 Algorithm 2
Cost Cost
arr[0] = 0; c1 for(i=0; i<N; i++) c2
arr[1] = 0; c1 arr[i] = 0; c1
arr[2] = 0; c1
... ...
arr[N-1] = 0; c1
----------- -------------
c1+c1+...+c1 = c1 x N (N+1) x c2 + N x c1 =
= O(N) = O(N)
69
Another Example
• Algorithm 3 Cost
sum = 0; c1
for(i=0; i<N; i++) c2
for(j=0; j<N; j++) c2
sum += arr[i][j]; c3
------------
c1 + c2 x (N+1) + c2 x (N )x (N+1) + c3 x N2
=O(N2)

More Related Content

What's hot

Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSwati Chauhan
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationAkhil Kaushik
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptxAkash Baruah
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++Kuntal Bhowmick
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lexAnusuya123
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction toolssunilchute1
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of CSuchit Patel
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programmingnmahi96
 
Compiler and symbol table
Compiler and symbol tableCompiler and symbol table
Compiler and symbol tableSunjid Hasan
 

What's hot (19)

Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Python Data Types
Python Data TypesPython Data Types
Python Data Types
 
Getting started with c++.pptx
Getting started with c++.pptxGetting started with c++.pptx
Getting started with c++.pptx
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++2 expressions (ppt-2) in C++
2 expressions (ppt-2) in C++
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Lexical analyzer generator lex
Lexical analyzer generator lexLexical analyzer generator lex
Lexical analyzer generator lex
 
Programming construction tools
Programming construction toolsProgramming construction tools
Programming construction tools
 
Cpu-fundamental of C
Cpu-fundamental of CCpu-fundamental of C
Cpu-fundamental of C
 
Arrays-Computer programming
Arrays-Computer programmingArrays-Computer programming
Arrays-Computer programming
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
Ch13
Ch13Ch13
Ch13
 
Lexical analysis-using-lex
Lexical analysis-using-lexLexical analysis-using-lex
Lexical analysis-using-lex
 
Compiler and symbol table
Compiler and symbol tableCompiler and symbol table
Compiler and symbol table
 

Similar to Linked List vs Array: Key Differences

Linked list basics
Linked list basicsLinked list basics
Linked list basicsRajesh Kumar
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environmentsJ'tong Atong
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfraji175286
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductionsirshad17
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1Amit Kapoor
 
Python programming
Python programmingPython programming
Python programmingsaroja20
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1DrSudeshna
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithmsNico Ludwig
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in CJabs6
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptxjack881
 
L1 - Recap.pdf
L1 - Recap.pdfL1 - Recap.pdf
L1 - Recap.pdfIfat Nix
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Techglyphs
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparationKushaal Singla
 

Similar to Linked List vs Array: Key Differences (20)

Data structure
 Data structure Data structure
Data structure
 
Linked list basics
Linked list basicsLinked list basics
Linked list basics
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Linked List
Linked ListLinked List
Linked List
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
What is c language
What is c languageWhat is c language
What is c language
 
linked list.pptx
linked list.pptxlinked list.pptx
linked list.pptx
 
Ch 1 intriductions
Ch 1 intriductionsCh 1 intriductions
Ch 1 intriductions
 
C interview question answer 1
C interview question answer 1C interview question answer 1
C interview question answer 1
 
Python programming
Python programmingPython programming
Python programming
 
Linked list (introduction) 1
Linked list (introduction) 1Linked list (introduction) 1
Linked list (introduction) 1
 
(2) collections algorithms
(2) collections algorithms(2) collections algorithms
(2) collections algorithms
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
UNIT 3a.pptx
UNIT 3a.pptxUNIT 3a.pptx
UNIT 3a.pptx
 
L1 - Recap.pdf
L1 - Recap.pdfL1 - Recap.pdf
L1 - Recap.pdf
 
Bt0067 c programming and data structures2
Bt0067 c programming and data structures2Bt0067 c programming and data structures2
Bt0067 c programming and data structures2
 
C interview-questions-techpreparation
C interview-questions-techpreparationC interview-questions-techpreparation
C interview-questions-techpreparation
 
linked_list.pptx
linked_list.pptxlinked_list.pptx
linked_list.pptx
 

More from SHIKHA GAUTAM

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionSHIKHA GAUTAM
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance SHIKHA GAUTAM
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in cSHIKHA GAUTAM
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computerSHIKHA GAUTAM
 
Generations of computer
Generations of computerGenerations of computer
Generations of computerSHIKHA GAUTAM
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and ImplementationSHIKHA GAUTAM
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and BasicsSHIKHA GAUTAM
 

More from SHIKHA GAUTAM (14)

Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock DetectionDistributed Mutual Exclusion and Distributed Deadlock Detection
Distributed Mutual Exclusion and Distributed Deadlock Detection
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
 
Unit ii_KCS201
Unit ii_KCS201Unit ii_KCS201
Unit ii_KCS201
 
Type conversion in c
Type conversion in cType conversion in c
Type conversion in c
 
4. algorithm
4. algorithm4. algorithm
4. algorithm
 
3. basic organization of a computer
3. basic organization of a computer3. basic organization of a computer
3. basic organization of a computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
c_programming
c_programmingc_programming
c_programming
 
Data Mining
Data MiningData Mining
Data Mining
 
Warehouse Planning and Implementation
Warehouse Planning and ImplementationWarehouse Planning and Implementation
Warehouse Planning and Implementation
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Dbms Introduction and Basics
Dbms Introduction and BasicsDbms Introduction and Basics
Dbms Introduction and Basics
 
DBMS
DBMSDBMS
DBMS
 

Recently uploaded

Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentBharaniDharan195623
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solidnamansinghjarodiya
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxachiever3003
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 

Recently uploaded (20)

Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solid
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Crystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptxCrystal Structure analysis and detailed information pptx
Crystal Structure analysis and detailed information pptx
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 

Linked List vs Array: Key Differences

  • 1.
  • 2.
  • 3.
  • 4. Linked List Vs Array 1. An array is the data structure that contains a collection of similar type data elements whereas the Linked list is considered as data structure contains a collection of unordered linked elements known as nodes. 2. Accessing an element in an array is fast using Index, Random access is not allowed in linked List. We have to access elements sequentially starting from the first node. 3. Operations like insertion and deletion in arrays consume a lot of time. On the other hand, the performance of these operations in Linked lists is fast.
  • 5. 5. Arrays are of fixed size. In contrast, Linked lists are dynamic and flexible and can expand and contract its size. 6. In an array, memory is assigned during compile time while in a Linked list it is allocated during execution or runtime. memory utilization is inefficient in the array. Conversely, memory utilization is efficient in the linked list. 7. Elements are stored consecutively in arrays whereas it is stored randomly in Linked lists. 8. The requirement of memory is less due to actual data being stored within the index in the array. As against, there is a need for more memory in Linked Lists due to storage of additional next and previous referencing elements.
  • 6. • A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value of head is NULL. • Each node in a list consists of at least two parts: 1) data 2) Pointer (Or Reference) to the next node In C language, a linked list can be implemented using structure and pointers.
  • 7. Declaring a Linked list : // A linked list node struct Node { int data; struct Node *next; }; • Each element in a linked list is stored in the form of a node..
  • 8. Types Of Linked Lists 1. Singly Linked List 2. Doubly Linked List 3. Circular Linked List
  • 10. o/p: 5 10 15
  • 11.
  • 12. • They are passed to main() function. • They are parameters/arguments supplied to the program when it is invoked. • They are used to control program from outside instead of hard coding those values inside the code. • Command-line arguments are given after the name of the program in command-line shell of Operating Systems. • To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
  • 13.
  • 14. • argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for program name and one for argument). • The value of argc should be positive always. • argv(ARGument Vector) is array of character pointers listing all the arguments. • argv[0] holds the name of the program , after that till argv[argc-1] every element is command - line arguments. • argv[argc] is a NULL pointer.
  • 15.
  • 16. Working with File • fopen() is used to open a file. • fopen() returns a pointer to structure FILE which is a predefined structure in "stdio.h" header file. • Opening a file means we bring the file contents from disk to RAM to perform operations on it.
  • 17. • If the file is successfully opened then fopen() returns a pointer to the file and if it is unable to open the file then it returns NULL. • The file to be opened must be present in the directory in which the executable file of this program is present. • fgetc() read a character from the file, and fputc() write a character into the file.
  • 18.
  • 20.
  • 21. • fclose() function closes the file.
  • 22.
  • 23.
  • 24.
  • 26.
  • 28. To copy content of one file into another
  • 29.
  • 32.
  • 33.
  • 34. o/p: This is C Programming Language
  • 35.
  • 37. Memory Allocation Static Memory Allocation Dynamic Memory Allocation Size must be defined before loading and executing the program Memory is only allocation at the time of execution.
  • 38. Dynamic memory allocation: functions • malloc(): – memory allocation – create memory block of given size. – By default value will be garbage value in allocated block. – Most application in allocating size for structures. – E.g: malloc(4)
  • 39.
  • 40. • calloc(): – calculated allocation – used to allocate the continuous memory on element by element by basis. – It is useful to create array type structure. – By default value will zero(0) in allocated block. – E.g: calloc(3,2)
  • 41. • realloc(): – re-allocation. – used to increase/decrease the size of the block while preserving the address and content of the beginning of the block. – E.g: realloc(ptr,4) • free(): used to release (de-allocate)memory. – Free(address of pointer which points to the allocated block)
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. It will print M1 as it found its match at first place.
  • 55. It will print hello as it doesn’t found its match.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. 67 Asymptotic Notation • O notation: Upper Bound: – f(n)=O(g(n)) implies: f(n) “≤” c.g(n) •  notation: Lower Bound: – f(n)=  (g(n)) implies: f(n) “≥” c. g(n) •  notation: Average Bound: – f(n)=  (g(n)) implies: c1.g(n) ≤ f(n) ≤ c2.g(n)
  • 68. 68 Example • Associate a "cost" with each statement. • Find the "total cost“ by finding the total number of times each statement is executed. Algorithm 1 Algorithm 2 Cost Cost arr[0] = 0; c1 for(i=0; i<N; i++) c2 arr[1] = 0; c1 arr[i] = 0; c1 arr[2] = 0; c1 ... ... arr[N-1] = 0; c1 ----------- ------------- c1+c1+...+c1 = c1 x N (N+1) x c2 + N x c1 = = O(N) = O(N)
  • 69. 69 Another Example • Algorithm 3 Cost sum = 0; c1 for(i=0; i<N; i++) c2 for(j=0; j<N; j++) c2 sum += arr[i][j]; c3 ------------ c1 + c2 x (N+1) + c2 x (N )x (N+1) + c3 x N2 =O(N2)