Presentation is loading. Please wait.

Presentation is loading. Please wait.

Growing Arrays in C Varoon Wadhwa.

Similar presentations


Presentation on theme: "Growing Arrays in C Varoon Wadhwa."— Presentation transcript:

1 Growing Arrays in C Varoon Wadhwa

2 Arrays An array is basically a variable that contains a list
Arrays are one of the simplest data structures in C They have many uses and a broad range of tools associated with them

3 What are Growing Arrays?
Growing Arrays are arrays that are constantly having new sorted values added to them They are used in situations where we need to keep track of a variable Often overshadowed by hash tables due to the amount of resources needed for large arrays

4 Comparisons to C++/Java
In C++ or Java, Growing Arrays would be replaced by classes from standard libraries In C, these Growing Arrays are constructed using a struct struct { char cname[8]; char sname[16]; char exam[16]; char grade; } record;

5 Struct A struct is used to declare a new data type
This basically means grouping variables together Similar to enum in C++

6 Why Grow Arrays? Growing arrays is usually a resource hungry operation
Used when elements added (n) is relatively small Very convenient data structure Fixed size data sets, arrays ideal

7 Why not use Growing Arrays?
Changing set of values in arrays can be expensive Number of elements unpredictable Number of elements potentially large n

8 Benefits of Growing Arrays
Arrays are simplest way to group data Most languages have efficient and convenient tools for arrays Arrays work well with sorting algorithms Provide easy access to any item

9 Drawbacks of Growing Arrays
Cannot handle large amounts of data change Requires resorting of entire array upon deletion of elements Elements can sometimes be overwritten by fast “squeezing” algorithms Must decide on correctness or speed

10 Deleting an element Deleting a element in an array is tricky
Deleting the element results in a gap in the array Easiest solution is to swap last element into the gap More complicated if order matters

11 Questions???


Download ppt "Growing Arrays in C Varoon Wadhwa."

Similar presentations


Ads by Google