This site works best with JavaScript enabled
Sign In
Discussions
Activity
Sign In
All
001 C Programming, Data Structures
Issues, queries and suggestions related to C, C programming, data structures using C and C based projects.
001 C Programming, Data Structures
Binary Search
spatlou
May 2020
niranjan
May 2020
output:
ani@ani-VirtualBox:~/share_data/project/P01_C_project/s06_array$ ls
arryPointer binarySearch.o creatArray.o displayArray.o exitFunc.o linearSearch.c main.c mainMenu.o Makefile
binarySearch.c creatArray.c displayArray.c exitFunc.c header.h linearSearch.o mainMenu.c main.o prototype.h
ani@ani-VirtualBox:~/share_data/project/P01_C_project/s06_array$ ./arryPointer
main 13: Start program
main 14:
Address of auto/stack :: choice=0xbfdaafd4 pos=0xbfdaafd8 arr=0xb7778000
mainMenu 12: Begin ..
mainMenu 13: 0 -> Exit the Program.
mainMenu 14: 1 -> Create Array.
mainMenu 15: 2 -> Linear Search In Array.
mainMenu 16: 3-> Dispaly Array.
mainMenu 17: 4 -> Binary Serch In Sorted Array.
mainMenu 18: Enter the choice Menu
1
mainMenu 20: choice 1 END ...
creatArray 13: Begin
creatArray 14:
Address of local *carr Pointer=0x1
before Memory Allocation using malloc
creatArray 21: Enter Element 10 times!! After Memory allocation
*carr Pointer address=0x9f72008
10
20
30
40
50
60
70
80
90
100
creatArray 28: array pointer address=0x9f72008 END ....
mainMenu 12: Begin ..
mainMenu 13: 0 -> Exit the Program.
mainMenu 14: 1 -> Create Array.
mainMenu 15: 2 -> Linear Search In Array.
mainMenu 16: 3-> Dispaly Array.
mainMenu 17: 4 -> Binary Serch In Sorted Array.
mainMenu 18: Enter the choice Menu
4
mainMenu 20: choice 4 END ...
binarySearch 14: Begin ..
binarySearch 15: Address of low=0xbfdaaf90 key =0xbfdaaf98 ->high =0xbfdaaf94
binarySearch 16: Enter element to search in sorted Array ..
70
binarySearch 21: low =0 high=9 mid =0 key =70
binarySearch 52: low =5 high=9 mid =4 key =70
binarySearch 52: low =5 high=6 mid =7 key =70
70 Element Found!! in Arry -->arr[6]
mainMenu 12: Begin ..
mainMenu 13: 0 -> Exit the Program.
mainMenu 14: 1 -> Create Array.
mainMenu 15: 2 -> Linear Search In Array.
mainMenu 16: 3-> Dispaly Array.
mainMenu 17: 4 -> Binary Serch In Sorted Array.
mainMenu 18: Enter the choice Menu
4
mainMenu 20: choice 4 END ...
binarySearch 14: Begin ..
binarySearch 15: Address of low=0xbfdaaf90 key =0xbfdaaf98 ->high =0xbfdaaf94
binarySearch 16: Enter element to search in sorted Array ..
65
binarySearch 21: low =0 high=9 mid =0 key =65
binarySearch 52: low =5 high=9 mid =4 key =65
binarySearch 52: low =5 high=6 mid =7 key =65
binarySearch 52: low =6 high=6 mid =5 key =65
65 Element not found!! In Arry Pointer
binarySearch 57: END ..
mainMenu 12: Begin ..
mainMenu 13: 0 -> Exit the Program.
mainMenu 14: 1 -> Create Array.
mainMenu 15: 2 -> Linear Search In Array.
mainMenu 16: 3-> Dispaly Array.
mainMenu 17: 4 -> Binary Serch In Sorted Array.
mainMenu 18: Enter the choice Menu
Query:
1. I try to Memory map of above program. But Not very clear picture memory map regarding pointer address & use in local pointer
2.In above output, print auto variable, pointer. How to define stack/ heap decleation?
3.In our system, how to define stack size, heap, data & code segment area ? or some default configuration
4. After compile code generate either in elf / bin / hex format , But last this store in HDD/ flash location.
when run program, which resource to handle to load flash/HDD to memory area?
How to handle stack, code & data segment area in memory?
niranjan
May 2020
code of binary search :
if((*(arr+low) <= key) && (*(arr +high) >= key))
{
do
{
if(arr[low] == key)
{
printf("%d Element Found!! in Arry -->arr[%d]\n",key,low);
return low;
}else if(arr[high] == key)
{
printf("%d Element Found!! in Arry -->arr[%d]\n",key,high);
return high;
}else
{
mid = (low + high)/2;
if(arr[mid] == key)
{
printf("%d Element Found!! in Arry -->arr[%d]\n",key,mid);
return mid;
}else if(arr[mid] > key)
{
high = mid -1;
}else
{
low = mid +1;
}
}
printf("%s %d: low =%d high=%d mid =%d key =%d \n", __func__,__LINE__,low ,high, mid ,key);
}while(low < high);
}
printf("%d Element not found!! In Arry Pointer\n",key);
Add a Comment
Powered by
Vanilla
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
0
000 Linux System Administration
24
001 C Programming, Data Structures
79
» 001.01.Introduction to C
1
002 OOPs using C++ with Eclipse on Linux
22
003 Linux System Programming
39
004 Linux Network Programming
9
005 Character Device Drivers Development
21
006.Project Evolution with GitLab
2
» 01.Introduction To GitLab
1
008 Block Device Driver Development
4
» 008.01.Introduction to Block Device Drivers
1
009 Embedded Linux-ARM. Storage
39
» 009.01.Linux Boot Process
27
» 009.01.14.Linux-Boot-Process
5
» 009.01.15.Introduction to BIOS
0
» 009.01.16.Introduction-to-BIOS-IQs
5
» 009.01.18.Introduction-to-BIOS-IQs
5
» 009.01.20.BIOS CMOS UEFI. IQs
5
» 009.02.Introduction To Embedded Linux
1
» 009.03.01.ARM Processor Architecture
1
» 009.03.02.Programmers Model
1
» 009.04.Boot Loaders
1
» 009.08.Board Bringup. Raspberry Pi4
1
010 Embedded Linux ARM, Configuring and Porting using Storage
0
011 Shell Scripting using Bash
7
» 011.12.File Operations and Commands
1
012 Linux Kernel Architecture and Internals
3
014. Linux Network Administration
270
» 014.01.Intro to NW and Configurations
220
» 014.01.12.Introduction to Networking
10
» 014.01.14.Packets-IQs
10
» 014.01.16.NetworkLayers
10
» 014.01.18.The Internet Layer
20
» 014.01.20.routes and the kernel routing table
10
» 014.01.22.The Default Gateway
5
» 014.01.24.IPv6 Addresses And Networks
20
» 014.01.26.Basic ICMP And DNS Tools
10
» 014.01.28.The Physical Layer And Ethernet
5
» 014.01.30.Understanding Linux Network Interface
5
» 014.01.32.Intro To Network Interface Configuration
5
» 014.01.34.Boot Activated Network Configuration
5
» 014.01.36.Manual and Boot Activated Nw Config
5
» 014.01.38.Network Configuration Managers
10
» 014.01.40.Resolving Hostnames
19
» 014.01.42.The Transport Layer TCP UDP Services.
10
» 014.01.44.Understanding DHCP
5
» 014.01.46.Automatic IPv6 Network Configuration. IQs
5
» 014.01.48.Configuring Linux as Router
5
» 014.01.50.Private Networks IPv4
5
» 014.01.52.Network Address Translation. IP Masquerading
5
» 014.01.54.Routers And Linux
5
» 014.01.56.Linux Firewall Basics
5
» 014.01.58.Setting Firewall Rules
5
» 014.01.60.Firewall Strategies
10
» 014.01.62.Ethernet-IP-ARP-NDP-IQs
5
» 014.01.64.Wireless Ethernet
5
» 014.02.Network Applications and Services
11
» 014.02.12.Basics of Services
3
» 014.02.14.Introduction to Network Servers
2
» 014.02.16.Network Servers. Secure Shell
5
» 014.06.Network Protocol Telnet
38
» 014.06.12.Introduction-To-Telnet
3
» 014.06.14.General Working. Telnet
5
» 014.06.16.General-Working-Telnet
5
» 014.06.18.Network Virtual Terminal
3
» 014.06.20.More About Telnet
3
» 014.06.22.Installing Telnet on Fedora
5
» 014.06.24.Telnet Commands-Fedora
3
» 014.06.26.Using Telnet in Linux
5
» 014.06.28.Secure telnet with FirewallD. Fedora.
3
» 014.06.30.Using Telnet in Linux
2
015 Python with Eclipse on Linux
27
101 Advanced Data Structures using C
18
105 Parallel Port Device Drivers Development
5
205 Serial Port Device Drivers Development
3
303 Linux System Programming
32
Project 22. Ethernet Network Device Driver Development
0
Query
556
Project.203 Linux System Programming. MySQL
0
Pravjot Sir Classes
161
Events at EmbLogic
2
Project 16: SPI Device Driver Development
2
Project 17: I2C Device Driver Development
0
Project 18: PCI Device Driver Development
0
Project 19: Embedded Linux on ARM Using Network TFTP
0
Project 20: CAN Bus Protocol and Driver Development
0
Project 21: USB Device Drivers Development
0
Embedded Linux
0
ARM Embedded Processor
0
Training
2
Members Area
1
Word From Admin
1