This is a presentation on Arrays, one of the most important topics on Data Structures and algorithms. Anyone who is new to DSA or wants to have a theoretical understanding of the same can refer to it :D
This is a presentation on Arrays, one of the most important topics on Data Structures and algorithms. Anyone who is new to DSA or wants to have a theoretical understanding of the same can refer to it :D
Queues
a. Concept and Definition
b. Queue as an ADT
c. Implementation of Insert and Delete operation of:
• Linear Queue
• Circular Queue
For More:
https://github.com/ashim888/dataStructureAndAlgorithm
http://www.ashimlamichhane.com.np/
Indexing is used to speed up access to desired data.
E.g. author catalog in library
A search key is an attribute or set of attributes used to look up records in a file. Unrelated to keys in the db schema.
An index file consists of records called index entries.
An index entry for key k may consist of
An actual data record (with search key value k)
A pair (k, rid) where rid is a pointer to the actual data record
A pair (k, bid) where bid is a pointer to a bucket of record pointers
Index files are typically much smaller than the original file if the actual data records are in a separate file.
If the index contains the data records, there is a single file with a special organization.
Searching and sorting
Types of Searching
1. Linear Searching
2. Binary Searching
Types of Sorting
1.Selection Sort
2. Insertion Sort
3.Bubble Sort
And the examples of Linear searching, Binary Searching
And also the examples of Selection sort, Insertion sort and Bubble sort and describing them in detail in this ppt
Queues
a. Concept and Definition
b. Queue as an ADT
c. Implementation of Insert and Delete operation of:
• Linear Queue
• Circular Queue
For More:
https://github.com/ashim888/dataStructureAndAlgorithm
http://www.ashimlamichhane.com.np/
Indexing is used to speed up access to desired data.
E.g. author catalog in library
A search key is an attribute or set of attributes used to look up records in a file. Unrelated to keys in the db schema.
An index file consists of records called index entries.
An index entry for key k may consist of
An actual data record (with search key value k)
A pair (k, rid) where rid is a pointer to the actual data record
A pair (k, bid) where bid is a pointer to a bucket of record pointers
Index files are typically much smaller than the original file if the actual data records are in a separate file.
If the index contains the data records, there is a single file with a special organization.
Searching and sorting
Types of Searching
1. Linear Searching
2. Binary Searching
Types of Sorting
1.Selection Sort
2. Insertion Sort
3.Bubble Sort
And the examples of Linear searching, Binary Searching
And also the examples of Selection sort, Insertion sort and Bubble sort and describing them in detail in this ppt
Feature selection is the process of selecting a subset of the terms occurring in the training set and using only this subset as features in text classification.
Wi-Fi stands for Wireless Fidelity. Fidelity: A faithful output.
Generally used to connect devices in wireless mode.
It is a term that refers to IEEE 802.11 communications
Li-Fi stands for Light Fidelity.
Uses light instead of radio waves.
Uses Visible part of electromagnetic spectrum.
Also known as Light based Wi-Fi.
Communication channels through which news entertainment, education, data, or promotional messages are delivered is known as media. Media includes every broadcasting and narrow-casting medium such as Newspaper, Magazines, Television, Radio, Billboards, Direct mail, Telephone, Fax and Internet.
AGILE TESTING is a testing practice that follows the rules and principles of agile software development. Unlike the Waterfall method, Agile Testing can begin at the start of the project with continuous integration between development and testing. Agile Testing is not sequential but continuous. Agile testing involves testing as early as possible in the software development life-cycle.
Ethical hacking also known as penetration testing or white-hat hacking, involves the same tools, tricks, and techniques that hackers use, but with one major difference that Ethical hacking is legal. It focuses on authorised attempts to gain unauthorised access to systems and find vulnerabilities. Ethical hacking is done with the legal permission of a company to test and increase the security of its systems and networks.
In software engineering and software architecture design, design decisions address architecturally significant requirements; they are perceived as hard to make and/or costly to change. It is called also architecture strategies and tactics.
An algorithm is a plan, a logical step-by-step process for solving a problem. Algorithms are normally written as a flowchart or in pseudo-code.
A flowchart is a diagram that represents a set of instructions. Flowcharts normally use standard symbols to represent the different types of instructions. These symbols are used to construct the flowchart and show the step-by-step solution to the problem.
Software Quality Assurance is a means and practice of monitoring the software engineering processes and methodologies used in a project to ensure proper quality of the software. Scrum is a framework utilising an agile mindset for developing, delivering, and sustaining products in a complex environment.
This presentation defines the asteroids and describes its role in our solar system and how to protect our earth from these space rocks in case of any mishap.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Strategies for Successful Data Migration Tools.pptxvarshanayak241
Data migration is a complex but essential task for organizations aiming to modernize their IT infrastructure and leverage new technologies. By understanding common challenges and implementing these strategies, businesses can achieve a successful migration with minimal disruption. Data Migration Tool like Ask On Data play a pivotal role in this journey, offering features that streamline the process, ensure data integrity, and maintain security. With the right approach and tools, organizations can turn the challenge of data migration into an opportunity for growth and innovation.
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
Data privacy is one of the most critical issues that businesses face. This presentation shares insights on the principles and best practices for ensuring the resilience and security of your workload.
Drawing on a real-life project from the HR industry, the various challenges will be demonstrated: data protection, self-healing, business continuity, security, and transparency of data processing. This systematized approach allowed to create a secure AWS cloud infrastructure that not only met strict compliance rules but also exceeded the client's expectations.
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
Your Digital Assistant.
Making complex approach simple. Straightforward process saves time. No more waiting to connect with people that matter to you. Safety first is not a cliché - Securely protect information in cloud storage to prevent any third party from accessing data.
Would you rather make your visitors feel burdened by making them wait? Or choose VizMan for a stress-free experience? VizMan is an automated visitor management system that works for any industries not limited to factories, societies, government institutes, and warehouses. A new age contactless way of logging information of visitors, employees, packages, and vehicles. VizMan is a digital logbook so it deters unnecessary use of paper or space since there is no requirement of bundles of registers that is left to collect dust in a corner of a room. Visitor’s essential details, helps in scheduling meetings for visitors and employees, and assists in supervising the attendance of the employees. With VizMan, visitors don’t need to wait for hours in long queues. VizMan handles visitors with the value they deserve because we know time is important to you.
Feasible Features
One Subscription, Four Modules – Admin, Employee, Receptionist, and Gatekeeper ensures confidentiality and prevents data from being manipulated
User Friendly – can be easily used on Android, iOS, and Web Interface
Multiple Accessibility – Log in through any device from any place at any time
One app for all industries – a Visitor Management System that works for any organisation.
Stress-free Sign-up
Visitor is registered and checked-in by the Receptionist
Host gets a notification, where they opt to Approve the meeting
Host notifies the Receptionist of the end of the meeting
Visitor is checked-out by the Receptionist
Host enters notes and remarks of the meeting
Customizable Components
Scheduling Meetings – Host can invite visitors for meetings and also approve, reject and reschedule meetings
Single/Bulk invites – Invitations can be sent individually to a visitor or collectively to many visitors
VIP Visitors – Additional security of data for VIP visitors to avoid misuse of information
Courier Management – Keeps a check on deliveries like commodities being delivered in and out of establishments
Alerts & Notifications – Get notified on SMS, email, and application
Parking Management – Manage availability of parking space
Individual log-in – Every user has their own log-in id
Visitor/Meeting Analytics – Evaluate notes and remarks of the meeting stored in the system
Visitor Management System is a secure and user friendly database manager that records, filters, tracks the visitors to your organization.
"Secure Your Premises with VizMan (VMS) – Get It Now"
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
Globus Connect Server Deep Dive - GlobusWorld 2024Globus
We explore the Globus Connect Server (GCS) architecture and experiment with advanced configuration options and use cases. This content is targeted at system administrators who are familiar with GCS and currently operate—or are planning to operate—broader deployments at their institution.
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
Worried about document security while sharing them in Salesforce? Fret no more! Here are the top-notch security standards XfilesPro upholds to ensure strong security for your Salesforce documents while sharing with internal or external people.
To learn more, read the blog: https://www.xfilespro.com/how-does-xfilespro-make-document-sharing-secure-and-seamless-in-salesforce/
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
top nidhi software solution freedownloadvrstrong314
This presentation emphasizes the importance of data security and legal compliance for Nidhi companies in India. It highlights how online Nidhi software solutions, like Vector Nidhi Software, offer advanced features tailored to these needs. Key aspects include encryption, access controls, and audit trails to ensure data security. The software complies with regulatory guidelines from the MCA and RBI and adheres to Nidhi Rules, 2014. With customizable, user-friendly interfaces and real-time features, these Nidhi software solutions enhance efficiency, support growth, and provide exceptional member services. The presentation concludes with contact information for further inquiries.
1. Data Structures and Alglorithms
Prepared by: Afaq Mansoor Khan
BSSE III- Group A
Session 2017-21
IMSciences, Peshawar.
2. Course Details
• Course Title: Data Structures
• Credit Hours: 3 + 1
• Course Objectives:
The course is designed to teach students
structures and schemes, which allow them to
write programs to efficiently manipulate,
store, and retrieve data.
3. Course Description
• In recent years the subject of computer programming
has been recognized as a discipline whose mastery is
fundamental and crucial to the success of many
engineering projects and which is close to scientific
treatment and presentation.
• It has advanced from a skill to an academic discipline
• it is abundantly clear that a systematic and scientific
approach to program construction primarily has a
bearing in the case of large, complex programs which
involve complicated sets of data.
• Hence, a methodology of programming is also bound to
include all aspects of data structuring.
4. Course Objectives
• To extend and deepen the student's knowledge and
understanding of algorithms and data structures
• To examine previously studied algorithms and data
structures more rigorously and introduce the
students to "new" algorithms and data structures.
• It focuses the student's attention on the design of
program structures that are correct, efficient in both
time and space utilization, and defined in terms of
appropriate abstractions.
5. Course Goals
• Upon completion of this course, a successful student will
be able to:
▫ Describe the strengths and limitations of linear data
structures, trees, graphs
▫ Select appropriate data structures for a specified problem
▫ Compare and contrast the basic data structures used in
Computer Science: lists, stacks, queues, trees and graphs
▫ Describe classic sorting techniques
▫ Recognize when and how to use the following data
structures: arrays, linked lists, stacks, queues and binary
trees.
▫ Identify and implement the basic operations for
manipulating each type of data structure
6. Course Goals
• Upon completion of this course, a successful student
will be able to:
▫ Perform sequential searching, binary searching and hashing
algorithms.
▫ Apply various sorting algorithms including bubble,
insertion, selection and quick sort.
▫ Understand recursion and be able to give examples of its
use
▫ Use dynamic data structures
7. Course Outline - I
• Introduction to data structures
• Linear and non-linear data structures
• Arrays and pointers
• List data structure
• Singly linked list
• Doubly linked list
• Circular linked list
• Stack; Implementation of stack using arrays and
linked list
• Applications of a stack
8. Course Outline - II
• Infix to postfix conversion
• Evaluation of postfix expressions
• Queues; Implementation of queues using arrays and
linked list
• Circular Queues; Priority Queues;
• Trees; Tree traversals; Binary search trees and
implementation
• Heaps and Heap sort;
• Graphs; Minimum spanning trees;
• Hashing
• Files
9. Recommended Books
Textbook:
• Robert L. Kruse, Alexander J. Ryba, Data Structures & Program Design in C++,
Prentice Hall, New Jersey, USA
Reference Books:
• Debasis Samanta, Classic Data Structures, 2nd Edition, Prentice Hall India,
2009
• ISRD Group, Data Structures Using C, Tata McGraw-Hill Publishing Company,
New Delhi, India, 2006.
10. Marks Distribution of Course
Assignments ……….……… 10%
Quizzes ..…………….. 10%
Midterm Exam .………….….. 30%
Final Exam .……………… 50%
11. Objectives Overview for this Lecture
• Introduction to Data Structures & Algorithms
• One Dimensional Arrays
• Two Dimensional Arrays
12. 12
What is it all about?
• Solving problems
▫ Get me from home to work
▫ Balance my checkbook
▫ Simulate a jet engine
▫ Graduate from SPU
• Using a computer to help solve problems
▫ Designing programs (architecture, algorithms)
▫ Writing programs
▫ Verifying programs
▫ Documenting programs
13. 13
Data Structures and Algorithms
• Algorithm
▫ Outline, the essence of a computational procedure,
step-by-step instructions
• Program – an implementation of an algorithm in
some programming language
• Data structure
▫ Organization of data needed to solve the problem
14. 14
Overall Picture
• This course is not about:
▫ Programming languages
▫ Computer architecture
▫ Software architecture
▫ Software design and implementation principles
Issues concerning small and large scale programming
• We will only touch upon the theory of complexity
and computability
15. What is Data Structures?
• Example:library
▫ is composed of elements
(books)
▫ Accessing a particular book
requires knowledge of the
arrangement of the books
▫ Users access books only
through the librarian
the logical arrangement of data
elements, combined with
the set of operations we need to access
the elements.
16. Basic Data Structures
• Structures include
▫ linked lists
▫ Stack, Queue
▫ binary trees
▫ …and others
17. What is Algorithm?
• Algorithm:
▫ A computable set of steps to achieve a desired result
▫ Ralationship to Data Structure
Example: Find an element
1 2 3 4 5 6 7
1
2
3
4
5
6
7
18. Introducing Arrays
Array is a data structure that represents a collection
of the same types of data.
myList[0]
myList[1]
myList[2]
myList[3]
myList[4]
myList[5]
myList[6]
myList[7]
myList[8]
myList[9]
double[] myList = new double[10];
myList reference
An Array of 10
Elements
of type double
20. Creating Arrays
arrayName = new datatype[arraySize];
Example:
myList = new double[10];
myList[0] references the first element in the array.
myList[9] references the last element in the array.
21. Declaring and Creating in One Step
• datatype[] arrayname = new
datatype[arraySize];
double[] myList = new double[10];
• datatype arrayname[] = new
datatype[arraySize];
double myList[] = new double[10];
22. The Length of Arrays
• Once an array is created, its size is fixed. It
cannot be changed. You can find its size using
arrayVariable.length
For example,
myList.length returns 10
23. Initializing Arrays
• Using a loop:
for (int i = 0; i < myList.length; i++)
myList[i] = i;
• Declaring, creating, initializing in one step:
double[] myList = {1.9, 2.9, 3.4, 3.5};
This shorthand syntax must be in one statement.
24. Declaring, creating, initializing Using the
Shorthand Notation
double[] myList = {1.9, 2.9, 3.4, 3.5};
This shorthand notation is equivalent to the following
statements:
double[] myList = new double[4];
myList[0] = 1.9;
myList[1] = 2.9;
myList[2] = 3.4;
myList[3] = 3.5;
25. CAUTION
Using the shorthand notation, you have to
declare, create, and initialize the array all in
one statement. Splitting it would cause a
syntax error. For example, the following is
wrong:
double[] myList;
myList = {1.9, 2.9, 3.4, 3.5};
26. Testing Arrays
• Objective: The program receives 6 numbers from
the keyboard, finds the largest number and
counts the occurrence of the largest number
entered from the keyboard.
Suppose you entered 3, 5, 2, 5, 5, and 5, the
largest number is 5 and its occurrence count is 4.
TestArray Run
27. Assigning Grades
• Objective: read student scores (int) from the
keyboard, get the best score, and then assign
grades based on the following scheme:
▫ Grade is A if score is >= best–10;
▫ Grade is B if score is >= best–20;
▫ Grade is C if score is >= best–30;
▫ Grade is D if score is >= best–40;
▫ Grade is F otherwise.
AssignGrade
Run
28. Passing Arrays as Arguments
• Objective: Demonstrate differences of
passing primitive data type variables
and array variables.
TestPassArray Run
30. Copying Arrays
In this example, you will see that a simple
assignment cannot copy arrays in the
following program. The program simply
creates two arrays and attempts to copy one
to the other, using an assignment statement.
TestCopyArray Run
35. Declaring, Creating, and Initializing Using Shorthand
Notations
You can also use a shorthand notation to declare, create and initialize a two-dimensional
array. For example,
int[][] array = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12}
};
This is equivalent to the following statements:
int[][] array = new int[4][3];
array[0][0] = 1; array[0][1] = 2; array[0][2] = 3;
array[1][0] = 4; array[1][1] = 5; array[1][2] = 6;
array[2][0] = 7; array[2][1] = 8; array[2][2] = 9;
array[3][0] = 10; array[3][1] = 11; array[3][2] = 12;
37. Definition – Pointer
• A value indicating the number of (the first byte of)
a data object
▫ Also called an Address or a Location
• Used in machine language to identify which data
to access
E.g., stack pointer is address of most recent entry of The Stack
• Usually 2, 4, or 8 bytes, depending upon machine
architecture
∙∙∙
2n-10 1 2 3 4 5 6 7 8 9 10 11
11
39. Declaring Pointers in C
• int *p; — a pointer to an int
• double *q; — a pointer to a double
• char **r; — a pointer to a pointer to a
char
• type *s; — a pointer to an object of
type type
E.g, a struct, union, function, something defined by a typedef, etc.
40. Declaring Pointers in C (continued)
• Pointer declarations:–read from right to left
• const int *p;
p is a pointer to an integer constant
I.e., pointer can change, thing it points to cannot
• int * const q;
q is a constant pointer to an integer variable
I.e., pointer cannot change, thing it points to can!
• const int * const r;
r is a constant pointer to an integer constant
41. Pointer Operations in C
• Creation
& variable Returns variable’s memory address
• Dereference
* pointer Returns contents stored at address
• Indirect assignment
• pointer = val Stores value at address
• Of course, still have...
• Assignment
pointer = ptr Stores pointer in another variable
42. Using Pointers
int i1;
int i2;
int *ptr1;
int *ptr2;
i1 = 1;
i2 = 2;
ptr1 = &i1;
ptr2 = ptr1;
*ptr1 = 3;
i2 = *ptr2;
i1:
i2:
ptr1:
0x1000
0x1004
0x1008
…
ptr2:
…
0x100C
0x1010
0x1014
1
2
0x1000
0x1000
3
3
43. Pointer Arithmetic
• int *p, *q;
q = p + 1;
▫ Construct a pointer to the next integer after *p and
assign it to q
• double *p, *r;
int n;
r = p + n;
▫ Construct a pointer to a double that is n doubles beyond
*p, and assign it to r
▫ n may be negative
44. Pointer Arithmetic (continued)
• long int *p, *q;
p++; q--;
▫ Increment p to point to the next long int; decrement q to
point to the previous long int
• float *p, *q;
int n;
n = p – q;
▫ n is the number of floats between *p and *q; i.e., what
would be added to q to get p
45. Pointer Arithmetic
pointer + number pointer – number
E.g., pointer + 1 adds 1 something to a pointer
char *p;
char a;
char b;
p = &a;
p += 1;
int *p;
int a;
int b;
p = &a;
p += 1;In each, p now points to b
(Assuming compiler doesn’t
reorder variables in memory)
Adds 1*sizeof(char) to
the memory address
Adds 1*sizeof(int) to
the memory address
Pointer arithmetic should be used cautiously
47. Arrays and Pointers
• Arrays and pointers are closely related in C
▫ In fact, they are essentially the same thing!
▫ Esp. when used as parameters of functions
• int A[10];
int *p;
▫ Type of A is int *
▫ p = A; and A = p; are legal assignments
▫ *p refers to A[0]
*(p + n) refers to A[n]
▫ p = &A[5]; is the same as p = A + 5;
48. Arrays and Pointers (continued)
• double A[10]; vs. double *A;
• Only difference:–
▫ double A[10] sets aside ten units of memory, each large
enough to hold a double
▫ double *A sets aside one pointer-sized unit of memory
You are expected to come up with the memory elsewhere!
▫ Note:– all pointer variables are the same size in any given
machine architecture
Regardless of what types they point to
49. Note
• C does not assign arrays to each other
• E.g,
▫ double A[10];
double B[10];
A = B;
assigns the pointer value B to the pointer value A
Contents of array A are untouched
50. Arrays as Function Parameters
• void init(float A[], int arraySize);
void init(float *A, int arraySize);
• Are identical function prototypes!
• Pointer is passed by value
• I.e. caller copies the value of a pointer to float into the
parameter A
• Called function can reference through that pointer to
reach thing pointed to
51. Arrays as Function Parameters (continued)
• void init(float A[], int arraySize){
int n;
for(n = 0; n < arraySize; n++)
A[n] = (float)n;
} //init
• Assigns values to the array A in place
▫ So that caller can see the changes!
52. Examples
while ((rc = scanf("%lf", &array[count])) !=EOF && rc==0)
…
double getLargest(const double A[], const int sizeA) {
double d;
if (sizeA > 0) {
d = getLargest(&A[1], sizeA-1);
return (d > A[0]) ? d : A[0];
} else
return A[0];
} // getLargest
53. Result
• Even though all arguments are passed by value to
functions …
• … pointers allow functions to assign back to data of
caller
• Arrays are pointers passed by value
54. Safety Note
• When passing arrays to functions, always specify const
if you don’t want function changing the value of any
elements
• Reason:– you don’t know whether your function would
pass array to another before returning to you
Exception – many software packages don’t specify const in
their own headers, so you can’t either!
55. Summary
• Introduction to Data Structures & Algorithms
• One Dimensional Arrays:
• Multi Dimensional Arrays:
▫ Declaration
▫ Initialization
▫ Representation
▫ Operations
▫ Arrays and functions
• Pointers
▫ Declaration, Initialization
▫ Arrays and pointers