Surprise Me!

Data structures: Array implementation of stacks

2017-10-19 2 Dailymotion

See completeon data structures here:\r<br>\r<br>\r<br>In this lesson, we have discussed array based implementation of stack data structure.\r<br>\r<br>Source Code:\r<br>C code: \r<br>\r<br>C++ code (Object oriented implementation) : \r<br>\r<br>Time complexity of push for dynamic array implementation:\r<br>\r<br>If we start with an array of size 1 and keep doubling the size with each overflow, for n pushes.. cost of copy will be\r<br>\r<br> (1 + 2 + 4 + 8 + . + n/2 + n) \r<br> = n *( 1+ 1/2 + 1/4 + 1/8 + . 1/n) - taking out n \r<br>= n*2 - the expression in bracket above will evaluate to 2. \r<br>\r<br>So, cost of copy in n pushes = O(n)\r<br>Cost of n normal pushes = O(n) - each push takes constant time\r<br>Total cost of n pushes = O(n)\r<br>Average cost of 1 push = O(1). \r<br>\r<br>\r<br>For price problems and more, visit: \r<br>\r<br>Like us on Facebook: \r<br>\r<br>Follow us on twitter:

Buy Now on CodeCanyon